|
4 | 4 | #include <Windows.h> |
5 | 5 | #include <TlHelp32.h> |
6 | 6 | #include <winternl.h> |
| 7 | +#include <array> |
| 8 | +#include <fstream> |
7 | 9 | #include <omath/utility/pe_pattern_scan.hpp> |
8 | 10 | #include <yail/yail.hpp> |
9 | | -#include <fstream> |
10 | 11 | namespace |
11 | 12 | { |
12 | 13 | // Resolve MSVC incremental-link jump stubs (ILT): E9 xx xx xx xx → target |
@@ -44,26 +45,40 @@ namespace |
44 | 45 | [[nodiscard]] |
45 | 46 | LdrpHandleTlsDataFn find_ldrp_handle_tls_data() |
46 | 47 | { |
47 | | - const auto result = omath::PePatternScanner::scan_for_pattern_in_loaded_module( |
48 | | - GetModuleHandleA("ntdll.dll"), "4C 8B DC 49 89 5B ? 49 89 73 ? 57 41 54 41 55 41 56 41 57 48 81 EC ? ? ? ? 48 8B 05 ? ? " |
49 | | - "? ? 48 33 C4 48 89 84 24 ? ? ? ? 48 8B F9"); |
| 48 | + constexpr std::array signatures = { |
| 49 | + "4C 8B DC 49 89 5B ? 49 89 73 ? 57 41 54 41 55 41 56 41 57 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 84 24 ? ? ? ? 48 8B F9", // Windows 11 24H2 |
| 50 | + "48 89 5C 24 ? 48 89 74 24 ? 48 89 7C 24 ? 41 55 41 56 41 57 48 81 EC", |
50 | 51 |
|
51 | | - if (!result) |
52 | | - throw std::runtime_error{"Failed to find LdrpHandleTlsData"}; |
| 52 | + }; |
53 | 53 |
|
54 | | - return reinterpret_cast<LdrpHandleTlsDataFn>(result.value()); |
| 54 | + const auto* ntdll = GetModuleHandleA("ntdll.dll"); |
| 55 | + for (const auto* sig : signatures) |
| 56 | + { |
| 57 | + const auto result = omath::PePatternScanner::scan_for_pattern_in_loaded_module(ntdll, sig); |
| 58 | + if (result) |
| 59 | + return reinterpret_cast<LdrpHandleTlsDataFn>(result.value()); |
| 60 | + } |
| 61 | + |
| 62 | + throw std::runtime_error{"Failed to find LdrpHandleTlsData"}; |
55 | 63 | } |
56 | 64 |
|
57 | 65 | [[nodiscard]] |
58 | 66 | RtlInsertInvertedFunctionTableFn find_rtl_insert_inverted_function_table() |
59 | 67 | { |
60 | | - const auto result = omath::PePatternScanner::scan_for_pattern_in_loaded_module( |
61 | | - GetModuleHandleA("ntdll.dll"), "48 8B C4 48 89 58 ? 48 89 68 ? 48 89 70 ? 57 48 83 EC ? 83 60"); |
| 68 | + constexpr std::array signatures = { |
| 69 | + "48 8B C4 48 89 58 ? 48 89 68 ? 48 89 70 ? 57 48 83 EC ? 83 60", // Windows 11 24H2 |
| 70 | + "4C 8B DC 49 89 5B ? 49 89 73 ? 57 48 83 EC ? 8B FA" |
| 71 | + }; |
62 | 72 |
|
63 | | - if (!result) |
64 | | - throw std::runtime_error{"Failed to find RtlInsertInvertedFunctionTable"}; |
| 73 | + const auto* ntdll = GetModuleHandleA("ntdll.dll"); |
| 74 | + for (const auto* sig : signatures) |
| 75 | + { |
| 76 | + const auto result = omath::PePatternScanner::scan_for_pattern_in_loaded_module(ntdll, sig); |
| 77 | + if (result) |
| 78 | + return reinterpret_cast<RtlInsertInvertedFunctionTableFn>(result.value()); |
| 79 | + } |
65 | 80 |
|
66 | | - return reinterpret_cast<RtlInsertInvertedFunctionTableFn>(result.value()); |
| 81 | + throw std::runtime_error{"Failed to find RtlInsertInvertedFunctionTable"}; |
67 | 82 | } |
68 | 83 | struct RemoteLoaderData final |
69 | 84 | { |
|
0 commit comments