fix kdmaper adjust loading method

This commit is contained in:
2026-10-08 09:57:32 +08:00
parent 1745e5097d
commit e530b283cd
7 changed files with 772 additions and 6060 deletions
+3 -15
View File
@@ -8,20 +8,12 @@ BOOL kdmapper::MapDriver(HANDLE device_handle, uint64_t ker_base, char* map_base
auto image_size = pNT_header->OptionalHeader.SizeOfImage;
auto map_image_base = reinterpret_cast<char*>(VirtualAlloc(nullptr, image_size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE));
if (!map_image_base)
{
//printf("vritualalloc fail!!\n");
return false;
}
if (!map_image_base) return false;
//image_size = image_size - TotalVirtualHeaderSize;
auto kernel_base = kd_driver::ExAllocatePool(device_handle, 0, image_size);
if (!kernel_base)
{
//printf("[-] ExAllocatePool fail\n");
return false;
}
if (!kernel_base) return false;
//写入pe头
memcpy(map_image_base, map_base, pNT_header->OptionalHeader.SizeOfHeaders);
@@ -36,8 +28,6 @@ BOOL kdmapper::MapDriver(HANDLE device_handle, uint64_t ker_base, char* map_base
//修复重定位表
//auto PReloc = reinterpret_cast<PIMAGE_BASE_RELOCATION>(map_image_base + pNT_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress);
auto current_base_relocation = reinterpret_cast<PIMAGE_BASE_RELOCATION>(reinterpret_cast<ULONG64>(map_image_base) + pNT_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress);
const auto reloc_end = reinterpret_cast<PIMAGE_BASE_RELOCATION>(reinterpret_cast<ULONG64>(current_base_relocation) + pNT_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].Size);
@@ -56,7 +46,6 @@ BOOL kdmapper::MapDriver(HANDLE device_handle, uint64_t ker_base, char* map_base
*RelocAddr += (DWORD64)kernel_base;
}
}
current_base_relocation = reinterpret_cast<PIMAGE_BASE_RELOCATION>(reinterpret_cast<DWORD64>(current_base_relocation) + current_base_relocation->SizeOfBlock);
}
@@ -71,6 +60,7 @@ BOOL kdmapper::MapDriver(HANDLE device_handle, uint64_t ker_base, char* map_base
if (*(uintptr_t*)(stack_cookie) != 0x2B992DDFA232)
return false;
auto new_cookie = 0x2B992DDFA232 ^ GetCurrentProcessId() ^ GetCurrentThreadId(); // here we don't really care about the value of stack cookie, it will still works and produce nice result
if (new_cookie == 0x2B992DDFA232)
new_cookie = 0x2B992DDFA233;
@@ -82,8 +72,6 @@ BOOL kdmapper::MapDriver(HANDLE device_handle, uint64_t ker_base, char* map_base
auto pimpor = reinterpret_cast<PIMAGE_IMPORT_DESCRIPTOR>(map_image_base + pNT_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress);
while (pimpor->Name)
{
const auto Module = utils::GetKernelModule((char*)map_image_base + pimpor->Name);
auto Int = reinterpret_cast<PIMAGE_THUNK_DATA>(map_image_base + pimpor->OriginalFirstThunk);
auto Iat = reinterpret_cast<PIMAGE_THUNK_DATA>(map_image_base + pimpor->FirstThunk);