feat(ess): reconstruct+verify wave 5 6

This commit is contained in:
ulw-execute committed 2026-11-29 10:59:56 -05:00
1 parent ce95a861e3
commit 33de29fc59
8 files changed
+268 -6

No files matched your search

+6 -6
View File
@@ -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": [],
+106
View File
@@ -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("<I", run_recon(exe, mode, b""))[0]
eax_equal(f"{rva:#x} ess_{mode}", norm, recon, log, f"ptr_rva={norm:#x}")
def prove_wave5_global_reads(image: PeImage, log: list[str], exe: Path = RECON) -> None:
for seed in (0, 1, 0xDEADBEEF, 0xFFFFFFFF):
eax, _, _ = emulate(image, 0x35504,
global_writes=((G_W5_56B34, struct.pack("<I", seed)),))
assert eax == seed, (hex(seed), hex(eax))
recon = struct.unpack("<I", run_recon(exe, "global_56b34", struct.pack("<I", seed)))[0]
eax_equal(f"0x35504 sub_10035504 g={seed:#010x}", eax, recon, log, f"EAX={eax:#x}")
for b in (0x00, 0x7F, 0x80, 0xFF):
eax, _, _ = emulate(image, 0x24C90, global_writes=((G_W5_5201C5, bytes([b])),))
want = b if b < 0x80 else (0xFFFFFF00 | b)
assert eax == want, (hex(b), hex(eax), hex(want))
recon = struct.unpack("<I", run_recon(exe, "global_byte_5201c5", struct.pack("<I", b)))[0]
eax_equal(f"0x24c90 sub_10024c90 b={b:#04x}", eax, recon, log, f"EAX={eax:#x}")
def prove_wave5_global_write(image: PeImage, log: list[str], exe: Path = RECON) -> None:
for seed in (0xAAAAAAAA, 0xDEADBEEF, 1):
_, _, gouts = emulate(image, 0x2E769,
global_writes=((G_W5_52A7FC, struct.pack("<I", seed)),),
global_readback=(G_W5_52A7FC,))
after = struct.unpack("<I", gouts[G_W5_52A7FC])[0]
assert after == 0, (hex(seed), hex(after))
recon = struct.unpack("<I", run_recon(exe, "global_zero_52a7fc", struct.pack("<I", seed)))[0]
eax_equal(f"0x2e769 sub_1002e769 seed={seed:#010x}", after, recon, log, f"g={after:#x}")
def prove_wave5_nonvacuity_batch1(image: PeImage, log: list[str]) -> 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("<I", run_recon(exe, "ptr_542a0", b""))[0]
return RunResult(eax=norm, st0=None), RunResult(eax=r, st0=None)
def gread_case(exe: Path) -> tuple[RunResult, RunResult]:
eax, _, _ = emulate(image, 0x35504,
global_writes=((G_W5_56B34, struct.pack("<I", 0xDEADBEEF)),))
r = struct.unpack("<I", run_recon(exe, "global_56b34", struct.pack("<I", 0xDEADBEEF)))[0]
return RunResult(eax=eax, st0=None), RunResult(eax=r, st0=None)
def gbyte_case(exe: Path) -> tuple[RunResult, RunResult]:
eax, _, _ = emulate(image, 0x24C90, global_writes=((G_W5_5201C5, bytes([0x7F])),))
r = struct.unpack("<I", run_recon(exe, "global_byte_5201c5", struct.pack("<I", 0x7F)))[0]
return RunResult(eax=eax, st0=None), RunResult(eax=r, st0=None)
def gwrite_case(exe: Path) -> tuple[RunResult, RunResult]:
_, _, gouts = emulate(image, 0x2E769,
global_writes=((G_W5_52A7FC, struct.pack("<I", 0xAAAAAAAA)),),
global_readback=(G_W5_52A7FC,))
after = struct.unpack("<I", gouts[G_W5_52A7FC])[0]
r = struct.unpack("<I", run_recon(exe, "global_zero_52a7fc", struct.pack("<I", 0xAAAAAAAA)))[0]
return (RunResult(eax=0, st0=None, out_buffers=(("g", struct.pack("<I", after)),)),
RunResult(eax=0, st0=None, out_buffers=(("g", struct.pack("<I", r)),)))
cases = [
("370ec ptr+1",
"std::uint32_t GK_CDECL sub_100370ec() { return kEssPtr542a0Rva; }",
"std::uint32_t GK_CDECL sub_100370ec() { return kEssPtr542a0Rva + 1u; }", ptr_case),
("35504 gread+1",
"std::uint32_t GK_CDECL sub_10035504() { return g_dword_56b34; }",
"std::uint32_t GK_CDECL sub_10035504() { return g_dword_56b34 + 1u; }", gread_case),
("24c90 gbyte+1",
" return static_cast<std::int32_t>(static_cast<std::int8_t>(g_byte_5201c5));",
" return static_cast<std::int32_t>(static_cast<std::int8_t>(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("<II", 0xFFFFFFFF, 0xFFFFFFFF)
@@ -657,10 +759,14 @@ def main() -> 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
+27
View File
@@ -192,6 +192,27 @@ int RunThisDword(const std::vector<std::uint8_t> &in) {
return 0;
}
int RunGlobal56b34(const std::vector<std::uint8_t> &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<std::uint8_t> &in) {
gk::ess::g_byte_5201c5 = static_cast<std::uint8_t>(Word(in, 0));
const std::int32_t result = gk::ess::sub_10024c90();
PutHex(&result, sizeof(result));
return 0;
}
int RunGlobalZero52a7fc(const std::vector<std::uint8_t> &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<gk::ess::sub_10025b20>();
if (mode == "ptr_53470") return RunRetU32<gk::ess::sub_10029b3b>();
if (mode == "ptr_540c0") return RunRetU32<gk::ess::sub_10035354>();
if (mode == "catch_813e") return RunRetU32<gk::ess::sub_10008150>();
if (mode == "ptr_542a0") return RunRetU32<gk::ess::sub_100370ec>();
if (mode == "ptr_541f0") return RunRetU32<gk::ess::sub_100370f2>();
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;
}
+26
View File
@@ -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, <same-image pointer>; 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<std::int32_t>(static_cast<std::int8_t>(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; }
}
}
+21
View File
@@ -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, <absolute image pointer>; 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();
}
}
+14
View File
@@ -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
+33
View File
@@ -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())
+35
View File
@@ -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}")