cleanup
This commit is contained in:
parent
1da4092229
commit
b1d47d66ed
|
@ -54,6 +54,11 @@ extern "C" CXBXKRNL_API void NTAPI EmuInit(uint32 TlsAdjust, Xbe::LibraryVersion
|
|||
// ******************************************************************
|
||||
extern "C" CXBXKRNL_API void NTAPI EmuPanic();
|
||||
|
||||
// ******************************************************************
|
||||
// * func: EmuException
|
||||
// ******************************************************************
|
||||
extern int EmuException(LPEXCEPTION_POINTERS e);
|
||||
|
||||
// ******************************************************************
|
||||
// * data: KernelThunkTable
|
||||
// ******************************************************************
|
||||
|
|
|
@ -1136,7 +1136,7 @@ void Xbe::ConstructorInit()
|
|||
m_HeaderEx = 0;
|
||||
m_SectionHeader = 0;
|
||||
m_szSectionName = 0;
|
||||
m_LibraryVersion = 0;
|
||||
m_LibraryVersion = 0;
|
||||
m_KernelLibraryVersion = 0;
|
||||
m_XAPILibraryVersion = 0;
|
||||
m_TLS = 0;
|
||||
|
@ -1386,7 +1386,7 @@ void Xbe::DumpInformation(FILE *x_file)
|
|||
{
|
||||
if(m_LibraryVersion == 0 || m_Header.dwLibraryVersions == 0)
|
||||
{
|
||||
fprintf(x_file, "(This XBE contains no libraries)\n");
|
||||
fprintf(x_file, "(This XBE contains no Library Versions)\n");
|
||||
fprintf(x_file, "\n");
|
||||
}
|
||||
else
|
||||
|
|
|
@ -550,7 +550,8 @@ EmuExe::EmuExe(Xbe *x_Xbe, DebugMode x_debug_mode, char *x_debug_filename) : Exe
|
|||
// ******************************************************************
|
||||
// * append library versions
|
||||
// ******************************************************************
|
||||
memcpy(m_bzSection[i] + 0x100 + x_Xbe->m_Header.dwSizeofHeaders + 260, x_Xbe->m_LibraryVersion, sizeof(Xbe::LibraryVersion) * x_Xbe->m_Header.dwLibraryVersions);
|
||||
if(x_Xbe->m_LibraryVersion != 0)
|
||||
memcpy(m_bzSection[i] + 0x100 + x_Xbe->m_Header.dwSizeofHeaders + 260, x_Xbe->m_LibraryVersion, sizeof(Xbe::LibraryVersion) * x_Xbe->m_Header.dwLibraryVersions);
|
||||
|
||||
// ******************************************************************
|
||||
// * calculate TLS adjustment
|
||||
|
@ -588,7 +589,10 @@ EmuExe::EmuExe(Xbe *x_Xbe, DebugMode x_debug_mode, char *x_debug_filename) : Exe
|
|||
*(uint32 *)((uint32)m_bzSection[i] + 16) = m_SectionHeader[i].m_virtual_addr + m_OptionalHeader.m_image_base + 0x100;
|
||||
*(uint32 *)((uint32)m_bzSection[i] + 21) = m_SectionHeader[i].m_virtual_addr + m_OptionalHeader.m_image_base + 0x100 + x_Xbe->m_Header.dwSizeofHeaders;
|
||||
*(uint32 *)((uint32)m_bzSection[i] + 26) = x_debug_mode;
|
||||
*(uint32 *)((uint32)m_bzSection[i] + 31) = m_SectionHeader[i].m_virtual_addr + m_OptionalHeader.m_image_base + 0x100 + x_Xbe->m_Header.dwSizeofHeaders + 260;
|
||||
if(x_Xbe->m_LibraryVersion != 0)
|
||||
*(uint32 *)((uint32)m_bzSection[i] + 31) = m_SectionHeader[i].m_virtual_addr + m_OptionalHeader.m_image_base + 0x100 + x_Xbe->m_Header.dwSizeofHeaders + 260;
|
||||
else
|
||||
*(uint32 *)((uint32)m_bzSection[i] + 31) = 0;
|
||||
*(uint32 *)((uint32)m_bzSection[i] + 36) = TlsAdjust;
|
||||
|
||||
printf("OK\n");
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
WndAbout::WndAbout(HINSTANCE x_hInstance, HWND x_parent) : Wnd(x_hInstance)
|
||||
{
|
||||
m_classname = "WndAbout";
|
||||
m_wndname = "Cxbx : About (Version " _CXBX_VERSION ")";
|
||||
m_wndname = "Cxbx " _CXBX_VERSION;
|
||||
|
||||
m_w = 285;
|
||||
m_h = 180;
|
||||
|
|
|
@ -54,8 +54,7 @@ namespace xboxkrnl
|
|||
// * global / static
|
||||
// ******************************************************************
|
||||
static void EmuInstallWrappers(OOVPATable *OovpaTable, uint32 OovpaTableSize, void (*Entry)(), Xbe::Header *XbeHeader);
|
||||
|
||||
uint32 g_TlsAdjust = 0;
|
||||
extern uint32 g_TlsAdjust = 0;
|
||||
|
||||
// ******************************************************************
|
||||
// * func: DllMain
|
||||
|
@ -140,9 +139,50 @@ extern "C" CXBXKRNL_API void NTAPI EmuInit(uint32 TlsAdjust, Xbe::LibraryVersion
|
|||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * Locate functions and install wrapper vectors
|
||||
// * Load the necessary pieces of XBEHeader
|
||||
// ******************************************************************
|
||||
{
|
||||
Xbe::Header *MemXbeHeader = (Xbe::Header*)0x00010000;
|
||||
|
||||
uint32 old_protection = 0;
|
||||
|
||||
VirtualProtect(MemXbeHeader, 0x1000, PAGE_READWRITE, &old_protection);
|
||||
|
||||
// we sure hope we aren't corrupting anything necessary for an .exe to survive :]
|
||||
MemXbeHeader->dwSizeofHeaders = XbeHeader->dwSizeofHeaders;
|
||||
MemXbeHeader->dwCertificateAddr = XbeHeader->dwCertificateAddr;
|
||||
MemXbeHeader->dwPeHeapReserve = XbeHeader->dwPeHeapReserve;
|
||||
MemXbeHeader->dwPeHeapCommit = XbeHeader->dwPeHeapCommit;
|
||||
|
||||
memcpy(&MemXbeHeader->dwInitFlags, &XbeHeader->dwInitFlags, sizeof(XbeHeader->dwInitFlags));
|
||||
|
||||
memcpy((void*)XbeHeader->dwCertificateAddr, &((uint08*)XbeHeader)[XbeHeader->dwCertificateAddr - 0x00010000], sizeof(Xbe::Certificate));
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * Initialize all components
|
||||
// ******************************************************************
|
||||
{
|
||||
EmuInitFS();
|
||||
|
||||
EmuGenerateFS(TlsAdjust);
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * Initialize OpenXDK emulation
|
||||
// ******************************************************************
|
||||
if(LibraryVersion == 0)
|
||||
{
|
||||
printf("Emu: Detected OpenXDK application...\n");
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * Initialize Microsoft XDK emulation
|
||||
// ******************************************************************
|
||||
if(LibraryVersion != 0)
|
||||
{
|
||||
printf("Emu: Detected Microsoft XDK application...\n");
|
||||
|
||||
uint32 dwLibraryVersions = XbeHeader->dwLibraryVersions;
|
||||
uint32 dwHLEEntries = HLEDataBaseSize/sizeof(HLEData);
|
||||
|
||||
|
@ -182,47 +222,27 @@ extern "C" CXBXKRNL_API void NTAPI EmuInit(uint32 TlsAdjust, Xbe::LibraryVersion
|
|||
if(!found)
|
||||
printf("Skipped\n");
|
||||
}
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * Load the necessary pieces of XBEHeader
|
||||
// ******************************************************************
|
||||
{
|
||||
Xbe::Header *MemXbeHeader = (Xbe::Header*)0x00010000;
|
||||
|
||||
uint32 old_protection = 0;
|
||||
|
||||
VirtualProtect(MemXbeHeader, 0x1000, PAGE_READWRITE, &old_protection);
|
||||
|
||||
// we sure hope we aren't corrupting anything necessary for an .exe to survive :]
|
||||
MemXbeHeader->dwSizeofHeaders = XbeHeader->dwSizeofHeaders;
|
||||
MemXbeHeader->dwCertificateAddr = XbeHeader->dwCertificateAddr;
|
||||
MemXbeHeader->dwPeHeapReserve = XbeHeader->dwPeHeapReserve;
|
||||
MemXbeHeader->dwPeHeapCommit = XbeHeader->dwPeHeapCommit;
|
||||
|
||||
memcpy(&MemXbeHeader->dwInitFlags, &XbeHeader->dwInitFlags, sizeof(XbeHeader->dwInitFlags));
|
||||
|
||||
memcpy((void*)XbeHeader->dwCertificateAddr, &((uint08*)XbeHeader)[XbeHeader->dwCertificateAddr - 0x00010000], sizeof(Xbe::Certificate));
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * Initialize all components
|
||||
// ******************************************************************
|
||||
{
|
||||
EmuInitFS();
|
||||
|
||||
EmuGenerateFS(TlsAdjust);
|
||||
|
||||
EmuInitD3D(XbeHeader, XbeHeaderSize);
|
||||
}
|
||||
|
||||
printf("Emu (0x%.08X): Initial thread starting.\n", GetCurrentThreadId());
|
||||
|
||||
EmuSwapFS(); // XBox FS
|
||||
// ******************************************************************
|
||||
// * Entry Point
|
||||
// ******************************************************************
|
||||
__try
|
||||
{
|
||||
EmuSwapFS(); // XBox FS
|
||||
|
||||
Entry();
|
||||
Entry();
|
||||
|
||||
EmuSwapFS(); // Win2k/XP FS
|
||||
EmuSwapFS(); // Win2k/XP FS
|
||||
}
|
||||
__except(EmuException(GetExceptionInformation()))
|
||||
{
|
||||
printf("Emu: WARNING!! Problem with ExceptionFilter\n");
|
||||
}
|
||||
|
||||
printf("Emu (0x%.08X): Initial thread ended.\n", GetCurrentThreadId());
|
||||
|
||||
|
@ -402,5 +422,17 @@ void EmuInstallWrappers(OOVPATable *OovpaTable, uint32 OovpaTableSize, void (*En
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// ******************************************************************
|
||||
// * func: EmuException
|
||||
// ******************************************************************
|
||||
int EmuException(LPEXCEPTION_POINTERS e)
|
||||
{
|
||||
int ret = MessageBox(NULL, "WARNING: This thread has performed an illegal operation.\n\nPress 'OK' to terminate emulation.\nPress 'Cancel' to debug.", "Cxbx", MB_ICONSTOP | MB_OKCANCEL);
|
||||
|
||||
if(ret == IDOK)
|
||||
ExitProcess(1);
|
||||
|
||||
return EXCEPTION_CONTINUE_SEARCH;
|
||||
}
|
||||
|
|
|
@ -104,6 +104,7 @@ VOID EmuInitD3D(Xbe::Header *XbeHeader, uint32 XbeHeaderSize)
|
|||
// ******************************************************************
|
||||
{
|
||||
using namespace xd3d8;
|
||||
|
||||
// xbox Direct3DCreate8 returns "1" always, so we need our own ptr
|
||||
g_pD3D8 = Direct3DCreate8(D3D_SDK_VERSION);
|
||||
|
||||
|
@ -163,7 +164,7 @@ void EmuRenderWindow(PVOID)
|
|||
wcstombs(tAsciiTitle, XbeCert->wszTitleName, 40);
|
||||
}
|
||||
|
||||
sprintf(AsciiTitle, "%s - Cxbx Version " _CXBX_VERSION, tAsciiTitle);
|
||||
sprintf(AsciiTitle, "Cxbx : Emulating %s", tAsciiTitle);
|
||||
}
|
||||
|
||||
g_EmuWindow = CreateWindow
|
||||
|
|
|
@ -118,18 +118,28 @@ DWORD WINAPI PCSTProxy
|
|||
// ******************************************************************
|
||||
// * use the special calling convention
|
||||
// ******************************************************************
|
||||
__try
|
||||
{
|
||||
__asm
|
||||
{
|
||||
mov esi, StartRoutine
|
||||
push StartContext2
|
||||
push StartContext1
|
||||
push offset callComplete
|
||||
lea ebp, [esp-4]
|
||||
jmp near esi
|
||||
}
|
||||
}
|
||||
__except(EmuException(GetExceptionInformation()))
|
||||
{
|
||||
printf("Emu: WARNING!! Problem with ExceptionFilter\n");
|
||||
}
|
||||
|
||||
__asm
|
||||
{
|
||||
mov esi, StartRoutine
|
||||
push StartContext2
|
||||
push StartContext1
|
||||
push offset callComplete
|
||||
lea ebp, [esp-4]
|
||||
jmp near esi
|
||||
|
||||
callComplete:
|
||||
callComplete: nop
|
||||
|
||||
nop
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue