![]() |
|
|
|
#1
|
|||
|
|||
|
Indeed I should contact him, good idea
![]() But now lets talk about what we can get from the relevant header files: ...\10.0.22000.0\um\winnt.h and ...\10.0.22000.0\km\ntimage.h With the attached FindDllExport we can extract exports from a loaded image with the below example we run a arm64 process and target a x64 process. For ourselves we get the normal ntdll.dll!LdrLoadDll while for the x64 process we get the ntdll.dll!EXP+#LdrLoadDll Code:
//ntdllBase 0x00007ffa5a7d0000
//0x00007ffa5a811050 {ntdll.dll!LdrLoadDll(void)}
//0x00007ffa5a7d1890 {ntdll.dll!EXP+#LdrLoadDll}
//0x00007ffa5a969920 {ntdll.dll!#LdrLoadDll}
HMODULE hNtdll = GetModuleHandle(L"ntdll.dll");
//DWORD64 LLW1 = GetProcAddress(hNtdll, "LdrLoadDll");
DWORD64 LLW1 = FindDllExport(GetCurrentProcess(), (DWORD64)hNtdll, "LdrLoadDll");
DWORD64 ntdllBase = FindDllBase(hProcess, L"\\system32\\ntdll.dll");
DWORD64 LLW2 = FindDllExport(hProcess, ntdllBase, "LdrLoadDll");
for the x64 process the value at 0x178 is overwritten with 0x308810 what is the alternative export directory. This operation is indicated by PE Anatomist in "Loader Config -> Dyn. Value Relocs", 2nd entry. So if we don't have a loaded process we could extract the value from there and read the second export directory from disk directly. In "Debug->POGO" we see that the export directory starts at 0x308810 and is 0x2b224 in size First the alternative directory 0x308810 to 0x31E1A0 and given the entry size it seams the primary starting at 0x31E1A0 goes to 0x333A34 booth are similar in size, so there does not seam to be a 3rd one for the ntdll.dll!#.... exports I assume that's because there is no typical use case where a process would want those directly, a arm64 will load the primary table a x64 process the alternative table, and 32 bit once have their own ntdll's in the wow folders. So where do we go from here, we notice that "Loader Config -> hybrid PE -> WoW Thunks Metadata" seams to hold all the RVA's we get from the export directory, and the destinations are the addresses of the #... functions. So we can get the !EXP+#... function addresses form the export dir and look up the #... addresses in this RedirectionMetadata table, the FindDllExport now checks if the first char is a '#' and if so triggers the additional lookup. Code:
DWORD64 LLW3 = FindDllExport(hProcess, ntdllBase, "#LdrLoadDll"); One thing I haven't figured yet out is how we get the alternative export directory if we don't have a process with emulation at at our disposal. I'm not sure how PE Anatomist gets the "Dyn. Value Relocs" from, for me in a live process DynamicValueRelocTable is NULL and base + DynamicValueRelocTableOffset or loaderConfig + DynamicValueRelocTableOffset do not seam to result in valid data. While for the use case at hand its not required I would like to know how to get to this list as well, any tips would be greatly appreciated. |
| The Following User Says Thank You to DavidXanatos For This Useful Post: | ||
sh3dow (02-26-2022) | ||
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Windows 11 ARM64 version 24H2 | blue_devil | General Discussion | 9 | 11-20-2024 13:55 |
| Question about PE format (ARM64) | DavidXanatos | General Discussion | 0 | 04-28-2022 01:09 |