feat(ess): reconstruct+verify wave 5 7
This commit is contained in:
1 parent
33de29fc59
commit
8b7d480f55
5 files changed
+159
-7
No files matched your search
@@ -227661,7 +227661,7 @@
|
||||
"owning_module_guess": "unknown",
|
||||
"rva": "0x00024ca0",
|
||||
"signature": "undefined FUN_10024ca0(void)",
|
||||
"status": "orig"
|
||||
"status": "verified"
|
||||
},
|
||||
{
|
||||
"callees": [
|
||||
@@ -227897,7 +227897,7 @@
|
||||
"owning_module_guess": "unknown",
|
||||
"rva": "0x00025320",
|
||||
"signature": "undefined FUN_10025320(void)",
|
||||
"status": "orig"
|
||||
"status": "verified"
|
||||
},
|
||||
{
|
||||
"callees": [],
|
||||
@@ -227909,7 +227909,7 @@
|
||||
"owning_module_guess": "unknown",
|
||||
"rva": "0x00025330",
|
||||
"signature": "undefined FUN_10025330(void)",
|
||||
"status": "orig"
|
||||
"status": "verified"
|
||||
},
|
||||
{
|
||||
"callees": [],
|
||||
@@ -227921,7 +227921,7 @@
|
||||
"owning_module_guess": "unknown",
|
||||
"rva": "0x00025340",
|
||||
"signature": "undefined FUN_10025340(void)",
|
||||
"status": "orig"
|
||||
"status": "verified"
|
||||
},
|
||||
{
|
||||
"callees": [],
|
||||
@@ -227945,7 +227945,7 @@
|
||||
"owning_module_guess": "unknown",
|
||||
"rva": "0x00025370",
|
||||
"signature": "undefined FUN_10025370(void)",
|
||||
"status": "orig"
|
||||
"status": "verified"
|
||||
},
|
||||
{
|
||||
"callees": [
|
||||
@@ -228014,7 +228014,7 @@
|
||||
"owning_module_guess": "unknown",
|
||||
"rva": "0x00025490",
|
||||
"signature": "undefined FUN_10025490(void)",
|
||||
"status": "orig"
|
||||
"status": "verified"
|
||||
},
|
||||
{
|
||||
"callees": [],
|
||||
@@ -228038,7 +228038,7 @@
|
||||
"owning_module_guess": "unknown",
|
||||
"rva": "0x000254b0",
|
||||
"signature": "undefined FUN_100254b0(void)",
|
||||
"status": "orig"
|
||||
"status": "verified"
|
||||
},
|
||||
{
|
||||
"callees": [
|
||||
|
||||
@@ -640,6 +640,76 @@ def prove_wave5_nonvacuity_batch1(image: PeImage, log: list[str]) -> None:
|
||||
log.append("NON-VACUITY (wave 5 batch1): PASS (injected reconstruction bugs caught)")
|
||||
|
||||
|
||||
# wave 5: thiscall double-deref field readers (pointer at this+0x34).
|
||||
_WAVE5_F34_DWORD = ((0x25320, "f34_10", 0x10), (0x25340, "f34_18", 0x18),
|
||||
(0x25370, "f34_1c", 0x1C))
|
||||
_WAVE5_F34_BYTE = ((0x25330, "f34_14", 0x14), (0x25490, "f34_23", 0x23),
|
||||
(0x254B0, "f34_24", 0x24), (0x24CA0, "f34_02", 0x02))
|
||||
|
||||
|
||||
def _f34_scratch(inner_off: int, value_bytes: bytes) -> bytes:
|
||||
scratch = bytearray(b"\xAA" * 0x80)
|
||||
scratch[0x34:0x38] = struct.pack("<I", SCRATCH_BASE + 0x40)
|
||||
scratch[0x40 + inner_off:0x40 + inner_off + len(value_bytes)] = value_bytes
|
||||
return bytes(scratch)
|
||||
|
||||
|
||||
def prove_wave5_f34_dword(image: PeImage, log: list[str], exe: Path = RECON) -> None:
|
||||
for rva, mode, off in _WAVE5_F34_DWORD:
|
||||
for val in (0x00000000, 0xDEADBEEF, 0x11223344, 0xFFFFFFFF):
|
||||
scratch = _f34_scratch(off, struct.pack("<I", val))
|
||||
eax, _, _ = emulate(image, rva, ecx=SCRATCH_BASE, scratch_init=scratch, args=(0,))
|
||||
assert eax == val, (mode, hex(eax), hex(val))
|
||||
recon = struct.unpack("<I", run_recon(exe, mode, struct.pack("<I", val)))[0]
|
||||
eax_equal(f"{rva:#x} ess_{mode} val={val:#010x}", eax, recon, log, f"EAX={eax:#x}")
|
||||
|
||||
|
||||
def prove_wave5_f34_byte(image: PeImage, log: list[str], exe: Path = RECON) -> None:
|
||||
for rva, mode, off in _WAVE5_F34_BYTE:
|
||||
for b in (0x00, 0x7F, 0x80, 0xFF):
|
||||
scratch = _f34_scratch(off, bytes([b]))
|
||||
eax, _, _ = emulate(image, rva, ecx=SCRATCH_BASE, scratch_init=scratch, args=(0,))
|
||||
want = b if b < 0x80 else (0xFFFFFF00 | b)
|
||||
assert eax == want, (mode, hex(b), hex(eax), hex(want))
|
||||
recon = struct.unpack("<I", run_recon(exe, mode, struct.pack("<I", b)))[0]
|
||||
eax_equal(f"{rva:#x} ess_{mode} b={b:#04x}", eax, recon, log, f"EAX={eax:#x}")
|
||||
|
||||
|
||||
def prove_wave5_nonvacuity_batch2(image: PeImage, log: list[str]) -> None:
|
||||
source = SRC.read_text(encoding="utf-8")
|
||||
|
||||
def f34d_case(exe: Path) -> tuple[RunResult, RunResult]:
|
||||
scratch = _f34_scratch(0x10, struct.pack("<I", 0xDEADBEEF))
|
||||
eax, _, _ = emulate(image, 0x25320, ecx=SCRATCH_BASE, scratch_init=scratch, args=(0,))
|
||||
r = struct.unpack("<I", run_recon(exe, "f34_10", struct.pack("<I", 0xDEADBEEF)))[0]
|
||||
return RunResult(eax=eax, st0=None), RunResult(eax=r, st0=None)
|
||||
|
||||
def f34b_case(exe: Path) -> tuple[RunResult, RunResult]:
|
||||
scratch = _f34_scratch(0x14, bytes([0x7F]))
|
||||
eax, _, _ = emulate(image, 0x25330, ecx=SCRATCH_BASE, scratch_init=scratch, args=(0,))
|
||||
r = struct.unpack("<I", run_recon(exe, "f34_14", struct.pack("<I", 0x7F)))[0]
|
||||
return RunResult(eax=eax, st0=None), RunResult(eax=r, st0=None)
|
||||
|
||||
cases = [
|
||||
("25320 off10->14",
|
||||
" return *reinterpret_cast<const std::uint32_t *>(p + 0x10);",
|
||||
" return *reinterpret_cast<const std::uint32_t *>(p + 0x14);", f34d_case),
|
||||
("25330 off14->18",
|
||||
" return static_cast<std::int32_t>(static_cast<std::int8_t>(p[0x14]));",
|
||||
" return static_cast<std::int32_t>(static_cast<std::int8_t>(p[0x18]));", f34b_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 batch2): 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)
|
||||
@@ -762,11 +832,14 @@ def main() -> int:
|
||||
prove_wave5_ptr_returns(image, log)
|
||||
prove_wave5_global_reads(image, log)
|
||||
prove_wave5_global_write(image, log)
|
||||
prove_wave5_f34_dword(image, log)
|
||||
prove_wave5_f34_byte(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)
|
||||
prove_wave5_nonvacuity_batch2(image, log)
|
||||
log.append("ALL DIFFERENTIALS PASS")
|
||||
print("\n".join(log))
|
||||
return 0
|
||||
|
||||
@@ -213,6 +213,31 @@ int RunGlobalZero52a7fc(const std::vector<std::uint8_t> &in) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <std::uint32_t (GK_THISCALL *Fn)(const std::uint8_t *), std::size_t InnerOff>
|
||||
int RunField34Dword(const std::vector<std::uint8_t> &in) {
|
||||
std::vector<std::uint8_t> obj(0x80, 0xAA);
|
||||
const std::uint32_t val = Word(in, 0);
|
||||
std::memcpy(obj.data() + 0x40 + InnerOff, &val, 4);
|
||||
const std::uint32_t ptr =
|
||||
static_cast<std::uint32_t>(reinterpret_cast<std::uintptr_t>(obj.data() + 0x40));
|
||||
std::memcpy(obj.data() + 0x34, &ptr, 4);
|
||||
const std::uint32_t result = Fn(obj.data());
|
||||
PutHex(&result, sizeof(result));
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <std::int32_t (GK_THISCALL *Fn)(const std::uint8_t *), std::size_t InnerOff>
|
||||
int RunField34Byte(const std::vector<std::uint8_t> &in) {
|
||||
std::vector<std::uint8_t> obj(0x80, 0xAA);
|
||||
obj[0x40 + InnerOff] = static_cast<std::uint8_t>(Word(in, 0));
|
||||
const std::uint32_t ptr =
|
||||
static_cast<std::uint32_t>(reinterpret_cast<std::uintptr_t>(obj.data() + 0x40));
|
||||
std::memcpy(obj.data() + 0x34, &ptr, 4);
|
||||
const std::int32_t result = Fn(obj.data());
|
||||
PutHex(&result, sizeof(result));
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
@@ -260,6 +285,13 @@ int main(int argc, char **argv) {
|
||||
if (mode == "global_56b34") return RunGlobal56b34(in);
|
||||
if (mode == "global_byte_5201c5") return RunGlobalByte5201c5(in);
|
||||
if (mode == "global_zero_52a7fc") return RunGlobalZero52a7fc(in);
|
||||
if (mode == "f34_10") return RunField34Dword<gk::ess::sub_10025320, 0x10>(in);
|
||||
if (mode == "f34_18") return RunField34Dword<gk::ess::sub_10025340, 0x18>(in);
|
||||
if (mode == "f34_1c") return RunField34Dword<gk::ess::sub_10025370, 0x1c>(in);
|
||||
if (mode == "f34_14") return RunField34Byte<gk::ess::sub_10025330, 0x14>(in);
|
||||
if (mode == "f34_23") return RunField34Byte<gk::ess::sub_10025490, 0x23>(in);
|
||||
if (mode == "f34_24") return RunField34Byte<gk::ess::sub_100254b0, 0x24>(in);
|
||||
if (mode == "f34_02") return RunField34Byte<gk::ess::sub_10024ca0, 0x02>(in);
|
||||
std::fprintf(stderr, "unknown mode %s\n", argv[1]);
|
||||
return 2;
|
||||
}
|
||||
@@ -248,5 +248,42 @@ std::int32_t GK_CDECL sub_10024c90() {
|
||||
// the dword module global at rva 0x52a7fc to zero.
|
||||
void GK_CDECL sub_1002e769() { g_dword_52a7fc = 0u; }
|
||||
|
||||
// rva=0x10025320/0x10025340/0x10025370 (orig FUN_*): mov eax,[ecx+0x34];
|
||||
// mov eax,[eax+<off>]; ret. Load the pointer at this+0x34 and return the dword
|
||||
// field at <inner>+0x10 / +0x18 / +0x1c. 0x10025370 pops one ignored stdcall arg.
|
||||
std::uint32_t GK_THISCALL sub_10025320(const std::uint8_t *self) {
|
||||
const std::uint8_t *p = *reinterpret_cast<const std::uint8_t *const *>(self + 0x34);
|
||||
return *reinterpret_cast<const std::uint32_t *>(p + 0x10);
|
||||
}
|
||||
std::uint32_t GK_THISCALL sub_10025340(const std::uint8_t *self) {
|
||||
const std::uint8_t *p = *reinterpret_cast<const std::uint8_t *const *>(self + 0x34);
|
||||
return *reinterpret_cast<const std::uint32_t *>(p + 0x18);
|
||||
}
|
||||
std::uint32_t GK_THISCALL sub_10025370(const std::uint8_t *self) {
|
||||
const std::uint8_t *p = *reinterpret_cast<const std::uint8_t *const *>(self + 0x34);
|
||||
return *reinterpret_cast<const std::uint32_t *>(p + 0x1c);
|
||||
}
|
||||
|
||||
// rva=0x10025330/0x10025490/0x100254b0/0x10024ca0 (orig FUN_*): mov eax,[ecx+0x34];
|
||||
// movsx eax, byte ptr [eax+<off>]; ret. Load the pointer at this+0x34 and return
|
||||
// the sign-extended byte field at <inner>+0x14 / +0x23 / +0x24 / +0x02.
|
||||
// 0x10024ca0 pops one ignored stdcall arg.
|
||||
std::int32_t GK_THISCALL sub_10025330(const std::uint8_t *self) {
|
||||
const std::uint8_t *p = *reinterpret_cast<const std::uint8_t *const *>(self + 0x34);
|
||||
return static_cast<std::int32_t>(static_cast<std::int8_t>(p[0x14]));
|
||||
}
|
||||
std::int32_t GK_THISCALL sub_10025490(const std::uint8_t *self) {
|
||||
const std::uint8_t *p = *reinterpret_cast<const std::uint8_t *const *>(self + 0x34);
|
||||
return static_cast<std::int32_t>(static_cast<std::int8_t>(p[0x23]));
|
||||
}
|
||||
std::int32_t GK_THISCALL sub_100254b0(const std::uint8_t *self) {
|
||||
const std::uint8_t *p = *reinterpret_cast<const std::uint8_t *const *>(self + 0x34);
|
||||
return static_cast<std::int32_t>(static_cast<std::int8_t>(p[0x24]));
|
||||
}
|
||||
std::int32_t GK_THISCALL sub_10024ca0(const std::uint8_t *self) {
|
||||
const std::uint8_t *p = *reinterpret_cast<const std::uint8_t *const *>(self + 0x34);
|
||||
return static_cast<std::int32_t>(static_cast<std::int8_t>(p[0x02]));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -106,5 +106,15 @@ std::uint32_t GK_CDECL sub_10035504();
|
||||
std::int32_t GK_CDECL sub_10024c90();
|
||||
void GK_CDECL sub_1002e769();
|
||||
|
||||
// wave 5 thiscall double-deref field readers: each loads the pointer at
|
||||
// this+0x34 and reads a dword / sign-extended byte field through it.
|
||||
std::uint32_t GK_THISCALL sub_10025320(const std::uint8_t *self);
|
||||
std::uint32_t GK_THISCALL sub_10025340(const std::uint8_t *self);
|
||||
std::uint32_t GK_THISCALL sub_10025370(const std::uint8_t *self);
|
||||
std::int32_t GK_THISCALL sub_10025330(const std::uint8_t *self);
|
||||
std::int32_t GK_THISCALL sub_10025490(const std::uint8_t *self);
|
||||
std::int32_t GK_THISCALL sub_100254b0(const std::uint8_t *self);
|
||||
std::int32_t GK_THISCALL sub_10024ca0(const std::uint8_t *self);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user