Latest commit

History

230 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Restunts - The Stunts reverse engineering project
https://wiki.stunts.hu/wiki/Restunts
Repository contents:
docs
Various technical docs related to (re)stunts itself.
src\execombiner
Tool which combines the original game and video drivers into a single
debugable executable.
src\idc
Script for IdaPro to generate .asm-files from an ida project.
src\restunts
Project directory containing disassembly, ported c and makefiles to
produce various executables based on the (re)stunts code.
stunts
Stunts 1.1 the game.
tools
Contains binaries, libraries, headers with a full toolchain for
building restunts on Windows. The toolchain is based on TASM, TLINK,
Turbo Debugger, Borland C++, DOSBox, and various other tools.
Contents of src\restunts:
src\restunts\game_mod3.idb
The analysis database for IDAPro.
src\restunts\asm
Contains patched, compilable disassembly generated by the script for
IdaPro. This code is patched to work with our ported c code.
Note 2025-02-03: the asm is not in sync with IDA any more, since some
variable names were modified by the script src\restunts\annotate-vars.sh
src\restunts\asmorig
Contains the same files as src\restunts\asm, but unpatched and does not
use any of the ported c code.
src\restunts\c
Contains c functions ported from the disassembly.
src\restunts\dos
Makefile to build restunts for DOS.
src\restunts\repldump
Tool based on the original game code, loads replays and dumps the game
state contents at each frame in a file for further analysis.
The build environment
How to build restunts on Windows:
1) Double click tools\mount_stunts_to_s.bat (only needed once per reboot)
2) Start cmd.exe and enter the following commands:
S:
cd tools
setpath.bat
cd \src\restunts
make
How to build restunts on Linux:
1) Install Wine
2) Mount the restunts dir as drive S using winecfg
3) In the Linux console type `wineconsole cmd`
4) In the resulting Wine console type (mind the inverted slashes and the lack of tab completion):
```
s:
cd src\restunts
..\..\tools\setpath
```
On both platforms:
If everything went fine, there should be a new s:\stunts\restunts.exe which can
be run in DOSBox. Note that the drive letter S: is hardcoded many places in the
makefiles, and is also mounted inside DOSBox as a fixed point of reference.
The makefile supports the following targets:
make restunts
The default restunts target builds an executable based on ported C code
and patched disassembly.
make restunts-original
Builds an executable based on unpatched disassembly with the original
codepaths intact. Does not use any of the ported C code.
make repldump
Builds the replay dump tool using ported C code and patched
disassembly.
make repldump-original
Builds the replay dump tool without ported C code.
The toolchain
The toolchain has evolved over the years and is now (2014) fully based on Borland tools. For various reasons, the build process uses both 16 and 32-bit
tools. In order to compile on modern 64 bit Windows systems, the 16-bit apps
run via DOSBox. A DOSBox window pops up multiple times during a build, and
stays open in case of build errors.
Tools used:
- TASMX + TLINK (16 bit DOS, from Borland Turbo Assembler 4.0)
- Borland C++ 5.2 (Win32)
- Borland Make 5.2 (Win32, from Borland C++ 5.5, patched binary)
The 16-bit tools are:
tasmx.exe, invoked in DOSBox by tasmbox.bat
tlink.exe, invoked in DOSBox by tlinkbox.bat
Analysis in IDA and the development cycle
Analysis happens continously in IDA 6.1 (Win32). Using a custom script in IDA,
the entire disassembly is exported to compilable .asm and .inc files in src\restunts\asm. This allows using latest analysis results in the build
process. As code is ported manually to C, the custom script is updated and kept
in sync, such that it generates patched assembly code calling into the ported C
functions.
The custom script also runs a second pass, where it exports a separate set of .asm files to src\restunts\asmorig. These files are unpatched and produce code
that behaves 100% identically to the original game.
When doing analysis and (re)naming variables and functions, it is important to
always check the ported C code if there are any references to the previous
symbol names. All symbol references in the C code need to be kept in sync with
the analysis manually. Obviously, the linker will complain about missing
symbols in case a symbol was renamed in IDA, but not in the C files.
Debugging restunts.exe
Restunts can be debugged with Turbo Debugger inside DOSBox. The DOSBox
debugging environment is an extension of the build environment described above:
1) Double click tools\mount_stunts_to_s.bat (only needed once per reboot)
2) Start DOSBox and enter the following commands:
mount S S:
S:
cd tools
setpath.bat
cd \stunts
td restunts.exe
Turbo Debugger is preconfigured to automatically find and show the source code.
Setting breakpoints, stepping etc works. The TD configuration file is stored in
stunts\tdconfig.td.
Notes regarding make
Borland Make was chosen because the first makefile was written for the DOS
version. Ultimately the DOS version ran into memory problems with the largest asm-files. Too late and too lazy to find a new make utility, the Windows
version of Borland Make, included in Borland C++ 5.5, was used instead. But:
Borland Make 5.2 uses MAKEFILE.@@@ as the filename for temporary inline files.
WLINK interprets @ in a special way on the command line and will not take the inline file as a parameter. As such make.exe was patched to use MAKEFILE.!!!
as the temporary filename instead.
Notes regarding the linker
WLINK from the Open Watcom C/C++ compiler suite was originally chosen because
it supports detailed control on how to order segment classes in the final
executable image.
Our requirement is to put the original code and data first in the file, exactly
as in the original game, only patching up function calls and data access. TLINK and OPTLINK were tested in the early days, but after having difficulties
with segment ordering and subsequent crashes, the project settled on WLINK.
The problems with TLINK were revisited and fixed years later, after an urgent
need to get debug information for the restunts executable. As WLINK is not able
to use the debug information format created by BCC/TASM, it became necessary to
replace either of them. After the initial attempts of using TLINK were
successful, no further investigation were made into replacing TASM. It should
be noted that MASM seems a promising TASM replacement candidate: the syntax is
close to TASM, and it produces CodeView debug format usable by WLINK.
Notes regarding 16-bit tasmx, tlink and DOSBox
The choice of reverting to TLINK was not easy either. Only the 16-bit version
of TLINK can produce 16-bit executables such as restunts.exe, and it can only
use object files produced by the 16-bit TASM. In order to use 16-bit tools on a
64-bit Windows host, they need to be emulated. And so DOSBox became
incorporated in the build process. Another problem is the regular 16-bit
tasm.exe exceeds the available 640k of memory when compiling the largest
restunts source files. This was overcome by using the DPMI-enabled tasmx.exe
instead.
Notes regarding the CRT (libc)
When linking with cm.lib from Borland C++ 5.1, TLINK is not able to produce an
executable. To get around this, the tlib tool was used to extract object files
from cm.lib, and now restunts links with these instead.
When the project used WLINK, it was able to link with cm.lib from Borland C++
5.1, but was not able to link correctly with cm.lib from Borland C++ 3.1.
Before upgrading to Borland C++ 5.1, the makefile would link to single obj
files from Borland 3.1's CRT. The linker can complain about weird missing symbols f.ex at first time use of
some compiler feature or CRT function. This can be fixed by extracting the
object file from cm.lib, and adding it to the makefile.
cm.lib is the medium model libc from Borland C++ 5.2. tlib.exe is a 16-bit
Borland utility for manipulating lib files and has to be run via DOSBox.
Using a binary file viewer with cm.lib it's possible to locate missing CRT
symbol names and work out/guess the object file name by looking at strings in
the binary data before it.
To extract the object file
1) Double click tools\mount_stunts_to_s.bat (only needed once per reboot)
2) Start DOSBox and initialize the restunts development environment:
mount S S:
S:
cd tools
setpath.bat
cd \tools\lib
3) Run tlib to extract the object file, some examples:
tlib cm.lib * GETVECT
tlib cm.lib * LABS
tlib cm.lib * STRCPY
tlib cm.lib * MEMCPY
tlib cm.lib * FMEMCPY
tlib cm.lib * H_LDIV
tlib cm.lib * F_LXMUL
tlib cm.lib * F_SCOPY
tlib cm.lib * H_LRSH
tlib cm.lib * H_PADD
tlib cm.lib * H_PINA
tlib cm.lib * H_PADA
tlib cm.lib * N_PCMP
tlib cm.lib * F_PCMP
tlib cm.lib * H_LURSH
tlib cm.lib * H_PSBP
tlib cm.lib * H_LLSH
4) Add new CRT object files in dos\makefile - at the end of the line
starting with CTARGETS =
Porting a function from ASM to C
1. Open src\idc\anders.idc in a text editor and locate the PortFuncName() function. The IDA script needs to be aware of all the functions that have been ported in order to generate asm that does not conflict with the ported
code. Add a line in PortFuncName() for the function you've chosen.
2. Run anders.idc from within IDA to regenerate the asm files (or skip step 1+2
and rename the respective extrn, public and function manually in the .inc
and asm files)
3. Add a function stub to one of the existing .c files in src\restunts\c 3.1 If you want to add a new .c-file to the project, you need to - add a target for it in c\makefile
- add a reference to the obj in RESTUNTS_OBJFILES in dos\makefile
4. Add an extrn for the c-function in asm\custom.inc
5. Start make to see if it compiles + links
6. Port to c!

About

A clone of clvn's restunts SVN repository

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Latest commit

