feat(gamekdm): reconstruct+verify wave 10 5
This commit is contained in:
1 parent
0e63f98ef4
commit
1b5d376273
6 files changed
+726
-10
No files matched your search
@@ -0,0 +1,316 @@
|
||||
"""Wave 10 faithful differential + non-vacuity proof: prove_game_w10.py.
|
||||
|
||||
Faithful differential of a fifteen-routine gamekdm.dll flat-leaf shard, proving
|
||||
the Unicorn-run original equal to the compiled MinGW/wine reconstruction on
|
||||
identical inputs: exact 32-bit return (EAX), exact low byte (AL) for the byte
|
||||
getters, and exact object/inner buffer bytes for the void setters.
|
||||
|
||||
The shard extends wave 9's indirect family with the direct-field family: five
|
||||
direct dword getters (three plain, one plus a constant, one shift-and-mask), two
|
||||
nested dword getters and two nested byte getters, two direct dword setters, one
|
||||
nested dword setter, one constant-one direct byte setter, and two direct boolean
|
||||
predicates (field != 0).
|
||||
|
||||
Every selected RVA is a globals-first clean leaf (no callees, no imported
|
||||
callees, no touched globals), so capture_state=True fails closed on any module
|
||||
memory access. The nested routines dereference a member pointer modelled the same
|
||||
way on both sides: the inner buffer is seeded first so it lands at the scratch
|
||||
base, and the object's +K field holds that scratch address, so the original
|
||||
dereferences [[ECX+K]+J] into the seeded inner buffer (outside the module image)
|
||||
and the reconstruction follows the same pointer into its own inner buffer. A
|
||||
per-function non-crashing mutation is injected and every function's differential
|
||||
must flag it. Optional positional arguments run only the named entries, so the
|
||||
proof can be driven in bounded foreground sub-batches.
|
||||
|
||||
tools/unicorn_diff/.venv/bin/python re/game/prove_game_w10.py [name ...]
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import dataclasses
|
||||
import json
|
||||
import struct
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
from typing import Literal, assert_never
|
||||
|
||||
from prove_game import ROOT, MCFGTHREAD_LIB, run_recon, mutate
|
||||
from udiff import (
|
||||
Buffer, CallConv, CallSpec, DiffReport, RegValue, ReturnKind, RunResult, StackValue,
|
||||
UnicornRunner, Verdict, diff,
|
||||
)
|
||||
from udiff.image import PeImage
|
||||
from udiff.scaffold import resolve_oracle
|
||||
|
||||
SRC = ROOT / "src/game/leaf_ops_w10.cpp"
|
||||
HARNESS = ROOT / "re/game/recon_game_w10_harness.cpp"
|
||||
THIS = CallConv.THISCALL
|
||||
INT, VOID = ReturnKind.INT, ReturnKind.VOID
|
||||
|
||||
SCRATCH_BASE = 0x00400000
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True, slots=True)
|
||||
class Case:
|
||||
spec: CallSpec
|
||||
payload: bytes
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True, slots=True)
|
||||
class Entry:
|
||||
rva: int
|
||||
mode: str
|
||||
symbol: str
|
||||
ret: Literal["int", "al", "void"]
|
||||
cases: tuple[Case, ...]
|
||||
anchor: str
|
||||
old: str
|
||||
new: str
|
||||
|
||||
|
||||
def u32(value: int) -> bytes:
|
||||
return struct.pack("<I", value & 0xFFFFFFFF)
|
||||
|
||||
|
||||
def object_with_dword(size: int, offset: int, value: int) -> bytes:
|
||||
buf = bytearray(size)
|
||||
buf[offset:offset + 4] = u32(value)
|
||||
return bytes(buf)
|
||||
|
||||
|
||||
def object_with_pointer(size: int, offset: int) -> bytes:
|
||||
buf = bytearray(size)
|
||||
buf[offset:offset + 4] = u32(SCRATCH_BASE)
|
||||
return bytes(buf)
|
||||
|
||||
|
||||
def direct_getter_case(rva: int, size: int, offset: int, value: int) -> Case:
|
||||
spec = CallSpec(rva=rva, conv=THIS, ret=INT, capture_state=True,
|
||||
regs=(RegValue("ecx", buffer=Buffer("obj", object_with_dword(size, offset, value))),))
|
||||
return Case(spec, u32(value))
|
||||
|
||||
|
||||
def nested_getter_case(rva: int, osize: int, ooff: int, isize: int, ioff: int, value: int) -> Case:
|
||||
inner = bytearray(isize)
|
||||
inner[ioff:ioff + 4] = u32(value)
|
||||
spec = CallSpec(rva=rva, conv=THIS, ret=INT, capture_state=True,
|
||||
regs=(RegValue("ecx", buffer=Buffer("obj", object_with_pointer(osize, ooff))),),
|
||||
buffers=(Buffer("inner", bytes(inner)),))
|
||||
return Case(spec, u32(value))
|
||||
|
||||
|
||||
def nested_byte_getter_case(rva: int, osize: int, ooff: int, isize: int, ioff: int, value: int) -> Case:
|
||||
inner = bytearray(isize)
|
||||
inner[ioff] = value & 0xFF
|
||||
spec = CallSpec(rva=rva, conv=THIS, ret=INT, capture_state=True,
|
||||
regs=(RegValue("ecx", buffer=Buffer("obj", object_with_pointer(osize, ooff))),),
|
||||
buffers=(Buffer("inner", bytes(inner)),))
|
||||
return Case(spec, bytes([value & 0xFF]))
|
||||
|
||||
|
||||
def direct_setter_case(rva: int, size: int, arg: int) -> Case:
|
||||
spec = CallSpec(rva=rva, conv=THIS, ret=VOID, capture_state=True,
|
||||
regs=(RegValue("ecx", buffer=Buffer("obj", bytes(size), out_size=size)),),
|
||||
stack_args=(StackValue(immediate=arg),))
|
||||
return Case(spec, u32(arg))
|
||||
|
||||
|
||||
def nested_setter_case(rva: int, osize: int, ooff: int, isize: int, arg: int) -> Case:
|
||||
spec = CallSpec(rva=rva, conv=THIS, ret=VOID, capture_state=True,
|
||||
regs=(RegValue("ecx", buffer=Buffer("obj", object_with_pointer(osize, ooff))),),
|
||||
stack_args=(StackValue(immediate=arg),),
|
||||
buffers=(Buffer("inner", bytes(isize), out_size=isize),))
|
||||
return Case(spec, u32(arg))
|
||||
|
||||
|
||||
def const_byte_setter_case(rva: int, size: int) -> Case:
|
||||
spec = CallSpec(rva=rva, conv=THIS, ret=VOID, capture_state=True,
|
||||
regs=(RegValue("ecx", buffer=Buffer("obj", bytes(size), out_size=size)),))
|
||||
return Case(spec, b"")
|
||||
|
||||
|
||||
def entries() -> tuple[Entry, ...]:
|
||||
return (
|
||||
Entry(0x1b2c60, "GetField20", "gk::game::GetField20", "int",
|
||||
(direct_getter_case(0x1b2c60, 0x28, 0x20, 0xCAFEBABE),
|
||||
direct_getter_case(0x1b2c60, 0x28, 0x20, 0)),
|
||||
"GetField20(const void* self)",
|
||||
"return Load32(self, 0x20);", "return Load32(self, 0x20) + 1;"),
|
||||
Entry(0x1add50, "GetField48", "gk::game::GetField48", "int",
|
||||
(direct_getter_case(0x1add50, 0x50, 0x48, 0xCAFEBABE),
|
||||
direct_getter_case(0x1add50, 0x50, 0x48, 0)),
|
||||
"GetField48(const void* self)",
|
||||
"return Load32(self, 0x48);", "return Load32(self, 0x48) + 1;"),
|
||||
Entry(0x1bdd50, "GetFieldEc", "gk::game::GetFieldEc", "int",
|
||||
(direct_getter_case(0x1bdd50, 0xf0, 0xec, 0xCAFEBABE),
|
||||
direct_getter_case(0x1bdd50, 0xf0, 0xec, 0)),
|
||||
"GetFieldEc(const void* self)",
|
||||
"return Load32(self, 0xec);", "return Load32(self, 0xec) + 1;"),
|
||||
Entry(0x1874e0, "GetFieldC0PlusDWORD28", "gk::game::GetFieldC0PlusDWORD28", "int",
|
||||
(direct_getter_case(0x1874e0, 0xc8, 0xc0, 0xCAFEBABE),
|
||||
direct_getter_case(0x1874e0, 0xc8, 0xc0, 0)),
|
||||
"GetFieldC0PlusDWORD28(const void* self)",
|
||||
"return Load32(self, 0xc0) + 0x28u;", "return Load32(self, 0xc0) + 0x29u;"),
|
||||
Entry(0x1d91d0, "GetField0Bits1To10", "gk::game::GetField0Bits1To10", "int",
|
||||
(direct_getter_case(0x1d91d0, 0x8, 0x0, 0xFFFFFFFF),
|
||||
direct_getter_case(0x1d91d0, 0x8, 0x0, 0x12345678)),
|
||||
"GetField0Bits1To10(const void* self)",
|
||||
"return (Load32(self, 0x00) >> 1) & 0x3ffu;",
|
||||
"return (Load32(self, 0x00) >> 1) & 0x1ffu;"),
|
||||
Entry(0x13c690, "GetIndirect8", "gk::game::GetIndirect8", "int",
|
||||
(nested_getter_case(0x13c690, 0xc, 0x8, 0x4, 0x0, 0xCAFEBABE),
|
||||
nested_getter_case(0x13c690, 0xc, 0x8, 0x4, 0x0, 0)),
|
||||
"GetIndirect8(const void* self)",
|
||||
"return Load32(DerefPtr(self, 0x08), 0x00);",
|
||||
"return Load32(DerefPtr(self, 0x08), 0x00) + 1;"),
|
||||
Entry(0x1a6660, "GetIndirect4_4", "gk::game::GetIndirect4_4", "int",
|
||||
(nested_getter_case(0x1a6660, 0x8, 0x4, 0x8, 0x4, 0xCAFEBABE),
|
||||
nested_getter_case(0x1a6660, 0x8, 0x4, 0x8, 0x4, 0)),
|
||||
"GetIndirect4_4(const void* self)",
|
||||
"return Load32(DerefPtr(self, 0x04), 0x04);",
|
||||
"return Load32(DerefPtr(self, 0x04), 0x04) + 1;"),
|
||||
Entry(0x95bd0, "GetIndirectByte4_c", "gk::game::GetIndirectByte4_c", "al",
|
||||
(nested_byte_getter_case(0x95bd0, 0x8, 0x4, 0xd, 0xc, 0x7E),
|
||||
nested_byte_getter_case(0x95bd0, 0x8, 0x4, 0xd, 0xc, 0)),
|
||||
"GetIndirectByte4_c(const void* self)",
|
||||
"return LoadU8(DerefPtr(self, 0x04), 0x0c);",
|
||||
"return static_cast<std::uint8_t>(LoadU8(DerefPtr(self, 0x04), 0x0c) + 1);"),
|
||||
Entry(0x134ce0, "GetIndirectByte8_c", "gk::game::GetIndirectByte8_c", "al",
|
||||
(nested_byte_getter_case(0x134ce0, 0xc, 0x8, 0xd, 0xc, 0x7E),
|
||||
nested_byte_getter_case(0x134ce0, 0xc, 0x8, 0xd, 0xc, 0)),
|
||||
"GetIndirectByte8_c(const void* self)",
|
||||
"return LoadU8(DerefPtr(self, 0x08), 0x0c);",
|
||||
"return static_cast<std::uint8_t>(LoadU8(DerefPtr(self, 0x08), 0x0c) + 1);"),
|
||||
Entry(0x120bb0, "SetFieldC4", "gk::game::SetFieldC4", "void",
|
||||
(direct_setter_case(0x120bb0, 0xc8, 0xDEADBEEF),),
|
||||
"SetFieldC4(void* self, std::uint32_t value)",
|
||||
"Store32(self, 0xc4, value);", "Store32(self, 0xc4, value + 1);"),
|
||||
Entry(0x14eff0, "SetFieldC", "gk::game::SetFieldC", "void",
|
||||
(direct_setter_case(0x14eff0, 0x10, 0xDEADBEEF),),
|
||||
"SetFieldC(void* self, std::uint32_t value)",
|
||||
"Store32(self, 0x0c, value);", "Store32(self, 0x0c, value + 1);"),
|
||||
Entry(0x13c6a0, "SetIndirect8", "gk::game::SetIndirect8", "void",
|
||||
(nested_setter_case(0x13c6a0, 0xc, 0x8, 0x4, 0xDEADBEEF),),
|
||||
"SetIndirect8(void* self, std::uint32_t value)",
|
||||
"Store32(DerefPtrMut(self, 0x08), 0x00, value);",
|
||||
"Store32(DerefPtrMut(self, 0x08), 0x00, value + 1);"),
|
||||
Entry(0x132500, "SetByte9One", "gk::game::SetByte9One", "void",
|
||||
(const_byte_setter_case(0x132500, 0xa),),
|
||||
"SetByte9One(void* self)",
|
||||
"StoreU8(self, 0x09, 1);", "StoreU8(self, 0x09, 2);"),
|
||||
Entry(0x1c1430, "IsField10NonZero", "gk::game::IsField10NonZero", "int",
|
||||
(direct_getter_case(0x1c1430, 0x14, 0x10, 0x1234),
|
||||
direct_getter_case(0x1c1430, 0x14, 0x10, 0)),
|
||||
"IsField10NonZero(const void* self)",
|
||||
"return Load32(self, 0x10) != 0 ? 1u : 0u;",
|
||||
"return Load32(self, 0x10) == 0 ? 1u : 0u;"),
|
||||
Entry(0x1d8470, "IsField4NonZero", "gk::game::IsField4NonZero", "int",
|
||||
(direct_getter_case(0x1d8470, 0x8, 0x4, 0x1234),
|
||||
direct_getter_case(0x1d8470, 0x8, 0x4, 0)),
|
||||
"IsField4NonZero(const void* self)",
|
||||
"return Load32(self, 0x04) != 0 ? 1u : 0u;",
|
||||
"return Load32(self, 0x04) == 0 ? 1u : 0u;"),
|
||||
)
|
||||
|
||||
|
||||
def build(src: Path, exe: Path) -> None:
|
||||
import subprocess
|
||||
subprocess.run(
|
||||
["i686-w64-mingw32-g++", "-std=c++20", "-O2", "-mfpmath=sse", "-msse2",
|
||||
"-Wall", "-Wextra", "-Werror",
|
||||
"-ffp-contract=off", "-fno-fast-math", f"-I{ROOT}/include", f"-I{ROOT}/src",
|
||||
str(HARNESS), str(src),
|
||||
f"-L{MCFGTHREAD_LIB}", "-o", str(exe),
|
||||
"-static", "-static-libgcc", "-static-libstdc++"],
|
||||
check=True,
|
||||
)
|
||||
|
||||
|
||||
def slice_buffers(original: RunResult, recon: bytes, offset: int) -> tuple[tuple[str, bytes], ...]:
|
||||
buffers: list[tuple[str, bytes]] = []
|
||||
for tag, data in original.out_buffers:
|
||||
buffers.append((tag, recon[offset:offset + len(data)]))
|
||||
offset += len(data)
|
||||
assert offset == len(recon), (offset, len(recon), original.out_buffers)
|
||||
return tuple(buffers)
|
||||
|
||||
|
||||
def compare(entry: Entry, original: RunResult, recon: bytes) -> DiffReport:
|
||||
match entry.ret:
|
||||
case "int":
|
||||
eax = int.from_bytes(recon[:4], "little")
|
||||
return diff(original, RunResult(eax=eax, out_buffers=slice_buffers(original, recon, 4)))
|
||||
case "al":
|
||||
assert original.eax is not None
|
||||
masked = dataclasses.replace(original, eax=original.eax & 0xFF)
|
||||
return diff(masked, RunResult(eax=recon[0], out_buffers=slice_buffers(original, recon, 1)))
|
||||
case "void":
|
||||
return diff(original, RunResult(eax=None, out_buffers=slice_buffers(original, recon, 0)))
|
||||
case unreachable:
|
||||
assert_never(unreachable)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
selected = set(sys.argv[1:])
|
||||
wave = tuple(e for e in entries() if not selected or e.mode in selected)
|
||||
if selected and len(wave) != len(selected):
|
||||
print(f"unknown entries: {selected - {e.mode for e in wave}}", file=sys.stderr)
|
||||
return 2
|
||||
oracle = resolve_oracle("gamekdm.dll")
|
||||
runner = UnicornRunner(PeImage(oracle.path))
|
||||
print(f"DLL={oracle.path} sha256={oracle.sha256} comparison=faithful exact (EAX/AL/buffers)",
|
||||
flush=True)
|
||||
database = json.loads((ROOT / "re/rvadb.json").read_text())
|
||||
rows = {row["rva"]: row for row in database["functions"]}
|
||||
for entry in wave:
|
||||
row = rows[f"0x{entry.rva:08x}"]
|
||||
assert not row["callees"] and not row["external_callees"], entry.symbol
|
||||
assert row["globals_touched"] == [], entry.symbol
|
||||
print(f"GLOBALS-FIRST: PASS (no callees, no imports, no globals for all {len(wave)};"
|
||||
" capture_state=True; member pointer and object/inner bytes compared)", flush=True)
|
||||
with TemporaryDirectory(prefix="gamekdm-wave10-") as temporary:
|
||||
directory = Path(temporary)
|
||||
exe = directory / "recon_game_w10.exe"
|
||||
build(SRC, exe)
|
||||
print("BUILD: PASS (-Wall -Wextra -Werror -mfpmath=sse -msse2 -ffp-contract=off"
|
||||
" -fno-fast-math)", flush=True)
|
||||
total = 0
|
||||
runs: dict[int, list[tuple[Case, RunResult]]] = {}
|
||||
for entry in wave:
|
||||
captured: list[tuple[Case, RunResult]] = []
|
||||
for index, case in enumerate(entry.cases):
|
||||
original = runner.run(case.spec)
|
||||
report = compare(entry, original, run_recon(exe, entry.mode, case.payload))
|
||||
assert report.verdict is Verdict.EQUAL, (entry.symbol, index, report)
|
||||
captured.append((case, original))
|
||||
total += 1
|
||||
runs[entry.rva] = captured
|
||||
print(f"0x{entry.rva:08x} {entry.symbol}: PASS ({len(entry.cases)} cases)", flush=True)
|
||||
text = SRC.read_text()
|
||||
for entry in wave:
|
||||
text = mutate(text, entry.anchor, entry.old, entry.new)
|
||||
assert text != SRC.read_text(), "no mutation applied"
|
||||
bug_src = directory / "leaf_ops_w10_bug.cpp"
|
||||
bug_src.write_text(text)
|
||||
bug_exe = directory / "leaf_ops_w10_bug.exe"
|
||||
build(bug_src, bug_exe)
|
||||
for entry in wave:
|
||||
caught = 0
|
||||
witness: tuple[str, ...] = ()
|
||||
for case, original in runs[entry.rva]:
|
||||
report = compare(entry, original, run_recon(bug_exe, entry.mode, case.payload))
|
||||
if report.verdict is Verdict.DIFF:
|
||||
caught += 1
|
||||
if not witness:
|
||||
witness = report.differences
|
||||
assert caught > 0, ("mutation survived every case", entry.symbol)
|
||||
print(f"NON-VACUITY 0x{entry.rva:08x}: PASS ({caught}/{len(runs[entry.rva])}"
|
||||
f" cases flag the injected bug) {witness}", flush=True)
|
||||
print(f"NON-VACUITY: PASS ({len(wave)}/{len(wave)} independent function mutations)",
|
||||
flush=True)
|
||||
print(f"ALL DIFFERENTIALS PASS ({total} cases across {len(wave)} functions)", flush=True)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -0,0 +1,154 @@
|
||||
// Differential harness for gamekdm.dll wave-10 flat-leaf reconstructions. Reads
|
||||
// a hex payload on stdin, rebuilds the object (and, for the nested routines, the
|
||||
// member-pointer graph the Unicorn side seeds), runs the reconstruction named by
|
||||
// argv[1] on the same inputs, and writes one hex string: the 32-bit return (EAX)
|
||||
// for the dword getters and predicates, the low byte (AL) for the byte getters,
|
||||
// or the mutated object/inner buffer for the void setters, in the order the
|
||||
// differ expects.
|
||||
#include <cctype>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "game/leaf_ops_w10.h"
|
||||
|
||||
using namespace gk::game;
|
||||
|
||||
namespace {
|
||||
|
||||
std::vector<std::uint8_t> ReadHex() {
|
||||
std::vector<std::uint8_t> out;
|
||||
std::string digits;
|
||||
int c = 0;
|
||||
while ((c = std::getchar()) != EOF) {
|
||||
if (std::isxdigit(c) != 0) {
|
||||
digits.push_back(static_cast<char>(c));
|
||||
}
|
||||
}
|
||||
for (std::size_t i = 0; i + 1 < digits.size(); i += 2) {
|
||||
out.push_back(static_cast<std::uint8_t>(
|
||||
std::strtol(digits.substr(i, 2).c_str(), nullptr, 16)));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
void Emit(const void* data, std::size_t size) {
|
||||
const auto* bytes = static_cast<const std::uint8_t*>(data);
|
||||
for (std::size_t i = 0; i < size; ++i) {
|
||||
std::printf("%02x", bytes[i]);
|
||||
}
|
||||
std::printf("\n");
|
||||
}
|
||||
|
||||
void SetPtr(std::uint8_t* object, std::size_t offset, const void* target) {
|
||||
std::uint32_t pointer = static_cast<std::uint32_t>(reinterpret_cast<std::uintptr_t>(target));
|
||||
std::memcpy(object + offset, &pointer, sizeof(pointer));
|
||||
}
|
||||
|
||||
std::uint32_t U32(const std::uint8_t* p) {
|
||||
std::uint32_t v = 0;
|
||||
std::memcpy(&v, p, 4);
|
||||
return v;
|
||||
}
|
||||
|
||||
int Dispatch(const std::string& mode, const std::vector<std::uint8_t>& in) {
|
||||
if (mode == "GetField20") {
|
||||
std::uint8_t object[0x28] = {0};
|
||||
std::memcpy(object + 0x20, in.data(), 4);
|
||||
std::uint32_t result = GetField20(object);
|
||||
Emit(&result, 4);
|
||||
} else if (mode == "GetField48") {
|
||||
std::uint8_t object[0x50] = {0};
|
||||
std::memcpy(object + 0x48, in.data(), 4);
|
||||
std::uint32_t result = GetField48(object);
|
||||
Emit(&result, 4);
|
||||
} else if (mode == "GetFieldEc") {
|
||||
std::uint8_t object[0xf0] = {0};
|
||||
std::memcpy(object + 0xec, in.data(), 4);
|
||||
std::uint32_t result = GetFieldEc(object);
|
||||
Emit(&result, 4);
|
||||
} else if (mode == "GetFieldC0PlusDWORD28") {
|
||||
std::uint8_t object[0xc8] = {0};
|
||||
std::memcpy(object + 0xc0, in.data(), 4);
|
||||
std::uint32_t result = GetFieldC0PlusDWORD28(object);
|
||||
Emit(&result, 4);
|
||||
} else if (mode == "GetField0Bits1To10") {
|
||||
std::uint8_t object[0x8] = {0};
|
||||
std::memcpy(object + 0x0, in.data(), 4);
|
||||
std::uint32_t result = GetField0Bits1To10(object);
|
||||
Emit(&result, 4);
|
||||
} else if (mode == "GetIndirect8") {
|
||||
std::uint8_t inner[0x4] = {0};
|
||||
std::memcpy(inner + 0x0, in.data(), 4);
|
||||
std::uint8_t object[0xc] = {0};
|
||||
SetPtr(object, 0x8, inner);
|
||||
std::uint32_t result = GetIndirect8(object);
|
||||
Emit(&result, 4);
|
||||
} else if (mode == "GetIndirect4_4") {
|
||||
std::uint8_t inner[0x8] = {0};
|
||||
std::memcpy(inner + 0x4, in.data(), 4);
|
||||
std::uint8_t object[0x8] = {0};
|
||||
SetPtr(object, 0x4, inner);
|
||||
std::uint32_t result = GetIndirect4_4(object);
|
||||
Emit(&result, 4);
|
||||
} else if (mode == "GetIndirectByte4_c") {
|
||||
std::uint8_t inner[0xd] = {0};
|
||||
inner[0xc] = in.at(0);
|
||||
std::uint8_t object[0x8] = {0};
|
||||
SetPtr(object, 0x4, inner);
|
||||
std::uint8_t result = GetIndirectByte4_c(object);
|
||||
Emit(&result, 1);
|
||||
} else if (mode == "GetIndirectByte8_c") {
|
||||
std::uint8_t inner[0xd] = {0};
|
||||
inner[0xc] = in.at(0);
|
||||
std::uint8_t object[0xc] = {0};
|
||||
SetPtr(object, 0x8, inner);
|
||||
std::uint8_t result = GetIndirectByte8_c(object);
|
||||
Emit(&result, 1);
|
||||
} else if (mode == "SetFieldC4") {
|
||||
std::uint8_t object[0xc8] = {0};
|
||||
SetFieldC4(object, U32(in.data()));
|
||||
Emit(object, 0xc8);
|
||||
} else if (mode == "SetFieldC") {
|
||||
std::uint8_t object[0x10] = {0};
|
||||
SetFieldC(object, U32(in.data()));
|
||||
Emit(object, 0x10);
|
||||
} else if (mode == "SetIndirect8") {
|
||||
std::uint8_t inner[0x4] = {0};
|
||||
std::uint8_t object[0xc] = {0};
|
||||
SetPtr(object, 0x8, inner);
|
||||
SetIndirect8(object, U32(in.data()));
|
||||
Emit(inner, 0x4);
|
||||
} else if (mode == "SetByte9One") {
|
||||
std::uint8_t object[0xa] = {0};
|
||||
SetByte9One(object);
|
||||
Emit(object, 0xa);
|
||||
} else if (mode == "IsField10NonZero") {
|
||||
std::uint8_t object[0x14] = {0};
|
||||
std::memcpy(object + 0x10, in.data(), 4);
|
||||
std::uint32_t result = IsField10NonZero(object);
|
||||
Emit(&result, 4);
|
||||
} else if (mode == "IsField4NonZero") {
|
||||
std::uint8_t object[0x8] = {0};
|
||||
std::memcpy(object + 0x4, in.data(), 4);
|
||||
std::uint32_t result = IsField4NonZero(object);
|
||||
Emit(&result, 4);
|
||||
} else {
|
||||
std::fprintf(stderr, "unknown mode %s\n", mode.c_str());
|
||||
return 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc < 2) {
|
||||
std::fprintf(stderr, "usage: recon_game_w10 <mode>\n");
|
||||
return 2;
|
||||
}
|
||||
const std::vector<std::uint8_t> in = ReadHex();
|
||||
return Dispatch(argv[1], in);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
===== WAVE 10 BATCH 1 Sun, 29 Nov 2026 15:55:29 GMT =====
|
||||
DLL=/home/athapa/kdm-re/orig/gamekdm.dll sha256=0595cb1dd98e4c02e2700f22f29d6504a9a74b401238ba5ec539d666ee8f0804 comparison=faithful exact (EAX/AL/buffers)
|
||||
GLOBALS-FIRST: PASS (no callees, no imports, no globals for all 5; capture_state=True; object/member-pointer bytes compared)
|
||||
BUILD: PASS (-Wall -Wextra -Werror -mfpmath=sse -msse2 -ffp-contract=off -fno-fast-math)
|
||||
0x001b2c60 gk::game::GetField20: PASS (2 cases)
|
||||
0x001add50 gk::game::GetField48: PASS (2 cases)
|
||||
0x001bdd50 gk::game::GetFieldEc: PASS (2 cases)
|
||||
0x001874e0 gk::game::GetFieldC0PlusDWORD28: PASS (2 cases)
|
||||
0x001d91d0 gk::game::GetField0Bits1To10: PASS (2 cases)
|
||||
NON-VACUITY 0x001b2c60: PASS (2/2 cases flag the injected bug) ('EAX: orig=3405691582, ref=3405691583',)
|
||||
NON-VACUITY 0x001add50: PASS (2/2 cases flag the injected bug) ('EAX: orig=3405691582, ref=3405691583',)
|
||||
NON-VACUITY 0x001bdd50: PASS (2/2 cases flag the injected bug) ('EAX: orig=3405691582, ref=3405691583',)
|
||||
NON-VACUITY 0x001874e0: PASS (2/2 cases flag the injected bug) ('EAX: orig=3405691622, ref=3405691623',)
|
||||
NON-VACUITY 0x001d91d0: PASS (2/2 cases flag the injected bug) ('EAX: orig=1023, ref=511',)
|
||||
NON-VACUITY: PASS (5/5 independent function mutations)
|
||||
ALL DIFFERENTIALS PASS (10 cases across 5 functions)
|
||||
EXIT=0
|
||||
+35
-10
@@ -1619764,14 +1619764,19 @@
|
||||
{
|
||||
"callees": [],
|
||||
"callers": [],
|
||||
"calling_convention": "unknown",
|
||||
"calling_convention": "__thiscall",
|
||||
"evidence": "T1 re/game/prove_game_w10.py: gk::game::GetFieldC0PlusDWORD28; 2 exact EAX/AL/buffer differential cases + injected-bug non-vacuity; globals-first capture_state; re/game/task-16-wave10.log",
|
||||
"external_callees": [],
|
||||
"fp_model": "none",
|
||||
"globals_touched": [],
|
||||
"name": "FUN_101874e0",
|
||||
"owning_module_guess": "unknown",
|
||||
"portability": "port",
|
||||
"register_abi": "ECX=this; bare ret; EAX=[this+0xc0]+0x28",
|
||||
"rva": "0x001874e0",
|
||||
"semantic_name": "gk::game::GetFieldC0PlusDWORD28",
|
||||
"signature": "undefined FUN_101874e0(void)",
|
||||
"status": "orig"
|
||||
"status": "verified"
|
||||
},
|
||||
{
|
||||
"callees": [
|
||||
@@ -1628578,14 +1628583,19 @@
|
||||
{
|
||||
"callees": [],
|
||||
"callers": [],
|
||||
"calling_convention": "unknown",
|
||||
"calling_convention": "__thiscall",
|
||||
"evidence": "T1 re/game/prove_game_w10.py: gk::game::GetField48; 2 exact EAX/AL/buffer differential cases + injected-bug non-vacuity; globals-first capture_state; re/game/task-16-wave10.log",
|
||||
"external_callees": [],
|
||||
"fp_model": "none",
|
||||
"globals_touched": [],
|
||||
"name": "FUN_101add50",
|
||||
"owning_module_guess": "unknown",
|
||||
"portability": "port",
|
||||
"register_abi": "ECX=this; bare ret; EAX=[this+0x48]",
|
||||
"rva": "0x001add50",
|
||||
"semantic_name": "gk::game::GetField48",
|
||||
"signature": "undefined FUN_101add50(void)",
|
||||
"status": "orig"
|
||||
"status": "verified"
|
||||
},
|
||||
{
|
||||
"callees": [
|
||||
@@ -1631608,14 +1631618,19 @@
|
||||
{
|
||||
"callees": [],
|
||||
"callers": [],
|
||||
"calling_convention": "unknown",
|
||||
"calling_convention": "__thiscall",
|
||||
"evidence": "T1 re/game/prove_game_w10.py: gk::game::GetField20; 2 exact EAX/AL/buffer differential cases + injected-bug non-vacuity; globals-first capture_state; re/game/task-16-wave10.log",
|
||||
"external_callees": [],
|
||||
"fp_model": "none",
|
||||
"globals_touched": [],
|
||||
"name": "FUN_101b2c60",
|
||||
"owning_module_guess": "unknown",
|
||||
"portability": "port",
|
||||
"register_abi": "ECX=this; bare ret; EAX=[this+0x20]",
|
||||
"rva": "0x001b2c60",
|
||||
"semantic_name": "gk::game::GetField20",
|
||||
"signature": "undefined FUN_101b2c60(void)",
|
||||
"status": "orig"
|
||||
"status": "verified"
|
||||
},
|
||||
{
|
||||
"callees": [
|
||||
@@ -1638261,14 +1638276,19 @@
|
||||
{
|
||||
"callees": [],
|
||||
"callers": [],
|
||||
"calling_convention": "unknown",
|
||||
"calling_convention": "__thiscall",
|
||||
"evidence": "T1 re/game/prove_game_w10.py: gk::game::GetFieldEc; 2 exact EAX/AL/buffer differential cases + injected-bug non-vacuity; globals-first capture_state; re/game/task-16-wave10.log",
|
||||
"external_callees": [],
|
||||
"fp_model": "none",
|
||||
"globals_touched": [],
|
||||
"name": "FUN_101bdd50",
|
||||
"owning_module_guess": "unknown",
|
||||
"portability": "port",
|
||||
"register_abi": "ECX=this; bare ret; EAX=[this+0xec]",
|
||||
"rva": "0x001bdd50",
|
||||
"semantic_name": "gk::game::GetFieldEc",
|
||||
"signature": "undefined FUN_101bdd50(void)",
|
||||
"status": "orig"
|
||||
"status": "verified"
|
||||
},
|
||||
{
|
||||
"callees": [],
|
||||
@@ -1655296,14 +1655316,19 @@
|
||||
"callers": [
|
||||
"0x001da490"
|
||||
],
|
||||
"calling_convention": "unknown",
|
||||
"calling_convention": "__thiscall",
|
||||
"evidence": "T1 re/game/prove_game_w10.py: gk::game::GetField0Bits1To10; 2 exact EAX/AL/buffer differential cases + injected-bug non-vacuity; globals-first capture_state; re/game/task-16-wave10.log",
|
||||
"external_callees": [],
|
||||
"fp_model": "none",
|
||||
"globals_touched": [],
|
||||
"name": "FUN_101d91d0",
|
||||
"owning_module_guess": "unknown",
|
||||
"portability": "port",
|
||||
"register_abi": "ECX=this; bare ret; EAX=([this+0x00]>>1)&0x3ff",
|
||||
"rva": "0x001d91d0",
|
||||
"semantic_name": "gk::game::GetField0Bits1To10",
|
||||
"signature": "undefined FUN_101d91d0(void)",
|
||||
"status": "orig"
|
||||
"status": "verified"
|
||||
},
|
||||
{
|
||||
"callees": [],
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
#include "game/leaf_ops_w10.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
namespace gk {
|
||||
namespace game {
|
||||
|
||||
namespace {
|
||||
|
||||
std::uint32_t Load32(const void* base, std::size_t offset) {
|
||||
std::uint32_t value;
|
||||
std::memcpy(&value, static_cast<const std::uint8_t*>(base) + offset, sizeof(value));
|
||||
return value;
|
||||
}
|
||||
|
||||
std::uint8_t LoadU8(const void* base, std::size_t offset) {
|
||||
return static_cast<const std::uint8_t*>(base)[offset];
|
||||
}
|
||||
|
||||
void Store32(void* base, std::size_t offset, std::uint32_t value) {
|
||||
std::memcpy(static_cast<std::uint8_t*>(base) + offset, &value, sizeof(value));
|
||||
}
|
||||
|
||||
void StoreU8(void* base, std::size_t offset, std::uint8_t value) {
|
||||
static_cast<std::uint8_t*>(base)[offset] = value;
|
||||
}
|
||||
|
||||
const std::uint8_t* DerefPtr(const void* self, std::size_t offset) {
|
||||
std::uint32_t pointer;
|
||||
std::memcpy(&pointer, static_cast<const std::uint8_t*>(self) + offset, sizeof(pointer));
|
||||
return reinterpret_cast<const std::uint8_t*>(static_cast<std::uintptr_t>(pointer));
|
||||
}
|
||||
|
||||
std::uint8_t* DerefPtrMut(void* self, std::size_t offset) {
|
||||
std::uint32_t pointer;
|
||||
std::memcpy(&pointer, static_cast<std::uint8_t*>(self) + offset, sizeof(pointer));
|
||||
return reinterpret_cast<std::uint8_t*>(static_cast<std::uintptr_t>(pointer));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
std::uint32_t GK_THISCALL GetField20(const void* self) {
|
||||
return Load32(self, 0x20);
|
||||
}
|
||||
|
||||
std::uint32_t GK_THISCALL GetField48(const void* self) {
|
||||
return Load32(self, 0x48);
|
||||
}
|
||||
|
||||
std::uint32_t GK_THISCALL GetFieldEc(const void* self) {
|
||||
return Load32(self, 0xec);
|
||||
}
|
||||
|
||||
std::uint32_t GK_THISCALL GetFieldC0PlusDWORD28(const void* self) {
|
||||
return Load32(self, 0xc0) + 0x28u;
|
||||
}
|
||||
|
||||
std::uint32_t GK_THISCALL GetField0Bits1To10(const void* self) {
|
||||
return (Load32(self, 0x00) >> 1) & 0x3ffu;
|
||||
}
|
||||
|
||||
std::uint32_t GK_THISCALL GetIndirect8(const void* self) {
|
||||
return Load32(DerefPtr(self, 0x08), 0x00);
|
||||
}
|
||||
|
||||
std::uint32_t GK_THISCALL GetIndirect4_4(const void* self) {
|
||||
return Load32(DerefPtr(self, 0x04), 0x04);
|
||||
}
|
||||
|
||||
std::uint8_t GK_THISCALL GetIndirectByte4_c(const void* self) {
|
||||
return LoadU8(DerefPtr(self, 0x04), 0x0c);
|
||||
}
|
||||
|
||||
std::uint8_t GK_THISCALL GetIndirectByte8_c(const void* self) {
|
||||
return LoadU8(DerefPtr(self, 0x08), 0x0c);
|
||||
}
|
||||
|
||||
void GK_THISCALL SetFieldC4(void* self, std::uint32_t value) {
|
||||
Store32(self, 0xc4, value);
|
||||
}
|
||||
|
||||
void GK_THISCALL SetFieldC(void* self, std::uint32_t value) {
|
||||
Store32(self, 0x0c, value);
|
||||
}
|
||||
|
||||
void GK_THISCALL SetIndirect8(void* self, std::uint32_t value) {
|
||||
Store32(DerefPtrMut(self, 0x08), 0x00, value);
|
||||
}
|
||||
|
||||
void GK_THISCALL SetByte9One(void* self) {
|
||||
StoreU8(self, 0x09, 1);
|
||||
}
|
||||
|
||||
std::uint32_t GK_THISCALL IsField10NonZero(const void* self) {
|
||||
return Load32(self, 0x10) != 0 ? 1u : 0u;
|
||||
}
|
||||
|
||||
std::uint32_t GK_THISCALL IsField4NonZero(const void* self) {
|
||||
return Load32(self, 0x04) != 0 ? 1u : 0u;
|
||||
}
|
||||
|
||||
} // namespace game
|
||||
} // namespace gk
|
||||
@@ -0,0 +1,101 @@
|
||||
#pragma once
|
||||
// Reconstructed gamekdm.dll flat-leaf cluster (wave 10). Fifteen single-level
|
||||
// leaves from the globals-first clean pool (no callees, no imported callees, no
|
||||
// touched globals), each confirmed reducible by orig/gamekdm.dll disassembly.
|
||||
// The shapes extend wave 9 with the direct-field family that wave 9 did not
|
||||
// cover:
|
||||
// - three direct dword getters that return the dword at a fixed object field;
|
||||
// - one direct dword getter that adds a constant to the loaded dword;
|
||||
// - one direct dword getter that shifts and masks the loaded dword;
|
||||
// - two nested dword getters [[this+K]+J] and two nested byte getters;
|
||||
// - two direct dword setters that store a stack argument into an object field;
|
||||
// - one nested dword setter that stores through a member pointer;
|
||||
// - one constant-one direct byte setter;
|
||||
// - two direct boolean predicates (field != 0).
|
||||
// Every routine is integer only (no x87, no SSE in the reconstructed semantics),
|
||||
// so fp_model is "none" and portability is "port" for the whole file, per
|
||||
// docs/conventions.md.
|
||||
//
|
||||
// Register-input ABI read off the validity-gate disasm: `this` arrives in ECX
|
||||
// (thiscall) for every routine. The dword setters clean one stack argument
|
||||
// (ret 4); the getters, predicates, and constant byte setter take no stack
|
||||
// argument and use a bare ret. The convention for each routine is recorded in
|
||||
// its RVA database calling_convention and register_abi fields.
|
||||
//
|
||||
// The nested routines dereference a 32-bit member pointer: the original reads
|
||||
// [[ECX+K]+J]. The reconstruction takes the object as a real buffer whose field
|
||||
// at +K holds a valid pointer to an inner buffer, exactly as the differential
|
||||
// seeds it (member pointer -> inner scratch buffer), and the differential proves
|
||||
// behavioural equality (Unicorn-run original vs MinGW/wine reconstruction), not
|
||||
// the C++ ABI. Field offsets are preserved in the names and comments so a later
|
||||
// struct-recovery wave can rename without losing the evidence.
|
||||
#include <cstdint>
|
||||
|
||||
#include "gk/types.h"
|
||||
|
||||
namespace gk {
|
||||
namespace game {
|
||||
|
||||
// rva=0x101b2c60 (orig FUN_101b2c60) thiscall (ECX=this, bare ret): return the
|
||||
// dword at this+0x20.
|
||||
std::uint32_t GK_THISCALL GetField20(const void* self);
|
||||
|
||||
// rva=0x101add50 (orig FUN_101add50) thiscall (ECX=this, bare ret): return the
|
||||
// dword at this+0x48.
|
||||
std::uint32_t GK_THISCALL GetField48(const void* self);
|
||||
|
||||
// rva=0x101bdd50 (orig FUN_101bdd50) thiscall (ECX=this, bare ret): return the
|
||||
// dword at this+0xec.
|
||||
std::uint32_t GK_THISCALL GetFieldEc(const void* self);
|
||||
|
||||
// rva=0x101874e0 (orig FUN_101874e0) thiscall (ECX=this, bare ret): return the
|
||||
// dword at this+0xc0 plus 0x28.
|
||||
std::uint32_t GK_THISCALL GetFieldC0PlusDWORD28(const void* self);
|
||||
|
||||
// rva=0x101d91d0 (orig FUN_101d91d0) thiscall (ECX=this, bare ret): return the
|
||||
// dword at this+0x00 shifted right by one and masked to ten bits.
|
||||
std::uint32_t GK_THISCALL GetField0Bits1To10(const void* self);
|
||||
|
||||
// rva=0x1013c690 (orig FUN_1013c690) thiscall (ECX=this, bare ret): load the
|
||||
// member pointer at +0x08 and return the dword [[this+0x08]].
|
||||
std::uint32_t GK_THISCALL GetIndirect8(const void* self);
|
||||
|
||||
// rva=0x101a6660 (orig FUN_101a6660) thiscall (ECX=this, bare ret): load the
|
||||
// member pointer at +0x04 and return the dword [[this+0x04]+0x04].
|
||||
std::uint32_t GK_THISCALL GetIndirect4_4(const void* self);
|
||||
|
||||
// rva=0x10095bd0 (orig FUN_10095bd0) thiscall (ECX=this, bare ret): load the
|
||||
// member pointer at +0x04 and return the byte [[this+0x04]+0x0c].
|
||||
std::uint8_t GK_THISCALL GetIndirectByte4_c(const void* self);
|
||||
|
||||
// rva=0x10134ce0 (orig FUN_10134ce0) thiscall (ECX=this, bare ret): load the
|
||||
// member pointer at +0x08 and return the byte [[this+0x08]+0x0c].
|
||||
std::uint8_t GK_THISCALL GetIndirectByte8_c(const void* self);
|
||||
|
||||
// rva=0x10120bb0 (orig FUN_10120bb0) thiscall (ECX=this) + one stack arg
|
||||
// (ret 4): store the argument into the dword at this+0xc4.
|
||||
void GK_THISCALL SetFieldC4(void* self, std::uint32_t value);
|
||||
|
||||
// rva=0x1014eff0 (orig FUN_1014eff0) thiscall (ECX=this) + one stack arg
|
||||
// (ret 4): store the argument into the dword at this+0x0c.
|
||||
void GK_THISCALL SetFieldC(void* self, std::uint32_t value);
|
||||
|
||||
// rva=0x1013c6a0 (orig FUN_1013c6a0) thiscall (ECX=this) + one stack arg
|
||||
// (ret 4): load the member pointer at +0x08 and store the argument at
|
||||
// [[this+0x08]].
|
||||
void GK_THISCALL SetIndirect8(void* self, std::uint32_t value);
|
||||
|
||||
// rva=0x10132500 (orig FUN_10132500) thiscall (ECX=this, bare ret): store the
|
||||
// constant byte 1 at this+0x09.
|
||||
void GK_THISCALL SetByte9One(void* self);
|
||||
|
||||
// rva=0x101c1430 (orig FUN_101c1430) thiscall (ECX=this, bare ret): return 1
|
||||
// when the dword at this+0x10 is nonzero, else 0.
|
||||
std::uint32_t GK_THISCALL IsField10NonZero(const void* self);
|
||||
|
||||
// rva=0x101d8470 (orig FUN_101d8470) thiscall (ECX=this, bare ret): return 1
|
||||
// when the dword at this+0x04 is nonzero, else 0.
|
||||
std::uint32_t GK_THISCALL IsField4NonZero(const void* self);
|
||||
|
||||
} // namespace game
|
||||
} // namespace gk
|
||||
Reference in new issue
Block a user