From 33de29fc5983bb9bfe0e1012ab8aa3feb6f37fa9 Mon Sep 17 00:00:00 2001 From: ulw-execute Date: Sun, 29 Nov 2026 10:59:56 -0500 Subject: [PATCH] feat(ess): reconstruct+verify wave 5 6 --- re/ess/ess_rvadb.json | 12 ++-- re/ess/prove_ess.py | 106 +++++++++++++++++++++++++++++++++++ re/ess/recon_ess_harness.cpp | 27 +++++++++ src/ess/ess.cpp | 26 +++++++++ src/ess/ess.h | 21 +++++++ tools/wave/dis_ess.py | 14 +++++ tools/wave/flip_status.py | 33 +++++++++++ tools/wave/scan_pure.py | 35 ++++++++++++ 8 files changed, 268 insertions(+), 6 deletions(-) create mode 100644 tools/wave/dis_ess.py create mode 100644 tools/wave/flip_status.py create mode 100644 tools/wave/scan_pure.py diff --git a/re/ess/ess_rvadb.json b/re/ess/ess_rvadb.json index b52db9d..d84ba63 100644 --- a/re/ess/ess_rvadb.json +++ b/re/ess/ess_rvadb.json @@ -212587,7 +212587,7 @@ "owning_module_guess": "unknown", "rva": "0x00008150", "signature": "undefined Catch_All@10008150(void)", - "status": "orig" + "status": "verified" }, { "callees": [ @@ -227649,7 +227649,7 @@ "owning_module_guess": "unknown", "rva": "0x00024c90", "signature": "undefined FUN_10024c90(void)", - "status": "orig" + "status": "verified" }, { "callees": [], @@ -234418,7 +234418,7 @@ "owning_module_guess": "unknown", "rva": "0x0002e769", "signature": "undefined FUN_1002e769(void)", - "status": "orig" + "status": "verified" }, { "callees": [ @@ -237046,7 +237046,7 @@ "owning_module_guess": "unknown", "rva": "0x00035504", "signature": "undefined FUN_10035504(void)", - "status": "orig" + "status": "verified" }, { "callees": [ @@ -238679,7 +238679,7 @@ "owning_module_guess": "unknown", "rva": "0x000370ec", "signature": "undefined FUN_100370ec(void)", - "status": "orig" + "status": "verified" }, { "callees": [], @@ -238695,7 +238695,7 @@ "owning_module_guess": "unknown", "rva": "0x000370f2", "signature": "undefined FUN_100370f2(void)", - "status": "orig" + "status": "verified" }, { "callees": [], diff --git a/re/ess/prove_ess.py b/re/ess/prove_ess.py index 797e690..51860a7 100644 --- a/re/ess/prove_ess.py +++ b/re/ess/prove_ess.py @@ -538,6 +538,108 @@ def prove_wave4_nonvacuity(image: PeImage, log: list[str]) -> None: log.append("NON-VACUITY (wave 4): PASS (injected reconstruction bugs caught)") +# wave 5: same-image pointer returns + module-global read/write leaves. +_WAVE5_PTR_RETURNS = ( + (0x8150, "catch_813e", 0x813E), + (0x370EC, "ptr_542a0", 0x542A0), + (0x370F2, "ptr_541f0", 0x541F0), +) +G_W5_56B34 = 0x56B34 +G_W5_5201C5 = 0x5201C5 +G_W5_52A7FC = 0x52A7FC + + +def prove_wave5_ptr_returns(image: PeImage, log: list[str], exe: Path = RECON) -> None: + for rva, mode, want in _WAVE5_PTR_RETURNS: + eax, _, _ = emulate(image, rva) + norm = (eax - image.image_base) & 0xFFFFFFFF + assert norm == want, (mode, hex(eax), hex(norm)) + recon = struct.unpack(" None: + for seed in (0, 1, 0xDEADBEEF, 0xFFFFFFFF): + eax, _, _ = emulate(image, 0x35504, + global_writes=((G_W5_56B34, struct.pack(" None: + for seed in (0xAAAAAAAA, 0xDEADBEEF, 1): + _, _, gouts = emulate(image, 0x2E769, + global_writes=((G_W5_52A7FC, struct.pack(" None: + source = SRC.read_text(encoding="utf-8") + base = image.image_base + + def ptr_case(exe: Path) -> tuple[RunResult, RunResult]: + eax, _, _ = emulate(image, 0x370EC) + norm = (eax - base) & 0xFFFFFFFF + r = struct.unpack(" tuple[RunResult, RunResult]: + eax, _, _ = emulate(image, 0x35504, + global_writes=((G_W5_56B34, struct.pack(" tuple[RunResult, RunResult]: + eax, _, _ = emulate(image, 0x24C90, global_writes=((G_W5_5201C5, bytes([0x7F])),)) + r = struct.unpack(" tuple[RunResult, RunResult]: + _, _, gouts = emulate(image, 0x2E769, + global_writes=((G_W5_52A7FC, struct.pack("(static_cast(g_byte_5201c5));", + " return static_cast(static_cast(g_byte_5201c5)) + 1;", gbyte_case), + ("2e769 zero->1", + "void GK_CDECL sub_1002e769() { g_dword_52a7fc = 0u; }", + "void GK_CDECL sub_1002e769() { g_dword_52a7fc = 1u; }", gwrite_case), + ] + for label, old, new, runner in cases: + bug = source.replace(old, new) + assert bug != source, f"injection anchor not found: {label}" + with tempfile.TemporaryDirectory() as td: + exe = build_variant(bug, td) + orig, ref = runner(exe) + report = diff(orig, ref) + assert report.verdict is Verdict.DIFF, (label, orig, ref) + log.append(f" injected bug [{label}] -> {report.verdict.value} {report.differences[0]}") + log.append("NON-VACUITY (wave 5 batch1): PASS (injected reconstruction bugs caught)") + + def prove_injected_bug(image: PeImage, log: list[str]) -> None: source = SRC.read_text(encoding="utf-8") real = struct.pack(" int: prove_wave3_fields(image, log) prove_wave4_ret0(image, log) prove_wave4_ptr_returns(image, log) + prove_wave5_ptr_returns(image, log) + prove_wave5_global_reads(image, log) + prove_wave5_global_write(image, log) prove_injected_bug(image, log) prove_wave2_nonvacuity(image, log) prove_wave3_nonvacuity(image, log) prove_wave4_nonvacuity(image, log) + prove_wave5_nonvacuity_batch1(image, log) log.append("ALL DIFFERENTIALS PASS") print("\n".join(log)) return 0 diff --git a/re/ess/recon_ess_harness.cpp b/re/ess/recon_ess_harness.cpp index 023913b..2fd9724 100644 --- a/re/ess/recon_ess_harness.cpp +++ b/re/ess/recon_ess_harness.cpp @@ -192,6 +192,27 @@ int RunThisDword(const std::vector &in) { return 0; } +int RunGlobal56b34(const std::vector &in) { + gk::ess::g_dword_56b34 = Word(in, 0); + const std::uint32_t result = gk::ess::sub_10035504(); + PutHex(&result, sizeof(result)); + return 0; +} + +int RunGlobalByte5201c5(const std::vector &in) { + gk::ess::g_byte_5201c5 = static_cast(Word(in, 0)); + const std::int32_t result = gk::ess::sub_10024c90(); + PutHex(&result, sizeof(result)); + return 0; +} + +int RunGlobalZero52a7fc(const std::vector &in) { + gk::ess::g_dword_52a7fc = Word(in, 0); + gk::ess::sub_1002e769(); + PutHex(&gk::ess::g_dword_52a7fc, sizeof(gk::ess::g_dword_52a7fc)); + return 0; +} + } // namespace int main(int argc, char **argv) { @@ -233,6 +254,12 @@ int main(int argc, char **argv) { if (mode == "ptr_557a0") return RunRetU32(); if (mode == "ptr_53470") return RunRetU32(); if (mode == "ptr_540c0") return RunRetU32(); + if (mode == "catch_813e") return RunRetU32(); + if (mode == "ptr_542a0") return RunRetU32(); + if (mode == "ptr_541f0") return RunRetU32(); + if (mode == "global_56b34") return RunGlobal56b34(in); + if (mode == "global_byte_5201c5") return RunGlobalByte5201c5(in); + if (mode == "global_zero_52a7fc") return RunGlobalZero52a7fc(in); std::fprintf(stderr, "unknown mode %s\n", argv[1]); return 2; } diff --git a/src/ess/ess.cpp b/src/ess/ess.cpp index 30edc36..d2dd84c 100644 --- a/src/ess/ess.cpp +++ b/src/ess/ess.cpp @@ -7,6 +7,9 @@ std::uint32_t g_state_3ddf0 = 0xFFFFFFFFu; std::uint32_t g_state_3ddf4 = 0xFFFFFFFFu; std::uint32_t g_log_change_func = 0u; std::uint8_t g_is_active = 0u; +std::uint32_t g_dword_56b34 = 0u; +std::uint8_t g_byte_5201c5 = 0u; +std::uint32_t g_dword_52a7fc = 0u; namespace { @@ -222,5 +225,28 @@ std::uint32_t GK_CDECL sub_10025b20() { return kEssPtr557a0Rva; } std::uint32_t GK_CDECL sub_10029b3b() { return kEssPtr53470Rva; } std::uint32_t GK_CDECL sub_10035354() { return kEssPtr540c0Rva; } +// rva=0x10008150 (orig Catch_All@10008150): mov eax, 0x1000813e; ret. Returns a +// same-image code pointer (offset-normalized rva 0x813e, Todo-23 channel). +std::uint32_t GK_CDECL sub_10008150() { return kEssCatch813eRva; } + +// rva=0x100370ec / 0x100370f2 (orig FUN_*): mov eax, ; ret. +// Each returns a static same-image table pointer (offset-normalized rva). +std::uint32_t GK_CDECL sub_100370ec() { return kEssPtr542a0Rva; } +std::uint32_t GK_CDECL sub_100370f2() { return kEssPtr541f0Rva; } + +// rva=0x10035504 (orig FUN_10035504): mov eax,[0x10056b34]; ret. Returns the +// dword module global at rva 0x56b34. +std::uint32_t GK_CDECL sub_10035504() { return g_dword_56b34; } + +// rva=0x10024c90 (orig FUN_10024c90): movsx eax, byte ptr [0x105201c5]; ret. +// Returns the sign-extended byte module global at rva 0x5201c5. +std::int32_t GK_CDECL sub_10024c90() { + return static_cast(static_cast(g_byte_5201c5)); +} + +// rva=0x1002e769 (orig FUN_1002e769): and dword ptr [0x1052a7fc], 0; ret. Clears +// the dword module global at rva 0x52a7fc to zero. +void GK_CDECL sub_1002e769() { g_dword_52a7fc = 0u; } + } } diff --git a/src/ess/ess.h b/src/ess/ess.h index 2394370..b992a68 100644 --- a/src/ess/ess.h +++ b/src/ess/ess.h @@ -85,5 +85,26 @@ std::uint32_t GK_CDECL sub_10025b20(); std::uint32_t GK_CDECL sub_10029b3b(); std::uint32_t GK_CDECL sub_10035354(); +// wave 5 reconstructions. +// +// Same-image pointer channel (Todo-23): each constant below is an +// offset-normalized pointer into the module's own image; the original does +// `mov eax, ; ret` (or stores one into memory). +inline constexpr std::uint32_t kEssCatch813eRva = 0x0000813eu; // 0x10008150 return +inline constexpr std::uint32_t kEssPtr542a0Rva = 0x000542a0u; // 0x100370ec return +inline constexpr std::uint32_t kEssPtr541f0Rva = 0x000541f0u; // 0x100370f2 return + +// Module-state globals, seeded from the image (Todo-22 read/write leaves). +extern std::uint32_t g_dword_56b34; // orig rva 0x56b34 (read by sub_10035504) +extern std::uint8_t g_byte_5201c5; // orig rva 0x5201c5 (read by sub_10024c90) +extern std::uint32_t g_dword_52a7fc; // orig rva 0x52a7fc (cleared by sub_1002e769) + +std::uint32_t GK_CDECL sub_10008150(); +std::uint32_t GK_CDECL sub_100370ec(); +std::uint32_t GK_CDECL sub_100370f2(); +std::uint32_t GK_CDECL sub_10035504(); +std::int32_t GK_CDECL sub_10024c90(); +void GK_CDECL sub_1002e769(); + } } diff --git a/tools/wave/dis_ess.py b/tools/wave/dis_ess.py new file mode 100644 index 0000000..0b63f66 --- /dev/null +++ b/tools/wave/dis_ess.py @@ -0,0 +1,14 @@ +import sys, json, pefile, capstone +_dll=json.load(open('re/oracles.json'))['ess.dll']['path'] +pe=pefile.PE(_dll, fast_load=True) +base=pe.OPTIONAL_HEADER.ImageBase +data=pe.get_memory_mapped_image() +md=capstone.Cs(capstone.CS_ARCH_X86, capstone.CS_MODE_32) +for a in sys.argv[1:]: + rva=int(a,16) + print(f"=== {rva:#x} ===") + buf=data[rva:rva+256] + for ins in md.disasm(buf, base+rva): + print(f" {ins.address-base:#06x}: {ins.mnemonic} {ins.op_str}") + if ins.mnemonic=='ret': + break diff --git a/tools/wave/flip_status.py b/tools/wave/flip_status.py new file mode 100644 index 0000000..8d49367 --- /dev/null +++ b/tools/wave/flip_status.py @@ -0,0 +1,33 @@ +"""Flip ess RVADB rows from status=orig to verified in place, by RVA. + +Usage: python tools/wave/flip_status.py re/ess/ess_rvadb.json 0x00008150 0x000370ec ... +Only the matched status lines change; every other byte is preserved so the +canonical formatting is left untouched (no full-file reserialization). +""" +import sys + + +def main() -> int: + path = sys.argv[1] + targets = set(sys.argv[2:]) + with open(path, encoding="utf-8") as handle: + lines = handle.readlines() + flipped = [] + for i, line in enumerate(lines): + for rva in targets: + if f'"rva": "{rva}"' in line: + status_index = i + 2 + assert '"status": "orig"' in lines[status_index], (rva, lines[status_index]) + lines[status_index] = lines[status_index].replace( + '"status": "orig"', '"status": "verified"') + flipped.append(rva) + missing = targets - set(flipped) + assert not missing, f"unmatched rvas: {sorted(missing)}" + with open(path, "w", encoding="utf-8") as handle: + handle.writelines(lines) + print(f"flipped {len(flipped)} -> {sorted(flipped)}") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/tools/wave/scan_pure.py b/tools/wave/scan_pure.py new file mode 100644 index 0000000..2f605af --- /dev/null +++ b/tools/wave/scan_pure.py @@ -0,0 +1,35 @@ +import json, re, pefile, capstone +db=json.load(open('re/ess/ess_rvadb.json')) +funcs=[f for f in db['functions'] if f['status']=='orig'] +_dll=json.load(open('re/oracles.json'))['ess.dll']['path'] +pe=pefile.PE(_dll, fast_load=True); base=pe.OPTIONAL_HEADER.ImageBase +data=pe.get_memory_mapped_image() +md=capstone.Cs(capstone.CS_ARCH_X86, capstone.CS_MODE_32) +md.detail=True +IMPORT=re.compile(r'^[A-Z0-9_-]+\.DLL::') +FPU=('fld','fst','fild','fadd','fmul','fdiv','fsub','fcom','fucom','fchs','fabs','fsqrt','fstp','fxch','emms','movss','movsd','mulss','addss','cvt') +def decode(rva, cap=400): + insns=[] + for ins in md.disasm(data[rva:rva+cap], base+rva): + insns.append(ins) + if ins.mnemonic=='ret': return insns, True + if ins.mnemonic in ('jmp',) and ins.operands and ins.operands[0].type!=capstone.x86.X86_OP_IMM: + return insns, False # indirect jmp/tailcall + return insns, False +out=[] +for f in funcs: + rva=int(f['rva'],16); name=f['name'] + if IMPORT.match(name): continue + if f['callees'] or f['external_callees']: continue + insns, ok=decode(rva) + if not ok: continue + mns=[i.mnemonic for i in insns] + if any(m=='call' for m in mns): continue + if any(m.startswith('f') and m in FPU or m in FPU for m in mns): continue + if any('xmm' in (i.op_str) for i in insns): continue + # length and global touches + out.append((rva,name,len(insns),len(f.get('globals_touched',[])),f.get('calling_convention'),f.get('signature','')[:60])) +out.sort(key=lambda x:(x[2])) +print('pure-leaf candidates:', len(out)) +for rva,name,n,ng,cc,sig in out[:40]: + print(f"{rva:#08x} n={n:<3} glob={ng} cc={cc:<10} {name[:34]:34} | {sig}")