History

230 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Restunts - The Stunts reverse engineering project
https://wiki.stunts.hu/wiki/Restunts
Repository contents:
docs
Various technical docs related to (re)stunts itself.
src\execombiner
Tool which combines the original game and video drivers into a single
debugable executable.
src\idc
Script for IdaPro to generate .asm-files from an ida project.
src\restunts
Project directory containing disassembly, ported c and makefiles to
produce various executables based on the (re)stunts code.
stunts
Stunts 1.1 the game.
tools
Contains binaries, libraries, headers with a full toolchain for
building restunts on Windows. The toolchain is based on TASM, TLINK,
Turbo Debugger, Borland C++, DOSBox, and various other tools.
Contents of src\restunts:
src\restunts\game_mod3.idb
The analysis database for IDAPro.
src\restunts\asm
Contains patched, compilable disassembly generated by the script for
IdaPro. This code is patched to work with our ported c code.
Note 2025-02-03: the asm is not in sync with IDA any more, since some
variable names were modified by the script src\restunts\annotate-vars.sh
src\restunts\asmorig
Contains the same files as src\restunts\asm, but unpatched and does not
use any of the ported c code.
src\restunts\c
Contains c functions ported from the disassembly.
src\restunts\dos
Makefile to build restunts for DOS.
src\restunts\repldump
Tool based on the original game code, loads replays and dumps the game
state contents at each frame in a file for further analysis.
The build environment
How to build restunts on Windows:
1) Double click tools\mount_stunts_to_s.bat (only needed once per reboot)
2) Start cmd.exe and enter the following commands:
S:
cd tools
setpath.bat
cd \src\restunts
make
How to build restunts on Linux:
1) Install Wine
2) Mount the restunts dir as drive S using winecfg
3) In the Linux console type `wineconsole cmd`
4) In the resulting Wine console type (mind the inverted slashes and the lack of tab completion):
```
s:
cd src\restunts
..\..\tools\setpath
```
On both platforms:
If everything went fine, there should be a new s:\stunts\restunts.exe which can
be run in DOSBox. Note that the drive letter S: is hardcoded many places in the
makefiles, and is also mounted inside DOSBox as a fixed point of reference.
The makefile supports the following targets:
make restunts
The default restunts target builds an executable based on ported C code
and patched disassembly.
make restunts-original
Builds an executable based on unpatched disassembly with the original
codepaths intact. Does not use any of the ported C code.
make repldump
Builds the replay dump tool using ported C code and patched
disassembly.
make repldump-original
Builds the replay dump tool without ported C code.
The toolchain
The toolchain has evolved over the years and is now (2014) fully based on Borland tools. For various reasons, the build process uses both 16 and 32-bit
tools. In order to compile on modern 64 bit Windows systems, the 16-bit apps
run via DOSBox. A DOSBox window pops up multiple times during a build, and
stays open in case of build errors.
Tools used:
- TASMX + TLINK (16 bit DOS, from Borland Turbo Assembler 4.0)
- Borland C++ 5.2 (Win32)
- Borland Make 5.2 (Win32, from Borland C++ 5.5, patched binary)
The 16-bit tools are:
tasmx.exe, invoked in DOSBox by tasmbox.bat
tlink.exe, invoked in DOSBox by tlinkbox.bat
Analysis in IDA and the development cycle
Analysis happens continously in IDA 6.1 (Win32). Using a custom script in IDA,
the entire disassembly is exported to compilable .asm and .inc files in src\restunts\asm. This allows using latest analysis results in the build
process. As code is ported manually to C, the custom script is updated and kept
in sync, such that it generates patched assembly code calling into the ported C
functions.
The custom script also runs a second pass, where it exports a separate set of .asm files to src\restunts\asmorig. These files are unpatched and produce code
that behaves 100% identically to the original game.
When doing analysis and (re)naming variables and functions, it is important to
always check the ported C code if there are any references to the previous
symbol names. All symbol references in the C code need to be kept in sync with
the analysis manually. Obviously, the linker will complain about missing
symbols in case a symbol was renamed in IDA, but not in the C files.
Debugging restunts.exe
Restunts can be debugged with Turbo Debugger inside DOSBox. The DOSBox
debugging environment is an extension of the build environment described above:
1) Double click tools\mount_stunts_to_s.bat (only needed once per reboot)
2) Start DOSBox and enter the following commands:
mount S S:
S:
cd tools
setpath.bat
cd \stunts
td restunts.exe
Turbo Debugger is preconfigured to automatically find and show the source code.
Setting breakpoints, stepping etc works. The TD configuration file is stored in
stunts\tdconfig.td.
Notes regarding make
Borland Make was chosen because the first makefile was written for the DOS
version. Ultimately the DOS version ran into memory problems with the largest asm-files. Too late and too lazy to find a new make utility, the Windows
version of Borland Make, included in Borland C++ 5.5, was used instead. But:
Borland Make 5.2 uses MAKEFILE.@@@ as the filename for temporary inline files.
WLINK interprets @ in a special way on the command line and will not take the inline file as a parameter. As such make.exe was patched to use MAKEFILE.!!!
as the temporary filename instead.
Notes regarding the linker
WLINK from the Open Watcom C/C++ compiler suite was originally chosen because
it supports detailed control on how to order segment classes in the final
executable image.
Our requirement is to put the original code and data first in the file, exactly
as in the original game, only patching up function calls and data access. TLINK and OPTLINK were tested in the early days, but after having difficulties
with segment ordering and subsequent crashes, the project settled on WLINK.
The problems with TLINK were revisited and fixed years later, after an urgent
need to get debug information for the restunts executable. As WLINK is not able
to use the debug information format created by BCC/TASM, it became necessary to
replace either of them. After the initial attempts of using TLINK were
successful, no further investigation were made into replacing TASM. It should
be noted that MASM seems a promising TASM replacement candidate: the syntax is
close to TASM, and it produces CodeView debug format usable by WLINK.
Notes regarding 16-bit tasmx, tlink and DOSBox
The choice of reverting to TLINK was not easy either. Only the 16-bit version
of TLINK can produce 16-bit executables such as restunts.exe, and it can only
use object files produced by the 16-bit TASM. In order to use 16-bit tools on a
64-bit Windows host, they need to be emulated. And so DOSBox became
incorporated in the build process. Another problem is the regular 16-bit
tasm.exe exceeds the available 640k of memory when compiling the largest
restunts source files. This was overcome by using the DPMI-enabled tasmx.exe
instead.
Notes regarding the CRT (libc)
When linking with cm.lib from Borland C++ 5.1, TLINK is not able to produce an
executable. To get around this, the tlib tool was used to extract object files
from cm.lib, and now restunts links with these instead.
When the project used WLINK, it was able to link with cm.lib from Borland C++
5.1, but was not able to link correctly with cm.lib from Borland C++ 3.1.
Before upgrading to Borland C++ 5.1, the makefile would link to single obj
files from Borland 3.1's CRT. The linker can complain about weird missing symbols f.ex at first time use of
some compiler feature or CRT function. This can be fixed by extracting the
object file from cm.lib, and adding it to the makefile.
cm.lib is the medium model libc from Borland C++ 5.2. tlib.exe is a 16-bit
Borland utility for manipulating lib files and has to be run via DOSBox.
Using a binary file viewer with cm.lib it's possible to locate missing CRT
symbol names and work out/guess the object file name by looking at strings in
the binary data before it.
To extract the object file
1) Double click tools\mount_stunts_to_s.bat (only needed once per reboot)
2) Start DOSBox and initialize the restunts development environment:
mount S S:
S:
cd tools
setpath.bat
cd \tools\lib
3) Run tlib to extract the object file, some examples:
tlib cm.lib * GETVECT
tlib cm.lib * LABS
tlib cm.lib * STRCPY
tlib cm.lib * MEMCPY
tlib cm.lib * FMEMCPY
tlib cm.lib * H_LDIV
tlib cm.lib * F_LXMUL
tlib cm.lib * F_SCOPY
tlib cm.lib * H_LRSH
tlib cm.lib * H_PADD
tlib cm.lib * H_PINA
tlib cm.lib * H_PADA
tlib cm.lib * N_PCMP
tlib cm.lib * F_PCMP
tlib cm.lib * H_LURSH
tlib cm.lib * H_PSBP
tlib cm.lib * H_LLSH
4) Add new CRT object files in dos\makefile - at the end of the line
starting with CTARGETS =
Porting a function from ASM to C
1. Open src\idc\anders.idc in a text editor and locate the PortFuncName() function. The IDA script needs to be aware of all the functions that have been ported in order to generate asm that does not conflict with the ported
code. Add a line in PortFuncName() for the function you've chosen.
2. Run anders.idc from within IDA to regenerate the asm files (or skip step 1+2
and rename the respective extrn, public and function manually in the .inc
and asm files)
3. Add a function stub to one of the existing .c files in src\restunts\c 3.1 If you want to add a new .c-file to the project, you need to - add a target for it in c\makefile
- add a reference to the obj in RESTUNTS_OBJFILES in dos\makefile
4. Add an extrn for the c-function in asm\custom.inc
5. Start make to see if it compiles + links
6. Port to c!

About

A clone of clvn's restunts SVN repository

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Latest commit

