Tiny steps towards implementing C runtime

This commit is contained in:
KeybadeBlox 2026-02-14 12:34:28 -05:00
parent ccd2cd37a5
commit c38d9b5628
6 changed files with 65 additions and 14 deletions

View file

@ -1,10 +1,27 @@
all: src/JSRF/Jet2.obj # JSRF Decompilation Makefile
# An NMAKE Makefile to compile the game with the Visual C++ 7.0 toolchain
# All object files to link together
OBJ = src/JSRF/Jet2.obj src/JSRF/Core.obj src/JSRF/GameData.obj\
src/XDK/CRT/CRT0.obj
# Linking into an executable; expect this to fail with undefined references
# until we've made at least stubs for everything in the game
#all: src/JSRF/Jet2.exe
#src/JSRF/Jet2.exe: $(OBJ)
# LINK.EXE /NOLOGO /NODEFAULTLIB /MERGE:.CRT=.data /OUT:$@ $**
# For now, just compile all the object files
all: $(OBJ)
# Simple inference rule for producing object files # Simple inference rule for producing object files
.SUFFIXES: .cpp .obj .SUFFIXES: .cpp .obj
.cpp.obj: .cpp.obj:
CL.EXE /nologo /Wall /W4 /Ogityb0 /GfX /Fo$@ /c $< CL.EXE /nologo /Wall /W4 /Ogityb0 /GfX /Fo$@ /c $<
# Header files used for each object # Header files used for each object
src/JSRF/Jet2.obj: src/JSRF/Core.hpp src/Std.hpp src/XDK/D3D.hpp\ src/JSRF/Jet2.obj: src/JSRF/Core.hpp src/Std.hpp src/XDK/D3D.hpp\
src/XDK/Win32.hpp src/XDK/Win32.hpp
@ -13,3 +30,5 @@ src/JSRF/Core.obj: src/JSRF/Core.hpp src/Smilebit/MMatrix.hpp src/Std.hpp\
src/XDK/D3D.hpp src/XDK/Win32.hpp src/XDK/D3D.hpp src/XDK/Win32.hpp
src/JSRF/GameData.obj: src/JSRF/GameData.hpp src/JSRF/GameData.obj: src/JSRF/GameData.hpp
src/XDK/CRT/CRT0.obj: src/XDK/Win32.hpp

View file

@ -14,10 +14,10 @@
"source_path": "src/JSRF/Jet2.cpp" "source_path": "src/JSRF/Jet2.cpp"
}, },
"symbol_mappings": { "symbol_mappings": {
"?main_funcinfo@@3UFuncInfo@@A": "$T754", "?main_funcinfo@@3UFuncInfo@@A": "$T745",
"?main_handler@@YAXPAUEHExceptionRecord@@PAKPAXPAU_xDISPATCHER_CONTEXT@@@Z": "$L758", "?main_handler@@YAXPAUEHExceptionRecord@@PAKPAXPAU_xDISPATCHER_CONTEXT@@@Z": "$L749",
"?main_handler_unwind1@@YAXXZ": "$L750", "?main_handler_unwind1@@YAXXZ": "$L741",
"?main_unwindmap@@3PAUUnwindMapEntry@@A": "$T760", "?main_unwindmap@@3PAUUnwindMapEntry@@A": "$T751",
"[.rdata-0]": "[.xdata$x-0]" "[.rdata-0]": "[.xdata$x-0]"
} }
}, },

View file

@ -0,0 +1,32 @@
/* JSRF Decompilation: XDK/CRT0.cpp
C runtime initialization.
Like other CRT code, there's some magic here with symbols that get special
treatment from the compiler and linker.
*/
#include "Win32.hpp"
// Every program is supposed to have a main(), so we can just assume its
// existence with a declaration here
int main();
void __stdcall mainCRTStartup ();
static DWORD _mainXapiStartup(LPVOID lpThreadParameter);
// Address: 0x00148023
// Matching: no
void __stdcall mainCRTStartup() {
/* The true entrypoint of the game, spawning a thread for the rest to run in
The linker automatically sets this function to the entrypoint.
*/
}
// Address: 0x00147FB4
// Matching: no
DWORD _mainXapiStartup(LPVOID const lpThreadParameter) {
/* Runs some initialization and then calls main() */
main();
}

