| 44 | } |
| 45 | |
| 46 | uint64_t utils::GetKernelModuleAddress(const std::string& module_name) { |
| 47 | void* buffer = nullptr; |
| 48 | DWORD buffer_size = 0; |
| 49 | |
| 50 | NTSTATUS status = NtQuerySystemInformation(static_cast<SYSTEM_INFORMATION_CLASS>(nt::SystemModuleInformation), buffer, buffer_size, &buffer_size); |
| 51 | |
| 52 | while (status == nt::STATUS_INFO_LENGTH_MISMATCH) { |
| 53 | if (buffer != nullptr) |
| 54 | VirtualFree(buffer, 0, MEM_RELEASE); |
| 55 | |
| 56 | buffer = VirtualAlloc(nullptr, buffer_size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); |
| 57 | status = NtQuerySystemInformation(static_cast<SYSTEM_INFORMATION_CLASS>(nt::SystemModuleInformation), buffer, buffer_size, &buffer_size); |
| 58 | } |
| 59 | |
| 60 | if (!NT_SUCCESS(status)) { |
| 61 | if (buffer != nullptr) |
| 62 | VirtualFree(buffer, 0, MEM_RELEASE); |
| 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | const auto modules = static_cast<nt::PRTL_PROCESS_MODULES>(buffer); |
| 67 | if (!modules) |
| 68 | return 0; |
| 69 | |
| 70 | for (auto i = 0u; i < modules->NumberOfModules; ++i) { |
| 71 | const std::string current_module_name = std::string(reinterpret_cast<char*>(modules->Modules[i].FullPathName) + modules->Modules[i].OffsetToFileName); |
| 72 | |
| 73 | if (!_stricmp(current_module_name.c_str(), module_name.c_str())) |
| 74 | { |
| 75 | const uint64_t result = reinterpret_cast<uint64_t>(modules->Modules[i].ImageBase); |
| 76 | |
| 77 | VirtualFree(buffer, 0, MEM_RELEASE); |
| 78 | return result; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | VirtualFree(buffer, 0, MEM_RELEASE); |
| 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | BOOLEAN utils::bDataCompare(const BYTE* pData, const BYTE* bMask, const char* szMask) { |
| 87 | for (; *szMask; ++szMask, ++pData, ++bMask) |
nothing calls this directly
no outgoing calls
no test coverage detected