History

230 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Restunts - The Stunts reverse engineering project
https://wiki.stunts.hu/wiki/Restunts
Repository contents:
docs
Various technical docs related to (re)stunts itself.
src\execombiner
Tool which combines the original game and video drivers into a single
debugable executable.
src\idc
Script for IdaPro to generate .asm-files from an ida project.
src\restunts
Project directory containing disassembly, ported c and makefiles to
produce various executables based on the (re)stunts code.
stunts
Stunts 1.1 the game.
tools
Contains binaries, libraries, headers with a full toolchain for
building restunts on Windows. The toolchain is based on TASM, TLINK,
Turbo Debugger, Borland C++, DOSBox, and various other tools.
Contents of src\restunts:
src\restunts\game_mod3.idb
The analysis database for IDAPro.
src\restunts\asm
Contains patched, compilable disassembly generated by the script for
IdaPro. This code is patched to work with our ported c code.
Note 2025-02-03: the asm is not in sync with IDA any more, since some
variable names were modified by the script src\restunts\annotate-vars.sh
src\restunts\asmorig
Contains the same files as src\restunts\asm, but unpatched and does not
use any of the ported c code.
src\restunts\c
Contains c functions ported from the disassembly.
src\restunts\dos
Makefile to build restunts for DOS.
src\restunts\repldump
Tool based on the original game code, loads replays and dumps the game
state contents at each frame in a file for further analysis.
The build environment
How to build restunts on Windows:
1) Double click tools\mount_stunts_to_s.bat (only needed once per reboot)
2) Start cmd.exe and enter the following commands:
S:
cd tools
setpath.bat
cd \src\restunts
make
How to build restunts on Linux:
1) Install Wine
2) Mount the restunts dir as drive S using winecfg
3) In the Linux console type `wineconsole cmd`
4) In the resulting Wine console type (mind the inverted slashes and the lack of tab completion):
```
s:
cd src\restunts
..\..\tools\setpath
```
On both platforms:
If everything went fine, there should be a new s:\stunts\restunts.exe which can
be run in DOSBox. Note that the drive letter S: is hardcoded many places in the
makefiles, and is also mounted inside DOSBox as a fixed point of reference.
The makefile supports the following targets:
make restunts
The default restunts target builds an executable based on ported C code
and patched disassembly.
make restunts-original
Builds an executable based on unpatched disassembly with the original
codepaths intact. Does not use any of the ported C code.
make repldump
Builds the replay dump tool using ported C code and patched
disassembly.
make repldump-original
Builds the replay dump tool without ported C code.
The toolchain
The toolchain has evolved over the years and is now (2014) fully based on Borland tools. For various reasons, the build process uses both 16 and 32-bit
tools. In order to compile on modern 64 bit Windows systems, the 16-bit apps
run via DOSBox. A DOSBox window pops up multiple times during a build, and
stays open in case of build errors.
Tools used:
- TASMX + TLINK (16 bit DOS, from Borland Turbo Assembler 4.0)
- Borland C++ 5.2 (Win32)
- Borland Make 5.2 (Win32, from Borland C++ 5.5, patched binary)
The 16-bit tools are:
tasmx.exe, invoked in DOSBox by tasmbox.bat
tlink.exe, invoked in DOSBox by tlinkbox.bat
Analysis in IDA and the development cycle
Analysis happens continously in IDA 6.1 (Win32). Using a custom script in IDA,
the entire disassembly is exported to compilable .asm and .inc files in src\restunts\asm. This allows using latest analysis results in the build
process. As code is ported manually to C, the custom script is updated and kept
in sync, such that it generates patched assembly code calling into the ported C
functions.
The custom script also runs a second pass, where it exports a separate set of .asm files to src\restunts\asmorig. These files are unpatched and produce code
that behaves 100% identically to the original game.
When doing analysis and (re)naming variables and functions, it is important to
always check the ported C code if there are any references to the previous
symbol names. All symbol references in the C code need to be kept in sync with
the analysis manually. Obviously, the linker will complain about missing
symbols in case a symbol was renamed in IDA, but not in the C files.
Debugging restunts.exe
Restunts can be debugged with Turbo Debugger inside DOSBox. The DOSBox
debugging environment is an extension of the build environment described above:
1) Double click tools\mount_stunts_to_s.bat (only needed once per reboot)
2) Start DOSBox and enter the following commands:
mount S S:
S:
cd tools
setpath.bat
cd \stunts
td restunts.exe
Turbo Debugger is preconfigured to automatically find and show the source code.
Setting breakpoints, stepping etc works. The TD configuration file is stored in
stunts\tdconfig.td.
Notes regarding make
Borland Make was chosen because the first makefile was written for the DOS
version. Ultimately the DOS version ran into memory problems with the largest asm-files. Too late and too lazy to find a new make utility, the Windows
version of Borland Make, included in Borland C++ 5.5, was used instead. But:
Borland Make 5.2 uses MAKEFILE.@@@ as the filename for temporary inline files.
WLINK interprets @ in a special way on the command line and will not take the inline file as a parameter. As such make.exe was patched to use MAKEFILE.!!!
as the temporary filename instead.
Notes regarding the linker
WLINK from the Open Watcom C/C++ compiler suite was originally chosen because
it supports detailed control on how to order segment classes in the final
executable image.
Our requirement is to put the original code and data first in the file, exactly
as in the original game, only patching up function calls and data access. TLINK and OPTLINK were tested in the early days, but after having difficulties
with segment ordering and subsequent crashes, the project settled on WLINK.
The problems with TLINK were revisited and fixed years later, after an urgent
need to get debug information for the restunts executable. As WLINK is not able
to use the debug information format created by BCC/TASM, it became necessary to
replace either of them. After the initial attempts of using TLINK were
successful, no further investigation were made into replacing TASM. It should
be noted that MASM seems a promising TASM replacement candidate: the syntax is
close to TASM, and it produces CodeView debug format usable by WLINK.
Notes regarding 16-bit tasmx, tlink and DOSBox
The choice of reverting to TLINK was not easy either. Only the 16-bit version
of TLINK can produce 16-bit executables such as restunts.exe, and it can only
use object files produced by the 16-bit TASM. In order to use 16-bit tools on a
64-bit Windows host, they need to be emulated. And so DOSBox became
incorporated in the build process. Another problem is the regular 16-bit
tasm.exe exceeds the available 640k of memory when compiling the largest
restunts source files. This was overcome by using the DPMI-enabled tasmx.exe
instead.
Notes regarding the CRT (libc)
When linking with cm.lib from Borland C++ 5.1, TLINK is not able to produce an
executable. To get around this, the tlib tool was used to extract object files
from cm.lib, and now restunts links with these instead.
When the project used WLINK, it was able to link with cm.lib from Borland C++
5.1, but was not able to link correctly with cm.lib from Borland C++ 3.1.
Before upgrading to Borland C++ 5.1, the makefile would link to single obj
files from Borland 3.1's CRT. The linker can complain about weird missing symbols f.ex at first time use of
some compiler feature or CRT function. This can be fixed by extracting the
object file from cm.lib, and adding it to the makefile.
cm.lib is the medium model libc from Borland C++ 5.2. tlib.exe is a 16-bit
Borland utility for manipulating lib files and has to be run via DOSBox.
Using a binary file viewer with cm.lib it's possible to locate missing CRT
symbol names and work out/guess the object file name by looking at strings in
the binary data before it.
To extract the object file
1) Double click tools\mount_stunts_to_s.bat (only needed once per reboot)
2) Start DOSBox and initialize the restunts development environment:
mount S S:
S:
cd tools
setpath.bat
cd \tools\lib
3) Run tlib to extract the object file, some examples:
tlib cm.lib * GETVECT
tlib cm.lib * LABS
tlib cm.lib * STRCPY
tlib cm.lib * MEMCPY
tlib cm.lib * FMEMCPY
tlib cm.lib * H_LDIV
tlib cm.lib * F_LXMUL
tlib cm.lib * F_SCOPY
tlib cm.lib * H_LRSH
tlib cm.lib * H_PADD
tlib cm.lib * H_PINA
tlib cm.lib * H_PADA
tlib cm.lib * N_PCMP
tlib cm.lib * F_PCMP
tlib cm.lib * H_LURSH
tlib cm.lib * H_PSBP
tlib cm.lib * H_LLSH
4) Add new CRT object files in dos\makefile - at the end of the line
starting with CTARGETS =
Porting a function from ASM to C
1. Open src\idc\anders.idc in a text editor and locate the PortFuncName() function. The IDA script needs to be aware of all the functions that have been ported in order to generate asm that does not conflict with the ported
code. Add a line in PortFuncName() for the function you've chosen.
2. Run anders.idc from within IDA to regenerate the asm files (or skip step 1+2
and rename the respective extrn, public and function manually in the .inc
and asm files)
3. Add a function stub to one of the existing .c files in src\restunts\c 3.1 If you want to add a new .c-file to the project, you need to - add a target for it in c\makefile
- add a reference to the obj in RESTUNTS_OBJFILES in dos\makefile
4. Add an extrn for the c-function in asm\custom.inc
5. Start make to see if it compiles + links
6. Port to c!

About

A clone of clvn's restunts SVN repository

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Latest commit

