Implement fake kernel header to allow XapiRestrictCodeSelectorLimit to succeed

Cxbx now requires support for large address space on 32-bit applications, this may break some 32-bit operating systems.
This commit is contained in:
Luke Usher 2016-08-19 19:55:18 +01:00
parent 3f70ed9f7c
commit afa9d02e2e
2 changed files with 30 additions and 2 deletions

View File

@ -61,7 +61,7 @@ EmuExe::EmuExe(Xbe *x_Xbe, DebugMode x_debug_mode, char *x_debug_filename, HWND
m_Header.m_symbol_table_addr = 0; // unused
m_Header.m_symbols = 0; // unused
m_Header.m_sizeof_optional_header = sizeof(OptionalHeader); // size of optional header
m_Header.m_characteristics = 0x010F; // should be fine..
m_Header.m_characteristics = 0x012F; // should be fine..
printf("OK\n");
}

View File

@ -297,6 +297,35 @@ extern "C" CXBXKRNL_API void CxbxKrnlInit
#endif
}
{
// Create a fake kernel header for XapiRestrictCodeSelectorLimit
// Thanks advancingdragon / DirtBox
typedef struct DUMMY_KERNEL
{
IMAGE_DOS_HEADER DosHeader;
DWORD Signature;
IMAGE_FILE_HEADER FileHeader;
IMAGE_SECTION_HEADER SectionHeader;
} *PDUMMY_KERNEL;
PDUMMY_KERNEL DummyKernel = (PDUMMY_KERNEL)VirtualAlloc(
(PVOID)0x80010000, sizeof(DUMMY_KERNEL),
MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE
);
if (DummyKernel == NULL)
CxbxKrnlCleanup("InitializeDummyKernel: Could not allocate dummy kernel.");
memset(DummyKernel, 0, sizeof(DUMMY_KERNEL));
// XapiRestrictCodeSelectorLimit only checks these fields.
DummyKernel->DosHeader.e_lfanew = sizeof(IMAGE_DOS_HEADER); // RVA of NtHeaders
DummyKernel->FileHeader.SizeOfOptionalHeader = 0;
DummyKernel->FileHeader.NumberOfSections = 1;
// as long as this doesn't start with "INIT"
strncpy_s((PSTR)DummyKernel->SectionHeader.Name, 8, "DONGS", 8);
}
//
// load the necessary pieces of XbeHeader
//
@ -320,7 +349,6 @@ extern "C" CXBXKRNL_API void CxbxKrnlInit
}
// Initialize devices :
char szBuffer[260];
SHGetSpecialFolderPath(NULL, szBuffer, CSIDL_APPDATA, TRUE);
strcat(szBuffer, "\\Cxbx\\");