diff options
| author | auth12 <[email protected]> | 2020-07-21 13:07:42 -0700 |
|---|---|---|
| committer | auth12 <[email protected]> | 2020-07-21 13:07:42 -0700 |
| commit | f09669dd5846d95b063712571ccb7519910a0d6e (patch) | |
| tree | 902f5ad201651f2d96ccf619e90b76cfa06a7b9b /client/src/util | |
| parent | Syscalls. (diff) | |
| download | loader-f09669dd5846d95b063712571ccb7519910a0d6e.tar.xz loader-f09669dd5846d95b063712571ccb7519910a0d6e.zip | |
Added game selection.
Started process wrapper.
Removed asmjit.
Diffstat (limited to 'client/src/util')
| -rw-r--r-- | client/src/util/events.h | 28 | ||||
| -rw-r--r-- | client/src/util/io.cpp | 8 | ||||
| -rw-r--r-- | client/src/util/io.h | 4 | ||||
| -rw-r--r-- | client/src/util/native.h | 6 | ||||
| -rw-r--r-- | client/src/util/pe.h | 74 | ||||
| -rw-r--r-- | client/src/util/syscalls.cpp | 8 | ||||
| -rw-r--r-- | client/src/util/syscalls.h | 10 | ||||
| -rw-r--r-- | client/src/util/util.cpp | 54 | ||||
| -rw-r--r-- | client/src/util/util.h | 22 |
9 files changed, 110 insertions, 104 deletions
diff --git a/client/src/util/events.h b/client/src/util/events.h index b8d7781..67c4b1f 100644 --- a/client/src/util/events.h +++ b/client/src/util/events.h @@ -2,23 +2,23 @@ template <typename... Args> class event { - using func_type = std::function<void(Args...)>; + using func_type = std::function<void(Args...)>; - std::mutex event_lock; - std::list<func_type> m_funcs; + std::mutex event_lock; + std::list<func_type> m_funcs; - public: - void add(const func_type& func) { - std::lock_guard<std::mutex> lock(event_lock); +public: + void add(const func_type& func) { + std::lock_guard<std::mutex> lock(event_lock); - m_funcs.push_back(std::move(func)); - } + m_funcs.push_back(std::move(func)); + } - void call(Args... params) { - std::lock_guard<std::mutex> lock(event_lock); + void call(Args... params) { + std::lock_guard<std::mutex> lock(event_lock); - for (auto& func : m_funcs) { - if (func) func(std::forward<Args>(params)...); - } - } + for (auto& func : m_funcs) { + if (func) func(std::forward<Args>(params)...); + } + } };
\ No newline at end of file diff --git a/client/src/util/io.cpp b/client/src/util/io.cpp index 06d2b9a..019ec3f 100644 --- a/client/src/util/io.cpp +++ b/client/src/util/io.cpp @@ -4,9 +4,9 @@ std::shared_ptr<spdlog::logger> io::logger; void io::init() { - spdlog::sink_ptr sink = - std::make_shared<spdlog::sinks::stdout_color_sink_mt>(); - sink->set_pattern("%^~>%$ %v"); + spdlog::sink_ptr sink = + std::make_shared<spdlog::sinks::stdout_color_sink_mt>(); + sink->set_pattern("%^~>%$ %v"); - logger = std::make_shared<spdlog::logger>("client", sink); + logger = std::make_shared<spdlog::logger>("client", sink); } diff --git a/client/src/util/io.h b/client/src/util/io.h index b1a09f9..a69940e 100644 --- a/client/src/util/io.h +++ b/client/src/util/io.h @@ -5,7 +5,7 @@ #include <spdlog/sinks/stdout_color_sinks.h> namespace io { -extern std::shared_ptr<spdlog::logger> logger; + extern std::shared_ptr<spdlog::logger> logger; -void init(); + void init(); }; // namespace io diff --git a/client/src/util/native.h b/client/src/util/native.h index 623e577..bb80bd1 100644 --- a/client/src/util/native.h +++ b/client/src/util/native.h @@ -206,4 +206,10 @@ namespace native { uint32_t ReferenceCount; }; + using NtQuerySystemInformation = NTSTATUS(__stdcall*)(SYSTEM_INFORMATION_CLASS, PVOID, ULONG, PULONG); + using NtOpenProcess = NTSTATUS(__stdcall*)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES, CLIENT_ID*); + using NtReadVirtualMemory = NTSTATUS(__stdcall*)(HANDLE, PVOID, PVOID, ULONG, PULONG); + using NtAllocateVirtualMemory = NTSTATUS(__stdcall*)(HANDLE, PVOID*, ULONG, PULONG, ULONG, ULONG); + using NtWiteVirtualMemory = NTSTATUS(__stdcall*)(HANDLE, PVOID, PVOID, ULONG, PULONG); + }; // namespace native
\ No newline at end of file diff --git a/client/src/util/pe.h b/client/src/util/pe.h index a4d835d..56ba8ea 100644 --- a/client/src/util/pe.h +++ b/client/src/util/pe.h @@ -2,54 +2,54 @@ namespace pe { -class image { - std::unordered_map<std::string, uintptr_t> m_exports; + class image { + std::unordered_map<std::string, uintptr_t> m_exports; - IMAGE_NT_HEADERS64 *m_nt; - uintptr_t m_base; - bool m_valid; + IMAGE_NT_HEADERS64* m_nt; + uintptr_t m_base; + bool m_valid; - public: - image(){}; - image(const uintptr_t base) : m_valid{false}, m_base{base}, m_nt{nullptr} { - auto dos = reinterpret_cast<IMAGE_DOS_HEADER *>(base); - if (!dos || dos->e_magic != IMAGE_DOS_SIGNATURE) { - return; - } + public: + image() {}; + image(const uintptr_t base) : m_valid{ false }, m_base{ base }, m_nt{ nullptr } { + auto dos = reinterpret_cast<IMAGE_DOS_HEADER*>(base); + if (!dos || dos->e_magic != IMAGE_DOS_SIGNATURE) { + return; + } - m_nt = reinterpret_cast<IMAGE_NT_HEADERS64 *>(base + dos->e_lfanew); - if (m_nt->Signature != IMAGE_NT_SIGNATURE) { - return; - } + m_nt = reinterpret_cast<IMAGE_NT_HEADERS64*>(base + dos->e_lfanew); + if (m_nt->Signature != IMAGE_NT_SIGNATURE) { + return; + } - m_valid = true; - } + m_valid = true; + } - void parse_exports() { - auto dir = m_nt->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT]; - auto exp = - reinterpret_cast<IMAGE_EXPORT_DIRECTORY *>(m_base + dir.VirtualAddress); + void parse_exports() { + auto dir = m_nt->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT]; + auto exp = + reinterpret_cast<IMAGE_EXPORT_DIRECTORY*>(m_base + dir.VirtualAddress); - if (exp->NumberOfFunctions == 0) return; + if (exp->NumberOfFunctions == 0) return; - auto names = reinterpret_cast<uint32_t *>(m_base + exp->AddressOfNames); - auto funcs = reinterpret_cast<uint32_t *>(m_base + exp->AddressOfFunctions); - auto ords = - reinterpret_cast<uint16_t *>(m_base + exp->AddressOfNameOrdinals); + auto names = reinterpret_cast<uint32_t*>(m_base + exp->AddressOfNames); + auto funcs = reinterpret_cast<uint32_t*>(m_base + exp->AddressOfFunctions); + auto ords = + reinterpret_cast<uint16_t*>(m_base + exp->AddressOfNameOrdinals); - if (!names || !funcs || !ords) return; + if (!names || !funcs || !ords) return; - for (size_t i{}; i < exp->NumberOfFunctions; i++) { - uintptr_t va = m_base + funcs[ords[i]]; - std::string name = reinterpret_cast<const char *>(m_base + names[i]); + for (size_t i{}; i < exp->NumberOfFunctions; i++) { + uintptr_t va = m_base + funcs[ords[i]]; + std::string name = reinterpret_cast<const char*>(m_base + names[i]); - m_exports[name] = va; - } - } + m_exports[name] = va; + } + } - auto &exports() { return m_exports; } + auto& exports() { return m_exports; } - operator bool() { return m_valid; } -}; + operator bool() { return m_valid; } + }; }; // namespace pe
\ No newline at end of file diff --git a/client/src/util/syscalls.cpp b/client/src/util/syscalls.cpp index 624ce5a..279a936 100644 --- a/client/src/util/syscalls.cpp +++ b/client/src/util/syscalls.cpp @@ -23,7 +23,7 @@ void syscalls::init() { uint16_t offset; auto idx = get_index(addr, offset); - if(!idx) continue; + if (!idx) continue; m_indexes[exp.first] = std::make_pair(idx, offset); @@ -49,7 +49,7 @@ void syscalls::init() { } } -bool syscalls::valid(const uintptr_t addr, const size_t &size) { +bool syscalls::valid(const uintptr_t addr, const size_t& size) { auto func = reinterpret_cast<uint8_t*>(addr); // mov r10, rcx @@ -70,13 +70,13 @@ bool syscalls::valid(const uintptr_t addr, const size_t &size) { return false; } -uint16_t syscalls::get_index(const uintptr_t va, uint16_t &offset) { +uint16_t syscalls::get_index(const uintptr_t va, uint16_t& offset) { auto func = reinterpret_cast<uint8_t*>(va); auto size = func_size(reinterpret_cast<uint8_t*>(va)); if (!valid(va, size)) { return 0; } - + for (size_t i{}; i < size; i++) { auto op = func[i]; if (op == 0xb8) { diff --git a/client/src/util/syscalls.h b/client/src/util/syscalls.h index 0d73e4e..45d0ee1 100644 --- a/client/src/util/syscalls.h +++ b/client/src/util/syscalls.h @@ -4,15 +4,15 @@ class syscalls { std::unordered_map<std::string, std::pair<uint16_t, uint16_t>> m_indexes; std::vector<char> m_stub; - void *m_call_table; + void* m_call_table; public: syscalls(); ~syscalls(); void init(); - bool valid(const uintptr_t func, const size_t &size); - uint16_t get_index(const uintptr_t va, uint16_t &offset); - size_t func_size(const uint8_t *func); - + bool valid(const uintptr_t func, const size_t& size); + uint16_t get_index(const uintptr_t va, uint16_t& offset); + size_t func_size(const uint8_t* func); + template<class T> T get(const std::string_view func) { return reinterpret_cast<T>(uintptr_t(m_call_table) + (m_indexes[func.data()].first * m_stub.size())); diff --git a/client/src/util/util.cpp b/client/src/util/util.cpp index a23c03c..dbee015 100644 --- a/client/src/util/util.cpp +++ b/client/src/util/util.cpp @@ -4,49 +4,49 @@ std::unordered_map<std::string, pe::image> util::loaded_modules; -std::string util::wide_to_multibyte(const std::wstring &str) { - std::string ret; - int32_t str_len; +std::string util::wide_to_multibyte(const std::wstring& str) { + std::string ret; + int32_t str_len; - // check if not empty str - if (str.empty()) - return{}; + // check if not empty str + if (str.empty()) + return{}; - // count size - str_len = WideCharToMultiByte(CP_UTF8, 0, &str[0], (int32_t) str.size(), 0, 0, 0, 0); + // count size + str_len = WideCharToMultiByte(CP_UTF8, 0, &str[0], (int32_t)str.size(), 0, 0, 0, 0); - // setup return value - ret = std::string(str_len, 0); + // setup return value + ret = std::string(str_len, 0); - // final conversion - WideCharToMultiByte(CP_UTF8, 0, &str[0], (int32_t) str.size(), &ret[0], str_len, 0, 0); + // final conversion + WideCharToMultiByte(CP_UTF8, 0, &str[0], (int32_t)str.size(), &ret[0], str_len, 0, 0); - return ret; + return ret; } native::_PEB* util::get_peb() { - return reinterpret_cast<native::_PEB*>(__readgsqword(0x60)); + return reinterpret_cast<native::_PEB*>(__readgsqword(0x60)); } bool util::init() { - auto peb = get_peb(); - if (!peb) return false; + auto peb = get_peb(); + if (!peb) return false; - if (!peb->Ldr->InMemoryOrderModuleList.Flink) return false; + if (!peb->Ldr->InMemoryOrderModuleList.Flink) return false; - auto* list = &peb->Ldr->InMemoryOrderModuleList; + auto* list = &peb->Ldr->InMemoryOrderModuleList; - for (auto i = list->Flink; i != list; i = i->Flink) { - auto entry = CONTAINING_RECORD(i, native::LDR_DATA_TABLE_ENTRY, InMemoryOrderLinks); - if (!entry) - continue; + for (auto i = list->Flink; i != list; i = i->Flink) { + auto entry = CONTAINING_RECORD(i, native::LDR_DATA_TABLE_ENTRY, InMemoryOrderLinks); + if (!entry) + continue; - auto name = wide_to_multibyte(entry->BaseDllName.Buffer); - std::transform(name.begin(), name.end(), name.begin(), ::tolower); + auto name = wide_to_multibyte(entry->BaseDllName.Buffer); + std::transform(name.begin(), name.end(), name.begin(), ::tolower); - loaded_modules[name] = pe::image(entry->DllBase); - } + loaded_modules[name] = pe::image(entry->DllBase); + } - return true; + return true; } diff --git a/client/src/util/util.h b/client/src/util/util.h index b4bf699..8658ce6 100644 --- a/client/src/util/util.h +++ b/client/src/util/util.h @@ -5,22 +5,22 @@ namespace util { -extern std::unordered_map<std::string, pe::image> loaded_modules; + extern std::unordered_map<std::string, pe::image> loaded_modules; -std::string wide_to_multibyte(const std::wstring &str); + std::string wide_to_multibyte(const std::wstring& str); -native::_PEB *get_peb(); + native::_PEB* get_peb(); -bool init(); + bool init(); -static pe::image& ntdll() { - static pe::image nt{}; - if (!nt) { - nt = loaded_modules["ntdll.dll"]; - nt.parse_exports(); + static pe::image& ntdll() { + static pe::image nt{}; + if (!nt) { + nt = loaded_modules["ntdll.dll"]; + nt.parse_exports(); + } + return nt; } - return nt; -} }; // namespace util |