History

230 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Restunts - The Stunts reverse engineering project
https://wiki.stunts.hu/wiki/Restunts
Repository contents:
docs
Various technical docs related to (re)stunts itself.
src\execombiner
Tool which combines the original game and video drivers into a single
debugable executable.
src\idc
Script for IdaPro to generate .asm-files from an ida project.
src\restunts
Project directory containing disassembly, ported c and makefiles to
produce various executables based on the (re)stunts code.
stunts
Stunts 1.1 the game.
tools
Contains binaries, libraries, headers with a full toolchain for
building restunts on Windows. The toolchain is based on TASM, TLINK,
Turbo Debugger, Borland C++, DOSBox, and various other tools.
Contents of src\restunts:
src\restunts\game_mod3.idb
The analysis database for IDAPro.
src\restunts\asm
Contains patched, compilable disassembly generated by the script for
IdaPro. This code is patched to work with our ported c code.
Note 2025-02-03: the asm is not in sync with IDA any more, since some
variable names were modified by the script src\restunts\annotate-vars.sh
src\restunts\asmorig
Contains the same files as src\restunts\asm, but unpatched and does not
use any of the ported c code.
src\restunts\c
Contains c functions ported from the disassembly.
src\restunts\dos
Makefile to build restunts for DOS.
src\restunts\repldump
Tool based on the original game code, loads replays and dumps the game
state contents at each frame in a file for further analysis.
The build environment
How to build restunts on Windows:
1) Double click tools\mount_stunts_to_s.bat (only needed once per reboot)
2) Start cmd.exe and enter the following commands:
S:
cd tools
setpath.bat
cd \src\restunts
make
How to build restunts on Linux:
1) Install Wine
2) Mount the restunts dir as drive S using winecfg
3) In the Linux console type `wineconsole cmd`
4) In the resulting Wine console type (mind the inverted slashes and the lack of tab completion):
```
s:
cd src\restunts
..\..\tools\setpath
```
On both platforms:
If everything went fine, there should be a new s:\stunts\restunts.exe which can
be run in DOSBox. Note that the drive letter S: is hardcoded many places in the
makefiles, and is also mounted inside DOSBox as a fixed point of reference.
The makefile supports the following targets:
make restunts
The default restunts target builds an executable based on ported C code
and patched disassembly.
make restunts-original
Builds an executable based on unpatched disassembly with the original
codepaths intact. Does not use any of the ported C code.
make repldump
Builds the replay dump tool using ported C code and patched
disassembly.
make repldump-original
Builds the replay dump tool without ported C code.
The toolchain
The toolchain has evolved over the years and is now (2014) fully based on Borland tools. For various reasons, the build process uses both 16 and 32-bit
tools. In order to compile on modern 64 bit Windows systems, the 16-bit apps
run via DOSBox. A DOSBox window pops up multiple times during a build, and
stays open in case of build errors.
Tools used:
- TASMX + TLINK (16 bit DOS, from Borland Turbo Assembler 4.0)
- Borland C++ 5.2 (Win32)
- Borland Make 5.2 (Win32, from Borland C++ 5.5, patched binary)
The 16-bit tools are:
tasmx.exe, invoked in DOSBox by tasmbox.bat
tlink.exe, invoked in DOSBox by tlinkbox.bat
Analysis in IDA and the development cycle
Analysis happens continously in IDA 6.1 (Win32). Using a custom script in IDA,
the entire disassembly is exported to compilable .asm and .inc files in src\restunts\asm. This allows using latest analysis results in the build
process. As code is ported manually to C, the custom script is updated and kept
in sync, such that it generates patched assembly code calling into the ported C
functions.
The custom script also runs a second pass, where it exports a separate set of .asm files to src\restunts\asmorig. These files are unpatched and produce code
that behaves 100% identically to the original game.
When doing analysis and (re)naming variables and functions, it is important to
always check the ported C code if there are any references to the previous
symbol names. All symbol references in the C code need to be kept in sync with
the analysis manually. Obviously, the linker will complain about missing
symbols in case a symbol was renamed in IDA, but not in the C files.
Debugging restunts.exe
Restunts can be debugged with Turbo Debugger inside DOSBox. The DOSBox
debugging environment is an extension of the build environment described above:
1) Double click tools\mount_stunts_to_s.bat (only needed once per reboot)
2) Start DOSBox and enter the following commands:
mount S S:
S:
cd tools
setpath.bat
cd \stunts
td restunts.exe
Turbo Debugger is preconfigured to automatically find and show the source code.
Setting breakpoints, stepping etc works. The TD configuration file is stored in
stunts\tdconfig.td.
Notes regarding make
Borland Make was chosen because the first makefile was written for the DOS
version. Ultimately the DOS version ran into memory problems with the largest asm-files. Too late and too lazy to find a new make utility, the Windows
version of Borland Make, included in Borland C++ 5.5, was used instead. But:
Borland Make 5.2 uses MAKEFILE.@@@ as the filename for temporary inline files.
WLINK interprets @ in a special way on the command line and will not take the inline file as a parameter. As such make.exe was patched to use MAKEFILE.!!!
as the temporary filename instead.
Notes regarding the linker
WLINK from the Open Watcom C/C++ compiler suite was originally chosen because
it supports detailed control on how to order segment classes in the final
executable image.
Our requirement is to put the original code and data first in the file, exactly
as in the original game, only patching up function calls and data access. TLINK and OPTLINK were tested in the early days, but after having difficulties
with segment ordering and subsequent crashes, the project settled on WLINK.
The problems with TLINK were revisited and fixed years later, after an urgent
need to get debug information for the restunts executable. As WLINK is not able
to use the debug information format created by BCC/TASM, it became necessary to
replace either of them. After the initial attempts of using TLINK were
successful, no further investigation were made into replacing TASM. It should
be noted that MASM seems a promising TASM replacement candidate: the syntax is
close to TASM, and it produces CodeView debug format usable by WLINK.
Notes regarding 16-bit tasmx, tlink and DOSBox
The choice of reverting to TLINK was not easy either. Only the 16-bit version
of TLINK can produce 16-bit executables such as restunts.exe, and it can only
use object files produced by the 16-bit TASM. In order to use 16-bit tools on a
64-bit Windows host, they need to be emulated. And so DOSBox became
incorporated in the build process. Another problem is the regular 16-bit
tasm.exe exceeds the available 640k of memory when compiling the largest
restunts source files. This was overcome by using the DPMI-enabled tasmx.exe
instead.
Notes regarding the CRT (libc)
When linking with cm.lib from Borland C++ 5.1, TLINK is not able to produce an
executable. To get around this, the tlib tool was used to extract object files
from cm.lib, and now restunts links with these instead.
When the project used WLINK, it was able to link with cm.lib from Borland C++
5.1, but was not able to link correctly with cm.lib from Borland C++ 3.1.
Before upgrading to Borland C++ 5.1, the makefile would link to single obj
files from Borland 3.1's CRT. The linker can complain about weird missing symbols f.ex at first time use of
some compiler feature or CRT function. This can be fixed by extracting the
object file from cm.lib, and adding it to the makefile.
cm.lib is the medium model libc from Borland C++ 5.2. tlib.exe is a 16-bit
Borland utility for manipulating lib files and has to be run via DOSBox.
Using a binary file viewer with cm.lib it's possible to locate missing CRT
symbol names and work out/guess the object file name by looking at strings in
the binary data before it.
To extract the object file
1) Double click tools\mount_stunts_to_s.bat (only needed once per reboot)
2) Start DOSBox and initialize the restunts development environment:
mount S S:
S:
cd tools
setpath.bat
cd \tools\lib
3) Run tlib to extract the object file, some examples:
tlib cm.lib * GETVECT
tlib cm.lib * LABS
tlib cm.lib * STRCPY
tlib cm.lib * MEMCPY
tlib cm.lib * FMEMCPY
tlib cm.lib * H_LDIV
tlib cm.lib * F_LXMUL
tlib cm.lib * F_SCOPY
tlib cm.lib * H_LRSH
tlib cm.lib * H_PADD
tlib cm.lib * H_PINA
tlib cm.lib * H_PADA
tlib cm.lib * N_PCMP
tlib cm.lib * F_PCMP
tlib cm.lib * H_LURSH
tlib cm.lib * H_PSBP
tlib cm.lib * H_LLSH
4) Add new CRT object files in dos\makefile - at the end of the line
starting with CTARGETS =
Porting a function from ASM to C
1. Open src\idc\anders.idc in a text editor and locate the PortFuncName() function. The IDA script needs to be aware of all the functions that have been ported in order to generate asm that does not conflict with the ported
code. Add a line in PortFuncName() for the function you've chosen.
2. Run anders.idc from within IDA to regenerate the asm files (or skip step 1+2
and rename the respective extrn, public and function manually in the .inc
and asm files)
3. Add a function stub to one of the existing .c files in src\restunts\c 3.1 If you want to add a new .c-file to the project, you need to - add a target for it in c\makefile
- add a reference to the obj in RESTUNTS_OBJFILES in dos\makefile
4. Add an extrn for the c-function in asm\custom.inc
5. Start make to see if it compiles + links
6. Port to c!

About

A clone of clvn's restunts SVN repository

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Latest commit

