| 6 | using namespace OpenGlass; |
| 7 | |
| 8 | HMODULE HookHelper::GetRemoteModuleBase(DWORD processId, LPCWSTR moduleName) |
| 9 | { |
| 10 | HMODULE result{ nullptr }; |
| 11 | wil::unique_handle snapshot{ CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, processId) }; |
| 12 | if (!snapshot.is_valid()) |
| 13 | { |
| 14 | return result; |
| 15 | } |
| 16 | |
| 17 | wil::unique_handle processHandle{ OpenProcess(PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, FALSE, processId) }; |
| 18 | if (!processHandle) |
| 19 | { |
| 20 | return result; |
| 21 | } |
| 22 | |
| 23 | MODULEENTRY32W me{ sizeof(me) }; |
| 24 | if (!Module32FirstW(snapshot.get(), &me)) |
| 25 | { |
| 26 | return result; |
| 27 | } |
| 28 | |
| 29 | do |
| 30 | { |
| 31 | if (!_wcsicmp(me.szModule, moduleName)) |
| 32 | { |
| 33 | result = me.hModule; |
| 34 | break; |
| 35 | } |
| 36 | WCHAR modulePath[MAX_PATH]{}; |
| 37 | if (GetModuleFileNameExW(processHandle.get(), me.hModule, modulePath, std::size(modulePath))) |
| 38 | { |
| 39 | if (!_wcsicmp(modulePath, moduleName)) |
| 40 | { |
| 41 | result = me.hModule; |
| 42 | break; |
| 43 | } |
| 44 | } |
| 45 | } while (Module32NextW(snapshot.get(), &me)); |
| 46 | |
| 47 | return result; |
| 48 | } |
| 49 | |
| 50 | const uint8_t* HookHelper::FindPattern(std::span<const uint8_t> base, std::span<const uint16_t> pat) |
| 51 | { |