diff --git a/src/xenia/kernel/xboxkrnl/xboxkrnl_rtl.cc b/src/xenia/kernel/xboxkrnl/xboxkrnl_rtl.cc index 2b3ab5f67..3b71a4dd5 100644 --- a/src/xenia/kernel/xboxkrnl/xboxkrnl_rtl.cc +++ b/src/xenia/kernel/xboxkrnl/xboxkrnl_rtl.cc @@ -312,6 +312,30 @@ dword_result_t RtlUnicodeToMultiByteN(pointer_t destination_ptr, DECLARE_XBOXKRNL_EXPORT3(RtlUnicodeToMultiByteN, kNone, kImplemented, kHighFrequency, kSketchy); +// https://undocumented.ntinternals.net/UserMode/Undocumented%20Functions/Executable%20Images/RtlImageNtHeader.html +pointer_result_t RtlImageNtHeader(lpvoid_t module) { + if (!module) { + return 0; + } + + // Little-endian! no swapping! + + auto dos_header = module.as(); + auto dos_magic = *reinterpret_cast(&dos_header[0x00]); + if (dos_magic != 0x5A4D) { // 'MZ' + return 0; + } + auto dos_lfanew = *reinterpret_cast(&dos_header[0x3C]); + + auto nt_header = &dos_header[dos_lfanew]; + auto nt_magic = *reinterpret_cast(&nt_header[0x00]); + if (nt_magic != 0x4550) { // 'PE' + return 0; + } + return static_cast(nt_header - kernel_memory()->virtual_membase()); +} +DECLARE_XBOXKRNL_EXPORT1(RtlImageNtHeader, kNone, kImplemented); + pointer_result_t RtlImageXexHeaderField(pointer_t xex_header, dword_t field_dword) { uint32_t field_value = 0;