Commit Graph

4 Commits

Author SHA1 Message Date
sp00nz 343df3088d tools: in-tree XDVDFS reader so step one is not "install Rust"
docs/formats/disc-image.md documented the format and then pointed at
xdvdfs-cli and extract-xiso for the actual extraction, which makes the
first step of the pipeline -- get me the XBE -- a dependency install.
Reading a tree of fixed-size directory entries is not worth that.

  py -3 -m tools.xiso ls     game.iso
  py -3 -m tools.xiso get    game.iso default.xbe -o game/
  py -3 -m tools.xiso unpack game.iso -o extracted/

Two decisions worth keeping:

The partition base is found by probing for MICROSOFT*XBOX*MEDIA at each
known offset rather than inferred from file size, because images turn up
both as bare game partitions and with a video partition in front.

Directory entries are walked per-sector rather than by following the
binary tree's left/right links. Entries are laid out contiguously within
each 2048-byte sector, so a linear walk with per-sector resync reads all
of them, and a padded or malformed link cannot silently drop a whole
subtree. Losing a file quietly is worse than being slow.

A non-XDVDFS file raises rather than returning an empty listing, which
would otherwise read as "this disc has no files on it".

Verified against the retail Crimson Skies image: 226 files, default.xbe
extracted at 3,219,456 bytes and parsed cleanly by tools.xbe_parser.
test_xdvdfs.py builds synthetic images in a temp dir so it runs without
one.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-23 02:38:56 -07:00
sp00nz 8a0bf9dbd2 kernel: fix 37 shifted ordinals in the thunk and export tables
The Xbox kernel export table includes DATA exports -- ExEventObjectType (16),
HalDiskCachePartitionCount (40), HalDiskModelNumber (41), IoFileObjectType
(71), KdDebuggerEnabled (88) and others -- which occupy ordinals but are
variables, not callable functions. Both xbox_resolve_ordinal() and
docs/formats/kernel-exports.md had been built by numbering only the callable
exports sequentially, so every data-export slot shifted all later ordinals by
one and dispatched a neighbouring function.

The failure is silent. A game importing ordinal 15 (ExAllocatePoolWithTag)
received ExAllocatePool, which takes one fewer argument; the call returns, the
stack is off, and the crash surfaces somewhere unrelated. Ordinal 49
(HalReturnToFirmware, a reboot) resolved to HalRequestSoftwareInterrupt.

Ordinals verified against xboxdevwiki.net/Kernel for the ranges 8-10, 14-25,
38-52, 61-90 and 93-105; the table in tools/xbe_parser/xbe_parser.py matched
it exactly and is now the single source of truth for both consumers.

Wrong-function bindings, before -> after:
  Xbox Dashboard                 18 -> 0
  Blood Wake                     18 -> 0
  Steel Battalion                19 -> 0
  Steel Battalion: LoC (retail)  25 -> 0
  Steel Battalion: LoC (debug)   25 -> 0

Also wires up 31 kernel functions that were implemented but never reachable
because their ordinal was occupied by a misplaced entry, among them
XcRC4Crypt, XcHMAC, MmAllocateSystemMemory, XeLoadSection and ExFreePool.
Ordinals with no implementation are now omitted entirely so the default arm
logs them, rather than pointing at an adjacent function.

Adds tools/validate_ordinals.py, which fails if either table drifts from the
export table again.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-19 23:15:22 -07:00
sp00nz e5af1d9063 Add new kernel stubs and fix MSVC label-before-brace issue
New kernel function implementations in kernel_stubs.h:
- DbgPrint (ord 7): __cdecl variadic debug output
- KdDebuggerNotPresent (ord 5): debug data export
- KeQueryInterruptTime (ord 125): monotonic time in 100ns units
- NtResumeThread (ord 302): resume suspended thread
- NtSuspendThread (ord 304): suspend thread

kernel-exports.md: document the 6 new ordinals in their
respective categories (Debug, Threading, HAL)

lifter.py: emit (void)0 instead of bare comments for cmp/test
instructions to prevent MSVC error when a label precedes a
comment-only line at end of function body

translator.py: add end-of-function fixup pass that inserts a
null statement after any trailing label with no following
statement

Discovered while bringing up Wreckless: The Yakuza Missions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-06 13:13:19 -08:00
sp00nz ef5ad3a734 Initial release: Xbox static recompilation toolkit
Complete toolchain for statically recompiling original Xbox (2001-2005) games
into native Windows executables. Includes:

- XBE parser, x86 disassembler, function identifier, and x86-to-C lifter
- 6-step pipeline documentation (parse, disassemble, identify, lift, runtime, debug)
- 8 technical deep dives (register model, memory layout, ICALLs, D3D, kernel, SEH, etc.)
- 3 Xbox format references (XBE, kernel exports, disc images)
- Runtime templates (recomp_types.h, xbox_memory.h, kernel_stubs.h)
- Candidate game analysis for future recompilation targets

Proven on Burnout 3: Takedown — 22,097 functions lifted from machine code to C.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-06 02:27:26 -08:00