# kdm-re A reverse-engineering and reconstruction project for **DanceEvolution Arcade** (DEA) — a Konami arcade Kinect dance game whose game logic ships as `gamekdm.dll` (internal engine/module codename **KDM**). The goal is to rebuild `gamekdm.dll`'s observable behavior from static and dynamic analysis of the shipped binary, one function at a time, each proven behaviorally equal to the original before it is shipped. > **Behavioral, not byte-identical.** Given the same inputs, the reconstruction > aims to produce the same outputs and global-state effects as the original — > proven function-by-function — not to reproduce the original machine code. The > toolchain (MinGW/GCC, i686) differs from the original's (MSVC/VS2010 SP1) by > construction. ## What the game is DEA is a Konami arcade dance game driven by a Kinect sensor: the player dances in front of a depth camera and the game scores the match between the tracked body pose and the choreography. It targets **Win32 x86** on Konami's **AVS2** middleware stack, with the **ARK** cabinet engine (`arkkdm.dll`) and **e-Amusement v3** networking. The game analyzed throughout is the clean **`KDM-2016021900`** release. The main logic DLL, `gamekdm.dll` (PE32 x86), exports a single symbol, `gameMain` (RVA `0x00009e20`, cdecl), and contains **9,728** functions tracked in `re/rvadb.json`. ### Official scope The spec and reverse engineering reference **only the official game** — the clean release's `contents/` tree: its asset/config trees (`data/`, `arkdata/`, `prop/`) and exactly **9 Konami modules** in `contents/modules/`: `libavs-win32.dll`, `libavs-win32-ea3.dll`, `libafp-win32.dll`, `libafputils-win32.dll`, `ess.dll`, `libacio.dll`, `arkkdm.dll`, `arkkdmtest.dll`, `gamekdm.dll`. Community or PC-hardware glue that may appear in a non-clean install — `launcher.exe`, `deahook.dll`, spice2x/bemanitools, NVENC/CUDA stubs, a Kinect shim, and non-release Konami modules — is **not** part of the game and is not used as evidence. `Kinect10.dll` (Microsoft's Kinect-for-Windows NUI runtime) is referenced only as an external dependency that `gamekdm.dll`'s import table requires, never as a shipped game module. See [`docs/companion-inventory.md`](docs/companion-inventory.md). ## Repository layout | Path | What it holds | |---|---| | `docs/spec/` | The full technical specification — start here (see below). | | `docs/` | Process docs: `companion-inventory.md`, `conventions.md`, `pipeline.md`, `reconstruction-loop.md`, `cutover.md`, `provenance.md`. | | `src/`, `include/` | The hand-reviewed MinGW C/C++ reconstruction, layered by subsystem (`game`, `gs`, `render`, `movie`, `particle`, `mm`, `ui`, `util`, `platform`, `hybrid`, `pure`, `entry`). | | `re/` | The RVA function database (`rvadb.json`, 9,728 records), `pure-slice-status.json`, import libs, and AVS notes. | | `tools/` | `unicorn_diff/` (the differential verifier), `ghidra/` helpers, `gen_importlibs.sh`. | | `tests/` | Golden-I/O fixtures, import-lib checks, smoke tests. | | `cmake/` | `toolchain-mingw-i686.cmake` (cross toolchain file) and `check_pure_coverage.py` (the fail-closed coverage gate). | | `activate.sh` | Sources the pinned no-sudo i686-w64-mingw32 cross toolchain + wine onto `PATH`. | | `toolchain.lock` | Exact toolchain provenance (nixpkgs rev, package versions, store paths). | | `orig/`, `export/`, `bin/` | Gitignored originals drop zone, the hand-authored `gamekdm.def`, and the `activate.sh`-generated tool aliases. | ## Specification The authoritative, fully-cited technical spec lives in **[`docs/spec/`](docs/spec/README.md)**. Every claim in it is grounded in a real artifact (a `file:line`, an RVA, an `objdump` listing, or a game-dir path); anything unverifiable is marked `UNVERIFIED`. Sections: - [00 — Overview and high-level architecture](docs/spec/00-overview.md) - [01 — Runtime environment and boot/startup chain](docs/spec/01-runtime-boot.md) - [02 — DLL architecture and dependency graph](docs/spec/02-dll-architecture.md) - [03 — Kinect input and skeleton pipeline](docs/spec/03-kinect-skeleton.md) - [04 — Player validity gate and menu hand cursor](docs/spec/04-validity-cursor.md) - [05 — Data formats](docs/spec/05-data-formats.md) - [06 — gamekdm.dll subsystem map](docs/spec/06-gamekdm-subsystems.md) - [07 — Companion DLL API surfaces](docs/spec/07-companion-apis.md) - [08 — ABI, calling conventions, and struct layouts](docs/spec/08-abi-conventions.md) - [09 — The kdm-re reconstruction codebase](docs/spec/09-reconstruction-codebase.md) ## Build The build targets a 32-bit Windows DLL and **never touches system packages** — it uses a pinned, no-sudo i686-w64-mingw32 cross toolchain plus wine, sourced onto `PATH` by `activate.sh`. ```bash source ./activate.sh # must be sourced, not executed cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-mingw-i686.cmake cmake --build build i686-w64-mingw32-objdump -p build/gamekdm.dll | grep -A6 'Export Address Table' ``` Output is `build/gamekdm.dll`, a PE32 (i386) DLL. ### Build modes - **Hybrid (default)** — builds `gamekdm.dll` as a shared proxy plus the detour static library; reconstructed functions override the original where proven. - **PURE** (`-DBUILD_PURE=ON`) — links/loads no original DLL at all. A fail-closed coverage gate (`cmake/check_pure_coverage.py`) runs at configure time and before every build; in full mode it demands 100% `verified` status across the call graph. - **PURE slice** (`-DBUILD_PURE=ON -DPURE_SLICE=ON`) — builds only the verified slice with explicit stubs for the remainder. ## Verification Each reconstructed function is proven behaviorally equal to the original before it ships: - **Unicorn differential** (`tools/unicorn_diff/`) emulates the real routine inside the shipping `gamekdm.dll` as the oracle, runs the compiled C++ reconstruction under wine on the same inputs, and asserts behavioral equality, with an injected-bug non-vacuity check. - **Golden I/O** fixtures under `tests/golden/`. - **Detours** are gated by an ownership allowlist: only `pod_only` functions may hot-patch the original image; `shared_mutable_globals` and `foreign_object_abi` functions are blocked even when verified. ## Status Reconstruction is **early and explicitly tracked**. As of this writing, `re/rvadb.json` records **1 of 9,728** functions as `verified`, and the subsystem map classifies ~2.7% of functions into named subsystems by design (positive-evidence-only). The runtime cutover path exists as a mechanism but is deliberately gated and incomplete. Treat any claim about "what a function does" beyond one explicitly reconstructed, decompiled, or cited to a disassembly as unestablished. ## Scope and license - **No copyrighted creative asset** (song audio, video, lyrics, or art) is reproduced anywhere in this repository or spec. Only file/container formats, directory structure, and code behavior are described. - Original game binaries are **not** committed; see [`docs/provenance.md`](docs/provenance.md) for origin and handling. - This repository is **private and unlicensed** — see [`LICENSE`](LICENSE). No rights to use, copy, modify, or distribute any part of it are granted; the final license (if any) has not been decided.