feat(libacio): reconstruct+verify wave 3 6 functions

Wave 3 shard on libacio.dll, pure-leaf scanner (tools/wave/scan_pure.py) over
status=orig. Six genuinely-provable leaves reconstructed in src/libacio and
verified by the differential (prove_libacio.py): emulated original vs MinGW
reconstruction under wine, owned globals seeded/read back, register ABIs set up
explicitly, pointer returns offset-normalized; each with an injected-bug
non-vacuity case that the differential flags.

  0x1000174c FUN_1000174c      returns &0xd000 data object (offset-normalized)
  0x10004264 FUN_10004264      register-ABI status-code map (input EAX)
  0x10005000 __aulldvrm        unsigned 64-bit divide/remainder (EDX:EAX,EBX:ECX)
  0x10005704 __initp_misc_winsig broadcast arg into owned globals 0xe8e0..0xe8ec
  0x10008509 __NLG_Notify      record EAX/code/EBP into NLG struct 0xde14..0xde1c
  0x1000571d siglookup         12-byte-entry table search, key EDX, count 0xd4dc

Four irreducible leaves deferred as orig [~]-candidate with defer_reason:
FUN_10005b24 (false mid-loop leaf), __alloca_probe (ESP-relocating stack probe),
__SEH_prolog4/__SEH_epilog4 (fs:[0] SEH chain). No carve-outs, no fake-verify.

libacio verified 29 -> 35 / 256. validate_rvadb.py: RVADB_VALID.
Evidence: .omo/evidence/kdm-full-decompilation/task-13-libacio-wave3.log
This commit is contained in:
ulw-execute committed 2026-11-29 10:52:38 -05:00
1 parent a144f5e2ed
commit 0e63f98ef4
5 files changed
+441 -11

No files matched your search