History

230 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Restunts - The Stunts reverse engineering project
https://wiki.stunts.hu/wiki/Restunts
Repository contents:
docs
Various technical docs related to (re)stunts itself.
src\execombiner
Tool which combines the original game and video drivers into a single
debugable executable.
src\idc
Script for IdaPro to generate .asm-files from an ida project.
src\restunts
Project directory containing disassembly, ported c and makefiles to
produce various executables based on the (re)stunts code.
stunts
Stunts 1.1 the game.
tools
Contains binaries, libraries, headers with a full toolchain for
building restunts on Windows. The toolchain is based on TASM, TLINK,
Turbo Debugger, Borland C++, DOSBox, and various other tools.
Contents of src\restunts:
src\restunts\game_mod3.idb
The analysis database for IDAPro.
src\restunts\asm
Contains patched, compilable disassembly generated by the script for
IdaPro. This code is patched to work with our ported c code.
Note 2025-02-03: the asm is not in sync with IDA any more, since some
variable names were modified by the script src\restunts\annotate-vars.sh
src\restunts\asmorig
Contains the same files as src\restunts\asm, but unpatched and does not
use any of the ported c code.
src\restunts\c
Contains c functions ported from the disassembly.
src\restunts\dos
Makefile to build restunts for DOS.
src\restunts\repldump
Tool based on the original game code, loads replays and dumps the game
state contents at each frame in a file for further analysis.
The build environment
How to build restunts on Windows:
1) Double click tools\mount_stunts_to_s.bat (only needed once per reboot)
2) Start cmd.exe and enter the following commands:
S:
cd tools
setpath.bat
cd \src\restunts
make
How to build restunts on Linux:
1) Install Wine
2) Mount the restunts dir as drive S using winecfg
3) In the Linux console type `wineconsole cmd`
4) In the resulting Wine console type (mind the inverted slashes and the lack of tab completion):
```
s:
cd src\restunts
..\..\tools\setpath
```
On both platforms:
If everything went fine, there should be a new s:\stunts\restunts.exe which can
be run in DOSBox. Note that the drive letter S: is hardcoded many places in the
makefiles, and is also mounted inside DOSBox as a fixed point of reference.
The makefile supports the following targets:
make restunts
The default restunts target builds an executable based on ported C code
and patched disassembly.
make restunts-original
Builds an executable based on unpatched disassembly with the original
codepaths intact. Does not use any of the ported C code.
make repldump
Builds the replay dump tool using ported C code and patched
disassembly.
make repldump-original
Builds the replay dump tool without ported C code.
The toolchain
The toolchain has evolved over the years and is now (2014) fully based on Borland tools. For various reasons, the build process uses both 16 and 32-bit
tools. In order to compile on modern 64 bit Windows systems, the 16-bit apps
run via DOSBox. A DOSBox window pops up multiple times during a build, and
stays open in case of build errors.
Tools used:
- TASMX + TLINK (16 bit DOS, from Borland Turbo Assembler 4.0)
- Borland C++ 5.2 (Win32)
- Borland Make 5.2 (Win32, from Borland C++ 5.5, patched binary)
The 16-bit tools are:
tasmx.exe, invoked in DOSBox by tasmbox.bat
tlink.exe, invoked in DOSBox by tlinkbox.bat
Analysis in IDA and the development cycle
Analysis happens continously in IDA 6.1 (Win32). Using a custom script in IDA,
the entire disassembly is exported to compilable .asm and .inc files in src\restunts\asm. This allows using latest analysis results in the build
process. As code is ported manually to C, the custom script is updated and kept
in sync, such that it generates patched assembly code calling into the ported C
functions.
The custom script also runs a second pass, where it exports a separate set of .asm files to src\restunts\asmorig. These files are unpatched and produce code
that behaves 100% identically to the original game.
When doing analysis and (re)naming variables and functions, it is important to
always check the ported C code if there are any references to the previous
symbol names. All symbol references in the C code need to be kept in sync with
the analysis manually. Obviously, the linker will complain about missing
symbols in case a symbol was renamed in IDA, but not in the C files.
Debugging restunts.exe
Restunts can be debugged with Turbo Debugger inside DOSBox. The DOSBox
debugging environment is an extension of the build environment described above:
1) Double click tools\mount_stunts_to_s.bat (only needed once per reboot)
2) Start DOSBox and enter the following commands:
mount S S:
S:
cd tools
setpath.bat
cd \stunts
td restunts.exe
Turbo Debugger is preconfigured to automatically find and show the source code.
Setting breakpoints, stepping etc works. The TD configuration file is stored in
stunts\tdconfig.td.
Notes regarding make
Borland Make was chosen because the first makefile was written for the DOS
version. Ultimately the DOS version ran into memory problems with the largest asm-files. Too late and too lazy to find a new make utility, the Windows
version of Borland Make, included in Borland C++ 5.5, was used instead. But:
Borland Make 5.2 uses MAKEFILE.@@@ as the filename for temporary inline files.
WLINK interprets @ in a special way on the command line and will not take the inline file as a parameter. As such make.exe was patched to use MAKEFILE.!!!
as the temporary filename instead.
Notes regarding the linker
WLINK from the Open Watcom C/C++ compiler suite was originally chosen because
it supports detailed control on how to order segment classes in the final
executable image.
Our requirement is to put the original code and data first in the file, exactly
as in the original game, only patching up function calls and data access. TLINK and OPTLINK were tested in the early days, but after having difficulties
with segment ordering and subsequent crashes, the project settled on WLINK.
The problems with TLINK were revisited and fixed years later, after an urgent
need to get debug information for the restunts executable. As WLINK is not able
to use the debug information format created by BCC/TASM, it became necessary to
replace either of them. After the initial attempts of using TLINK were
successful, no further investigation were made into replacing TASM. It should
be noted that MASM seems a promising TASM replacement candidate: the syntax is
close to TASM, and it produces CodeView debug format usable by WLINK.
Notes regarding 16-bit tasmx, tlink and DOSBox
The choice of reverting to TLINK was not easy either. Only the 16-bit version
of TLINK can produce 16-bit executables such as restunts.exe, and it can only
use object files produced by the 16-bit TASM. In order to use 16-bit tools on a
64-bit Windows host, they need to be emulated. And so DOSBox became
incorporated in the build process. Another problem is the regular 16-bit
tasm.exe exceeds the available 640k of memory when compiling the largest
restunts source files. This was overcome by using the DPMI-enabled tasmx.exe
instead.
Notes regarding the CRT (libc)
When linking with cm.lib from Borland C++ 5.1, TLINK is not able to produce an
executable. To get around this, the tlib tool was used to extract object files
from cm.lib, and now restunts links with these instead.
When the project used WLINK, it was able to link with cm.lib from Borland C++
5.1, but was not able to link correctly with cm.lib from Borland C++ 3.1.
Before upgrading to Borland C++ 5.1, the makefile would link to single obj
files from Borland 3.1's CRT. The linker can complain about weird missing symbols f.ex at first time use of
some compiler feature or CRT function. This can be fixed by extracting the
object file from cm.lib, and adding it to the makefile.
cm.lib is the medium model libc from Borland C++ 5.2. tlib.exe is a 16-bit
Borland utility for manipulating lib files and has to be run via DOSBox.
Using a binary file viewer with cm.lib it's possible to locate missing CRT
symbol names and work out/guess the object file name by looking at strings in
the binary data before it.
To extract the object file
1) Double click tools\mount_stunts_to_s.bat (only needed once per reboot)
2) Start DOSBox and initialize the restunts development environment:
mount S S:
S:
cd tools
setpath.bat
cd \tools\lib
3) Run tlib to extract the object file, some examples:
tlib cm.lib * GETVECT
tlib cm.lib * LABS
tlib cm.lib * STRCPY
tlib cm.lib * MEMCPY
tlib cm.lib * FMEMCPY
tlib cm.lib * H_LDIV
tlib cm.lib * F_LXMUL
tlib cm.lib * F_SCOPY
tlib cm.lib * H_LRSH
tlib cm.lib * H_PADD
tlib cm.lib * H_PINA
tlib cm.lib * H_PADA
tlib cm.lib * N_PCMP
tlib cm.lib * F_PCMP
tlib cm.lib * H_LURSH
tlib cm.lib * H_PSBP
tlib cm.lib * H_LLSH
4) Add new CRT object files in dos\makefile - at the end of the line
starting with CTARGETS =
Porting a function from ASM to C
1. Open src\idc\anders.idc in a text editor and locate the PortFuncName() function. The IDA script needs to be aware of all the functions that have been ported in order to generate asm that does not conflict with the ported
code. Add a line in PortFuncName() for the function you've chosen.
2. Run anders.idc from within IDA to regenerate the asm files (or skip step 1+2
and rename the respective extrn, public and function manually in the .inc
and asm files)
3. Add a function stub to one of the existing .c files in src\restunts\c 3.1 If you want to add a new .c-file to the project, you need to - add a target for it in c\makefile
- add a reference to the obj in RESTUNTS_OBJFILES in dos\makefile
4. Add an extrn for the c-function in asm\custom.inc
5. Start make to see if it compiles + links
6. Port to c!

About

A clone of clvn's restunts SVN repository

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Latest commit

