From d7900d016e39d30279825b4715af1c3920cf5586 Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Mon, 10 Feb 2003 04:51:49 +0000 Subject: [PATCH] I forget --- Doc/RemovedCode.txt | 51 ++++++++++++++++++++++++++++++++++ Doc/Todo.txt | 3 ++ Include/Win32/CxbxKrnl/EmuX.h | 2 +- Source/Win32/CxbxKrnl/EmuX.cpp | 33 +++++++++++----------- 4 files changed, 71 insertions(+), 18 deletions(-) diff --git a/Doc/RemovedCode.txt b/Doc/RemovedCode.txt index 5e0872b2a..e5f256422 100644 --- a/Doc/RemovedCode.txt +++ b/Doc/RemovedCode.txt @@ -1,3 +1,54 @@ +disassemble + + // ****************************************************************** + // * disassemble entry point 0x50 bytes + // ****************************************************************** + { + const int BUF_SIZE = 0x50; + + disassemble_init(0, INTEL_SYNTAX); + + char buf[BUF_SIZE]; /* buffer of bytes to disassemble */ + int pos = 0; /* current position in buffer */ + int size = 0; /* size of instruction */ + struct instr i; /* representation of the code instruction */ + + while(pos > BUF_SIZE) + { + disassemble_address(buf + pos, &i); + + if(size) + { + printf("%.08X: %s", pos, i.mnemonic); + + if(i.destType) + { + printf(" %s", i.dest); + if(i.srcType) + { + printf(", %s", i.src); + if(i.auxType) + { + printf(", %s", i.aux); + } + } + } + + printf("\n"); + + pos += size; + } + else + { + pos++; + } + + } + + disassemble_cleanup(); + } + + xboxkrnl::NtOpenFile : /* diff --git a/Doc/Todo.txt b/Doc/Todo.txt index e93ab8048..b7b74c844 100644 --- a/Doc/Todo.txt +++ b/Doc/Todo.txt @@ -2,6 +2,9 @@ Cxbx Todo: Recent files (for .exe and .xbe) in menu. (Use registry) + Attempt to add compatibility with ME by using LLDT assembly. This + may not even work, but might as well try it. + Xbe files should associate with Cxbx (by user configuration). There should be configuration allowing the Xbe to execute automatically without a GUI at all, or for the Xbe to open in the Cxbx GUI. This diff --git a/Include/Win32/CxbxKrnl/EmuX.h b/Include/Win32/CxbxKrnl/EmuX.h index 876bdb0bd..e196a3649 100644 --- a/Include/Win32/CxbxKrnl/EmuX.h +++ b/Include/Win32/CxbxKrnl/EmuX.h @@ -64,7 +64,7 @@ extern "C" // ****************************************************************** // * func: EmuXInit // ****************************************************************** -CXBXKRNL_API void NTAPI EmuXInit(DebugMode DebugConsole, char *DebugFilename, uint08 *XBEHeader, uint32 XBEHeaderSize, void (*Entry)()); +CXBXKRNL_API void NTAPI EmuXInit(DebugMode DebugConsole, char *DebugFilename, Xbe::Header *XbeHeader, uint32 XbeHeaderSize, void (*Entry)()); // ****************************************************************** // * func: EmuXDummy diff --git a/Source/Win32/CxbxKrnl/EmuX.cpp b/Source/Win32/CxbxKrnl/EmuX.cpp index 728539aed..13c17465b 100644 --- a/Source/Win32/CxbxKrnl/EmuX.cpp +++ b/Source/Win32/CxbxKrnl/EmuX.cpp @@ -51,12 +51,12 @@ namespace xntdll // ****************************************************************** // * static functions // ****************************************************************** -static void EmuXInstallWrappers(void (*Entry)()); +static void EmuXInstallWrappers(void (*Entry)(), Xbe::Header *XbeHeader); // ****************************************************************** // * func: EmuXInit // ****************************************************************** -CXBXKRNL_API void NTAPI EmuXInit(DebugMode DebugConsole, char *DebugFilename, uint08 *XBEHeader, uint32 XBEHeaderSize, void (*Entry)()) +CXBXKRNL_API void NTAPI EmuXInit(DebugMode DebugConsole, char *DebugFilename, Xbe::Header *XbeHeader, uint32 XbeHeaderSize, void (*Entry)()) { // ****************************************************************** // * debug console allocation (if configured) @@ -95,38 +95,35 @@ CXBXKRNL_API void NTAPI EmuXInit(DebugMode DebugConsole, char *DebugFilename, ui " XBEHeaderSize : 0x%.08X\n" " Entry : 0x%.08X\n" ");\n", - DebugConsole, DebugFilename, XBEHeader, XBEHeaderSize, Entry); + DebugConsole, DebugFilename, XbeHeader, XbeHeaderSize, Entry); } // ****************************************************************** // * Locate functions and install wrapper vectors // ****************************************************************** { - EmuXInstallWrappers(Entry); + EmuXInstallWrappers(Entry, XbeHeader); } // ****************************************************************** // * Load the necessary pieces of XBEHeader // ****************************************************************** { + Xbe::Header *MemXbeHeader = (Xbe::Header*)0x00010000; + uint32 old_protection = 0; - VirtualProtect((void*)0x00010000, 0x1000, PAGE_READWRITE, &old_protection); + VirtualProtect(MemXbeHeader, 0x1000, PAGE_READWRITE, &old_protection); // we sure hope we aren't corrupting anything necessary for an .exe to survive :] - uint32 dwSizeofHeaders = *(uint32*)&XBEHeader[0x0108]; - uint32 dwCertificateAddr = *(uint32*)&XBEHeader[0x0118]; - uint32 dwInitFlags = *(uint32*)&XBEHeader[0x0124]; - uint32 dwPeHeapReserve = *(uint32*)&XBEHeader[0x0134]; - uint32 dwPeHeapCommit = *(uint32*)&XBEHeader[0x0138]; + MemXbeHeader->dwSizeofHeaders = XbeHeader->dwSizeofHeaders; + MemXbeHeader->dwCertificateAddr = XbeHeader->dwCertificateAddr; + MemXbeHeader->dwPeHeapReserve = XbeHeader->dwPeHeapReserve; + MemXbeHeader->dwPeHeapCommit = XbeHeader->dwPeHeapCommit; - *(uint32 *)0x00010108 = dwSizeofHeaders; - *(uint32 *)0x00010118 = dwCertificateAddr; - *(uint32 *)0x00010124 = dwInitFlags; - *(uint32 *)0x00010134 = dwPeHeapReserve; - *(uint32 *)0x00010138 = dwPeHeapCommit; + memcpy(&MemXbeHeader->dwInitFlags, &XbeHeader->dwInitFlags, sizeof(XbeHeader->dwInitFlags)); - memcpy((void*)dwCertificateAddr, &XBEHeader[dwCertificateAddr - 0x00010000], sizeof(Xbe::Certificate)); + memcpy((void*)XbeHeader->dwCertificateAddr, &((uint08*)XbeHeader)[XbeHeader->dwCertificateAddr - 0x00010000], sizeof(Xbe::Certificate)); } // ****************************************************************** @@ -229,7 +226,7 @@ inline void EmuXInstallWrapper(void *FunctionAddr, void *WrapperAddr) // ****************************************************************** // * func: EmuXInstallWrappers // ****************************************************************** -void EmuXInstallWrappers(void (*Entry)()) +void EmuXInstallWrappers(void (*Entry)(), Xbe::Header *XbeHeader) { // ****************************************************************** // * debug trace @@ -250,6 +247,8 @@ void EmuXInstallWrappers(void (*Entry)()) printf("EmuXInstallWrappers: mainXapiStartup -> 0x%.08X\n", RealmainXapiStartup); + // Known to work on : XAPILIB Version 1.0.4627 + // ****************************************************************** // * install CreateThread vector // ******************************************************************