View file

@ -32,10 +32,6 @@ typedef int BOOL;
// 64-bit integer compatibility type // 64-bit integer compatibility type
union LARGE_INTEGER { union LARGE_INTEGER {
struct {
DWORD LowPart;
LONG HighPart;
};
struct { struct {
DWORD LowPart; DWORD LowPart;
LONG HighPart; LONG HighPart;

View file

@ -140,11 +140,15 @@ public class MSVC7Mangle extends GhidraScript{
/* Generate a mangled name for a function */ /* Generate a mangled name for a function */
final String nameRaw = f.getName(true); final String nameRaw = f.getName(true);
// Special case for main() // Internal symbols like intrinsics aren't mangled
if (nameRaw.equals("main")) return "_main"; if (nameRaw.startsWith("_")) return nameRaw;
// Special symbols like intrinsics aren't mangled // Other special cases
if (nameRaw.startsWith("__")) return nameRaw; switch (nameRaw) {
case "atexit": return "_atexit";
case "main" : return "_main" ;
default : {}
}
final ArrayList<String> dict = new ArrayList<>(); final ArrayList<String> dict = new ArrayList<>();

View file

@ -1,4 +1,4 @@
Object,Delink?,.text,.text$XCU1,.text$XCU2,.text$x,D3D,DSOUND,MMATRIX,XGRPH,XPP,.rdata,.rdata$x,.data$CRT,.data,DOLBY Object,Delink?,.text,.text$XC*1,.text$XC*2,.text$x,D3D,DSOUND,MMATRIX,XGRPH,XPP,.rdata,.rdata$x,.data$CRT,.data,DOLBY
JSRF/Core.obj,true,0x00011000-0x00013FEB,,,0x00186BA0-0x00186C14,,,,,,0x001C4390-0x001C44F9,0x001E4D20-0x001E4DAB,,0x001EB880-0x001EB933, JSRF/Core.obj,true,0x00011000-0x00013FEB,,,0x00186BA0-0x00186C14,,,,,,0x001C4390-0x001C44F9,0x001E4D20-0x001E4DAB,,0x001EB880-0x001EB933,
JSRF/GameData.obj,true,0x00039B50-0x0003B937,0x0018AD60-0x0018AD75,0x0018C9A0-0x0018C9AA,,,,,,,0x001CA16C-0x001CA3DB,,0x001EB790-0x001EB793,0x001EFC88-0x001F7047, JSRF/GameData.obj,true,0x00039B50-0x0003B937,0x0018AD60-0x0018AD75,0x0018C9A0-0x0018C9AA,,,,,,,0x001CA16C-0x001CA3DB,,0x001EB790-0x001EB793,0x001EFC88-0x001F7047,
JSRF/Jet2.obj,true,0x0006F9E0-0x0006FA6F,,,0x00187710-0x00187724,,,,,,,0x001E620C-0x001E622F,,0x0022FCE0-0x0022FCE3, JSRF/Jet2.obj,true,0x0006F9E0-0x0006FA6F,,,0x00187710-0x00187724,,,,,,,0x001E620C-0x001E622F,,0x0022FCE0-0x0022FCE3,

1 Object Delink? .text .text$XCU1 .text$XC*1 .text$XCU2 .text$XC*2 .text$x D3D DSOUND MMATRIX XGRPH XPP .rdata .rdata$x .data$CRT .data DOLBY
2 JSRF/Core.obj true 0x00011000-0x00013FEB 0x00186BA0-0x00186C14 0x001C4390-0x001C44F9 0x001E4D20-0x001E4DAB 0x001EB880-0x001EB933
3 JSRF/GameData.obj true 0x00039B50-0x0003B937 0x0018AD60-0x0018AD75 0x0018C9A0-0x0018C9AA 0x001CA16C-0x001CA3DB 0x001EB790-0x001EB793 0x001EFC88-0x001F7047
4 JSRF/Jet2.obj true 0x0006F9E0-0x0006FA6F 0x00187710-0x00187724 0x001E620C-0x001E622F 0x0022FCE0-0x0022FCE3