Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
S

Spice86

> 数据库
Open source

Reverse engineer and rewrite real mode DOS programs!

653 stars0 likes0 views
WebsiteGitHub

About

Reverse engineer and rewrite real mode DOS programs!

Spice86 - A PC emulator for real mode reverse engineering

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.

Approach

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:

  • You start by emulating the program in the Spice86 emulator.
  • As the program runs, Spice86 builds a Control Flow Graph (CFG) of the executed code.
  • At the end of each run, the emulator dumps some runtime data (memory dump, execution flow and the CFG).
  • From that CFG, Spice86 directly generates a self-contained, runnable C# project that overrides the original assembly with equivalent C# code.
  • You then gradually rewrite the generated C# functions, replacing the mechanical translation with readable, intentful code (a task an LLM can help with).
  • This is helpful because:
    • Small sequences of assembly can be statically analyzed and are generally easy to translate to a higher level language.
    • You work all the time with a fully working version of the program so it is relatively easy to catch mistakes early.
    • Rewriting code function by function allows you to discover the intent of the author.

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.

Running your exe

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

Dumping data

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:

  • spice86dumpMemoryDump.bin: Snapshot of the real mode address space
  • spice86dumpExecutionFlow.json: Contains function addresses, labels, and executed instructions
  • spice86dumpGhidraSymbols.txt: Ghidra-compatible symbols (function and label addresses), for optional import into Ghidra
  • spice86dumpCfgBlocks.json: The explored CFG as basic blocks with execution-context metadata
  • spice86dumpCfgPartitions.json: The recovered function/helper partitions and inter-partition transfers, derived from the block graph
  • spice86dumpCfgGeneratedOverrides.cs: C# overrides generated from the explored CFG
  • GeneratedProject/: A self-contained, runnable C# override project (see Generated C# override project)

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.

CPU Heavy Logging

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,0x0080

Usage:

bash
# 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]"

Command line options

…

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.

Overriding emulated code with C# code

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.

Defining 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.

Debugger

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.

Structure viewer

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.

HTTP server

Spice86 includes a built-in HTTP server for quick runtime inspection and memory access.

  • The HTTP server is disabled by default. Enable it by specifying a port with --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

Misc details

C Drive

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.

Emulated program arguments

You can pass arguments (max 127 chars!) to the emulated program with the option --ExeArgs. Default is empty.

Time

The emulated Timer hardware of the PC (Intel 8259) supports measuring time from either:

  • The real elapsed time. Speed can be altered with parameter --TimeMultiplier.
  • The number of instructions the emulated CPU executed. This is the behaviour that is activated with parameter --InstructionTimeScale and is forced when in GDB mode so that you can debug with peace of mind without the timer triggering.

Compatibility list available here.

How to build on your machine

  • Install the .NET 10 SDK (once)
  • clone the repo
  • run this where Spice86.sln is located:
bash
   dotnet build

How to run

bash
   Spice86 -e 

or use this where Spice86.csproj is located:

bash
   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:

bash
   ./run.sh -e 

Ghidra plugin

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.

Cfg Cpu

Doc here

MCP

MCP server documentation is available in doc/mcp.md.

Some screenshots

Cryo dune:

Prince of persia:

Stunts:

Betray

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C#assemblyavaloniauicross-platformdebugger

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库