Kernel re-organization. Soooo pretty now :-)
This commit is contained in:
parent
66e9158048
commit
6c8676231d
|
@ -140,6 +140,9 @@
|
|||
<File
|
||||
RelativePath="Doc\Changelog.txt">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="Doc\RemovedCode.txt">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="Doc\Thanks.txt">
|
||||
</File>
|
||||
|
|
|
@ -146,6 +146,9 @@ upxCxbx.bat
|
|||
<File
|
||||
RelativePath="Doc\Changelog.txt">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="Doc\RemovedCode.txt">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="Doc\Thanks.txt">
|
||||
</File>
|
||||
|
|
34
CxbxKrnl.dsp
34
CxbxKrnl.dsp
|
@ -128,15 +128,23 @@ SOURCE=.\Doc\Todo.txt
|
|||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Include\Win32\CxbxKrnl\CxbxKrnl.h
|
||||
SOURCE=.\Include\Win32\CxbxKrnl\EmuX.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Include\Win32\CxbxKrnl\EmuXapi.h
|
||||
SOURCE=.\Include\Win32\CxbxKrnl\EmuXFS.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Include\Win32\CxbxKrnl\LDT.h
|
||||
SOURCE=.\Include\Win32\CxbxKrnl\EmuXKrnl.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Include\Win32\CxbxKrnl\EmuXLDT.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Include\Win32\CxbxKrnl\EmuXxapi.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
|
@ -152,20 +160,28 @@ SOURCE=.\Include\Win32\CxbxKrnl\xntdll.h
|
|||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Source\Win32\CxbxKrnl\CxbxKrnl.cpp
|
||||
SOURCE=.\Source\Win32\CxbxKrnl\EmuX.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Source\Win32\CxbxKrnl\EmuXapi.cpp
|
||||
SOURCE=.\Source\Win32\CxbxKrnl\EmuXFS.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Source\Win32\CxbxKrnl\EmuXKrnl.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Source\Win32\CxbxKrnl\EmuXLDT.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Source\Win32\CxbxKrnl\EmuXxapi.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Source\Win32\CxbxKrnl\KernelThunk.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Source\Win32\CxbxKrnl\LDT.cpp
|
||||
# End Source File
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
||||
|
|
|
@ -143,6 +143,9 @@
|
|||
<File
|
||||
RelativePath="Doc\Changelog.txt">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="Doc\RemovedCode.txt">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="Doc\Thanks.txt">
|
||||
</File>
|
||||
|
@ -154,10 +157,19 @@
|
|||
Name="Include"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\Include\Win32\CxbxKrnl\CxbxKrnl.h">
|
||||
RelativePath="Include\Win32\CxbxKrnl\EmuX.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="Include\Win32\CxbxKrnl\LDT.h">
|
||||
RelativePath="Include\Win32\CxbxKrnl\EmuXFS.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="Include\Win32\CxbxKrnl\EmuXKrnl.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="Include\Win32\CxbxKrnl\EmuXLDT.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="Include\Win32\CxbxKrnl\EmuXxapi.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Include\Win32\CxbxKrnl\xntdll.h">
|
||||
|
@ -171,14 +183,23 @@
|
|||
Name="Source"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\Source\Win32\CxbxKrnl\CxbxKrnl.cpp">
|
||||
RelativePath="Source\Win32\CxbxKrnl\EmuX.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="Source\Win32\CxbxKrnl\EmuXFS.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="Source\Win32\CxbxKrnl\EmuXKrnl.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="Source\Win32\CxbxKrnl\EmuXLDT.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="Source\Win32\CxbxKrnl\EmuXxapi.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Source\Win32\CxbxKrnl\KernelThunk.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="Source\Win32\CxbxKrnl\LDT.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
|
|
|
@ -196,8 +196,8 @@ class Exe : public Error
|
|||
// ******************************************************************
|
||||
// * PE File/Segment alignments: these must always both equal 0x0020
|
||||
// ******************************************************************
|
||||
static uint32 PE_FILE_ALIGN (0x0020);
|
||||
static uint32 PE_SEGM_ALIGN (0x0020);
|
||||
#define PE_FILE_ALIGN 0x00000020 // File alignment
|
||||
#define PE_SEGM_ALIGN 0x00000020 // Segment alignment
|
||||
|
||||
// ******************************************************************
|
||||
// * Section Characeristics
|
||||
|
|
|
@ -291,18 +291,18 @@ class Xbe : public Error
|
|||
// ******************************************************************
|
||||
// * Debug / Retail XOR Keys
|
||||
// ******************************************************************
|
||||
const uint32 XOR_EP_DEBUG = 0x94859D4B; // Entry Point (Debug)
|
||||
const uint32 XOR_EP_RETAIL = 0xA8FC57AB; // Entry Point (Retail)
|
||||
const uint32 XOR_KT_DEBUG = 0xEFB1F152; // Kernel Thunk (Debug)
|
||||
const uint32 XOR_KT_RETAIL = 0x5B6D40B6; // Kernel Thunk (Retail)
|
||||
const uint32 XOR_EP_DEBUG = 0x94859D4B; // Entry Point (Debug)
|
||||
const uint32 XOR_EP_RETAIL = 0xA8FC57AB; // Entry Point (Retail)
|
||||
const uint32 XOR_KT_DEBUG = 0xEFB1F152; // Kernel Thunk (Debug)
|
||||
const uint32 XOR_KT_RETAIL = 0x5B6D40B6; // Kernel Thunk (Retail)
|
||||
|
||||
// ******************************************************************
|
||||
// * Game region flags for XBE certificate
|
||||
// ******************************************************************
|
||||
const uint32 XBEIMAGE_GAME_REGION_NA = 0x00000001;
|
||||
const uint32 XBEIMAGE_GAME_REGION_JAPAN = 0x00000002;
|
||||
const uint32 XBEIMAGE_GAME_REGION_RESTOFWORLD = 0x00000004;
|
||||
const uint32 XBEIMAGE_GAME_REGION_MANUFACTURING = 0x80000000;
|
||||
const uint32 XBEIMAGE_GAME_REGION_NA = 0x00000001;
|
||||
const uint32 XBEIMAGE_GAME_REGION_JAPAN = 0x00000002;
|
||||
const uint32 XBEIMAGE_GAME_REGION_RESTOFWORLD = 0x00000004;
|
||||
const uint32 XBEIMAGE_GAME_REGION_MANUFACTURING = 0x80000000;
|
||||
|
||||
// ******************************************************************
|
||||
// * Media type flags for XBE certificate
|
||||
|
|
|
@ -52,7 +52,7 @@ typedef signed long sint32;
|
|||
// ******************************************************************
|
||||
// * Version Information
|
||||
// ******************************************************************
|
||||
#define CXBX_VERSION "0.6.0-pre10"
|
||||
#define CXBX_VERSION "0.6.0-pre11"
|
||||
|
||||
// ******************************************************************
|
||||
// * Define this to trace intercepted function calls
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo,
|
||||
// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm,
|
||||
// *
|
||||
// * Cxbx->Win32->CxbxKrnl->CxbxKrnl.h
|
||||
// * Cxbx->Win32->CxbxKrnl->EmuX.h
|
||||
// *
|
||||
// * This file is part of the Cxbx project.
|
||||
// *
|
||||
|
@ -31,29 +31,8 @@
|
|||
// * All rights reserved
|
||||
// *
|
||||
// ******************************************************************
|
||||
#ifndef CXBXKRNL_H
|
||||
#define CXBXKRNL_H
|
||||
|
||||
// ******************************************************************
|
||||
// * func: EmuXSwapFS
|
||||
// ******************************************************************
|
||||
// *
|
||||
// * This function is used to swap between the native Win2k/XP FS:
|
||||
// * structure, and the EmuX FS: structure. Before running Windows
|
||||
// * code, you *must* swap over to Win2k/XP FS. Similarly, before
|
||||
// * running Xbox code, you *must* swap back over to EmuX FS.
|
||||
// *
|
||||
// ******************************************************************
|
||||
inline void EmuXSwapFS()
|
||||
{
|
||||
__asm
|
||||
{
|
||||
mov ax, fs:[0x14] // FS.ArbitraryUserPointer
|
||||
mov fs, ax
|
||||
}
|
||||
}
|
||||
|
||||
void EmuXGenerateFS();
|
||||
#ifndef EMUX_H
|
||||
#define EMUX_H
|
||||
|
||||
// ******************************************************************
|
||||
// * namespace used to avoid collisions with ntdll and win32
|
||||
|
@ -61,9 +40,13 @@ void EmuXGenerateFS();
|
|||
namespace xboxkrnl
|
||||
{
|
||||
#include <xboxkrnl/xboxkrnl.h>
|
||||
#include "EmuXapi.h"
|
||||
#include "EmuXxapi.h"
|
||||
};
|
||||
|
||||
#include "EmuXKrnl.h"
|
||||
#include "EmuXLDT.h"
|
||||
#include "EmuXFS.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
|
@ -78,11 +61,6 @@ extern "C"
|
|||
#define CXBXKRNL_API DECLSPEC_EXPORT
|
||||
#endif
|
||||
|
||||
// ******************************************************************
|
||||
// * data: KernelThunkTable
|
||||
// ******************************************************************
|
||||
extern CXBXKRNL_API uint32 KernelThunkTable[367];
|
||||
|
||||
// ******************************************************************
|
||||
// * func: EmuXInit
|
||||
// ******************************************************************
|
||||
|
@ -98,6 +76,11 @@ CXBXKRNL_API void NTAPI EmuXDummy();
|
|||
// ******************************************************************
|
||||
CXBXKRNL_API void NTAPI EmuXPanic();
|
||||
|
||||
// ******************************************************************
|
||||
// * data: KernelThunkTable
|
||||
// ******************************************************************
|
||||
extern CXBXKRNL_API uint32 KernelThunkTable[367];
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,66 @@
|
|||
// ******************************************************************
|
||||
// *
|
||||
// * .,-::::: .,:: .::::::::. .,:: .:
|
||||
// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;;
|
||||
// * [[[ '[[,,[[' [[[__[[\. '[[,,[['
|
||||
// * $$$ Y$$$P $$""""Y$$ Y$$$P
|
||||
// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo,
|
||||
// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm,
|
||||
// *
|
||||
// * Cxbx->Win32->CxbxKrnl->EmuXFS.h
|
||||
// *
|
||||
// * This file is part of the Cxbx project.
|
||||
// *
|
||||
// * Cxbx and Cxbe are free software; you can redistribute them
|
||||
// * and/or modify them under the terms of the GNU General Public
|
||||
// * License as published by the Free Software Foundation; either
|
||||
// * version 2 of the license, or (at your option) any later version.
|
||||
// *
|
||||
// * This program is distributed in the hope that it will be useful,
|
||||
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// * GNU General Public License for more details.
|
||||
// *
|
||||
// * You should have recieved a copy of the GNU General Public License
|
||||
// * along with this program; see the file COPYING.
|
||||
// * If not, write to the Free Software Foundation, Inc.,
|
||||
// * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA.
|
||||
// *
|
||||
// * (c) 2002-2003 Aaron Robinson <caustik@caustik.com>
|
||||
// *
|
||||
// * All rights reserved
|
||||
// *
|
||||
// ******************************************************************
|
||||
#ifndef EMUXFS_H
|
||||
#define EMUXFS_H
|
||||
|
||||
// ******************************************************************
|
||||
// * func: EmuXSwapFS
|
||||
// ******************************************************************
|
||||
// *
|
||||
// * This function is used to swap between the native Win2k/XP FS:
|
||||
// * structure, and the EmuX FS: structure. Before running Windows
|
||||
// * code, you *must* swap over to Win2k/XP FS. Similarly, before
|
||||
// * running Xbox code, you *must* swap back over to EmuX FS.
|
||||
// *
|
||||
// ******************************************************************
|
||||
static inline void EmuXSwapFS()
|
||||
{
|
||||
__asm
|
||||
{
|
||||
mov ax, fs:[0x14] // FS.ArbitraryUserPointer
|
||||
mov fs, ax
|
||||
}
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * func: EmuXGenerateFS
|
||||
// ******************************************************************
|
||||
void EmuXGenerateFS();
|
||||
|
||||
// ******************************************************************
|
||||
// * func: EmuXInitFS
|
||||
// ******************************************************************
|
||||
void EmuXInitFS();
|
||||
|
||||
#endif
|
|
@ -7,7 +7,7 @@
|
|||
// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo,
|
||||
// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm,
|
||||
// *
|
||||
// * Cxbx->Win32->CxbxKrnl->LDT.h
|
||||
// * Cxbx->Win32->CxbxKrnl->EmuXKrnl.h
|
||||
// *
|
||||
// * This file is part of the Cxbx project.
|
||||
// *
|
||||
|
@ -31,13 +31,8 @@
|
|||
// * All rights reserved
|
||||
// *
|
||||
// ******************************************************************
|
||||
#ifndef LDT_H
|
||||
#define LDT_H
|
||||
#ifndef EMUXKRNL_H
|
||||
#define EMUXKRNL_H
|
||||
|
||||
void LDTSystemInit();
|
||||
|
||||
uint16 LDTAllocate(uint32 dwBaseAddr, uint32 dwLimit);
|
||||
|
||||
void LDTDeallocate(uint16 wSelector);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,52 @@
|
|||
// ******************************************************************
|
||||
// *
|
||||
// * .,-::::: .,:: .::::::::. .,:: .:
|
||||
// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;;
|
||||
// * [[[ '[[,,[[' [[[__[[\. '[[,,[['
|
||||
// * $$$ Y$$$P $$""""Y$$ Y$$$P
|
||||
// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo,
|
||||
// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm,
|
||||
// *
|
||||
// * Cxbx->Win32->CxbxKrnl->EmuXLDT.h
|
||||
// *
|
||||
// * This file is part of the Cxbx project.
|
||||
// *
|
||||
// * Cxbx and Cxbe are free software; you can redistribute them
|
||||
// * and/or modify them under the terms of the GNU General Public
|
||||
// * License as published by the Free Software Foundation; either
|
||||
// * version 2 of the license, or (at your option) any later version.
|
||||
// *
|
||||
// * This program is distributed in the hope that it will be useful,
|
||||
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// * GNU General Public License for more details.
|
||||
// *
|
||||
// * You should have recieved a copy of the GNU General Public License
|
||||
// * along with this program; see the file COPYING.
|
||||
// * If not, write to the Free Software Foundation, Inc.,
|
||||
// * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA.
|
||||
// *
|
||||
// * (c) 2002-2003 Aaron Robinson <caustik@caustik.com>
|
||||
// *
|
||||
// * All rights reserved
|
||||
// *
|
||||
// ******************************************************************
|
||||
#ifndef EMUXLDT_H
|
||||
#define EMUXLDT_H
|
||||
|
||||
// ******************************************************************
|
||||
// * func: EmuXInitLDT
|
||||
// ******************************************************************
|
||||
void EmuXInitLDT();
|
||||
|
||||
// ******************************************************************
|
||||
// * func: EmuXAllocateLDT
|
||||
// ******************************************************************
|
||||
uint16 EmuXAllocateLDT(uint32 dwBaseAddr, uint32 dwLimit);
|
||||
|
||||
// ******************************************************************
|
||||
// * func: EmuXDeallocateLDT
|
||||
// ******************************************************************
|
||||
void EmuXDeallocateLDT(uint16 wSelector);
|
||||
|
||||
#endif
|
|
@ -7,7 +7,7 @@
|
|||
// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo,
|
||||
// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm,
|
||||
// *
|
||||
// * Cxbx->Win32->CxbxKrnl->EmuXapi.h
|
||||
// * Cxbx->Win32->CxbxKrnl->EmuXxapi.h
|
||||
// *
|
||||
// * This file is part of the Cxbx project.
|
||||
// *
|
||||
|
@ -34,7 +34,7 @@
|
|||
#ifndef EMUXAPI_H
|
||||
#define EMUXAPI_H
|
||||
|
||||
#include "CxbxKrnl.h"
|
||||
#include "EmuX.h"
|
||||
|
||||
// ******************************************************************
|
||||
// * calling conventions
|
||||
|
@ -47,9 +47,9 @@
|
|||
typedef int BOOL;
|
||||
|
||||
// ******************************************************************
|
||||
// * func: EmuCreateThread
|
||||
// * func: EmuXCreateThread
|
||||
// ******************************************************************
|
||||
HANDLE WINAPI EmuCreateThread
|
||||
HANDLE WINAPI EmuXCreateThread
|
||||
(
|
||||
LPSECURITY_ATTRIBUTES lpThreadAttributes,
|
||||
DWORD dwStackSize,
|
||||
|
@ -60,9 +60,9 @@ HANDLE WINAPI EmuCreateThread
|
|||
);
|
||||
|
||||
// ******************************************************************
|
||||
// * func: EmuCloseHandle
|
||||
// * func: EmuXCloseHandle
|
||||
// ******************************************************************
|
||||
BOOL WINAPI EmuCloseHandle
|
||||
BOOL WINAPI EmuXCloseHandle
|
||||
(
|
||||
HANDLE hObject
|
||||
);
|
|
@ -43,7 +43,7 @@ Exe::Exe(const char *x_szFilename)
|
|||
{
|
||||
ConstructorInit();
|
||||
|
||||
printf("Exe::Exe: Reading Exe file...");
|
||||
printf("Exe::Exe: Opening Exe file...");
|
||||
|
||||
FILE *ExeFile = fopen(x_szFilename, "rb");
|
||||
|
||||
|
@ -52,7 +52,7 @@ Exe::Exe(const char *x_szFilename)
|
|||
// ******************************************************************
|
||||
if(ExeFile == 0)
|
||||
{
|
||||
SetError("could not open .exe file.", true);
|
||||
SetError("Could not open Exe file.", true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ Exe::Exe(const char *x_szFilename)
|
|||
|
||||
if(fread(&m_DOSHeader.m_magic, sizeof(m_DOSHeader.m_magic), 1, ExeFile) != 1)
|
||||
{
|
||||
SetError("unexpected read error while reading magic number", true);
|
||||
SetError("Unexpected read error while reading magic number", true);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ Exe::Exe(const char *x_szFilename)
|
|||
|
||||
if(fread(&m_DOSHeader.m_cblp, sizeof(m_DOSHeader)-2, 1, ExeFile) != 1)
|
||||
{
|
||||
SetError("unexpected read error while reading dos header", true);
|
||||
SetError("Unexpected read error while reading DOS stub", true);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -98,13 +98,13 @@ Exe::Exe(const char *x_szFilename)
|
|||
|
||||
if(fread(&m_Header, sizeof(m_Header), 1, ExeFile) != 1)
|
||||
{
|
||||
SetError("unexpected read error while reading pe header", true);
|
||||
SetError("Unexpected read error while reading PE header", true);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if(m_Header.m_magic != *(uint32*)"PE\0\0")
|
||||
{
|
||||
SetError("invalid file, could not locate PE header", true);
|
||||
SetError("Invalid file (could not locate PE header)", true);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -119,13 +119,13 @@ Exe::Exe(const char *x_szFilename)
|
|||
|
||||
if(fread(&m_OptionalHeader, sizeof(m_OptionalHeader), 1, ExeFile) != 1)
|
||||
{
|
||||
SetError("unexpected read error while reading optional header", true);
|
||||
SetError("Unexpected read error while reading PE optional header", true);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if(m_OptionalHeader.m_magic != 0x010B)
|
||||
{
|
||||
SetError("invalid file, could not locate optional header", true);
|
||||
SetError("Invalid file (could not locate PE optional header)", true);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -147,7 +147,7 @@ Exe::Exe(const char *x_szFilename)
|
|||
if(fread(&m_SectionHeader[v], sizeof(SectionHeader), 1, ExeFile) != 1)
|
||||
{
|
||||
char buffer[255];
|
||||
sprintf(buffer, "could not read pe section header %d (%Xh)", v, v);
|
||||
sprintf(buffer, "Could not read PE section header %d (%Xh)", v, v);
|
||||
SetError(buffer, true);
|
||||
goto cleanup;
|
||||
}
|
||||
|
@ -190,7 +190,7 @@ Exe::Exe(const char *x_szFilename)
|
|||
if(fread(m_bzSection[v], raw_size, 1, ExeFile) != 1)
|
||||
{
|
||||
char buffer[255];
|
||||
sprintf(buffer, "could not read pe section %d (%Xh)", v, v);
|
||||
sprintf(buffer, "Could not read PE section %d (%Xh)", v, v);
|
||||
SetError(buffer, true);
|
||||
goto cleanup;
|
||||
}
|
||||
|
@ -200,12 +200,15 @@ Exe::Exe(const char *x_szFilename)
|
|||
}
|
||||
}
|
||||
|
||||
printf("Exe::Exe: .Exe was successfully opened.\n", x_szFilename);
|
||||
printf("Exe::Exe: Exe was successfully opened.\n", x_szFilename);
|
||||
|
||||
cleanup:
|
||||
|
||||
if(GetError() != 0)
|
||||
{
|
||||
printf("FAILED!\n");
|
||||
printf("Exe::Exe: ERROR -> %s\n", GetError());
|
||||
}
|
||||
|
||||
fclose(ExeFile);
|
||||
}
|
||||
|
@ -243,7 +246,7 @@ void Exe::Export(const char *x_szExeFilename)
|
|||
if(GetError() != 0)
|
||||
return;
|
||||
|
||||
printf("Exe::Export: Writing Exe file...");
|
||||
printf("Exe::Export: Opening Exe file...");
|
||||
|
||||
FILE *ExeFile = fopen(x_szExeFilename, "wb");
|
||||
|
||||
|
@ -252,7 +255,7 @@ void Exe::Export(const char *x_szExeFilename)
|
|||
// ******************************************************************
|
||||
if(ExeFile == 0)
|
||||
{
|
||||
SetError("could not open .exe file.", false);
|
||||
SetError("Could not open .exe file.", false);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -266,7 +269,7 @@ void Exe::Export(const char *x_szExeFilename)
|
|||
|
||||
if(fwrite(bzDOSStub, sizeof(bzDOSStub), 1, ExeFile) != 1)
|
||||
{
|
||||
SetError("could not write dos stub", false);
|
||||
SetError("Could not write dos stub", false);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -281,7 +284,7 @@ void Exe::Export(const char *x_szExeFilename)
|
|||
|
||||
if(fwrite(&m_Header, sizeof(Header), 1, ExeFile) != 1)
|
||||
{
|
||||
SetError("could not write pe header", false);
|
||||
SetError("Could not write PE header", false);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -296,7 +299,7 @@ void Exe::Export(const char *x_szExeFilename)
|
|||
|
||||
if(fwrite(&m_OptionalHeader, sizeof(OptionalHeader), 1, ExeFile) != 1)
|
||||
{
|
||||
SetError("could not write pe optional header", false);
|
||||
SetError("Could not write PE optional header", false);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -316,7 +319,7 @@ void Exe::Export(const char *x_szExeFilename)
|
|||
if(fwrite(&m_SectionHeader[v], sizeof(SectionHeader), 1, ExeFile) != 1)
|
||||
{
|
||||
char buffer[255];
|
||||
sprintf(buffer, "could not write pe section header %d (%Xh)", v, v);
|
||||
sprintf(buffer, "Could not write PE section header %d (%Xh)", v, v);
|
||||
SetError(buffer, false);
|
||||
goto cleanup;
|
||||
}
|
||||
|
@ -349,7 +352,7 @@ void Exe::Export(const char *x_szExeFilename)
|
|||
if(fwrite(m_bzSection[v], RawSize, 1, ExeFile) != 1)
|
||||
{
|
||||
char Buffer[255];
|
||||
sprintf(Buffer, "could not write pe section %d (%Xh)", v, v);
|
||||
sprintf(Buffer, "Could not write PE section %d (%Xh)", v, v);
|
||||
SetError(Buffer, false);
|
||||
goto cleanup;
|
||||
}
|
||||
|
@ -363,7 +366,10 @@ void Exe::Export(const char *x_szExeFilename)
|
|||
cleanup:
|
||||
|
||||
if(GetError() != 0)
|
||||
{
|
||||
printf("FAILED!\n");
|
||||
printf("Exe::Export: ERROR -> %s\n", GetError());
|
||||
}
|
||||
|
||||
fclose(ExeFile);
|
||||
|
||||
|
|
|
@ -75,4 +75,4 @@ extern uint08 OpenXDK[] =
|
|||
0x33, 0xFA, 0x00, 0x13, 0x0F, 0x13, 0xBE, 0x06, 0x03,
|
||||
};
|
||||
|
||||
extern uint32 dwSizeOfOpenXDK = 0x0000017B;
|
||||
extern uint32 dwSizeOfOpenXDK = 0x0000017B;
|
||||
|
|
|
@ -34,7 +34,6 @@
|
|||
#include "Cxbx.h"
|
||||
|
||||
#include <memory.h>
|
||||
#include <stdlib.h>
|
||||
#include <locale.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
@ -46,7 +45,7 @@ Xbe::Xbe(const char *x_szFilename)
|
|||
{
|
||||
ConstructorInit();
|
||||
|
||||
printf("Xbe::Xbe: Reading Xbe file...");
|
||||
printf("Xbe::Xbe: Opening Xbe file...");
|
||||
|
||||
FILE *XbeFile = fopen(x_szFilename, "rb");
|
||||
|
||||
|
@ -55,7 +54,7 @@ Xbe::Xbe(const char *x_szFilename)
|
|||
// ******************************************************************
|
||||
if(XbeFile == 0)
|
||||
{
|
||||
SetError("could not open .xbe file.", true);
|
||||
SetError("Could not open Xbe file.", true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -69,13 +68,13 @@ Xbe::Xbe(const char *x_szFilename)
|
|||
|
||||
if(fread(&m_Header, sizeof(m_Header), 1, XbeFile) != 1)
|
||||
{
|
||||
SetError("unexpected end of file while reading .xbe image header", true);
|
||||
SetError("Unexpected end of file while reading Xbe Image Header", true);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if(m_Header.dwMagic != *(uint32 *)"XBEH")
|
||||
{
|
||||
SetError("invalid magic number in .xbe file", true);
|
||||
SetError("Invalid magic number in Xbe file", true);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -95,7 +94,7 @@ Xbe::Xbe(const char *x_szFilename)
|
|||
|
||||
if(fread(m_HeaderEx, ExSize, 1, XbeFile) != 1)
|
||||
{
|
||||
SetError("unexpected end of file while reading .xbe image header (ex)", true);
|
||||
SetError("Unexpected end of file while reading Xbe Image Header (Ex)", true);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -112,7 +111,7 @@ Xbe::Xbe(const char *x_szFilename)
|
|||
|
||||
if(fread(&m_Certificate, sizeof(m_Certificate), 1, XbeFile) != 1)
|
||||
{
|
||||
SetError("unexpected end of file while reading .xbe certificate", true);
|
||||
SetError("Unexpected end of file while reading Xbe Certificate", true);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -121,6 +120,8 @@ Xbe::Xbe(const char *x_szFilename)
|
|||
wcstombs(m_szAsciiTitle, m_Certificate.wszTitleName, 40);
|
||||
|
||||
printf("OK\n");
|
||||
|
||||
printf("Xbe::Xbe: Title identified as %s\n", m_szAsciiTitle);
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
|
@ -140,7 +141,7 @@ Xbe::Xbe(const char *x_szFilename)
|
|||
if(fread(&m_SectionHeader[v], sizeof(*m_SectionHeader), 1, XbeFile) != 1)
|
||||
{
|
||||
char buffer[255];
|
||||
sprintf(buffer, "unexpected end of file while reading .xbe section %d (%Xh)", v, v);
|
||||
sprintf(buffer, "Unexpected end of file while reading Xbe Section Header %d (%Xh)", v, v);
|
||||
SetError(buffer, true);
|
||||
goto cleanup;
|
||||
}
|
||||
|
@ -172,7 +173,7 @@ Xbe::Xbe(const char *x_szFilename)
|
|||
break;
|
||||
}
|
||||
|
||||
printf("OK [%s]\n", m_szSectionName[v]);
|
||||
printf("OK (%s)\n", m_szSectionName[v]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -194,7 +195,7 @@ Xbe::Xbe(const char *x_szFilename)
|
|||
if(fread(&m_LibraryVersion[v], sizeof(*m_LibraryVersion), 1, XbeFile) != 1)
|
||||
{
|
||||
char buffer[255];
|
||||
sprintf(buffer, "unexpected end of file while reading .xbe library version %d (%Xh)", v, v);
|
||||
sprintf(buffer, "Unexpected end of file while reading Xbe Library Version %d (%Xh)", v, v);
|
||||
SetError(buffer, true);
|
||||
goto cleanup;
|
||||
}
|
||||
|
@ -210,7 +211,7 @@ Xbe::Xbe(const char *x_szFilename)
|
|||
|
||||
if(m_Header.dwKernelLibraryVersionAddr == 0)
|
||||
{
|
||||
SetError("could not locate kernel library version", true);
|
||||
SetError("Could not locate kernel library version", true);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -220,7 +221,7 @@ Xbe::Xbe(const char *x_szFilename)
|
|||
|
||||
if(fread(m_KernelLibraryVersion, sizeof(*m_LibraryVersion), 1, XbeFile) != 1)
|
||||
{
|
||||
SetError("unexpected end of file while reading .xbe kernel version", true);
|
||||
SetError("Unexpected end of file while reading Xbe Kernel Version", true);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -231,11 +232,11 @@ Xbe::Xbe(const char *x_szFilename)
|
|||
// * read xbe xapi library version
|
||||
// ******************************************************************
|
||||
{
|
||||
printf("Xbe::Xbe: Reading XAPI Library Version...");
|
||||
printf("Xbe::Xbe: Reading Xapi Library Version...");
|
||||
|
||||
if(m_Header.dwXAPILibraryVersionAddr == 0)
|
||||
{
|
||||
SetError("could not locate xapi library version", true);
|
||||
SetError("Could not locate Xapi Library Version", true);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -245,7 +246,7 @@ Xbe::Xbe(const char *x_szFilename)
|
|||
|
||||
if(fread(m_XAPILibraryVersion, sizeof(*m_LibraryVersion), 1, XbeFile) != 1)
|
||||
{
|
||||
SetError("unexpected end of file while reading .xbe xapi version", true);
|
||||
SetError("Unexpected end of file while reading Xbe Xapi Version", true);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -283,7 +284,7 @@ Xbe::Xbe(const char *x_szFilename)
|
|||
if(fread(m_bzSection[v], RawSize, 1, XbeFile) != 1)
|
||||
{
|
||||
char buffer[255];
|
||||
sprintf(buffer, "unexpected end of file while reading .xbe section %d (%Xh) (%s)", v, v, m_szSectionName[v]);
|
||||
sprintf(buffer, "Unexpected end of file while reading Xbe Section %d (%Xh) (%s)", v, v, m_szSectionName[v]);
|
||||
SetError(buffer, true);
|
||||
goto cleanup;
|
||||
}
|
||||
|
@ -303,7 +304,7 @@ Xbe::Xbe(const char *x_szFilename)
|
|||
|
||||
if(Addr == 0)
|
||||
{
|
||||
SetError("could not locate thread local storage struct.", true);
|
||||
SetError("Could not locate Thread Local Storage", true);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -317,7 +318,10 @@ Xbe::Xbe(const char *x_szFilename)
|
|||
cleanup:
|
||||
|
||||
if(GetError() != 0)
|
||||
{
|
||||
printf("FAILED!\n");
|
||||
printf("Xbe::Xbe: ERROR -> %s\n", GetError());
|
||||
}
|
||||
|
||||
fclose(XbeFile);
|
||||
|
||||
|
@ -335,7 +339,7 @@ Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail)
|
|||
|
||||
time(&CurrentTime);
|
||||
|
||||
printf("Xbe::Xbe: Pass 1...");
|
||||
printf("Xbe::Xbe: Pass 1 (Simple Pass)...");
|
||||
|
||||
// ******************************************************************
|
||||
// * Pass 1
|
||||
|
@ -410,7 +414,7 @@ Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail)
|
|||
|
||||
printf("OK\n");
|
||||
|
||||
printf("Xbe::Xbe: Pass 2...");
|
||||
printf("Xbe::Xbe: Pass 2 (Calculating Requirements)...");
|
||||
|
||||
// ******************************************************************
|
||||
// * Pass 2
|
||||
|
@ -496,7 +500,7 @@ Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail)
|
|||
|
||||
printf("OK\n");
|
||||
|
||||
printf("Xbe::Xbe: Pass 3...");
|
||||
printf("Xbe::Xbe: Pass 3 (Generating Xbe)...\n");
|
||||
|
||||
// ******************************************************************
|
||||
// * Pass 3
|
||||
|
@ -508,6 +512,8 @@ Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail)
|
|||
// * encode entry point
|
||||
// ******************************************************************
|
||||
{
|
||||
printf("Xbe::Xbe: Encoding %s Entry Point...", x_bRetail?"Retail":"Debug");
|
||||
|
||||
uint32 ep = x_Exe->m_OptionalHeader.m_entry + m_Header.dwPeBaseAddr;
|
||||
|
||||
if(x_bRetail)
|
||||
|
@ -516,6 +522,8 @@ Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail)
|
|||
ep ^= XOR_EP_DEBUG;
|
||||
|
||||
m_Header.dwEntryAddr = ep;
|
||||
|
||||
printf("OK (0x%.08X)\n", ep);
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
|
@ -528,9 +536,13 @@ Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail)
|
|||
// ******************************************************************
|
||||
if(m_Header.dwSizeofHeaders > sizeof(m_Header))
|
||||
{
|
||||
printf("Xbe::Xbe: Found Extra Header Bytes...");
|
||||
|
||||
uint32 ExSize = RoundUp(m_Header.dwSizeofHeaders - sizeof(m_Header), 0x1000);
|
||||
|
||||
m_HeaderEx = new char[ExSize];
|
||||
|
||||
printf("OK\n");
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
|
@ -660,8 +672,12 @@ Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail)
|
|||
// ******************************************************************
|
||||
uint32 hwc_secn = hwc_htrc + (m_Header.dwSections+1)*2;
|
||||
|
||||
printf("Xbe::Xbe: Generating Section Headers...\n");
|
||||
|
||||
for(uint32 v=0;v<m_Header.dwSections;v++)
|
||||
{
|
||||
printf("Xbe::Xbe: Generating Section Header %.04X...", v);
|
||||
|
||||
uint32 characteristics = x_Exe->m_SectionHeader[v].m_characteristics;
|
||||
|
||||
memset(&m_SectionHeader[v].dwFlags, 0, sizeof(m_SectionHeader->dwFlags));
|
||||
|
@ -748,6 +764,8 @@ Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail)
|
|||
memcpy(Buffer, &m_SectionHeader[v], sizeof(*m_SectionHeader));
|
||||
|
||||
Buffer += sizeof(*m_SectionHeader);
|
||||
|
||||
printf("OK\n");
|
||||
}
|
||||
|
||||
hwc = hwc_secn;
|
||||
|
@ -767,6 +785,8 @@ Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail)
|
|||
// * write default "OpenXDK" logo bitmap
|
||||
// ******************************************************************
|
||||
{
|
||||
printf("Xbe::Xbe: Generating \"OpenXDK\" Logo Bitmap...");
|
||||
|
||||
uint08 *RawAddr = GetAddr(m_Header.dwLogoBitmapAddr);
|
||||
|
||||
memset(RawAddr, 0, 100*17);
|
||||
|
@ -774,30 +794,36 @@ Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail)
|
|||
memcpy(RawAddr, OpenXDK, dwSizeOfOpenXDK);
|
||||
|
||||
m_Header.dwSizeofLogoBitmap = dwSizeOfOpenXDK;
|
||||
|
||||
printf("OK\n");
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * write sections
|
||||
// ******************************************************************
|
||||
{
|
||||
printf("Xbe::Xbe: Generating Sections...\n");
|
||||
|
||||
m_bzSection = new uint08*[m_Header.dwSections];
|
||||
|
||||
memset(m_bzSection, 0, m_Header.dwSections);
|
||||
|
||||
for(uint32 v=0;v<m_Header.dwSections;v++)
|
||||
{
|
||||
printf("Xbe::Xbe: Generating Section %.04X...", v);
|
||||
|
||||
uint32 RawSize = m_SectionHeader[v].dwSizeofRaw;
|
||||
|
||||
m_bzSection[v] = new uint08[RawSize];
|
||||
|
||||
memcpy(m_bzSection[v], x_Exe->m_bzSection[v], RawSize);
|
||||
|
||||
printf("OK\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("OK\n");
|
||||
|
||||
printf("Xbe::Xbe: Pass 4...\n");
|
||||
printf("Xbe::Xbe: Pass 4 (Finalizing)...\n");
|
||||
|
||||
// ******************************************************************
|
||||
// * Pass 4
|
||||
|
@ -811,6 +837,10 @@ Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail)
|
|||
// * Relocate to base : 0x00010000
|
||||
// ******************************************************************
|
||||
{
|
||||
printf("Xbe::Xbe: Relocating to Base 0x00010000...");
|
||||
|
||||
uint32 fixCount = 0;
|
||||
|
||||
uint32 relo_addr = x_Exe->m_OptionalHeader.m_image_data_directory[5].m_virtual_addr;
|
||||
uint32 relo_size = x_Exe->m_OptionalHeader.m_image_data_directory[5].m_size;
|
||||
|
||||
|
@ -823,8 +853,6 @@ Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail)
|
|||
// ******************************************************************
|
||||
if(reloc != 0)
|
||||
{
|
||||
printf("Xbe::Xbe: Relocating...");
|
||||
|
||||
uint32 v = 0;
|
||||
|
||||
// ******************************************************************
|
||||
|
@ -857,6 +885,8 @@ Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail)
|
|||
// ******************************************************************
|
||||
if(type == IMAGE_REL_BASED_HIGHLOW)
|
||||
{
|
||||
fixCount++;
|
||||
|
||||
uint32 dwFixAddr = block_addr + (data & 0x0FFF) + m_Header.dwPeBaseAddr;
|
||||
|
||||
uint08 *bzModRVA = GetAddr(dwFixAddr);
|
||||
|
@ -866,16 +896,16 @@ Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail)
|
|||
}
|
||||
else
|
||||
{
|
||||
SetError("unsupported relocation type", true);
|
||||
SetError("Unsupported relocation type", true);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
v+=2;
|
||||
}
|
||||
}
|
||||
|
||||
printf("OK\n");
|
||||
}
|
||||
|
||||
printf("OK (%d Fixups)\n", fixCount);
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
|
@ -896,7 +926,10 @@ Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail)
|
|||
cleanup:
|
||||
|
||||
if(GetError() != 0)
|
||||
{
|
||||
printf("FAILED!\n");
|
||||
printf("Xbe::Xbe: ERROR -> %s\n", GetError());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -941,7 +974,7 @@ void Xbe::Export(const char *x_szXbeFilename)
|
|||
// ******************************************************************
|
||||
if(XbeFile == 0)
|
||||
{
|
||||
SetError("could not open .xbe file.", false);
|
||||
SetError("Could not open .xbe file.", false);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -955,7 +988,7 @@ void Xbe::Export(const char *x_szXbeFilename)
|
|||
|
||||
if(fwrite(&m_Header, sizeof(m_Header), 1, XbeFile) != 1)
|
||||
{
|
||||
SetError("recieved error while writing .xbe image header", false);
|
||||
SetError("Unexpected write error while writing Xbe Image Header", false);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -965,7 +998,7 @@ void Xbe::Export(const char *x_szXbeFilename)
|
|||
|
||||
if(fwrite(m_HeaderEx, m_Header.dwSizeofHeaders, 1, XbeFile) != 1)
|
||||
{
|
||||
SetError("recieved error while writing .xbe image header (ex)", false);
|
||||
SetError("Unexpected write error while writing Xbe Image Header (Ex)", false);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -982,7 +1015,7 @@ void Xbe::Export(const char *x_szXbeFilename)
|
|||
|
||||
if(fwrite(&m_Certificate, sizeof(m_Certificate), 1, XbeFile) != 1)
|
||||
{
|
||||
SetError("recieved error while writing .xbe certificate", false);
|
||||
SetError("Unexpected write error while writing Xbe Certificate", false);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -1004,7 +1037,7 @@ void Xbe::Export(const char *x_szXbeFilename)
|
|||
if(fwrite(&m_SectionHeader[v], sizeof(*m_SectionHeader), 1, XbeFile) != 1)
|
||||
{
|
||||
char Buffer[255];
|
||||
sprintf(Buffer, "recieved error while writing .xbe section %d (%Xh)", v, v);
|
||||
sprintf(Buffer, "Unexpected write error while writing Xbe Section %d (%Xh)", v, v);
|
||||
SetError(Buffer, false);
|
||||
goto cleanup;
|
||||
}
|
||||
|
@ -1021,7 +1054,7 @@ void Xbe::Export(const char *x_szXbeFilename)
|
|||
|
||||
for(uint32 v=0;v<m_Header.dwSections;v++)
|
||||
{
|
||||
printf("Xbe::Export: Writing Section 0x%.04X [%s]...", v, m_szSectionName[v]);
|
||||
printf("Xbe::Export: Writing Section 0x%.04X (%s)...", v, m_szSectionName[v]);
|
||||
|
||||
uint32 RawSize = m_SectionHeader[v].dwSizeofRaw;
|
||||
uint32 RawAddr = m_SectionHeader[v].dwRawAddr;
|
||||
|
@ -1037,7 +1070,7 @@ void Xbe::Export(const char *x_szXbeFilename)
|
|||
if(fwrite(m_bzSection[v], RawSize, 1, XbeFile) != 1)
|
||||
{
|
||||
char Buffer[255];
|
||||
sprintf(Buffer, "recieved error while writing .xbe section %d (%Xh) (%s)", v, v, m_szSectionName[v]);
|
||||
sprintf(Buffer, "Unexpected write error while writing Xbe Section %d (%Xh) (%s)", v, v, m_szSectionName[v]);
|
||||
SetError(Buffer, false);
|
||||
goto cleanup;
|
||||
}
|
||||
|
@ -1083,7 +1116,11 @@ cleanup:
|
|||
// * if we came across an error, delete the file we were creating
|
||||
// ******************************************************************
|
||||
if(GetError() != 0)
|
||||
{
|
||||
remove(x_szXbeFilename);
|
||||
printf("FAILED!\n");
|
||||
printf("Xbe::Export: ERROR -> %s\n", GetError());
|
||||
}
|
||||
|
||||
fclose(XbeFile);
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
|
||||
#include "EmuExe.h"
|
||||
#include "Prolog.h"
|
||||
#include "CxbxKrnl.h"
|
||||
#include "EmuX.h"
|
||||
|
||||
#undef FIELD_OFFSET // prevent macro redefinition warnings
|
||||
#include <windows.h>
|
||||
|
|
|
@ -32,8 +32,8 @@
|
|||
// *
|
||||
// ******************************************************************
|
||||
#include "Cxbx.h"
|
||||
#include "EmuX.h"
|
||||
#include "EmuExe.h"
|
||||
#include "CxbxKrnl.h"
|
||||
#include "WndMain.h"
|
||||
#include "WndAbout.h"
|
||||
|
||||
|
|
|
@ -0,0 +1,236 @@
|
|||
// ******************************************************************
|
||||
// *
|
||||
// * .,-::::: .,:: .::::::::. .,:: .:
|
||||
// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;;
|
||||
// * [[[ '[[,,[[' [[[__[[\. '[[,,[['
|
||||
// * $$$ Y$$$P $$""""Y$$ Y$$$P
|
||||
// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo,
|
||||
// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm,
|
||||
// *
|
||||
// * Cxbx->Win32->CxbxKrnl->EmuX.cpp
|
||||
// *
|
||||
// * This file is part of the Cxbx project.
|
||||
// *
|
||||
// * Cxbx and Cxbe are free software; you can redistribute them
|
||||
// * and/or modify them under the terms of the GNU General Public
|
||||
// * License as published by the Free Software Foundation; either
|
||||
// * version 2 of the license, or (at your option) any later version.
|
||||
// *
|
||||
// * This program is distributed in the hope that it will be useful,
|
||||
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// * GNU General Public License for more details.
|
||||
// *
|
||||
// * You should have recieved a copy of the GNU General Public License
|
||||
// * along with this program; see the file COPYING.
|
||||
// * If not, write to the Free Software Foundation, Inc.,
|
||||
// * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA.
|
||||
// *
|
||||
// * (c) 2002-2003 Aaron Robinson <caustik@caustik.com>
|
||||
// *
|
||||
// * All rights reserved
|
||||
// *
|
||||
// ******************************************************************
|
||||
#define CXBXKRNL_INTERNAL
|
||||
#define _XBOXKRNL_LOCAL_
|
||||
|
||||
#include "Cxbx.h"
|
||||
#include "EmuX.h"
|
||||
|
||||
// ******************************************************************
|
||||
// * ntdll wrapped in namespace to avoid collisions
|
||||
// ******************************************************************
|
||||
namespace xntdll
|
||||
{
|
||||
#include "xntdll.h"
|
||||
};
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// ******************************************************************
|
||||
// * static functions
|
||||
// ******************************************************************
|
||||
static void EmuXInstallWrappers(void (*Entry)());
|
||||
|
||||
// ******************************************************************
|
||||
// * func: EmuXInit
|
||||
// ******************************************************************
|
||||
CXBXKRNL_API void NTAPI EmuXInit(DebugMode DebugConsole, char *DebugFilename, uint08 *XBEHeader, uint32 XBEHeaderSize, void (*Entry)())
|
||||
{
|
||||
// ******************************************************************
|
||||
// * debug console allocation (if configured)
|
||||
// ******************************************************************
|
||||
if(DebugConsole == DM_CONSOLE)
|
||||
{
|
||||
if(AllocConsole())
|
||||
{
|
||||
freopen("CONOUT$", "wt", stdout);
|
||||
|
||||
printf("CxbxKrnl [0x%.08X]: Debug console allocated.\n", GetCurrentThreadId());
|
||||
}
|
||||
}
|
||||
else if(DebugConsole == DM_FILE)
|
||||
{
|
||||
FreeConsole();
|
||||
|
||||
freopen(DebugFilename, "wt", stdout);
|
||||
|
||||
printf("CxbxKrnl [0x%.08X]: Debug console allocated.\n", GetCurrentThreadId());
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * debug trace
|
||||
// ******************************************************************
|
||||
{
|
||||
printf("CxbxKrnl [0x%.08X]: EmuXInit\n"
|
||||
" (\n"
|
||||
" DebugConsole : 0x%.08X\n"
|
||||
" DebugFilename : \"%s\"\n"
|
||||
" XBEHeader : 0x%.08X\n"
|
||||
" XBEHeaderSize : 0x%.08X\n"
|
||||
" Entry : 0x%.08X\n"
|
||||
" );\n",
|
||||
GetCurrentThreadId(), DebugConsole, DebugFilename, XBEHeader, XBEHeaderSize, Entry);
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * Locate functions and install wrapper vectors
|
||||
// ******************************************************************
|
||||
{
|
||||
EmuXInstallWrappers(Entry);
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * Load the necessary pieces of XBEHeader
|
||||
// ******************************************************************
|
||||
{
|
||||
uint32 old_protection = 0;
|
||||
|
||||
VirtualProtect((void*)0x00010000, 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];
|
||||
|
||||
*(uint32 *)0x00010108 = dwSizeofHeaders;
|
||||
*(uint32 *)0x00010118 = dwCertificateAddr;
|
||||
*(uint32 *)0x00010124 = dwInitFlags;
|
||||
*(uint32 *)0x00010134 = dwPeHeapReserve;
|
||||
*(uint32 *)0x00010138 = dwPeHeapCommit;
|
||||
|
||||
memcpy((void*)dwCertificateAddr, &XBEHeader[dwCertificateAddr - 0x00010000], sizeof(Xbe::Certificate));
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * Initialize FS system
|
||||
// ******************************************************************
|
||||
{
|
||||
EmuXInitFS();
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * Initialize FS:* structure
|
||||
// ******************************************************************
|
||||
{
|
||||
EmuXGenerateFS();
|
||||
}
|
||||
|
||||
printf("CxbxKrnl [0x%.08X]: Initial thread starting.\n", GetCurrentThreadId());
|
||||
|
||||
EmuXSwapFS(); // XBox FS
|
||||
|
||||
// This must be enabled or the debugger may crash (sigh)
|
||||
//_asm _emit 0xF1
|
||||
|
||||
Entry();
|
||||
|
||||
EmuXSwapFS(); // Win2k/XP FS
|
||||
|
||||
printf("CxbxKrnl [0x%.08X]: Initial thread ended.\n", GetCurrentThreadId());
|
||||
|
||||
fflush(stdout);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * func: EmuXDummy
|
||||
// ******************************************************************
|
||||
CXBXKRNL_API void NTAPI EmuXDummy()
|
||||
{
|
||||
EmuXSwapFS(); // Win2k/XP FS
|
||||
|
||||
MessageBox(NULL, "EmuXDummy()", "CxbxKrnl", MB_OK);
|
||||
|
||||
EmuXSwapFS(); // XBox FS
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * func: EmuXPanic
|
||||
// ******************************************************************
|
||||
CXBXKRNL_API void NTAPI EmuXPanic()
|
||||
{
|
||||
EmuXSwapFS(); // Win2k/XP FS
|
||||
|
||||
printf("CxbxKrnl [0x%.08X]: EmuXPanic()\n", GetCurrentThreadId());
|
||||
|
||||
MessageBox(NULL, "Kernel Panic! Process will now terminate.", "CxbxKrnl", MB_OK | MB_ICONEXCLAMATION);
|
||||
|
||||
EmuXSwapFS(); // XBox FS
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * func: EmuXInstallWrappers
|
||||
// ******************************************************************
|
||||
void EmuXInstallWrappers(void (*Entry)())
|
||||
{
|
||||
// ******************************************************************
|
||||
// * debug trace
|
||||
// ******************************************************************
|
||||
{
|
||||
printf("CxbxKrnl [0x%.08X]: EmuXInstallWrappers()\n"
|
||||
" (\n"
|
||||
" Entry : 0x%.08X\n"
|
||||
" );\n",
|
||||
GetCurrentThreadId(), Entry);
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * install CreateThread vector
|
||||
// ******************************************************************
|
||||
{
|
||||
// ******************************************************************
|
||||
// * CreateThread is easily located using an offset from the standard
|
||||
// * xbe entry point
|
||||
// ******************************************************************
|
||||
uint32 RelCallAddr = (uint32)Entry + 0x54;
|
||||
uint32 RelRealCreateThread = *(uint32*)(RelCallAddr + 1);
|
||||
uint08 *RealCreateThread = (uint08*)(RelCallAddr + RelRealCreateThread + 5);
|
||||
|
||||
printf("RealCreateThread : %.08X\n", RealCreateThread);
|
||||
fflush(stdout);
|
||||
|
||||
*(uint08*)&RealCreateThread[0] = 0xE9;
|
||||
*(uint32*)&RealCreateThread[1] = (uint32)xboxkrnl::EmuXCreateThread - (uint32)RealCreateThread - 5;
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * install CloseHandle vector
|
||||
// ******************************************************************
|
||||
{
|
||||
// ******************************************************************
|
||||
// * CloseHandle is easily located using an offset from the standard
|
||||
// * xbe entry point
|
||||
// ******************************************************************
|
||||
uint32 RelCallAddr = (uint32)Entry + 0x6A;
|
||||
uint32 RelRealCloseHandle = *(uint32*)(RelCallAddr + 1);
|
||||
uint08 *RealCloseHandle = (uint08*)(RelCallAddr + RelRealCloseHandle + 5);
|
||||
|
||||
*(uint08*)&RealCloseHandle[0] = 0xE9;
|
||||
*(uint32*)&RealCloseHandle[1] = (uint32)xboxkrnl::EmuXCloseHandle - (uint32)RealCloseHandle - 5;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
// ******************************************************************
|
||||
// *
|
||||
// * .,-::::: .,:: .::::::::. .,:: .:
|
||||
// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;;
|
||||
// * [[[ '[[,,[[' [[[__[[\. '[[,,[['
|
||||
// * $$$ Y$$$P $$""""Y$$ Y$$$P
|
||||
// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo,
|
||||
// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm,
|
||||
// *
|
||||
// * Cxbx->Win32->CxbxKrnl->EmuXFS.cpp
|
||||
// *
|
||||
// * This file is part of the Cxbx project.
|
||||
// *
|
||||
// * Cxbx and Cxbe are free software; you can redistribute them
|
||||
// * and/or modify them under the terms of the GNU General Public
|
||||
// * License as published by the Free Software Foundation; either
|
||||
// * version 2 of the license, or (at your option) any later version.
|
||||
// *
|
||||
// * This program is distributed in the hope that it will be useful,
|
||||
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// * GNU General Public License for more details.
|
||||
// *
|
||||
// * You should have recieved a copy of the GNU General Public License
|
||||
// * along with this program; see the file COPYING.
|
||||
// * If not, write to the Free Software Foundation, Inc.,
|
||||
// * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA.
|
||||
// *
|
||||
// * (c) 2002-2003 Aaron Robinson <caustik@caustik.com>
|
||||
// *
|
||||
// * All rights reserved
|
||||
// *
|
||||
// ******************************************************************
|
||||
#include "Cxbx.h"
|
||||
#include "EmuX.h"
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// ******************************************************************
|
||||
// * func: EmuXInitFS
|
||||
// ******************************************************************
|
||||
void EmuXInitFS()
|
||||
{
|
||||
EmuXInitLDT();
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * func: EmuXGenerateFS
|
||||
// ******************************************************************
|
||||
void EmuXGenerateFS()
|
||||
{
|
||||
NT_TIB *OrgNtTib;
|
||||
xboxkrnl::KPCR *NewPcr;
|
||||
|
||||
uint16 NewFS=0;
|
||||
uint16 OrgFS=0;
|
||||
|
||||
uint32 dwSize = sizeof(xboxkrnl::KPCR);
|
||||
|
||||
NewPcr = (xboxkrnl::KPCR*)new char[dwSize];
|
||||
|
||||
NewFS = EmuXAllocateLDT((uint32)NewPcr, (uint32)NewPcr + dwSize);
|
||||
|
||||
// ******************************************************************
|
||||
// * Obtain "OrgFS"
|
||||
// ******************************************************************
|
||||
__asm
|
||||
{
|
||||
// Obtain "OrgFS"
|
||||
mov ax, fs
|
||||
mov OrgFS, ax
|
||||
|
||||
// Obtain "OrgNtTib"
|
||||
mov eax, fs:[0x18]
|
||||
mov OrgNtTib, eax
|
||||
|
||||
// Save "NewFS" inside OrgFS.ArbitraryUserPointer
|
||||
mov ax, NewFS
|
||||
mov fs:[0x14], ax
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * Generate TIB
|
||||
// ******************************************************************
|
||||
{
|
||||
void *TLSPtr = 0;
|
||||
|
||||
xboxkrnl::KTHREAD *KThread = new xboxkrnl::KTHREAD();
|
||||
|
||||
memcpy(&NewPcr->NtTib, OrgNtTib, sizeof(NT_TIB));
|
||||
|
||||
NewPcr->NtTib.Self = &NewPcr->NtTib;
|
||||
NewPcr->PrcbData.CurrentThread = KThread;
|
||||
|
||||
// Retrieve Win2k/XP TEB.ThreadLocalStoragePointer
|
||||
__asm
|
||||
{
|
||||
mov eax, fs:[0x2C]
|
||||
mov TLSPtr, eax
|
||||
}
|
||||
|
||||
KThread->TlsData = (void*)TLSPtr;
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * Swap into the "NewFS"
|
||||
// ******************************************************************
|
||||
EmuXSwapFS();
|
||||
|
||||
// ******************************************************************
|
||||
// * Save "OrgFS" inside NewFS.ArbitraryUserPointer
|
||||
// ******************************************************************
|
||||
__asm
|
||||
{
|
||||
mov ax, OrgFS
|
||||
mov fs:[0x14], ax // NewFS.ArbitraryUserPointer
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * Swap back into the "OrgFS"
|
||||
// ******************************************************************
|
||||
EmuXSwapFS();
|
||||
}
|
|
@ -7,7 +7,7 @@
|
|||
// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo,
|
||||
// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm,
|
||||
// *
|
||||
// * Cxbx->Win32->CxbxKrnl->CxbxKrnl.cpp
|
||||
// * Cxbx->Win32->CxbxKrnl->EmuXKrnl.cpp
|
||||
// *
|
||||
// * This file is part of the Cxbx project.
|
||||
// *
|
||||
|
@ -31,13 +31,11 @@
|
|||
// * All rights reserved
|
||||
// *
|
||||
// ******************************************************************
|
||||
#include "Cxbx.h"
|
||||
|
||||
#define CXBXKRNL_INTERNAL
|
||||
#define _XBOXKRNL_LOCAL_
|
||||
#include "CxbxKrnl.h"
|
||||
|
||||
#include "LDT.h"
|
||||
#include "Cxbx.h"
|
||||
#include "EmuX.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
@ -54,269 +52,11 @@ namespace xntdll
|
|||
// ******************************************************************
|
||||
namespace win32
|
||||
{
|
||||
#undef FIELD_OFFSET // prevent macro redefinition warnings
|
||||
#include <windows.h>
|
||||
};
|
||||
|
||||
using namespace win32;
|
||||
|
||||
// ******************************************************************
|
||||
// * func: EmuXInstallWrappers
|
||||
// ******************************************************************
|
||||
void EmuXInstallWrappers(void (*Entry)())
|
||||
{
|
||||
// ******************************************************************
|
||||
// * debug trace
|
||||
// ******************************************************************
|
||||
{
|
||||
printf("CxbxKrnl [0x%.08X]: EmuXInstallWrappers()\n"
|
||||
" (\n"
|
||||
" Entry : 0x%.08X\n"
|
||||
" );\n",
|
||||
GetCurrentThreadId(), Entry);
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * install CreateThread vector
|
||||
// ******************************************************************
|
||||
{
|
||||
// ******************************************************************
|
||||
// * CreateThread is easily located using an offset from the standard
|
||||
// * xbe entry point
|
||||
// ******************************************************************
|
||||
uint32 RelCallAddr = (uint32)Entry + 0x54;
|
||||
uint32 RelRealCreateThread = *(uint32*)(RelCallAddr + 1);
|
||||
uint08 *RealCreateThread = (uint08*)(RelCallAddr + RelRealCreateThread + 5);
|
||||
|
||||
*(uint08*)&RealCreateThread[0] = 0xE9;
|
||||
*(uint32*)&RealCreateThread[1] = (uint32)xboxkrnl::EmuCreateThread - (uint32)RealCreateThread - 5;
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * install CloseHandle vector
|
||||
// ******************************************************************
|
||||
{
|
||||
// ******************************************************************
|
||||
// * CloseHandle is easily located using an offset from the standard
|
||||
// * xbe entry point
|
||||
// ******************************************************************
|
||||
uint32 RelCallAddr = (uint32)Entry + 0x6A;
|
||||
uint32 RelRealCloseHandle = *(uint32*)(RelCallAddr + 1);
|
||||
uint08 *RealCloseHandle = (uint08*)(RelCallAddr + RelRealCloseHandle + 5);
|
||||
|
||||
*(uint08*)&RealCloseHandle[0] = 0xE9;
|
||||
*(uint32*)&RealCloseHandle[1] = (uint32)xboxkrnl::EmuCloseHandle - (uint32)RealCloseHandle - 5;
|
||||
}
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * func: EmuXGenerateFS
|
||||
// ******************************************************************
|
||||
void EmuXGenerateFS()
|
||||
{
|
||||
NT_TIB *OrgNtTib;
|
||||
xboxkrnl::KPCR *NewPcr;
|
||||
|
||||
uint16 NewFS=0;
|
||||
uint16 OrgFS=0;
|
||||
|
||||
uint32 dwSize = sizeof(xboxkrnl::KPCR);
|
||||
|
||||
NewPcr = (xboxkrnl::KPCR*)new char[dwSize];
|
||||
|
||||
NewFS = LDTAllocate((uint32)NewPcr, (uint32)NewPcr + dwSize);
|
||||
|
||||
// ******************************************************************
|
||||
// * Obtain "OrgFS"
|
||||
// ******************************************************************
|
||||
__asm
|
||||
{
|
||||
// Obtain "OrgFS"
|
||||
mov ax, fs
|
||||
mov OrgFS, ax
|
||||
|
||||
// Obtain "OrgNtTib"
|
||||
mov eax, fs:[0x18]
|
||||
mov OrgNtTib, eax
|
||||
|
||||
// Save "NewFS" inside OrgFS.ArbitraryUserPointer
|
||||
mov ax, NewFS
|
||||
mov fs:[0x14], ax
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * Generate TIB
|
||||
// ******************************************************************
|
||||
{
|
||||
void *TLSPtr = 0;
|
||||
|
||||
xboxkrnl::KTHREAD *KThread = new xboxkrnl::KTHREAD();
|
||||
|
||||
memcpy(&NewPcr->NtTib, OrgNtTib, sizeof(NT_TIB));
|
||||
|
||||
NewPcr->NtTib.Self = &NewPcr->NtTib;
|
||||
NewPcr->PrcbData.CurrentThread = KThread;
|
||||
|
||||
// Retrieve Win2k/XP TEB.ThreadLocalStoragePointer
|
||||
__asm
|
||||
{
|
||||
mov eax, fs:[0x2C]
|
||||
mov TLSPtr, eax
|
||||
}
|
||||
|
||||
KThread->TlsData = (void*)TLSPtr;
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * Swap into the "NewFS"
|
||||
// ******************************************************************
|
||||
EmuXSwapFS();
|
||||
|
||||
// ******************************************************************
|
||||
// * Save "OrgFS" inside NewFS.ArbitraryUserPointer
|
||||
// ******************************************************************
|
||||
__asm
|
||||
{
|
||||
mov ax, OrgFS
|
||||
mov fs:[0x14], ax // NewFS.ArbitraryUserPointer
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * Swap back into the "OrgFS"
|
||||
// ******************************************************************
|
||||
EmuXSwapFS();
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * func: EmuXInit
|
||||
// ******************************************************************
|
||||
CXBXKRNL_API void NTAPI EmuXInit(DebugMode DebugConsole, char *DebugFilename, uint08 *XBEHeader, uint32 XBEHeaderSize, void (*Entry)())
|
||||
{
|
||||
// ******************************************************************
|
||||
// * debug console allocation (if configured)
|
||||
// ******************************************************************
|
||||
if(DebugConsole == DM_CONSOLE)
|
||||
{
|
||||
if(AllocConsole())
|
||||
{
|
||||
freopen("CONOUT$", "wt", stdout);
|
||||
|
||||
printf("CxbxKrnl [0x%.08X]: Debug console allocated.\n", GetCurrentThreadId());
|
||||
}
|
||||
}
|
||||
else if(DebugConsole == DM_FILE)
|
||||
{
|
||||
FreeConsole();
|
||||
|
||||
freopen(DebugFilename, "wt", stdout);
|
||||
|
||||
printf("CxbxKrnl [0x%.08X]: Debug console allocated.\n", GetCurrentThreadId());
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * debug trace
|
||||
// ******************************************************************
|
||||
{
|
||||
printf("CxbxKrnl [0x%.08X]: EmuXInit\n"
|
||||
" (\n"
|
||||
" DebugConsole : 0x%.08X\n"
|
||||
" DebugFilename : \"%s\"\n"
|
||||
" XBEHeader : 0x%.08X\n"
|
||||
" XBEHeaderSize : 0x%.08X\n"
|
||||
" Entry : 0x%.08X\n"
|
||||
" );\n",
|
||||
GetCurrentThreadId(), DebugConsole, DebugFilename, XBEHeader, XBEHeaderSize, Entry);
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * Locate functions and install wrapper vectors
|
||||
// ******************************************************************
|
||||
{
|
||||
EmuXInstallWrappers(Entry);
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * Load the necessary pieces of XBEHeader
|
||||
// ******************************************************************
|
||||
{
|
||||
uint32 old_protection = 0;
|
||||
|
||||
VirtualProtect((void*)0x00010000, 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];
|
||||
|
||||
*(uint32 *)0x00010108 = dwSizeofHeaders;
|
||||
*(uint32 *)0x00010118 = dwCertificateAddr;
|
||||
*(uint32 *)0x00010124 = dwInitFlags;
|
||||
*(uint32 *)0x00010134 = dwPeHeapReserve;
|
||||
*(uint32 *)0x00010138 = dwPeHeapCommit;
|
||||
|
||||
memcpy((void*)dwCertificateAddr, &XBEHeader[dwCertificateAddr - 0x00010000], sizeof(Xbe::Certificate));
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * Initialize LDT system
|
||||
// ******************************************************************
|
||||
{
|
||||
LDTSystemInit();
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * Initialize FS:* structure
|
||||
// ******************************************************************
|
||||
{
|
||||
EmuXGenerateFS();
|
||||
}
|
||||
|
||||
printf("CxbxKrnl [0x%.08X]: Initial thread starting.\n", GetCurrentThreadId());
|
||||
|
||||
EmuXSwapFS(); // XBox FS
|
||||
|
||||
// This must be enabled or the debugger may crash (sigh)
|
||||
//_asm _emit 0xF1
|
||||
|
||||
Entry();
|
||||
|
||||
EmuXSwapFS(); // Win2k/XP FS
|
||||
|
||||
printf("CxbxKrnl [0x%.08X]: Initial thread ended.\n", GetCurrentThreadId());
|
||||
|
||||
fflush(stdout);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * func: EmuXDummy
|
||||
// ******************************************************************
|
||||
CXBXKRNL_API void NTAPI EmuXDummy()
|
||||
{
|
||||
EmuXSwapFS(); // Win2k/XP FS
|
||||
|
||||
MessageBox(NULL, "EmuXDummy()", "CxbxKrnl", MB_OK);
|
||||
|
||||
EmuXSwapFS(); // XBox FS
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * func: EmuXPanic
|
||||
// ******************************************************************
|
||||
CXBXKRNL_API void NTAPI EmuXPanic()
|
||||
{
|
||||
EmuXSwapFS(); // Win2k/XP FS
|
||||
|
||||
printf("CxbxKrnl [0x%.08X]: EmuXPanic()\n", GetCurrentThreadId());
|
||||
|
||||
MessageBox(NULL, "Kernel Panic! Process will now terminate.", "CxbxKrnl", MB_OK | MB_ICONEXCLAMATION);
|
||||
|
||||
EmuXSwapFS(); // XBox FS
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * (HELPER) PsCreateSystemThreadExProxyParam
|
||||
// ******************************************************************
|
|
@ -0,0 +1,167 @@
|
|||
// ******************************************************************
|
||||
// *
|
||||
// * .,-::::: .,:: .::::::::. .,:: .:
|
||||
// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;;
|
||||
// * [[[ '[[,,[[' [[[__[[\. '[[,,[['
|
||||
// * $$$ Y$$$P $$""""Y$$ Y$$$P
|
||||
// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo,
|
||||
// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm,
|
||||
// *
|
||||
// * Cxbx->Win32->CxbxKrnl->CxbxKrnl.cpp
|
||||
// *
|
||||
// * This file is part of the Cxbx project.
|
||||
// *
|
||||
// * Cxbx and Cxbe are free software; you can redistribute them
|
||||
// * and/or modify them under the terms of the GNU General Public
|
||||
// * License as published by the Free Software Foundation; either
|
||||
// * version 2 of the license, or (at your option) any later version.
|
||||
// *
|
||||
// * This program is distributed in the hope that it will be useful,
|
||||
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// * GNU General Public License for more details.
|
||||
// *
|
||||
// * You should have recieved a copy of the GNU General Public License
|
||||
// * along with this program; see the file COPYING.
|
||||
// * If not, write to the Free Software Foundation, Inc.,
|
||||
// * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA.
|
||||
// *
|
||||
// * (c) 2002-2003 Aaron Robinson <caustik@caustik.com>
|
||||
// *
|
||||
// * All rights reserved
|
||||
// *
|
||||
// ******************************************************************
|
||||
#include "Cxbx.h"
|
||||
#include "EmuX.h"
|
||||
|
||||
// ******************************************************************
|
||||
// * ntdll wrapped in namespace to avoid collisions
|
||||
// ******************************************************************
|
||||
namespace xntdll
|
||||
{
|
||||
#include "xntdll.h"
|
||||
};
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
// ******************************************************************
|
||||
// * Maximum number of threads this LDT system will handle
|
||||
// ******************************************************************
|
||||
#define MAXIMUM_XBOX_THREADS 32
|
||||
|
||||
// ******************************************************************
|
||||
// * Table of free LDT entries
|
||||
// ******************************************************************
|
||||
static uint16 FreeLDTEntries[MAXIMUM_XBOX_THREADS];
|
||||
|
||||
// ******************************************************************
|
||||
// * Critical section lock
|
||||
// ******************************************************************
|
||||
static CRITICAL_SECTION EmuXLDTLock;
|
||||
|
||||
// ******************************************************************
|
||||
// * func: EmuXInitLDT
|
||||
// ******************************************************************
|
||||
void EmuXInitLDT()
|
||||
{
|
||||
InitializeCriticalSection(&EmuXLDTLock);
|
||||
|
||||
for(uint32 v=0;v<MAXIMUM_XBOX_THREADS;v++)
|
||||
FreeLDTEntries[v] = (uint16)((v*8) + 7 + 8);
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * func: EmuXAllocateLDT
|
||||
// ******************************************************************
|
||||
uint16 EmuXAllocateLDT(uint32 dwBaseAddr, uint32 dwLimit)
|
||||
{
|
||||
xntdll::LDT_ENTRY LDTEntry;
|
||||
|
||||
int x=0;
|
||||
|
||||
EnterCriticalSection(&EmuXLDTLock);
|
||||
|
||||
// ******************************************************************
|
||||
// * Locate a free LDT entry
|
||||
// ******************************************************************
|
||||
{
|
||||
for(x=0;x<MAXIMUM_XBOX_THREADS;x++)
|
||||
if(FreeLDTEntries[x])
|
||||
break;
|
||||
|
||||
if(x == MAXIMUM_XBOX_THREADS)
|
||||
{
|
||||
LeaveCriticalSection(&EmuXLDTLock);
|
||||
|
||||
// TODO: cleaner error handling
|
||||
MessageBox(NULL, "Very strange error: Could not locate free LDT entry!", "CxbxKrnl", MB_OK | MB_ICONEXCLAMATION);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * Set up selector information
|
||||
// ******************************************************************
|
||||
{
|
||||
LDTEntry.BaseLow = (WORD)(dwBaseAddr & 0xFFFF);
|
||||
LDTEntry.HighWord.Bits.BaseMid = (dwBaseAddr >> 16) & 0xFF;
|
||||
LDTEntry.HighWord.Bits.BaseHi = (dwBaseAddr >> 24) & 0xFF;
|
||||
LDTEntry.HighWord.Bits.Type = 0x13; // RW data segment
|
||||
LDTEntry.HighWord.Bits.Dpl = 3; // user segment
|
||||
LDTEntry.HighWord.Bits.Pres = 1; // present
|
||||
LDTEntry.HighWord.Bits.Sys = 0;
|
||||
LDTEntry.HighWord.Bits.Reserved_0 = 0;
|
||||
LDTEntry.HighWord.Bits.Default_Big = 1; // 386 segment
|
||||
LDTEntry.HighWord.Bits.Granularity = (dwLimit >= 0x00100000) ? 1 : 0;
|
||||
|
||||
if(LDTEntry.HighWord.Bits.Granularity)
|
||||
dwLimit >>= 12;
|
||||
|
||||
LDTEntry.LimitLow = (WORD)(dwLimit & 0xFFFF);
|
||||
LDTEntry.HighWord.Bits.LimitHi = (dwLimit >> 16) & 0xF;
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * Allocate selector
|
||||
// ******************************************************************
|
||||
{
|
||||
using namespace xntdll;
|
||||
|
||||
if(!NT_SUCCESS(NtSetLdtEntries((x*8)+7+8, LDTEntry, 0, LDTEntry)))
|
||||
{
|
||||
LeaveCriticalSection(&EmuXLDTLock);
|
||||
|
||||
// TODO: cleaner error handling
|
||||
MessageBox(NULL, "Very strange error: Could not set LDT entry!", "CxbxKrnl", MB_OK | MB_ICONEXCLAMATION);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
LeaveCriticalSection(&EmuXLDTLock);
|
||||
|
||||
FreeLDTEntries[x] = 0;
|
||||
|
||||
return (x*8)+7+8;
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * func: EmuXDeallocateLDT
|
||||
// ******************************************************************
|
||||
void EmuXDeallocateLDT(uint16 wSelector)
|
||||
{
|
||||
xntdll::LDT_ENTRY LDTEntry;
|
||||
|
||||
EnterCriticalSection(&EmuXLDTLock);
|
||||
|
||||
ZeroMemory(&LDTEntry, sizeof(LDTEntry));
|
||||
|
||||
xntdll::NtSetLdtEntries(wSelector, LDTEntry, 0, LDTEntry);
|
||||
|
||||
FreeLDTEntries[(wSelector >> 3)-1] = wSelector;
|
||||
|
||||
LeaveCriticalSection(&EmuXLDTLock);
|
||||
|
||||
return;
|
||||
}
|
|
@ -0,0 +1,177 @@
|
|||
// ******************************************************************
|
||||
// *
|
||||
// * .,-::::: .,:: .::::::::. .,:: .:
|
||||
// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;;
|
||||
// * [[[ '[[,,[[' [[[__[[\. '[[,,[['
|
||||
// * $$$ Y$$$P $$""""Y$$ Y$$$P
|
||||
// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo,
|
||||
// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm,
|
||||
// *
|
||||
// * Cxbx->Win32->CxbxKrnl->EmuXapi.cpp
|
||||
// *
|
||||
// * This file is part of the Cxbx project.
|
||||
// *
|
||||
// * Cxbx and Cxbe are free software; you can redistribute them
|
||||
// * and/or modify them under the terms of the GNU General Public
|
||||
// * License as published by the Free Software Foundation; either
|
||||
// * version 2 of the license, or (at your option) any later version.
|
||||
// *
|
||||
// * This program is distributed in the hope that it will be useful,
|
||||
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// * GNU General Public License for more details.
|
||||
// *
|
||||
// * You should have recieved a copy of the GNU General Public License
|
||||
// * along with this program; see the file COPYING.
|
||||
// * If not, write to the Free Software Foundation, Inc.,
|
||||
// * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA.
|
||||
// *
|
||||
// * (c) 2002-2003 Aaron Robinson <caustik@caustik.com>
|
||||
// *
|
||||
// * All rights reserved
|
||||
// *
|
||||
// ******************************************************************
|
||||
#include "Cxbx.h"
|
||||
#include "EmuX.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
// ******************************************************************
|
||||
// * win32 wrapped in namespace to avoid collisions
|
||||
// ******************************************************************
|
||||
namespace win32
|
||||
{
|
||||
#include <windows.h>
|
||||
}
|
||||
|
||||
using namespace win32;
|
||||
|
||||
// ******************************************************************
|
||||
// * EmuXCreateThreadProxyParam
|
||||
// ******************************************************************
|
||||
typedef struct _EmuXCreateThreadProxyParam
|
||||
{
|
||||
LPVOID lpParameter;
|
||||
LPTHREAD_START_ROUTINE lpStartAddress;
|
||||
}
|
||||
EmuXCreateThreadProxyParam;
|
||||
|
||||
// ******************************************************************
|
||||
// * func: EmuXCreateThreadProxy
|
||||
// ******************************************************************
|
||||
static DWORD WINAPI EmuXCreateThreadProxy
|
||||
(
|
||||
LPVOID lpParameter
|
||||
)
|
||||
{
|
||||
EmuXCreateThreadProxyParam *iEmuXCreateThreadProxyParam = (EmuXCreateThreadProxyParam*)lpParameter;
|
||||
|
||||
LPTHREAD_START_ROUTINE ilpStartAddress = iEmuXCreateThreadProxyParam->lpStartAddress;
|
||||
LPVOID ilpParam = iEmuXCreateThreadProxyParam->lpParameter;
|
||||
|
||||
delete iEmuXCreateThreadProxyParam;
|
||||
|
||||
EmuXGenerateFS();
|
||||
|
||||
// ******************************************************************
|
||||
// * debug trace
|
||||
// ******************************************************************
|
||||
#ifdef _DEBUG_TRACE
|
||||
{
|
||||
printf("CxbxKrnl [0x%.08X]: EmuXCreateThreadProxy\n"
|
||||
" (\n"
|
||||
" lpParameter : 0x%.08X\n"
|
||||
" );\n",
|
||||
GetCurrentThreadId(), lpParameter);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
EmuXSwapFS(); // XBox FS
|
||||
|
||||
return ilpStartAddress(ilpParam);
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * func: EmuXCreateThread
|
||||
// ******************************************************************
|
||||
HANDLE WINAPI xboxkrnl::EmuXCreateThread
|
||||
(
|
||||
LPSECURITY_ATTRIBUTES lpThreadAttributes,
|
||||
DWORD dwStackSize,
|
||||
LPTHREAD_START_ROUTINE lpStartAddress,
|
||||
LPVOID lpParameter,
|
||||
DWORD dwCreationFlags,
|
||||
LPDWORD lpThreadId
|
||||
)
|
||||
{
|
||||
EmuXSwapFS(); // Win2k/XP FS
|
||||
|
||||
// ******************************************************************
|
||||
// * debug trace
|
||||
// ******************************************************************
|
||||
#ifdef _DEBUG_TRACE
|
||||
{
|
||||
printf("CxbxKrnl [0x%.08X]: EmuXCreateThread\n"
|
||||
" (\n"
|
||||
" lpThreadAttributes : 0x%.08X\n"
|
||||
" dwStackSize : 0x%.08X\n"
|
||||
" lpStartAddress : 0x%.08X\n"
|
||||
" lpParameter : 0x%.08X\n"
|
||||
" dwCreationFlags : 0x%.08X\n"
|
||||
" lpThreadId : 0x%.08X\n"
|
||||
" );\n",
|
||||
GetCurrentThreadId(), lpThreadAttributes, dwStackSize, lpStartAddress,
|
||||
lpParameter, dwCreationFlags, lpThreadId);
|
||||
}
|
||||
#endif
|
||||
|
||||
EmuXCreateThreadProxyParam *iEmuXCreateThreadProxyParam = new EmuXCreateThreadProxyParam();
|
||||
|
||||
iEmuXCreateThreadProxyParam->lpParameter = lpParameter;
|
||||
iEmuXCreateThreadProxyParam->lpStartAddress = lpStartAddress;
|
||||
|
||||
HANDLE RetHandle = CreateThread
|
||||
(
|
||||
NULL,
|
||||
dwStackSize,
|
||||
EmuXCreateThreadProxy,
|
||||
iEmuXCreateThreadProxyParam,
|
||||
dwCreationFlags,
|
||||
lpThreadId
|
||||
);
|
||||
|
||||
EmuXSwapFS(); // XBox FS
|
||||
|
||||
return RetHandle;
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * func: EmuXCloseHandle
|
||||
// ******************************************************************
|
||||
BOOL WINAPI xboxkrnl::EmuXCloseHandle
|
||||
(
|
||||
HANDLE hObject
|
||||
)
|
||||
{
|
||||
EmuXSwapFS(); // Win2k/XP FS
|
||||
|
||||
// ******************************************************************
|
||||
// * debug trace
|
||||
// ******************************************************************
|
||||
#ifdef _DEBUG_TRACE
|
||||
{
|
||||
printf("CxbxKrnl [0x%.08X]: EmuXCloseHandle\n"
|
||||
" (\n"
|
||||
" hObject : 0x%.08X\n"
|
||||
" );\n",
|
||||
GetCurrentThreadId(), hObject);
|
||||
}
|
||||
#endif
|
||||
|
||||
BOOL Ret = CloseHandle(hObject);
|
||||
|
||||
EmuXSwapFS(); // XBox FS
|
||||
|
||||
return Ret;
|
||||
}
|
|
@ -35,7 +35,7 @@
|
|||
|
||||
#define CXBXKRNL_INTERNAL
|
||||
#define _XBOXKRNL_LOCAL_
|
||||
#include "CxbxKrnl.h"
|
||||
#include "EmuX.h"
|
||||
|
||||
// ******************************************************************
|
||||
// * NOTE:
|
||||
|
|
Loading…
Reference in New Issue