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");
The export directory on disk (or in the arm64 case) is at RVA 0x31E1A0
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");
Gives us now the right #... function address which we can use as target for arm64 code injection as well as for function calls from the injected shell code.
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.