History

230 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Restunts - The Stunts reverse engineering project
https://wiki.stunts.hu/wiki/Restunts
Repository contents:
docs
Various technical docs related to (re)stunts itself.
src\execombiner
Tool which combines the original game and video drivers into a single
debugable executable.
src\idc
Script for IdaPro to generate .asm-files from an ida project.
src\restunts
Project directory containing disassembly, ported c and makefiles to
produce various executables based on the (re)stunts code.
stunts
Stunts 1.1 the game.
tools
Contains binaries, libraries, headers with a full toolchain for
building restunts on Windows. The toolchain is based on TASM, TLINK,
Turbo Debugger, Borland C++, DOSBox, and various other tools.
Contents of src\restunts:
src\restunts\game_mod3.idb
The analysis database for IDAPro.
src\restunts\asm
Contains patched, compilable disassembly generated by the script for
IdaPro. This code is patched to work with our ported c code.
Note 2025-02-03: the asm is not in sync with IDA any more, since some
variable names were modified by the script src\restunts\annotate-vars.sh
src\restunts\asmorig
Contains the same files as src\restunts\asm, but unpatched and does not
use any of the ported c code.
src\restunts\c
Contains c functions ported from the disassembly.
src\restunts\dos
Makefile to build restunts for DOS.
src\restunts\repldump
Tool based on the original game code, loads replays and dumps the game
state contents at each frame in a file for further analysis.
The build environment
How to build restunts on Windows:
1) Double click tools\mount_stunts_to_s.bat (only needed once per reboot)
2) Start cmd.exe and enter the following commands:
S:
cd tools
setpath.bat
cd \src\restunts
make
How to build restunts on Linux:
1) Install Wine
2) Mount the restunts dir as drive S using winecfg
3) In the Linux console type `wineconsole cmd`
4) In the resulting Wine console type (mind the inverted slashes and the lack of tab completion):
```
s:
cd src\restunts
..\..\tools\setpath
```
On both platforms:
If everything went fine, there should be a new s:\stunts\restunts.exe which can
be run in DOSBox. Note that the drive letter S: is hardcoded many places in the
makefiles, and is also mounted inside DOSBox as a fixed point of reference.
The makefile supports the following targets:
make restunts
The default restunts target builds an executable based on ported C code
and patched disassembly.
make restunts-original
Builds an executable based on unpatched disassembly with the original
codepaths intact. Does not use any of the ported C code.
make repldump
Builds the replay dump tool using ported C code and patched
disassembly.
make repldump-original
Builds the replay dump tool without ported C code.
The toolchain
The toolchain has evolved over the years and is now (2014) fully based on Borland tools. For various reasons, the build process uses both 16 and 32-bit
tools. In order to compile on modern 64 bit Windows systems, the 16-bit apps
run via DOSBox. A DOSBox window pops up multiple times during a build, and
stays open in case of build errors.
Tools used:
- TASMX + TLINK (16 bit DOS, from Borland Turbo Assembler 4.0)
- Borland C++ 5.2 (Win32)
- Borland Make 5.2 (Win32, from Borland C++ 5.5, patched binary)
The 16-bit tools are:
tasmx.exe, invoked in DOSBox by tasmbox.bat
tlink.exe, invoked in DOSBox by tlinkbox.bat
Analysis in IDA and the development cycle
Analysis happens continously in IDA 6.1 (Win32). Using a custom script in IDA,
the entire disassembly is exported to compilable .asm and .inc files in src\restunts\asm. This allows using latest analysis results in the build
process. As code is ported manually to C, the custom script is updated and kept
in sync, such that it generates patched assembly code calling into the ported C
functions.
The custom script also runs a second pass, where it exports a separate set of .asm files to src\restunts\asmorig. These files are unpatched and produce code
that behaves 100% identically to the original game.
When doing analysis and (re)naming variables and functions, it is important to
always check the ported C code if there are any references to the previous
symbol names. All symbol references in the C code need to be kept in sync with
the analysis manually. Obviously, the linker will complain about missing
symbols in case a symbol was renamed in IDA, but not in the C files.
Debugging restunts.exe
Restunts can be debugged with Turbo Debugger inside DOSBox. The DOSBox
debugging environment is an extension of the build environment described above:
1) Double click tools\mount_stunts_to_s.bat (only needed once per reboot)
2) Start DOSBox and enter the following commands:
mount S S:
S:
cd tools
setpath.bat
cd \stunts
td restunts.exe
Turbo Debugger is preconfigured to automatically find and show the source code.
Setting breakpoints, stepping etc works. The TD configuration file is stored in
stunts\tdconfig.td.
Notes regarding make
Borland Make was chosen because the first makefile was written for the DOS
version. Ultimately the DOS version ran into memory problems with the largest asm-files. Too late and too lazy to find a new make utility, the Windows
version of Borland Make, included in Borland C++ 5.5, was used instead. But:
Borland Make 5.2 uses MAKEFILE.@@@ as the filename for temporary inline files.
WLINK interprets @ in a special way on the command line and will not take the inline file as a parameter. As such make.exe was patched to use MAKEFILE.!!!
as the temporary filename instead.
Notes regarding the linker
WLINK from the Open Watcom C/C++ compiler suite was originally chosen because
it supports detailed control on how to order segment classes in the final
executable image.
Our requirement is to put the original code and data first in the file, exactly
as in the original game, only patching up function calls and data access. TLINK and OPTLINK were tested in the early days, but after having difficulties
with segment ordering and subsequent crashes, the project settled on WLINK.
The problems with TLINK were revisited and fixed years later, after an urgent
need to get debug information for the restunts executable. As WLINK is not able
to use the debug information format created by BCC/TASM, it became necessary to
replace either of them. After the initial attempts of using TLINK were
successful, no further investigation were made into replacing TASM. It should
be noted that MASM seems a promising TASM replacement candidate: the syntax is
close to TASM, and it produces CodeView debug format usable by WLINK.
Notes regarding 16-bit tasmx, tlink and DOSBox
The choice of reverting to TLINK was not easy either. Only the 16-bit version
of TLINK can produce 16-bit executables such as restunts.exe, and it can only
use object files produced by the 16-bit TASM. In order to use 16-bit tools on a
64-bit Windows host, they need to be emulated. And so DOSBox became
incorporated in the build process. Another problem is the regular 16-bit
tasm.exe exceeds the available 640k of memory when compiling the largest
restunts source files. This was overcome by using the DPMI-enabled tasmx.exe
instead.
Notes regarding the CRT (libc)
When linking with cm.lib from Borland C++ 5.1, TLINK is not able to produce an
executable. To get around this, the tlib tool was used to extract object files
from cm.lib, and now restunts links with these instead.
When the project used WLINK, it was able to link with cm.lib from Borland C++
5.1, but was not able to link correctly with cm.lib from Borland C++ 3.1.
Before upgrading to Borland C++ 5.1, the makefile would link to single obj
files from Borland 3.1's CRT. The linker can complain about weird missing symbols f.ex at first time use of
some compiler feature or CRT function. This can be fixed by extracting the
object file from cm.lib, and adding it to the makefile.
cm.lib is the medium model libc from Borland C++ 5.2. tlib.exe is a 16-bit
Borland utility for manipulating lib files and has to be run via DOSBox.
Using a binary file viewer with cm.lib it's possible to locate missing CRT
symbol names and work out/guess the object file name by looking at strings in
the binary data before it.
To extract the object file
1) Double click tools\mount_stunts_to_s.bat (only needed once per reboot)
2) Start DOSBox and initialize the restunts development environment:
mount S S:
S:
cd tools
setpath.bat
cd \tools\lib
3) Run tlib to extract the object file, some examples:
tlib cm.lib * GETVECT
tlib cm.lib * LABS
tlib cm.lib * STRCPY
tlib cm.lib * MEMCPY
tlib cm.lib * FMEMCPY
tlib cm.lib * H_LDIV
tlib cm.lib * F_LXMUL
tlib cm.lib * F_SCOPY
tlib cm.lib * H_LRSH
tlib cm.lib * H_PADD
tlib cm.lib * H_PINA
tlib cm.lib * H_PADA
tlib cm.lib * N_PCMP
tlib cm.lib * F_PCMP
tlib cm.lib * H_LURSH
tlib cm.lib * H_PSBP
tlib cm.lib * H_LLSH
4) Add new CRT object files in dos\makefile - at the end of the line
starting with CTARGETS =
Porting a function from ASM to C
1. Open src\idc\anders.idc in a text editor and locate the PortFuncName() function. The IDA script needs to be aware of all the functions that have been ported in order to generate asm that does not conflict with the ported
code. Add a line in PortFuncName() for the function you've chosen.
2. Run anders.idc from within IDA to regenerate the asm files (or skip step 1+2
and rename the respective extrn, public and function manually in the .inc
and asm files)
3. Add a function stub to one of the existing .c files in src\restunts\c 3.1 If you want to add a new .c-file to the project, you need to - add a target for it in c\makefile
- add a reference to the obj in RESTUNTS_OBJFILES in dos\makefile
4. Add an extrn for the c-function in asm\custom.inc
5. Start make to see if it compiles + links
6. Port to c!

About

A clone of clvn's restunts SVN repository

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Latest commit

