| 161 | |
| 162 | |
| 163 | void FillNtDllLUTs(HMODULE NtDll) { |
| 164 | ULONG Size; |
| 165 | const auto* LoadConfig = |
| 166 | reinterpret_cast<_IMAGE_LOAD_CONFIG_DIRECTORY64*>(RtlImageDirectoryEntryToData(NtDll, true, IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG, &Size)); |
| 167 | const auto* CHPEMetadata = reinterpret_cast<IMAGE_ARM64EC_METADATA*>(LoadConfig->CHPEMetadataPointer); |
| 168 | const auto* RedirectionTableBegin = reinterpret_cast<IMAGE_ARM64EC_REDIRECTION_ENTRY*>(NtDllBase + CHPEMetadata->RedirectionMetadata); |
| 169 | const auto* RedirectionTableEnd = RedirectionTableBegin + CHPEMetadata->RedirectionMetadataCount; |
| 170 | |
| 171 | NtDllRedirectionLUTSize = std::prev(RedirectionTableEnd)->Source + 1; |
| 172 | |
| 173 | SIZE_T AllocSize = NtDllRedirectionLUTSize * sizeof(uint32_t); |
| 174 | NtAllocateVirtualMemoryNative(NtCurrentProcess(), reinterpret_cast<void**>(&NtDllRedirectionLUT), 0, &AllocSize, MEM_COMMIT | MEM_RESERVE, |
| 175 | PAGE_READWRITE); |
| 176 | for (auto It = RedirectionTableBegin; It != RedirectionTableEnd; It++) { |
| 177 | NtDllRedirectionLUT[It->Source] = It->Destination; |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | template<typename T> |
| 182 | void WriteModuleRVA(HMODULE Module, LONG RVA, T Data) { |