From 661b73df47caae2cc62a9a2f7b85eb925ff1f80b Mon Sep 17 00:00:00 2001 From: auth12 <67507608+auth12@users.noreply.github.com> Date: Sun, 4 Jul 2021 01:15:09 +0100 Subject: initial commit --- sysmap/src/mapper/util.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 sysmap/src/mapper/util.h (limited to 'sysmap/src/mapper/util.h') diff --git a/sysmap/src/mapper/util.h b/sysmap/src/mapper/util.h new file mode 100644 index 0000000..f50192b --- /dev/null +++ b/sysmap/src/mapper/util.h @@ -0,0 +1,52 @@ +#pragma once + +namespace util { + struct module_data_t { + std::string name; + uintptr_t base; + size_t size; + std::string full_path; + }; + + std::string to_multibyte(std::wstring_view str) { + return std::filesystem::path(str.data()).string(); + } + + std::wstring to_wide(std::string_view str) { + return std::filesystem::path(str.data()).wstring(); + } + + TEB* get_teb() { + return reinterpret_cast(__readgsqword(0x30)); + } + + std::vector get_modules() { + std::vector ret{}; + + auto* list = &get_teb()->ProcessEnvironmentBlock->Ldr->InMemoryOrderModuleList; + + for (auto i = list->Flink; i != list; i = i->Flink) { + auto entry = CONTAINING_RECORD(i, LDR_DATA_TABLE_ENTRY, InMemoryOrderLinks); + if (!entry) + continue; + + auto name = util::to_multibyte(entry->BaseDllName.Buffer); + std::transform(name.begin(), name.end(), name.begin(), tolower); + + auto full_path = util::to_multibyte(entry->FullDllName.Buffer); + + ret.emplace_back(module_data_t{name, uintptr_t(entry->DllBase), entry->SizeOfImage, full_path}); + } + + return ret; + } +}; + +namespace x64 { + enum inst : uint8_t { + retn = 0xC3, + mov_imm16 = 0xB8, + nop = 0x90, + test_imm8 = 0xF6 + }; +}; \ No newline at end of file -- cgit v1.2.3