+32 -10
View File
@@ -30041,7 +30041,10 @@
"owning_module_guess": "unknown",
"rva": "0x0000174c",
"signature": "undefined * * __stdcall FUN_1000174c(void)",
"status": "orig"
"status": "verified",
"fp_model": "none",
"portability": "abi",
"evidence": "differential prove_libacio.py (wave 3): emulated original libacio.dll vs MinGW reconstruction; returns the image-relative 0xd000 data-object address, compared offset-normalized against that object (offset 0) -> EQUAL; non-vacuity +12 injected bug caught; see .omo/evidence/kdm-full-decompilation/task-13-libacio-wave3.log"
},
{
"callees": [
@@ -30553,7 +30556,8 @@
"owning_module_guess": "unknown",
"rva": "0x00002614",
"signature": "undefined __cdecl __SEH_prolog4(undefined4 param_1, int param_2)",
"status": "orig"
"status": "orig",
"defer_reason": "SEH frame setup: pushes an exception registration record onto the fs:[0] handler chain, carves a frame of caller-supplied size, and installs the security-cookie XOR guard. Its observable effect is the thread SEH chain and frame layout, which the register/global differential does not model. [~]-candidate"
},
{
"callees": [],
@@ -30595,7 +30599,8 @@
"owning_module_guess": "unknown",
"rva": "0x00002659",
"signature": "undefined __stdcall __SEH_epilog4(void)",
"status": "orig"
"status": "orig",
"defer_reason": "SEH frame teardown: restores the previous fs:[0] exception registration from the frame and unwinds the stack set up by __SEH_prolog4. Observable effect is the thread SEH chain, not a register/global/buffer value the differential compares. [~]-candidate"
},
{
"callees": [
@@ -32251,7 +32256,10 @@
"owning_module_guess": "unknown",
"rva": "0x00004264",
"signature": "undefined4 __stdcall FUN_10004264(void)",
"status": "orig"
"status": "verified",
"fp_model": "none",
"portability": "abi",
"evidence": "differential prove_libacio.py (wave 3): emulated original libacio.dll vs MinGW reconstruction; register-ABI status-code map (input in EAX) over all four table codes plus misses, exact EAX -> EQUAL; non-vacuity 0x411->0x412 injected bug caught; see .omo/evidence/kdm-full-decompilation/task-13-libacio-wave3.log"
},
{
"callees": [
@@ -32763,7 +32771,10 @@
"owning_module_guess": "unknown",
"rva": "0x00005000",
"signature": "undefined8 __stdcall __aulldvrm(uint param_1, uint param_2, uint param_3, uint param_4)",
"status": "orig"
"status": "verified",
"fp_model": "none",
"portability": "abi",
"evidence": "differential prove_libacio.py (wave 3): emulated original libacio.dll vs MinGW reconstruction; unsigned 64-bit divide-remainder helper, quotient (EDX:EAX) and remainder (EBX:ECX) compared over nine dividend/divisor cases -> EQUAL; non-vacuity quotient+1 injected bug caught; see .omo/evidence/kdm-full-decompilation/task-13-libacio-wave3.log"
},
{
"callees": [],
@@ -33150,7 +33161,10 @@
"owning_module_guess": "unknown",
"rva": "0x00005704",
"signature": "undefined __cdecl __initp_misc_winsig(undefined4 param_1)",
"status": "orig"
"status": "verified",
"fp_model": "none",
"portability": "port",
"evidence": "differential prove_libacio.py (wave 3): emulated original libacio.dll vs MinGW reconstruction; broadcasts the argument into owned globals 0xe8e0..0xe8ec, all four slots seeded and read back -> EQUAL; non-vacuity slot-2+1 injected bug caught; see .omo/evidence/kdm-full-decompilation/task-13-libacio-wave3.log"
},
{
"callees": [],
@@ -33166,7 +33180,10 @@
"owning_module_guess": "unknown",
"rva": "0x0000571d",
"signature": "uint __cdecl siglookup(uint param_1)",
"status": "orig"
"status": "verified",
"fp_model": "none",
"portability": "abi",
"evidence": "differential prove_libacio.py (wave 3): emulated original libacio.dll vs MinGW reconstruction; linear search of 12-byte entries (key in EDX, count from owned global 0xd4dc) returning the first in-range match or null, compared offset-normalized against the table buffer over hit/miss/count=0 cases -> EQUAL; non-vacuity +12 injected bug caught; see .omo/evidence/kdm-full-decompilation/task-13-libacio-wave3.log"
},
{
"callees": [
@@ -33460,7 +33477,8 @@
"owning_module_guess": "unknown",
"rva": "0x00005b24",
"signature": "undefined __thiscall FUN_10005b24(void * this, int param_1)",
"status": "orig"
"status": "orig",
"defer_reason": "false mid-function leaf: 0x5b24 is only the loop-condition label of the routine entered at 0x5b00 (which reads globals 0xea3c/0xea40 and jumps in); control at 0x5b24 falls into the loop body at 0x5b12 that dereferences a caller pointer at +0xc and the register pair eax/ecx set up by the real entry. Not an independently callable leaf, so no self-contained non-vacuous differential. [~]-candidate"
},
{
"callees": [
@@ -34448,7 +34466,10 @@
"owning_module_guess": "unknown",
"rva": "0x00008509",
"signature": "void __stdcall __NLG_Notify(ulong param_1)",
"status": "orig"
"status": "verified",
"fp_model": "none",
"portability": "abi",
"evidence": "differential prove_libacio.py (wave 3): emulated original libacio.dll vs MinGW reconstruction; records EAX/stack-code/EBP into the owned NLG struct at 0xde14/0xde18/0xde1c (0xde10 untouched), all slots seeded and read back -> EQUAL; non-vacuity ebp+1 injected bug caught; see .omo/evidence/kdm-full-decompilation/task-13-libacio-wave3.log"
},
{
"callees": [],
@@ -35148,7 +35169,8 @@
"owning_module_guess": "unknown",
"rva": "0x00009920",
"signature": "undefined __stdcall __alloca_probe(void)",
"status": "orig"
"status": "orig",
"defer_reason": "stack-probe ABI helper: takes the requested frame size in EAX and relocates ESP via 'xchg esp,eax' while touching guard pages, so its only effect is on the stack pointer and page residency. No EAX/global/buffer observable the T1/T2 differential can compare, and emulating it rewrites the harness stack. [~]-candidate"
},
{
"callees": [],
+246 -1
View File
@@ -23,7 +23,15 @@ from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
sys.path.insert(0, str(ROOT / "tools" / "unicorn_diff"))
from unicorn.x86_const import UC_X86_REG_EAX, UC_X86_REG_EIP, UC_X86_REG_ESP # noqa: E402
from unicorn.x86_const import ( # noqa: E402
UC_X86_REG_EAX,
UC_X86_REG_EBP,
UC_X86_REG_EBX,
UC_X86_REG_ECX,
UC_X86_REG_EDX,
UC_X86_REG_EIP,
UC_X86_REG_ESP,
)
from udiff import ( # noqa: E402
CallConv, CallSpec, PeImage, ReturnKind, RunResult, UnicornRunner, Verdict, diff,
@@ -505,6 +513,236 @@ def prove_ascii_strnicmp(image: PeImage, log: list[str]) -> None:
f"EAX={eax:#010x}")
def emulate_full(
image: PeImage, rva: int, *,
reg_in: dict[int, int] | None = None,
stack_args: tuple[object, ...] = (),
buffers: tuple[tuple[str, bytes], ...] = (),
global_writes: tuple[tuple[int, bytes], ...] = (),
reg_out: tuple[int, ...] = (),
global_readback: tuple[int, ...] = (),
) -> tuple[dict[int, int], dict[int, bytes], dict[str, int]]:
"""Run one call with explicit register inputs/outputs (register ABIs).
``reg_in`` seeds registers before entry; ``stack_args`` are integers or
``("buf", name)`` buffer references; ``reg_out`` reads registers after the
clean return; ``global_readback`` reads 4-byte module globals by RVA.
"""
uc = image.new_emulator()
for grva, data in global_writes:
uc.mem_write(image.va(grva), data)
addresses: dict[str, int] = {}
cursor = SCRATCH_BASE
for name, data in buffers:
uc.mem_write(cursor, data)
addresses[name] = cursor
cursor += ((len(data) + 15) & ~15) + 16
resolved: list[int] = []
for arg in stack_args:
if isinstance(arg, tuple):
resolved.append(addresses[arg[1]])
else:
resolved.append(int(arg) & 0xFFFFFFFF)
esp = STACK_BASE + STACK_SIZE - 0x100
for value in reversed(resolved):
esp -= 4
uc.mem_write(esp, struct.pack("<I", value & 0xFFFFFFFF))
esp -= 4
uc.mem_write(esp, struct.pack("<I", RETURN_SENTINEL))
uc.reg_write(UC_X86_REG_ESP, esp)
for reg, value in (reg_in or {}).items():
uc.reg_write(reg, value & 0xFFFFFFFF)
uc.emu_start(image.va(rva), RETURN_SENTINEL, count=200_000)
if uc.reg_read(UC_X86_REG_EIP) != RETURN_SENTINEL:
raise RuntimeError(f"{rva:#x} did not return cleanly")
regs = {reg: uc.reg_read(reg) & 0xFFFFFFFF for reg in reg_out}
gouts = {grva: bytes(uc.mem_read(image.va(grva), 4)) for grva in global_readback}
return regs, gouts, addresses
def prove_ptr_d000(image: PeImage, log: list[str]) -> None:
regs, _, _ = emulate_full(image, 0x174C, reg_out=(UC_X86_REG_EAX,))
offset = (regs[UC_X86_REG_EAX] - image.va(0xD000)) & 0xFFFFFFFF
assert offset == 0, hex(regs[UC_X86_REG_EAX])
recon = struct.unpack("<I", run_recon(RECON, "ptr_d000", b""))[0]
eax_equal("0x174c sub_1000174c ptr->0xd000", offset, recon, log, f"offset={offset:#x}")
def prove_map_status(image: PeImage, log: list[str]) -> None:
for code in (0x3A4, 0x3A8, 0x3B5, 0x3B6, 0, 1, 0x3A5, 0x3B7, 0xDEADBEEF, 0xFFFFFFFF):
regs, _, _ = emulate_full(image, 0x4264, reg_in={UC_X86_REG_EAX: code},
reg_out=(UC_X86_REG_EAX,))
eax = regs[UC_X86_REG_EAX]
recon = struct.unpack("<I", run_recon(RECON, "map_status", struct.pack("<I", code)))[0]
eax_equal(f"0x4264 map_status code={code:#x}", eax, recon, log, f"EAX={eax:#x}")
def prove_aulldvrm(image: PeImage, log: list[str]) -> None:
cases = [
(100, 7), (0xFFFFFFFFFFFFFFFF, 3), (1 << 40, 1 << 10),
(12345678901234, 1000), (5, 5), (0, 99), (0xDEADBEEFCAFE, 0x1234),
(1 << 63, 2), (0xFFFFFFFF00000000, 0x100000000),
]
for dividend, divisor in cases:
args = (dividend & 0xFFFFFFFF, (dividend >> 32) & 0xFFFFFFFF,
divisor & 0xFFFFFFFF, (divisor >> 32) & 0xFFFFFFFF)
regs, _, _ = emulate_full(
image, 0x5000, stack_args=args,
reg_out=(UC_X86_REG_EAX, UC_X86_REG_EDX, UC_X86_REG_ECX, UC_X86_REG_EBX))
q = regs[UC_X86_REG_EAX] | (regs[UC_X86_REG_EDX] << 32)
r = regs[UC_X86_REG_ECX] | (regs[UC_X86_REG_EBX] << 32)
assert q == dividend // divisor and r == dividend % divisor, (dividend, divisor, q, r)
rec = run_recon(RECON, "aulldvrm", struct.pack("<4I", *args))
rq = struct.unpack("<I", rec[0:4])[0] | (struct.unpack("<I", rec[4:8])[0] << 32)
rr = struct.unpack("<I", rec[8:12])[0] | (struct.unpack("<I", rec[12:16])[0] << 32)
orig = RunResult(eax=0, st0=None, out_buffers=(("qr", struct.pack("<QQ", q, r)),))
ref = RunResult(eax=0, st0=None, out_buffers=(("qr", struct.pack("<QQ", rq, rr)),))
equal(f"0x5000 aulldvrm {dividend}/{divisor}", orig, ref, log, f"q={q} r={r}")
def prove_initp_winsig(image: PeImage, log: list[str]) -> None:
slots = (0xE8E0, 0xE8E4, 0xE8E8, 0xE8EC)
for value in (0, 0x12345678, 0xFFFFFFFF, 0xB49C0001):
_, gouts, _ = emulate_full(
image, 0x5704, stack_args=(value,),
global_writes=((0xE8E0, b"\xAA\xAA\xAA\xAA" * 4),),
global_readback=slots)
after = b"".join(gouts[g] for g in slots)
assert after == struct.pack("<I", value) * 4, (value, after.hex())
recon = run_recon(RECON, "initp_winsig", struct.pack("<I", value))
equal(f"0x5704 initp_misc_winsig value={value:#010x}",
RunResult(eax=0, st0=None, out_buffers=(("w", after),)),
RunResult(eax=0, st0=None, out_buffers=(("w", recon),)), log,
f"winsig={after[:4].hex()}")
def prove_nlg_notify(image: PeImage, log: list[str]) -> None:
slots = (0xDE10, 0xDE14, 0xDE18, 0xDE1C)
cases = [(0x11111111, 0x22222222, 0x33333333), (0, 0, 0),
(0xDEADBEEF, 0xCAFE, 0x0BADF00D), (0xFFFFFFFF, 1, 0x80000000)]
for eax_in, code, ebp_in in cases:
_, gouts, _ = emulate_full(
image, 0x8509, stack_args=(code,),
reg_in={UC_X86_REG_EAX: eax_in, UC_X86_REG_EBP: ebp_in},
global_writes=((0xDE10, b"\xAA\xAA\xAA\xAA" * 4),),
global_readback=slots)
after = b"".join(gouts[g] for g in slots)
expect = b"\xAA\xAA\xAA\xAA" + struct.pack("<3I", eax_in, code, ebp_in)
assert after == expect, (after.hex(), expect.hex())
recon = run_recon(RECON, "nlg_notify", struct.pack("<3I", eax_in, code, ebp_in))
equal(f"0x8509 nlg_notify eax={eax_in:#x} code={code:#x} ebp={ebp_in:#x}",
RunResult(eax=0, st0=None, out_buffers=(("r", after),)),
RunResult(eax=0, st0=None, out_buffers=(("r", recon),)), log,
f"de14={after[4:8].hex()}")
def prove_siglookup(image: PeImage, log: list[str]) -> None:
def table(entries: list[tuple[int, int, int]]) -> bytes:
return b"".join(struct.pack("<III", a, k, c) for a, k, c in entries)
cases = [
(2, 0x55, [(1, 0x55, 9), (2, 0x66, 9)]),
(3, 0x66, [(1, 0x55, 9), (2, 0x66, 9), (3, 0x77, 9)]),
(3, 0x99, [(1, 0x55, 9), (2, 0x66, 9), (3, 0x77, 9)]),
(1, 0x55, [(1, 0x55, 9)]),
(0, 0x55, [(1, 0x55, 9)]),
(4, 0x77, [(1, 0x11, 9), (2, 0x22, 9), (3, 0x77, 9), (4, 0x77, 9)]),
]
for count, key, entries in cases:
buf = table(entries)
regs, _, addrs = emulate_full(
image, 0x571D, reg_in={UC_X86_REG_EDX: key},
stack_args=(("buf", "t"),), buffers=(("t", buf),),
global_writes=((0xD4DC, struct.pack("<I", count)),),
reg_out=(UC_X86_REG_EAX,))
eax = regs[UC_X86_REG_EAX]
offset = 0xFFFFFFFF if eax == 0 else (eax - addrs["t"]) & 0xFFFFFFFF
payload = struct.pack("<II", count, key) + buf
recon = struct.unpack("<I", run_recon(RECON, "siglookup", payload))[0]
eax_equal(f"0x571d siglookup count={count} key={key:#x}", offset, recon, log,
f"offset={offset:#x}")
def prove_injected_bug_wave3(image: PeImage, log: list[str]) -> None:
source = SRC.read_text(encoding="utf-8")
def build_bug(old: str, new: str) -> tuple[Path, object]:
bug = source.replace(old, new)
assert bug != source, f"injection anchor not found: {old!r}"
td = tempfile.mkdtemp()
bug_src = Path(td) / "ac_io_bug.cpp"
bug_src.write_text(bug, encoding="utf-8")
bug_exe = Path(td) / "recon_bug.exe"
build_recon(bug_exe, src=bug_src)
return bug_exe, td
# map_status: wrong mapped code
bug_exe, _ = build_bug("case 0x3A4u:\n return 0x411u;", "case 0x3A4u:\n return 0x412u;")
regs, _, _ = emulate_full(image, 0x4264, reg_in={UC_X86_REG_EAX: 0x3A4},
reg_out=(UC_X86_REG_EAX,))
eax = regs[UC_X86_REG_EAX]
recon = struct.unpack("<I", run_recon(bug_exe, "map_status", struct.pack("<I", 0x3A4)))[0]
report = diff(RunResult(eax=eax, st0=None), RunResult(eax=recon, st0=None))
assert report.verdict is Verdict.DIFF, (eax, recon)
log.append(f" injected bug [map_status 0x411->0x412] orig={eax:#x} recon={recon:#x} "
f"-> {report.verdict.value} {report.differences[0]}")
# aulldvrm: quotient off by one
bug_exe, _ = build_bug("return {dividend / divisor, dividend % divisor};",
"return {dividend / divisor + 1u, dividend % divisor};")
args = (100, 0, 7, 0)
regs, _, _ = emulate_full(image, 0x5000, stack_args=args,
reg_out=(UC_X86_REG_EAX, UC_X86_REG_EDX))
q = regs[UC_X86_REG_EAX] | (regs[UC_X86_REG_EDX] << 32)
rec = run_recon(bug_exe, "aulldvrm", struct.pack("<4I", *args))
rq = struct.unpack("<I", rec[0:4])[0] | (struct.unpack("<I", rec[4:8])[0] << 32)
report = diff(RunResult(eax=0, st0=None, out_buffers=(("q", struct.pack("<Q", q)),)),
RunResult(eax=0, st0=None, out_buffers=(("q", struct.pack("<Q", rq)),)))
assert report.verdict is Verdict.DIFF, (q, rq)
log.append(f" injected bug [aulldvrm q+1] orig_q={q} buggy_q={rq} -> {report.verdict.value}")
# initp_misc_winsig: one slot perturbed
bug_exe, _ = build_bug("g_winsig[2] = value;", "g_winsig[2] = value + 1u;")
_, gouts, _ = emulate_full(image, 0x5704, stack_args=(0x1234,),
global_writes=((0xE8E0, b"\x00" * 16),),
global_readback=(0xE8E0, 0xE8E4, 0xE8E8, 0xE8EC))
after = b"".join(gouts[g] for g in (0xE8E0, 0xE8E4, 0xE8E8, 0xE8EC))
recon_b = run_recon(bug_exe, "initp_winsig", struct.pack("<I", 0x1234))
report = diff(RunResult(eax=0, st0=None, out_buffers=(("w", after),)),
RunResult(eax=0, st0=None, out_buffers=(("w", recon_b),)))
assert report.verdict is Verdict.DIFF, (after.hex(), recon_b.hex())
log.append(f" injected bug [initp_winsig slot2+1] -> {report.verdict.value}")
# nlg_notify: ebp field perturbed
bug_exe, _ = build_bug("g_nlg_record[3] = frame_ebp;", "g_nlg_record[3] = frame_ebp + 1u;")
_, gouts, _ = emulate_full(
image, 0x8509, stack_args=(0xCAFE,),
reg_in={UC_X86_REG_EAX: 0x1111, UC_X86_REG_EBP: 0x2222},
global_writes=((0xDE10, b"\x00" * 16),),
global_readback=(0xDE10, 0xDE14, 0xDE18, 0xDE1C))
after = b"".join(gouts[g] for g in (0xDE10, 0xDE14, 0xDE18, 0xDE1C))
recon_b = run_recon(bug_exe, "nlg_notify", struct.pack("<3I", 0x1111, 0xCAFE, 0x2222))
report = diff(RunResult(eax=0, st0=None, out_buffers=(("r", after),)),
RunResult(eax=0, st0=None, out_buffers=(("r", recon_b),)))
assert report.verdict is Verdict.DIFF, (after.hex(), recon_b.hex())
log.append(f" injected bug [nlg_notify ebp+1] -> {report.verdict.value}")
# siglookup: returned entry shifted
bug_exe, _ = build_bug(" return entry;\n }\n }\n return nullptr;",
" return entry + 12;\n }\n }\n return nullptr;")
buf = b"".join(struct.pack("<III", a, k, 9) for a, k in [(1, 0x55), (2, 0x66)])
regs, _, addrs = emulate_full(
image, 0x571D, reg_in={UC_X86_REG_EDX: 0x55},
stack_args=(("buf", "t"),), buffers=(("t", buf),),
global_writes=((0xD4DC, struct.pack("<I", 2)),), reg_out=(UC_X86_REG_EAX,))
offset = 0xFFFFFFFF if regs[UC_X86_REG_EAX] == 0 else (regs[UC_X86_REG_EAX] - addrs["t"]) & 0xFFFFFFFF
recon = struct.unpack("<I", run_recon(bug_exe, "siglookup", struct.pack("<II", 2, 0x55) + buf))[0]
report = diff(RunResult(eax=offset, st0=None), RunResult(eax=recon, st0=None))
assert report.verdict is Verdict.DIFF, (offset, recon)
log.append(f" injected bug [siglookup +12] orig_off={offset:#x} buggy_off={recon:#x} "
f"-> {report.verdict.value}")
log.append("NON-VACUITY (wave 3): PASS (injected reconstruction bugs caught)")
def prove_injected_bug(image: PeImage, log: list[str]) -> None:
source = SRC.read_text(encoding="utf-8")
injections = [
@@ -593,7 +831,14 @@ def main() -> int:
prove_fast_zero(image, log)
prove_vec_memcpy(image, log)
prove_ascii_strnicmp(image, log)
prove_ptr_d000(image, log)
prove_map_status(image, log)
prove_aulldvrm(image, log)
prove_initp_winsig(image, log)
prove_nlg_notify(image, log)
prove_siglookup(image, log)
prove_injected_bug(image, log)
prove_injected_bug_wave3(image, log)
log.append("ALL DIFFERENTIALS PASS")
print("\n".join(log))
return 0
+67
View File
@@ -261,6 +261,67 @@ int RunAsciiStrnicmp(const std::vector<std::uint8_t> &in) {
return 0;
}
// --- wave 3 modes ---
int RunPtrD000(const std::vector<std::uint8_t> &) {
const std::uint8_t *ptr = gk::acio::sub_1000174c();
const std::uint32_t offset =
static_cast<std::uint32_t>(ptr - gk::acio::g_data_d000);
PutHex(&offset, sizeof(offset));
return 0;
}
int RunMapStatus(const std::vector<std::uint8_t> &in) {
const std::uint32_t result = gk::acio::map_status_10004264(Word(in, 0));
PutHex(&result, sizeof(result));
return 0;
}
int RunAulldvrm(const std::vector<std::uint8_t> &in) {
const std::uint64_t dividend =
Word(in, 0) | (static_cast<std::uint64_t>(Word(in, 4)) << 32);
const std::uint64_t divisor =
Word(in, 8) | (static_cast<std::uint64_t>(Word(in, 12)) << 32);
const gk::acio::DivRem64 r = gk::acio::aulldvrm(dividend, divisor);
std::uint32_t out[4] = {
static_cast<std::uint32_t>(r.quotient & 0xFFFFFFFFu),
static_cast<std::uint32_t>(r.quotient >> 32),
static_cast<std::uint32_t>(r.remainder & 0xFFFFFFFFu),
static_cast<std::uint32_t>(r.remainder >> 32),
};
PutHex(out, sizeof(out));
return 0;
}
int RunInitpWinsig(const std::vector<std::uint8_t> &in) {
for (std::uint32_t &slot : gk::acio::g_winsig) {
slot = 0xAAAAAAAAu;
}
gk::acio::initp_misc_winsig(Word(in, 0));
PutHex(gk::acio::g_winsig, sizeof(gk::acio::g_winsig));
return 0;
}
int RunNlgNotify(const std::vector<std::uint8_t> &in) {
for (std::uint32_t &slot : gk::acio::g_nlg_record) {
slot = 0xAAAAAAAAu;
}
gk::acio::nlg_notify(Word(in, 0), Word(in, 4), Word(in, 8));
PutHex(gk::acio::g_nlg_record, sizeof(gk::acio::g_nlg_record));
return 0;
}
int RunSiglookup(const std::vector<std::uint8_t> &in) {
gk::acio::g_siglookup_count = Word(in, 0);
const std::uint32_t key = Word(in, 4);
const std::uint8_t *table = in.data() + 8;
const std::uint8_t *found = gk::acio::siglookup(table, key);
const std::uint32_t offset =
found == nullptr ? 0xFFFFFFFFu : static_cast<std::uint32_t>(found - table);
PutHex(&offset, sizeof(offset));
return 0;
}
}
int main(int argc, char **argv) {
@@ -299,6 +360,12 @@ int main(int argc, char **argv) {
if (mode == "fast_zero") return RunFastZero(in);
if (mode == "vec_memcpy") return RunVecMemcpy(in);
if (mode == "ascii_strnicmp") return RunAsciiStrnicmp(in);
if (mode == "ptr_d000") return RunPtrD000(in);
if (mode == "map_status") return RunMapStatus(in);
if (mode == "aulldvrm") return RunAulldvrm(in);
if (mode == "initp_winsig") return RunInitpWinsig(in);
if (mode == "nlg_notify") return RunNlgNotify(in);
if (mode == "siglookup") return RunSiglookup(in);
std::fprintf(stderr, "unknown mode %s\n", argv[1]);
return 2;
}
+71
View File
@@ -15,6 +15,10 @@ std::uint32_t g_state_e900 = 0u;
std::uint32_t g_state_e904 = 0u;
std::uint32_t g_state_e908 = 0u;
std::uint32_t g_state_ea54 = 0u;
std::uint32_t g_winsig[4] = {0};
std::uint32_t g_nlg_record[4] = {0};
std::uint32_t g_siglookup_count = 0u;
std::uint8_t g_data_d000[32] = {0};
// rva=0x10001050 (orig ac_io_bmpu_consume_coinstock)
void GK_STDCALL ac_io_bmpu_consume_coinstock() {}
@@ -294,5 +298,72 @@ std::int32_t GK_CDECL crt_ascii_strnicmp(const char *a, const char *b, std::uint
}
}
// rva=0x1000174c (orig FUN_1000174c): `mov eax, 0x1000d000; ret` returns the
// address of the static data object at image-relative 0xd000.
const std::uint8_t *GK_STDCALL sub_1000174c() { return g_data_d000; }
// rva=0x10004264 (orig FUN_10004264): a chained-subtract switch that maps a
// status code (passed in EAX) to a normalized code, or 0 when it matches none.
std::uint32_t GK_STDCALL map_status_10004264(std::uint32_t code) {
switch (code) {
case 0x3A4u:
return 0x411u;
case 0x3A8u:
return 0x804u;
case 0x3B5u:
return 0x412u;
case 0x3B6u:
return 0x404u;
default:
return 0u;
}
}
// rva=0x10005000 (orig __aulldvrm): unsigned 64-bit divide-and-remainder CRT
// helper. The original returns the quotient in EDX:EAX and the remainder in
// EBX:ECX; the behaviour is exact integer division.
DivRem64 GK_STDCALL aulldvrm(std::uint64_t dividend, std::uint64_t divisor) {
return {dividend / divisor, dividend % divisor};
}
// rva=0x10005704 (orig __initp_misc_winsig): broadcast one value into the four
// adjacent winsig slots at 0xe8e0..0xe8ec.
void GK_CDECL initp_misc_winsig(std::uint32_t value) {
g_winsig[0] = value;
g_winsig[1] = value;
g_winsig[2] = value;
g_winsig[3] = value;
}
// rva=0x10008509 (orig __NLG_Notify): record a long-goto notification into the
// destination struct at 0xde10. The first dword (0xde10) is left untouched; the
// routine stores EAX at 0xde14, the stack code at 0xde18 and EBP at 0xde1c, then
// restores every scratch register via a push/pop shuffle (no other effect).
void GK_STDCALL nlg_notify(std::uint32_t eax_target, std::uint32_t code,
std::uint32_t frame_ebp) {
g_nlg_record[1] = eax_target;
g_nlg_record[2] = code;
g_nlg_record[3] = frame_ebp;
}
// rva=0x1000571d (orig siglookup): linear scan of a table of 12-byte entries for
// the first whose dword at offset +4 equals the key (passed in EDX). The entry
// count is read from the module global at 0xd4dc; returns the matching entry
// pointer or null. The original's final bound check means a key match is only
// honoured for an in-range entry [0, count), so the observable return is the
// first in-range entry whose +4 field equals the key, else null.
const std::uint8_t *GK_CDECL siglookup(const std::uint8_t *table, std::uint32_t key) {
const std::uint32_t count = g_siglookup_count;
for (std::uint32_t i = 0; i < count; ++i) {
const std::uint8_t *entry = table + static_cast<std::size_t>(i) * 12u;
std::uint32_t field = 0;
std::memcpy(&field, entry + 4, sizeof(field));
if (field == key) {
return entry;
}
}
return nullptr;
}
}
}
+25
View File
@@ -20,6 +20,19 @@ extern std::uint32_t g_state_e904;
extern std::uint32_t g_state_e908;
extern std::uint32_t g_state_ea54;
// wave 3 module-state globals (orig .data)
// 0xe8e0..0xe8ec: the four __p_* winsig slots broadcast by __initp_misc_winsig.
extern std::uint32_t g_winsig[4];
// 0xde10..0xde1c: the NLG-notify destination record (de10 untouched; de14=eax,
// de18=code, de1c=ebp).
extern std::uint32_t g_nlg_record[4];
// 0xd4dc: entry count scanned by siglookup.
extern std::uint32_t g_siglookup_count;
// 0xd000: a static data object whose address FUN_1000174c returns. Its contents
// are a separate data symbol not exercised by this accessor, so only the
// returned object identity is modelled here.
extern std::uint8_t g_data_d000[32];
void GK_STDCALL ac_io_bmpu_consume_coinstock();
void GK_CDECL ac_io_bmpu_current_coinstock(std::uint32_t device, std::uint32_t *out_coinstock);
void GK_CDECL ac_io_bmpu_get_control_status_buffer(std::uint32_t *out);
@@ -52,5 +65,17 @@ void GK_CDECL fast_zero(std::uint8_t *dst, std::uint32_t count);
void GK_CDECL vec_memcpy(std::uint8_t *dst, const std::uint8_t *src, std::uint32_t count);
std::int32_t GK_CDECL crt_ascii_strnicmp(const char *a, const char *b, std::uint32_t count);
// --- wave 3 reconstructions ---
const std::uint8_t *GK_STDCALL sub_1000174c();
std::uint32_t GK_STDCALL map_status_10004264(std::uint32_t code);
struct DivRem64 {
std::uint64_t quotient;
std::uint64_t remainder;
};
DivRem64 GK_STDCALL aulldvrm(std::uint64_t dividend, std::uint64_t divisor);
void GK_CDECL initp_misc_winsig(std::uint32_t value);
void GK_STDCALL nlg_notify(std::uint32_t eax_target, std::uint32_t code, std::uint32_t frame_ebp);
const std::uint8_t *GK_CDECL siglookup(const std::uint8_t *table, std::uint32_t key);
}
}