History

230 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Restunts - The Stunts reverse engineering project
https://wiki.stunts.hu/wiki/Restunts
Repository contents:
docs
Various technical docs related to (re)stunts itself.
src\execombiner
Tool which combines the original game and video drivers into a single
debugable executable.
src\idc
Script for IdaPro to generate .asm-files from an ida project.
src\restunts
Project directory containing disassembly, ported c and makefiles to
produce various executables based on the (re)stunts code.
stunts
Stunts 1.1 the game.
tools
Contains binaries, libraries, headers with a full toolchain for
building restunts on Windows. The toolchain is based on TASM, TLINK,
Turbo Debugger, Borland C++, DOSBox, and various other tools.
Contents of src\restunts:
src\restunts\game_mod3.idb
The analysis database for IDAPro.
src\restunts\asm
Contains patched, compilable disassembly generated by the script for
IdaPro. This code is patched to work with our ported c code.
Note 2025-02-03: the asm is not in sync with IDA any more, since some
variable names were modified by the script src\restunts\annotate-vars.sh
src\restunts\asmorig
Contains the same files as src\restunts\asm, but unpatched and does not
use any of the ported c code.
src\restunts\c
Contains c functions ported from the disassembly.
src\restunts\dos
Makefile to build restunts for DOS.
src\restunts\repldump
Tool based on the original game code, loads replays and dumps the game
state contents at each frame in a file for further analysis.
The build environment
How to build restunts on Windows:
1) Double click tools\mount_stunts_to_s.bat (only needed once per reboot)
2) Start cmd.exe and enter the following commands:
S:
cd tools
setpath.bat
cd \src\restunts
make
How to build restunts on Linux:
1) Install Wine
2) Mount the restunts dir as drive S using winecfg
3) In the Linux console type `wineconsole cmd`
4) In the resulting Wine console type (mind the inverted slashes and the lack of tab completion):
```
s:
cd src\restunts
..\..\tools\setpath
```
On both platforms:
If everything went fine, there should be a new s:\stunts\restunts.exe which can
be run in DOSBox. Note that the drive letter S: is hardcoded many places in the
makefiles, and is also mounted inside DOSBox as a fixed point of reference.
The makefile supports the following targets:
make restunts
The default restunts target builds an executable based on ported C code
and patched disassembly.
make restunts-original
Builds an executable based on unpatched disassembly with the original
codepaths intact. Does not use any of the ported C code.
make repldump
Builds the replay dump tool using ported C code and patched
disassembly.
make repldump-original
Builds the replay dump tool without ported C code.
The toolchain
The toolchain has evolved over the years and is now (2014) fully based on Borland tools. For various reasons, the build process uses both 16 and 32-bit
tools. In order to compile on modern 64 bit Windows systems, the 16-bit apps
run via DOSBox. A DOSBox window pops up multiple times during a build, and
stays open in case of build errors.
Tools used:
- TASMX + TLINK (16 bit DOS, from Borland Turbo Assembler 4.0)
- Borland C++ 5.2 (Win32)
- Borland Make 5.2 (Win32, from Borland C++ 5.5, patched binary)
The 16-bit tools are:
tasmx.exe, invoked in DOSBox by tasmbox.bat
tlink.exe, invoked in DOSBox by tlinkbox.bat
Analysis in IDA and the development cycle
Analysis happens continously in IDA 6.1 (Win32). Using a custom script in IDA,
the entire disassembly is exported to compilable .asm and .inc files in src\restunts\asm. This allows using latest analysis results in the build
process. As code is ported manually to C, the custom script is updated and kept
in sync, such that it generates patched assembly code calling into the ported C
functions.
The custom script also runs a second pass, where it exports a separate set of .asm files to src\restunts\asmorig. These files are unpatched and produce code
that behaves 100% identically to the original game.
When doing analysis and (re)naming variables and functions, it is important to
always check the ported C code if there are any references to the previous
symbol names. All symbol references in the C code need to be kept in sync with
the analysis manually. Obviously, the linker will complain about missing
symbols in case a symbol was renamed in IDA, but not in the C files.
Debugging restunts.exe
Restunts can be debugged with Turbo Debugger inside DOSBox. The DOSBox
debugging environment is an extension of the build environment described above:
1) Double click tools\mount_stunts_to_s.bat (only needed once per reboot)
2) Start DOSBox and enter the following commands:
mount S S:
S:
cd tools
setpath.bat
cd \stunts
td restunts.exe
Turbo Debugger is preconfigured to automatically find and show the source code.
Setting breakpoints, stepping etc works. The TD configuration file is stored in
stunts\tdconfig.td.
Notes regarding make
Borland Make was chosen because the first makefile was written for the DOS
version. Ultimately the DOS version ran into memory problems with the largest asm-files. Too late and too lazy to find a new make utility, the Windows
version of Borland Make, included in Borland C++ 5.5, was used instead. But:
Borland Make 5.2 uses MAKEFILE.@@@ as the filename for temporary inline files.
WLINK interprets @ in a special way on the command line and will not take the inline file as a parameter. As such make.exe was patched to use MAKEFILE.!!!
as the temporary filename instead.
Notes regarding the linker
WLINK from the Open Watcom C/C++ compiler suite was originally chosen because
it supports detailed control on how to order segment classes in the final
executable image.
Our requirement is to put the original code and data first in the file, exactly
as in the original game, only patching up function calls and data access. TLINK and OPTLINK were tested in the early days, but after having difficulties
with segment ordering and subsequent crashes, the project settled on WLINK.
The problems with TLINK were revisited and fixed years later, after an urgent
need to get debug information for the restunts executable. As WLINK is not able
to use the debug information format created by BCC/TASM, it became necessary to
replace either of them. After the initial attempts of using TLINK were
successful, no further investigation were made into replacing TASM. It should
be noted that MASM seems a promising TASM replacement candidate: the syntax is
close to TASM, and it produces CodeView debug format usable by WLINK.
Notes regarding 16-bit tasmx, tlink and DOSBox
The choice of reverting to TLINK was not easy either. Only the 16-bit version
of TLINK can produce 16-bit executables such as restunts.exe, and it can only
use object files produced by the 16-bit TASM. In order to use 16-bit tools on a
64-bit Windows host, they need to be emulated. And so DOSBox became
incorporated in the build process. Another problem is the regular 16-bit
tasm.exe exceeds the available 640k of memory when compiling the largest
restunts source files. This was overcome by using the DPMI-enabled tasmx.exe
instead.
Notes regarding the CRT (libc)
When linking with cm.lib from Borland C++ 5.1, TLINK is not able to produce an
executable. To get around this, the tlib tool was used to extract object files
from cm.lib, and now restunts links with these instead.
When the project used WLINK, it was able to link with cm.lib from Borland C++
5.1, but was not able to link correctly with cm.lib from Borland C++ 3.1.
Before upgrading to Borland C++ 5.1, the makefile would link to single obj
files from Borland 3.1's CRT. The linker can complain about weird missing symbols f.ex at first time use of
some compiler feature or CRT function. This can be fixed by extracting the
object file from cm.lib, and adding it to the makefile.
cm.lib is the medium model libc from Borland C++ 5.2. tlib.exe is a 16-bit
Borland utility for manipulating lib files and has to be run via DOSBox.
Using a binary file viewer with cm.lib it's possible to locate missing CRT
symbol names and work out/guess the object file name by looking at strings in
the binary data before it.
To extract the object file
1) Double click tools\mount_stunts_to_s.bat (only needed once per reboot)
2) Start DOSBox and initialize the restunts development environment:
mount S S:
S:
cd tools
setpath.bat
cd \tools\lib
3) Run tlib to extract the object file, some examples:
tlib cm.lib * GETVECT
tlib cm.lib * LABS
tlib cm.lib * STRCPY
tlib cm.lib * MEMCPY
tlib cm.lib * FMEMCPY
tlib cm.lib * H_LDIV
tlib cm.lib * F_LXMUL
tlib cm.lib * F_SCOPY
tlib cm.lib * H_LRSH
tlib cm.lib * H_PADD
tlib cm.lib * H_PINA
tlib cm.lib * H_PADA
tlib cm.lib * N_PCMP
tlib cm.lib * F_PCMP
tlib cm.lib * H_LURSH
tlib cm.lib * H_PSBP
tlib cm.lib * H_LLSH
4) Add new CRT object files in dos\makefile - at the end of the line
starting with CTARGETS =
Porting a function from ASM to C
1. Open src\idc\anders.idc in a text editor and locate the PortFuncName() function. The IDA script needs to be aware of all the functions that have been ported in order to generate asm that does not conflict with the ported
code. Add a line in PortFuncName() for the function you've chosen.
2. Run anders.idc from within IDA to regenerate the asm files (or skip step 1+2
and rename the respective extrn, public and function manually in the .inc
and asm files)
3. Add a function stub to one of the existing .c files in src\restunts\c 3.1 If you want to add a new .c-file to the project, you need to - add a target for it in c\makefile
- add a reference to the obj in RESTUNTS_OBJFILES in dos\makefile
4. Add an extrn for the c-function in asm\custom.inc
5. Start make to see if it compiles + links
6. Port to c!

About

A clone of clvn's restunts SVN repository

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Latest commit

