10 #include <unordered_map>
13 #include "Architecture.hpp"
20 using MemoryView = std::span<u8*>;
27 constexpr std::string_view Lower =
"abcdefghijklmnopqrstuvwxyz";
28 constexpr std::string_view Upper =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
29 constexpr std::string_view UpperLower =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
30 constexpr std::string_view Digits =
"0123456789";
31 constexpr std::string_view Alphanumeric =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
32 constexpr std::string_view AllPrintable =
33 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$ % &'()*+,-./:;<=>?@[\\]^_`{|}~ ";
34 constexpr std::string_view Basic64Characters =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/+";
36 constexpr std::wstring_view WideLower = L
"abcdefghijklmnopqrstuvwxyz";
37 constexpr std::wstring_view WideUpper = L
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
38 constexpr std::wstring_view WideUpperLower = L
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
39 constexpr std::wstring_view WideDigits = L
"0123456789";
40 constexpr std::wstring_view WideAlphanumeric = L
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
41 constexpr std::wstring_view WideAllPrintable =
42 L
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$ % &'()*+,-./:;<=>?@[\\]^_`{|}~ ";
54 template<
typename ToType,
typename FromType,
typename T =
char>
56 To(FromType
const& src)
62 std::back_inserter(dst),
65 return static_cast<T>(c);
71 To(std::wstring
const& src);
73 template<
typename T,
typename L>
75 Split(T
const& src,
const L delim)
82 [&dst, &cur, &delim](
const L& x)
104 template<
typename T,
typename L>
106 Join(
const std::vector<T>& Src,
const L delim)
112 [&Dst, &delim](
const T& x)
114 Dst += x + T {delim};
123 template<
typename T,
typename L>
125 Strip(T
const& Src,
const L c)
145 Seed(std::optional<u64> seed = std::nullopt);
165 Next(u64
const max, u64
const min) noexcept -> u64;
212 String(u32 length, std::string_view
const& charset = Utils::StringLib::Charset::AllPrintable) -> std::string;
219 WideString(u32 length, std::wstring_view
const& charset = Utils::StringLib::Charset::WideAllPrintable) -> std::wstring;
226 AlnumWideString(u32 length) -> std::wstring;
233 Buffer(u32 length) -> std::vector<u8>;
252 Encode(
const u8* buffer,
const usize buffer_length) -> Result<std::string>;
262 Encode(std::vector<u8>
const& bytes) -> Result<std::string>;
272 Decode(std::string_view
const& encoded_string) -> Result<std::vector<u8>>;
286 static std::vector<u8>
287 p64(u64 v, Endianess e = Endianess::unknown);
297 static std::vector<u8>
298 p32(u32 v, Endianess e = Endianess::unknown);
308 static std::vector<u8>
309 p16(u16 v, Endianess e = Endianess::unknown);
319 static std::vector<u8>
320 p8(u8 v, Endianess e = Endianess::unknown);
332 template<Flattenable T, Flattenable... Args>
333 static std::vector<u8>
338 if constexpr ( std::is_same_v<T, std::string> )
340 std::vector<u8> s = StringLib::To<std::vector<u8>>(std::string(arg));
341 out.insert(out.end(), s.begin(), s.end());
344 if constexpr ( std::is_same_v<T, std::wstring> )
346 std::vector<u8> s = StringLib::To<std::vector<u8>>(std::wstring(arg));
347 out.insert(out.end(), s.begin(), s.end());
350 if constexpr ( std::is_same_v<T, std::vector<u8>> )
352 out.insert(out.end(), arg.begin(), arg.end());
355 if constexpr (
sizeof...(args) > 0 )
357 auto rec = Flatten(args...);
358 out.insert(out.end(), rec.begin(), rec.end());
374 align(uptr a, u32 sz);
385 cyclic(u32 Size, u32 Period = 0) -> Result<std::vector<u8>>;
395 Hexdump(
const u8* Buffer,
const usize BufferSize);
402 Hexdump(std::vector<u8>
const& bytes);
409 Hexdump(Utils::MemoryView
const& view);
418 template<
class Rep,
class Period>
420 Sleep(
const std::chrono::duration<Rep, Period>& sleep_duration)
422 std::this_thread::sleep_for(sleep_duration);
449 Result<std::unordered_map<u16, bool>>
450 GetExecutableCharacteristics(std::filesystem::path
const& FilePath);
464 GetExecutableSignature(std::filesystem::path
const& FilePath);
Definition: Utils.hpp:242
static auto Decode(std::string_view const &encoded_string) -> Result< std::vector< u8 >>
Decode a base64 string.
static auto Encode(std::vector< u8 > const &bytes) -> Result< std::string >
Encode a vector of bytes to base64.
static auto Encode(const u8 *buffer, const usize buffer_length) -> Result< std::string >
Encode a buffer of a given size to base64.
Definition: Utils.hpp:277
static std::vector< u8 > Flatten(T arg, Args... args)
P.
Definition: Utils.hpp:334
static std::vector< u8 > p8(u8 v, Endianess e=Endianess::unknown)
Pack a 1-byte to a byte vector.
static std::vector< u8 > p16(u16 v, Endianess e=Endianess::unknown)
Pack a 2-byte to a byte vector.
static std::vector< u8 > p32(u32 v, Endianess e=Endianess::unknown)
Pack a 3-byte to a byte vector.
static std::vector< u8 > p64(u64 v, Endianess e=Endianess::unknown)
Pack a 8-byte to a byte vector.