Reverse engineer and rewrite real mode DOS programs!
Spice86 is a tool to execute, reverse engineer and rewrite real mode DOS programs for which source code is not available.
Releases are available on Nuget.
Pre-releases are also available on the Release page
NOTE: This is a port, and a continuation from the original Java Spice86.
It requires .NET 10 and runs on Windows, macOS, and Linux.
Rewriting a program from only the binary is a hard task.
Spice86 is a tool that helps you do so with a methodic divide and conquer approach.
General process:
Spice86 also dumps Ghidra-compatible symbols, so you can optionally load the memory dump into Ghidra via the spice86-ghidra-plugin for deeper static analysis. This is no longer required to produce C# overrides; it is just an extra analysis aid.
| Command | Description |
|---|---|
Spice86 -e file.exe |
Run the specified executable |
Spice86 -e file.com |
Run a COM file |
Spice86 -e file.bat |
Run a DOS batch file |
Spice86 -e file.bin |
Run a BIOS file |
| Setting | Description |
|---|---|
| Environment Variable | SPICE86_DUMPS_FOLDER - Set this to control the base directory where data is dumped |
| Command Line | Use --RecordedDataDirectory to specify the base dump location |
| Default Location | Current directory if neither of the above is specified |
Note: Regardless of the base directory setting, dumps are always placed in a subdirectory named with the program's SHA-256 hash. This ensures that multiple executables from the same game (e.g., SETUP.EXE, GAME.EXE) have isolated dump folders.
The emulator dumps the following files:
When there is already data in the specified location, the emulator will load it first and complement it.
CFG graph reload: The CFG instruction graph is also dumped (spice86dumpCfgReload.json) and, by default, reloaded from the recorded data directory at startup so previously explored program structure is preserved across runs. Disable with --ReloadCfgGraph false. It is a no-op if the file is absent.
Code overrides: When code overrides are active (--UseCodeOverride true with an --OverrideSupplierClassName), the CFG and execution flow dumps (spice86dumpExecutionFlow.json, spice86dumpCfgBlocks.json, spice86dumpCfgPartitions.json, spice86dumpCfgReload.json) are not written. Overrides replace the emulated asm, so the recorded graph would jump between overrides and no longer reflect the program.
For detailed debugging, you can enable CPU heavy logging which records every executed instruction to a file.
⚠️ Warning: This feature has a significant performance impact and should only be used for debugging purposes.
| Setting | Description |
|---|---|
--CpuHeavyLog |
Enables CPU heavy logging (default: false) |
--CpuHeavyLogDumpFile |
Custom path for the log file (optional). If set, will enable CpuHeavyLog as well. Default Location: {DumpDirectory}/cpu_heavy.log |
--CpuHeavyLogExpressions |
Named expressions appended to every CPU heavy log line. Repeat the option for each expression to append (for example: --CpuHeavyLogExpressions "life=AX+1" --CpuHeavyLogExpressions "myvalue=word ptr DS:[0x456]"). Only active when --CpuHeavyLog is true. |
Log Format: Each line contains: SegmentedAddress InstructionString
Example:
017D:0000 mov AX,0xDD1D
017D:0003 call near 0xE4AD
017D:E4AD mov SI,0x0080Usage:
# Enable with default location
Spice86 -e program.exe --CpuHeavyLog
# Use custom log file path
Spice86 -e program.exe --CpuHeavyLog --CpuHeavyLogDumpFile "C:\logs\cpu.log"
# Append named expressions to each log line (example)
Spice86 -e program.exe --CpuHeavyLog \
--CpuHeavyLogExpressions "life=AX+1" \
--CpuHeavyLogExpressions "myvalue=word ptr DS:[0x456]"…Then progressively replace the mechanically generated function bodies with your own readable C# implementations.
Note: while running with overrides active (
--UseCodeOverride true), the CFG and execution-flow dumps are not rewritten, so regenerating from scratch should be done from a plain (non-override) run.
You can provide your own C# code to override the program original assembly code. This is exactly what the generated project does for you automatically; the section below explains the API so you (or an LLM) can write or refine overrides.
Spice86 can take in input an instance of Spice86.Core.Emulator.Function.IOverrideSupplier that builds a mapping between the memory address of functions and their C# overrides.
For a complete example you can check the source code of Cryogenic.
Here is a simple example of how it would look like:
…The override method name encodes the address (Name___) so it can be parsed back into a FunctionInformation; pass an explicit name argument to DefineFunction if you prefer not to follow that convention.
Remember: You must tell Spice86 to use your C# code overrides with the command line argument "--UseCodeOverride true" when debugging your project, along with the mandatory path to your DOS program passed with the "-e" / "--Exe" argument.
Spice86 comes with a built-in debugger. that can be used to debug the emulated program. It is a simple debugger that allows you to inspect the memory, the disassembly, the registers, and the stack.
The structure viewer allows you to inspect the memory in a structured way. It is useful to inspect the memory as a structure, like the DOS PSP, the DOS MCB, the VGA registers, etc.
First you need a C header file that describes the structures in the application. You can generate one with Ghidra or IDA. Then you can load it with the --StructureFile commandline argument.
This will enable the "Structure view" button in the Memory tab of the debugger.
There you enter a segment:offset address and choose the structure you want to view. The structure will be displayed in a tree view and the memory in a hex view.
The display updates whenever the application is paused, so you can step through the program and see how the structure changes. Exporting a new C header file from Ghidra or IDA will also update the structure viewer with the new information real-time.
You can also enter the Structure view by selecting a range of bytes in the Memory tab and right-clicking on it.
Spice86 includes a built-in HTTP server for quick runtime inspection and memory access.
--HttpApiPort.Available endpoints:
| Method | Route | Description |
|---|---|---|
GET |
/api |
API metadata and endpoint list |
GET |
/api/status |
Current emulator status (pause state, CPU state, CS:IP, cycles, memory size) |
GET |
/api/memory/{address}/byte |
Read one byte at address |
PUT |
/api/memory/{address}/byte |
Write one byte at address |
GET |
/api/memory/{address}/range/{length} |
Read a memory range |
It is possible to provide a C: Drive for emulated DOS functions with the option --CDrive. Default is executed program folder. For some games you may need to set the C drive to the parent folder.
You can pass arguments (max 127 chars!) to the emulated program with the option --ExeArgs. Default is empty.
The emulated Timer hardware of the PC (Intel 8259) supports measuring time from either:
Compatibility list available here.
dotnet build Spice86 -e or use this where Spice86.csproj is located:
dotnet run -e if you don't want to manually build and run separately, use the helper script at the root of the repository which builds and runs the app, passing all arguments through:
./run.sh -e Importing the dump into Ghidra is optional. Spice86 already generates a runnable C# override project on its own (see Generated C# override project); the Ghidra plugin is only useful if you additionally want to explore the dump inside Ghidra (static analysis, labeling, or producing a --StructureFile C header for the structure viewer).
This uses Ghidra and Java 17.
Before using it, define an environnement variable named SPICE86_DUMPS_FOLDER pointing to a folder where the Spice86 dumps are located. They are generated on exit.
General procedure, in order:
1.Ghidra's own script 'ImportSymbolScript.py' (input used is "spice86dumpGhidraSymbols.txt")
2.Ghidra's Auto-Analyze (only enable 'Dissasemble Entry Points')
3.Now, you can use the plugin.
Remember: if Ghidra displays SUBROUTINES, use the 'f' key to convert them into functions.
Also, if you have any weird behaviour, make sure you have Java 17 and ONLY Java 17. That's how Ghidra likes it.
Doc here
MCP server documentation is available in doc/mcp.md.
Cryo dune:
Prince of persia:
Stunts:
Betray
No open issues yet, or sync has not completed.