History

230 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Restunts - The Stunts reverse engineering project
https://wiki.stunts.hu/wiki/Restunts
Repository contents:
docs
Various technical docs related to (re)stunts itself.
src\execombiner
Tool which combines the original game and video drivers into a single
debugable executable.
src\idc
Script for IdaPro to generate .asm-files from an ida project.
src\restunts
Project directory containing disassembly, ported c and makefiles to
produce various executables based on the (re)stunts code.
stunts
Stunts 1.1 the game.
tools
Contains binaries, libraries, headers with a full toolchain for
building restunts on Windows. The toolchain is based on TASM, TLINK,
Turbo Debugger, Borland C++, DOSBox, and various other tools.
Contents of src\restunts:
src\restunts\game_mod3.idb
The analysis database for IDAPro.
src\restunts\asm
Contains patched, compilable disassembly generated by the script for
IdaPro. This code is patched to work with our ported c code.
Note 2025-02-03: the asm is not in sync with IDA any more, since some
variable names were modified by the script src\restunts\annotate-vars.sh
src\restunts\asmorig
Contains the same files as src\restunts\asm, but unpatched and does not
use any of the ported c code.
src\restunts\c
Contains c functions ported from the disassembly.
src\restunts\dos
Makefile to build restunts for DOS.
src\restunts\repldump
Tool based on the original game code, loads replays and dumps the game
state contents at each frame in a file for further analysis.
The build environment
How to build restunts on Windows:
1) Double click tools\mount_stunts_to_s.bat (only needed once per reboot)
2) Start cmd.exe and enter the following commands:
S:
cd tools
setpath.bat
cd \src\restunts
make
How to build restunts on Linux:
1) Install Wine
2) Mount the restunts dir as drive S using winecfg
3) In the Linux console type `wineconsole cmd`
4) In the resulting Wine console type (mind the inverted slashes and the lack of tab completion):
```
s:
cd src\restunts
..\..\tools\setpath
```
On both platforms:
If everything went fine, there should be a new s:\stunts\restunts.exe which can
be run in DOSBox. Note that the drive letter S: is hardcoded many places in the
makefiles, and is also mounted inside DOSBox as a fixed point of reference.
The makefile supports the following targets:
make restunts
The default restunts target builds an executable based on ported C code
and patched disassembly.
make restunts-original
Builds an executable based on unpatched disassembly with the original
codepaths intact. Does not use any of the ported C code.
make repldump
Builds the replay dump tool using ported C code and patched
disassembly.
make repldump-original
Builds the replay dump tool without ported C code.
The toolchain
The toolchain has evolved over the years and is now (2014) fully based on Borland tools. For various reasons, the build process uses both 16 and 32-bit
tools. In order to compile on modern 64 bit Windows systems, the 16-bit apps
run via DOSBox. A DOSBox window pops up multiple times during a build, and
stays open in case of build errors.
Tools used:
- TASMX + TLINK (16 bit DOS, from Borland Turbo Assembler 4.0)
- Borland C++ 5.2 (Win32)
- Borland Make 5.2 (Win32, from Borland C++ 5.5, patched binary)
The 16-bit tools are:
tasmx.exe, invoked in DOSBox by tasmbox.bat
tlink.exe, invoked in DOSBox by tlinkbox.bat
Analysis in IDA and the development cycle
Analysis happens continously in IDA 6.1 (Win32). Using a custom script in IDA,
the entire disassembly is exported to compilable .asm and .inc files in src\restunts\asm. This allows using latest analysis results in the build
process. As code is ported manually to C, the custom script is updated and kept
in sync, such that it generates patched assembly code calling into the ported C
functions.
The custom script also runs a second pass, where it exports a separate set of .asm files to src\restunts\asmorig. These files are unpatched and produce code
that behaves 100% identically to the original game.
When doing analysis and (re)naming variables and functions, it is important to
always check the ported C code if there are any references to the previous
symbol names. All symbol references in the C code need to be kept in sync with
the analysis manually. Obviously, the linker will complain about missing
symbols in case a symbol was renamed in IDA, but not in the C files.
Debugging restunts.exe
Restunts can be debugged with Turbo Debugger inside DOSBox. The DOSBox
debugging environment is an extension of the build environment described above:
1) Double click tools\mount_stunts_to_s.bat (only needed once per reboot)
2) Start DOSBox and enter the following commands:
mount S S:
S:
cd tools
setpath.bat
cd \stunts
td restunts.exe
Turbo Debugger is preconfigured to automatically find and show the source code.
Setting breakpoints, stepping etc works. The TD configuration file is stored in
stunts\tdconfig.td.
Notes regarding make
Borland Make was chosen because the first makefile was written for the DOS
version. Ultimately the DOS version ran into memory problems with the largest asm-files. Too late and too lazy to find a new make utility, the Windows
version of Borland Make, included in Borland C++ 5.5, was used instead. But:
Borland Make 5.2 uses MAKEFILE.@@@ as the filename for temporary inline files.
WLINK interprets @ in a special way on the command line and will not take the inline file as a parameter. As such make.exe was patched to use MAKEFILE.!!!
as the temporary filename instead.
Notes regarding the linker
WLINK from the Open Watcom C/C++ compiler suite was originally chosen because
it supports detailed control on how to order segment classes in the final
executable image.
Our requirement is to put the original code and data first in the file, exactly
as in the original game, only patching up function calls and data access. TLINK and OPTLINK were tested in the early days, but after having difficulties
with segment ordering and subsequent crashes, the project settled on WLINK.
The problems with TLINK were revisited and fixed years later, after an urgent
need to get debug information for the restunts executable. As WLINK is not able
to use the debug information format created by BCC/TASM, it became necessary to
replace either of them. After the initial attempts of using TLINK were
successful, no further investigation were made into replacing TASM. It should
be noted that MASM seems a promising TASM replacement candidate: the syntax is
close to TASM, and it produces CodeView debug format usable by WLINK.
Notes regarding 16-bit tasmx, tlink and DOSBox
The choice of reverting to TLINK was not easy either. Only the 16-bit version
of TLINK can produce 16-bit executables such as restunts.exe, and it can only
use object files produced by the 16-bit TASM. In order to use 16-bit tools on a
64-bit Windows host, they need to be emulated. And so DOSBox became
incorporated in the build process. Another problem is the regular 16-bit
tasm.exe exceeds the available 640k of memory when compiling the largest
restunts source files. This was overcome by using the DPMI-enabled tasmx.exe
instead.
Notes regarding the CRT (libc)
When linking with cm.lib from Borland C++ 5.1, TLINK is not able to produce an
executable. To get around this, the tlib tool was used to extract object files
from cm.lib, and now restunts links with these instead.
When the project used WLINK, it was able to link with cm.lib from Borland C++
5.1, but was not able to link correctly with cm.lib from Borland C++ 3.1.
Before upgrading to Borland C++ 5.1, the makefile would link to single obj
files from Borland 3.1's CRT. The linker can complain about weird missing symbols f.ex at first time use of
some compiler feature or CRT function. This can be fixed by extracting the
object file from cm.lib, and adding it to the makefile.
cm.lib is the medium model libc from Borland C++ 5.2. tlib.exe is a 16-bit
Borland utility for manipulating lib files and has to be run via DOSBox.
Using a binary file viewer with cm.lib it's possible to locate missing CRT
symbol names and work out/guess the object file name by looking at strings in
the binary data before it.
To extract the object file
1) Double click tools\mount_stunts_to_s.bat (only needed once per reboot)
2) Start DOSBox and initialize the restunts development environment:
mount S S:
S:
cd tools
setpath.bat
cd \tools\lib
3) Run tlib to extract the object file, some examples:
tlib cm.lib * GETVECT
tlib cm.lib * LABS
tlib cm.lib * STRCPY
tlib cm.lib * MEMCPY
tlib cm.lib * FMEMCPY
tlib cm.lib * H_LDIV
tlib cm.lib * F_LXMUL
tlib cm.lib * F_SCOPY
tlib cm.lib * H_LRSH
tlib cm.lib * H_PADD
tlib cm.lib * H_PINA
tlib cm.lib * H_PADA
tlib cm.lib * N_PCMP
tlib cm.lib * F_PCMP
tlib cm.lib * H_LURSH
tlib cm.lib * H_PSBP
tlib cm.lib * H_LLSH
4) Add new CRT object files in dos\makefile - at the end of the line
starting with CTARGETS =
Porting a function from ASM to C
1. Open src\idc\anders.idc in a text editor and locate the PortFuncName() function. The IDA script needs to be aware of all the functions that have been ported in order to generate asm that does not conflict with the ported
code. Add a line in PortFuncName() for the function you've chosen.
2. Run anders.idc from within IDA to regenerate the asm files (or skip step 1+2
and rename the respective extrn, public and function manually in the .inc
and asm files)
3. Add a function stub to one of the existing .c files in src\restunts\c 3.1 If you want to add a new .c-file to the project, you need to - add a target for it in c\makefile
- add a reference to the obj in RESTUNTS_OBJFILES in dos\makefile
4. Add an extrn for the c-function in asm\custom.inc
5. Start make to see if it compiles + links
6. Port to c!

About

A clone of clvn's restunts SVN repository

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages