feat(libafp): reconstruct+verify wave 11 3

This commit is contained in:
ulw-execute committed 2026-11-29 10:44:11 -05:00
1 parent 65670927cd
commit 29bea39650
6 files changed
+568 -4

No files matched your search

+3 -3
View File
@@ -691029,7 +691029,7 @@
"owning_module_guess": "unknown",
"rva": "0x0000e76c",
"signature": "undefined4 __cdecl FUN_1000e76c(int param_1)",
"status": "reimpl"
"status": "verified"
},
{
"callees": [
@@ -691067,7 +691067,7 @@
"owning_module_guess": "unknown",
"rva": "0x0000e7a4",
"signature": "undefined4 __cdecl FUN_1000e7a4(undefined4 param_1)",
"status": "reimpl"
"status": "verified"
},
{
"callees": [
@@ -691323,7 +691323,7 @@
"owning_module_guess": "unknown",
"rva": "0x0000e934",
"signature": "undefined4 __cdecl FUN_1000e934(undefined4 param_1)",
"status": "reimpl"
"status": "verified"
},
{
"callees": [
+260 -1
View File
@@ -43,7 +43,7 @@ SOURCES = (SRC_DIR / "afp_state.cpp", SRC_DIR / "afp_matrix_build.cpp",
SRC_DIR / "afp_boot.cpp", SRC_DIR / "afp_matrix_transform.cpp",
SRC_DIR / "afp_matrix_transform2.cpp", SRC_DIR / "afp_matrix_transform3.cpp",
SRC_DIR / "afp_matrix_transform4.cpp", SRC_DIR / "afp_matrix_transform5.cpp",
SRC_DIR / "afp_node_ops.cpp")
SRC_DIR / "afp_node_ops.cpp", SRC_DIR / "afp_node_ops2.cpp")
_MCF = sorted(Path("/nix/store").glob("*mcfgthread-i686-w64-mingw32-2.5.1/lib/libmcfgthread.a"))
MCFGTHREAD_LIB = str(_MCF[0].parent) if _MCF else (
"/nix/store/g72bh3mrbh6gkh59axd2199js9kccxfs-mcfgthread-i686-w64-mingw32-2.5.1/lib")
@@ -3256,6 +3256,256 @@ def _run_wave9_selected(image: PeImage, log: list[str], tokens: list[str]) -> in
return 0
# --- wave 11: object/matrix init-finish + projection-init leaves ---
NODE_OPS2_SRC = SRC_DIR / "afp_node_ops2.cpp"
def _proj_seed(fov: float | None = None, salt: int = 0) -> bytes:
buf = bytearray(((i * 13 + 5 + salt) & 0xFF) for i in range(0x20))
if fov is not None:
struct.pack_into("<f", buf, 4, fov)
return bytes(buf)
def _o_proj2(image: PeImage, rva: int, seed: bytes, extra: tuple[object, ...]) -> bytes:
_, outs = emulate_call(image, rva, buffers=(("obj", seed),),
stack_args=(("buf", "obj"),) + extra, readback=(("obj", 0x20),))
return outs["obj"]
def _prove_memset_leaf(image: PeImage, rva: int, mode: str, size: int, log: list[str],
guarded: bool = False) -> None:
for seed in (bytes([0xCC]) * size, bytes(((i * 7) & 0xFF) for i in range(size))):
orig = _emu_memset_fn(image, rva, seed, size)
recon = run_recon(RECON, mode, seed)
equal_bytes(f"{rva:#06x} {mode} seed={seed[:4].hex()}", orig, recon, log,
f"out={orig[:8].hex()}..")
if guarded:
emulate_call(image, rva, stack_args=(0,))
recon = run_recon(RECON, mode, b"")
equal_bytes(f"{rva:#06x} {mode} null (no write)", b"", recon, log, "null -> no write")
def prove_obj_zero_1c(image: PeImage, log: list[str]) -> None:
_prove_memset_leaf(image, 0xe76c, "obj_zero_0x1c_guarded", 0x1c, log, guarded=True)
def prove_obj_zero_28(image: PeImage, log: list[str]) -> None:
_prove_memset_leaf(image, 0xe7a4, "obj_zero_0x28", 0x28, log)
def prove_obj_zero_60(image: PeImage, log: list[str]) -> None:
_prove_memset_leaf(image, 0xe934, "obj_zero_0x60", 0x60, log)
def prove_color_zero_init(image: PeImage, log: list[str]) -> None:
_prove_memset_leaf(image, 0xe8ac, "color_zero_init", 0x20, log)
def prove_color_zero_init_wrap(image: PeImage, log: list[str]) -> None:
_prove_memset_leaf(image, 0xe8cc, "color_zero_init_wrap", 0x20, log)
def prove_matrix44_finish(image: PeImage, log: list[str]) -> None:
_prove_memset_leaf(image, 0xe7b8, "matrix44_finish", 0x40, log, guarded=True)
def prove_matrix44_init(image: PeImage, log: list[str]) -> None:
_prove_memset_leaf(image, 0xe7e0, "matrix44_init", 0x40, log)
def prove_matrix_finish(image: PeImage, log: list[str]) -> None:
_prove_memset_leaf(image, 0xe840, "matrix_finish", 0x18, log, guarded=True)
def prove_matrix_init(image: PeImage, log: list[str]) -> None:
_prove_memset_leaf(image, 0xe868, "matrix_init", 0x18, log)
def prove_proj_set_extent(image: PeImage, log: list[str]) -> None:
cases = [(1.0, 100.0, 0x11223344), (0.5, 50.0, 0), (2.0, 10.0, 0xDEADBEEF),
(1.2, -4.0, 0x3F800000)]
for i, (fov, extent, f1c) in enumerate(cases):
seed = _proj_seed(fov=fov, salt=i)
orig = _o_proj2(image, 0xe788, seed, (fbits(extent), f1c))
recon = run_recon(RECON, "proj_set_extent",
seed + struct.pack("<II", fbits(extent), f1c & 0xFFFFFFFF))
equal_bytes(f"0xe788 proj_set_extent fov={fov} extent={extent}", orig, recon, log,
f"field8={orig[8:12].hex()}")
def prove_proj_init_fov(image: PeImage, log: list[str]) -> None:
cases = [(500.0, 500.0), (100.0, 200.0), (1.0, 2.0), (0.5, 0.5), (-3.0, 8.0)]
for i, (f2, f3) in enumerate(cases):
seed = _proj_seed(salt=i + 1)
orig = _o_proj2(image, 0xe024, seed, (fbits(f2), fbits(f3)))
recon = run_recon(RECON, "proj_init_fov", seed + f(f2, f3))
equal_bytes(f"0xe024 proj_init_fov f=({f2},{f3})", orig, recon, log,
f"out={orig[:12].hex()}")
def prove_proj_init_default(image: PeImage, log: list[str]) -> None:
for i in range(3):
seed = _proj_seed(salt=i + 9)
orig = _o_proj2(image, 0xe008, seed, ())
recon = run_recon(RECON, "proj_init_default", seed)
equal_bytes(f"0xe008 proj_init_default case{i}", orig, recon, log,
f"out={orig[:12].hex()}")
WAVE11_INJECTIONS = [
("obj_zero_0x1c width", NODE_OPS2_SRC,
"std::memset(obj, 0, 0x1c);", "std::memset(obj, 0, 0x4);",
"obj_zero_0x1c_guarded",
lambda image: _emu_memset_fn(image, 0xe76c, bytes([0xCC]) * 0x1c, 0x1c),
lambda: bytes([0xCC]) * 0x1c),
("obj_zero_0x28 width", NODE_OPS2_SRC,
"std::memset(obj, 0, 0x28);", "std::memset(obj, 0, 0x8);",
"obj_zero_0x28",
lambda image: _emu_memset_fn(image, 0xe7a4, bytes([0xCC]) * 0x28, 0x28),
lambda: bytes([0xCC]) * 0x28),
("obj_zero_0x60 width", NODE_OPS2_SRC,
"std::memset(obj, 0, 0x60);", "std::memset(obj, 0, 0x10);",
"obj_zero_0x60",
lambda image: _emu_memset_fn(image, 0xe934, bytes([0xCC]) * 0x60, 0x60),
lambda: bytes([0xCC]) * 0x60),
("color_zero_init white", NODE_OPS2_SRC,
"afp_color_init_white(reinterpret_cast<std::uint32_t *>(obj));", "(void)obj;",
"color_zero_init",
lambda image: _emu_memset_fn(image, 0xe8ac, bytes([0xCC]) * 0x20, 0x20),
lambda: bytes([0xCC]) * 0x20),
("color_zero_init_wrap delegate", NODE_OPS2_SRC,
"afp_color_zero_init(obj);", "afp_obj_zero_0x1c_guarded(obj);",
"color_zero_init_wrap",
lambda image: _emu_memset_fn(image, 0xe8cc, bytes([0xCC]) * 0x20, 0x20),
lambda: bytes([0xCC]) * 0x20),
("matrix44_finish identity", NODE_OPS2_SRC,
"std::memset(out, 0, 0x40);\n afp_matrix44_identity(reinterpret_cast<std::uint32_t *>(out));\n return 0;",
"std::memset(out, 0, 0x40);\n (void)out;\n return 0;",
"matrix44_finish",
lambda image: _emu_memset_fn(image, 0xe7b8, bytes([0xCC]) * 0x40, 0x40),
lambda: bytes([0xCC]) * 0x40),
("matrix44_init identity", NODE_OPS2_SRC,
"std::memset(out, 0, 0x40);\n afp_matrix44_identity(reinterpret_cast<std::uint32_t *>(out));\n }",
"std::memset(out, 0, 0x40);\n (void)out;\n }",
"matrix44_init",
lambda image: _emu_memset_fn(image, 0xe7e0, bytes([0xCC]) * 0x40, 0x40),
lambda: bytes([0xCC]) * 0x40),
("matrix_finish identity", NODE_OPS2_SRC,
"std::memset(out, 0, 0x18);\n afp_matrix_identity(reinterpret_cast<std::uint32_t *>(out));\n return 0;",
"std::memset(out, 0, 0x18);\n (void)out;\n return 0;",
"matrix_finish",
lambda image: _emu_memset_fn(image, 0xe840, bytes([0xCC]) * 0x18, 0x18),
lambda: bytes([0xCC]) * 0x18),
("matrix_init identity", NODE_OPS2_SRC,
"std::memset(out, 0, 0x18);\n afp_matrix_identity(reinterpret_cast<std::uint32_t *>(out));\n }",
"std::memset(out, 0, 0x18);\n (void)out;\n }",
"matrix_init",
lambda image: _emu_memset_fn(image, 0xe868, bytes([0xCC]) * 0x18, 0x18),
lambda: bytes([0xCC]) * 0x18),
("proj_set_extent offset", NODE_OPS2_SRC,
"std::memcpy(obj + 0x18, &extent_bits, 4);", "std::memcpy(obj + 0x14, &extent_bits, 4);",
"proj_set_extent",
lambda image: _o_proj2(image, 0xe788, _proj_seed(fov=1.0, salt=0), (fbits(100.0), 0x11223344)),
lambda: _proj_seed(fov=1.0, salt=0) + struct.pack("<II", fbits(100.0), 0x11223344)),
("proj_init_fov divisor", NODE_OPS2_SRC,
"static_cast<ld>(fov_h) / static_cast<ld>(g_const_ec09c)",
"static_cast<ld>(fov_h) * static_cast<ld>(g_const_ec09c)",
"proj_init_fov",
lambda image: _o_proj2(image, 0xe024, _proj_seed(salt=1), (fbits(500.0), fbits(500.0))),
lambda: _proj_seed(salt=1) + f(500.0, 500.0)),
("proj_init_default fov", NODE_OPS2_SRC,
"afp_proj_init_fov(obj, 500.0f, 500.0f);", "afp_proj_init_fov(obj, 400.0f, 500.0f);",
"proj_init_default",
lambda image: _o_proj2(image, 0xe008, _proj_seed(salt=9), ()),
lambda: _proj_seed(salt=9)),
]
def prove_injected_bugs_wave11(image: PeImage, log: list[str], indices) -> None:
for i in indices:
label, src, old, new, mode, orig_fn, payload_fn = WAVE11_INJECTIONS[i]
text = src.read_text(encoding="utf-8")
assert old in text, f"injection anchor not found: {label}"
orig_val = orig_fn(image)
payload = payload_fn()
with tempfile.TemporaryDirectory() as td:
patched = Path(td) / src.name
patched.write_text(text.replace(old, new, 1), encoding="utf-8")
bug_exe = Path(td) / "recon_bug.exe"
build_recon(bug_exe, overrides={src: patched})
buggy = run_recon(bug_exe, mode, payload)
report = diff(RunResult(eax=0, st0=None, out_buffers=(("out", orig_val),)),
RunResult(eax=0, st0=None, out_buffers=(("out", buggy),)))
assert report.verdict is Verdict.DIFF, (label, orig_val.hex(), buggy.hex(), report)
log.append(f" injected bug [{label}] orig={orig_val[:8].hex()} buggy={buggy[:8].hex()}"
f" -> {report.verdict.value}")
log.append("NON-VACUITY (wave 11): PASS (injected reconstruction bugs caught by the "
"differential)")
WAVE11_GLOBALS = (
"WAVE11 GLOBALS-FIRST: every function is a status=orig leaf whose only intra-image callees "
"are already verified: 0xe8ac/0xe8cc build the white colour block via afp_color_init_white "
"(0xa60c); 0xe7b8/0xe7e0 set 4x4 identity via afp_matrix44_identity (0xc1f0); 0xe840/0xe868 "
"set 2x3 identity via afp_matrix_identity (0xae48); 0xe788 recomputes the focal term via "
"afp_proj_focal_from_fov (0xe064); 0xe024 delegates to 0xe788 and 0xe008 to 0xe024. The only "
"read global is the read-only .data float const 0xec09c (value 2.0f, the 0xe024 projection "
"divisor), read from the oracle image and baked byte-identically as g_const_ec09c. The "
"0xe76c/0xe7a4/0xe934/0xe8ac/0xe8cc/0xe7b8/0xe7e0/0xe840/0xe868 leaves zero their buffer "
"through the LIBAVS-WIN32 ordinal-232 memset import (IAT slot 0xe41d8), modelled by an "
"IAT-redirected stub with the exact memset ABI; every buffer lives in seeded scratch and is "
"compared by output bytes, never a raw heap pointer, so results are image-base independent.")
WAVE11_FPMODEL = (
"WAVE11 FP-MODEL: only 0xe024 is x87 (two FDIVs of the field-of-view by the const 0xec09c = "
"2.0f); recon built -mfpmath=387 -ffp-contract=off -fno-fast-math, each quotient kept in "
"80-bit long double and rounded only at the float32 store (obj[+0xc]/[+0x10]). The focal term "
"written by the chained afp_proj_focal_from_fov (0xe064) uses x87 FSIN/FCOS, modelled in "
"double by the emulator and mirrored by the verified reconstruction. 0xe788 stores the extent "
"words as raw dwords and the remaining leaves move bytes bit-exactly.")
def _wave11_diff_steps():
return [
prove_obj_zero_1c, prove_obj_zero_28, prove_obj_zero_60, prove_color_zero_init,
prove_color_zero_init_wrap, prove_matrix44_finish,
prove_matrix44_init, prove_matrix_finish, prove_matrix_init, prove_proj_set_extent,
prove_proj_init_fov, prove_proj_init_default,
]
def _run_wave11_selected(image: PeImage, log: list[str], tokens: list[str]) -> int:
log.append(WAVE11_GLOBALS)
log.append(WAVE11_FPMODEL)
steps = _wave11_diff_steps()
by_name = {fn.__name__[len("prove_"):]: fn for fn in steps}
for tok in tokens:
if tok == "diffA":
for fn in steps[:6]:
fn(image, log)
elif tok == "diffB":
for fn in steps[6:]:
fn(image, log)
elif tok == "diff":
for fn in steps:
fn(image, log)
elif tok in by_name:
by_name[tok](image, log)
elif tok == "injectA":
prove_injected_bugs_wave11(image, log, range(0, 6))
elif tok == "injectB":
prove_injected_bugs_wave11(image, log, range(6, len(WAVE11_INJECTIONS)))
elif tok == "inject":
prove_injected_bugs_wave11(image, log, range(len(WAVE11_INJECTIONS)))
elif tok.startswith("inject:"):
prove_injected_bugs_wave11(image, log, [int(x) for x in tok.split(":", 1)[1].split(",")])
else:
print(f"unknown selector {tok}", file=sys.stderr)
return 2
print("\n".join(log))
return 0
def main() -> int:
import shutil
oracle = resolve_oracle("libafp-win32.dll")
@@ -3267,6 +3517,8 @@ def main() -> int:
log = [f"DLL={oracle.path} base={image.image_base:#x} program=libafp-win32.dll "
f"sha256={oracle.sha256[:12]}"]
tokens = sys.argv[1:]
if tokens and tokens[0] == "w11":
return _run_wave11_selected(image, log, tokens[1:])
if tokens and tokens[0] == "w9":
return _run_wave9_selected(image, log, tokens[1:])
if tokens and tokens[0] == "w8":
@@ -3445,6 +3697,13 @@ def main() -> int:
for _fn in _wave9_diff_steps():
_fn(image, log)
prove_injected_bugs_wave9(image, log, range(len(WAVE9_INJECTIONS)))
# --- wave 11 ---
log.append(WAVE11_GLOBALS)
log.append(WAVE11_FPMODEL)
for _fn in _wave11_diff_steps():
_fn(image, log)
prove_injected_bugs_wave11(image, log, range(len(WAVE11_INJECTIONS)))
log.append("ALL DIFFERENTIALS PASS")
print("\n".join(log))
return 0
@@ -1214,6 +1214,117 @@ int RunZero0x1c(const std::vector<std::uint8_t> &in) {
return 0;
}
int RunObjZero0x1cGuarded(const std::vector<std::uint8_t> &in) {
if (in.empty()) {
gk::afp::afp_obj_zero_0x1c_guarded(nullptr);
PutHex(nullptr, 0);
return 0;
}
std::uint8_t obj[0x1c];
std::memcpy(obj, in.data(), sizeof(obj));
gk::afp::afp_obj_zero_0x1c_guarded(obj);
PutHex(obj, sizeof(obj));
return 0;
}
int RunObjZero0x28(const std::vector<std::uint8_t> &in) {
std::uint8_t obj[0x28];
std::memcpy(obj, in.data(), sizeof(obj));
gk::afp::afp_obj_zero_0x28(obj);
PutHex(obj, sizeof(obj));
return 0;
}
int RunObjZero0x60(const std::vector<std::uint8_t> &in) {
std::uint8_t obj[0x60];
std::memcpy(obj, in.data(), sizeof(obj));
gk::afp::afp_obj_zero_0x60(obj);
PutHex(obj, sizeof(obj));
return 0;
}
int RunColorZeroInit(const std::vector<std::uint8_t> &in) {
std::uint8_t obj[0x20];
std::memcpy(obj, in.data(), sizeof(obj));
gk::afp::afp_color_zero_init(obj);
PutHex(obj, sizeof(obj));
return 0;
}
int RunColorZeroInitWrap(const std::vector<std::uint8_t> &in) {
std::uint8_t obj[0x20];
std::memcpy(obj, in.data(), sizeof(obj));
gk::afp::afp_color_zero_init_wrap(obj);
PutHex(obj, sizeof(obj));
return 0;
}
int RunMatrix44Finish(const std::vector<std::uint8_t> &in) {
if (in.empty()) {
gk::afp::afp_matrix44_finish(nullptr);
PutHex(nullptr, 0);
return 0;
}
std::uint8_t out[0x40];
std::memcpy(out, in.data(), sizeof(out));
gk::afp::afp_matrix44_finish(out);
PutHex(out, sizeof(out));
return 0;
}
int RunMatrix44InitBuf(const std::vector<std::uint8_t> &in) {
std::uint8_t out[0x40];
std::memcpy(out, in.data(), sizeof(out));
gk::afp::afp_matrix44_init(out);
PutHex(out, sizeof(out));
return 0;
}
int RunMatrixFinish(const std::vector<std::uint8_t> &in) {
if (in.empty()) {
gk::afp::afp_matrix_finish(nullptr);
PutHex(nullptr, 0);
return 0;
}
std::uint8_t out[0x18];
std::memcpy(out, in.data(), sizeof(out));
gk::afp::afp_matrix_finish(out);
PutHex(out, sizeof(out));
return 0;
}
int RunMatrixInitBuf(const std::vector<std::uint8_t> &in) {
std::uint8_t out[0x18];
std::memcpy(out, in.data(), sizeof(out));
gk::afp::afp_matrix_init(out);
PutHex(out, sizeof(out));
return 0;
}
int RunProjSetExtent(const std::vector<std::uint8_t> &in) {
std::uint8_t obj[0x20];
std::memcpy(obj, in.data(), sizeof(obj));
gk::afp::afp_proj_set_extent(obj, Word(in, 0x20), Word(in, 0x24));
PutHex(obj, sizeof(obj));
return 0;
}
int RunProjInitFov(const std::vector<std::uint8_t> &in) {
std::uint8_t obj[0x20];
std::memcpy(obj, in.data(), sizeof(obj));
gk::afp::afp_proj_init_fov(obj, Flt(in, 0x20), Flt(in, 0x24));
PutHex(obj, sizeof(obj));
return 0;
}
int RunProjInitDefault(const std::vector<std::uint8_t> &in) {
std::uint8_t obj[0x20];
std::memcpy(obj, in.data(), sizeof(obj));
gk::afp::afp_proj_init_default(obj);
PutHex(obj, sizeof(obj));
return 0;
}
}
int main(int argc, char **argv) {
@@ -1223,6 +1334,18 @@ int main(int argc, char **argv) {
}
const std::vector<std::uint8_t> in = ReadHex();
const std::string mode = argv[1];
if (mode == "obj_zero_0x1c_guarded") return RunObjZero0x1cGuarded(in);
if (mode == "obj_zero_0x28") return RunObjZero0x28(in);
if (mode == "obj_zero_0x60") return RunObjZero0x60(in);
if (mode == "color_zero_init") return RunColorZeroInit(in);
if (mode == "color_zero_init_wrap") return RunColorZeroInitWrap(in);
if (mode == "matrix44_finish") return RunMatrix44Finish(in);
if (mode == "matrix44_init") return RunMatrix44InitBuf(in);
if (mode == "matrix_finish") return RunMatrixFinish(in);
if (mode == "matrix_init") return RunMatrixInitBuf(in);
if (mode == "proj_set_extent") return RunProjSetExtent(in);
if (mode == "proj_init_fov") return RunProjInitFov(in);
if (mode == "proj_init_default") return RunProjInitDefault(in);
if (mode == "group_check_tag") return RunGroupCheckTag(in);
if (mode == "flag_800") return RunFlag800(in);
if (mode == "flag_20") return RunFlag20(in);
+16
View File
@@ -50,6 +50,7 @@ extern const float g_const_ec008;
extern const float g_const_ec00c;
extern const float g_const_ec010;
extern const float g_const_ec09c;
extern const float g_const_ec0a4;
extern const float g_const_ec0a8;
extern const float g_const_ec0ac;
@@ -234,5 +235,20 @@ std::uint32_t GK_CDECL afp_zero_dword(std::uint8_t *obj);
std::uint32_t GK_CDECL afp_copy_7dword(std::uint32_t *out, const std::uint32_t *src);
std::uint32_t GK_CDECL afp_zero_0x1c(std::uint8_t *obj);
// wave-11 object / matrix init-finish and projection-init leaves
std::uint32_t GK_CDECL afp_obj_zero_0x1c_guarded(std::uint8_t *obj);
std::uint32_t GK_CDECL afp_obj_zero_0x28(std::uint8_t *obj);
std::uint32_t GK_CDECL afp_obj_zero_0x60(std::uint8_t *obj);
std::uint32_t GK_CDECL afp_color_zero_init(std::uint8_t *obj);
void GK_CDECL afp_color_zero_init_wrap(std::uint8_t *obj);
std::uint32_t GK_CDECL afp_matrix44_finish(std::uint8_t *out);
std::uint32_t GK_CDECL afp_matrix44_init(std::uint8_t *out);
std::uint32_t GK_CDECL afp_matrix_finish(std::uint8_t *out);
std::uint32_t GK_CDECL afp_matrix_init(std::uint8_t *out);
std::uint32_t GK_CDECL afp_proj_set_extent(std::uint8_t *obj, std::uint32_t extent_bits,
std::uint32_t field1c_bits);
std::uint32_t GK_CDECL afp_proj_init_fov(std::uint8_t *obj, float fov_h, float fov_v);
std::uint32_t GK_CDECL afp_proj_init_default(std::uint8_t *obj);
}
}
+162
View File
@@ -0,0 +1,162 @@
#include "afp.h"
#include <cstring>
// libafp-win32 wave-11 object/matrix init-finish and projection-init leaves
// (sharder shard 0 of the remaining orig functions). Every function here either
// zeroes an owned flat buffer through the LIBAVS-WIN32 ordinal-232 memset import
// (IAT slot 0xe41d8, modelled by an IAT stub in the differential) and/or
// delegates to a verified intra-image leaf:
//
// 0xe76c afp_obj_zero_0x1c_guarded -> memset(0x1c) when non-null
// 0xe7a4 afp_obj_zero_0x28 -> memset(0x28)
// 0xe934 afp_obj_zero_0x60 -> memset(0x60)
// 0xe8ac afp_color_zero_init -> memset(0x20) + afp_color_init_white (0xa60c)
// 0xe8cc afp_color_zero_init_wrap -> afp_color_zero_init (0xe8ac)
// 0xe7b8 afp_matrix44_finish -> memset(0x40) + afp_matrix44_identity (0xc1f0)
// 0xe7e0 afp_matrix44_init -> memset(0x40) + afp_matrix44_identity (0xc1f0)
// 0xe840 afp_matrix_finish -> memset(0x18) + afp_matrix_identity (0xae48)
// 0xe868 afp_matrix_init -> memset(0x18) + afp_matrix_identity (0xae48)
// 0xe788 afp_proj_set_extent -> writes obj[+0x18]/[+0x1c] + afp_proj_focal_from_fov
// 0xe024 afp_proj_init_fov -> x87 obj[+0xc]/[+0x10] = fov / 2.0 + afp_proj_set_extent
// 0xe008 afp_proj_init_default -> afp_proj_init_fov(obj, 500.0f, 500.0f)
//
// FP-MODEL: only 0xe024 is x87 (two FDIVs by the read-only .data const 0xec09c,
// value 2.0f, baked byte-identically as g_const_ec09c). Recon built
// -mfpmath=387 -ffp-contract=off -fno-fast-math; the quotient is kept in 80-bit
// long double and rounded only at the float32 store. The other leaves move
// bytes/dwords bit-exactly. The matrix/color/projection callees are the already
// verified intra-image reconstructions, so the differential runs them natively
// inside Unicorn while the recon calls their reconstructions.
namespace gk {
namespace afp {
namespace {
using ld = long double;
} // namespace
// rva=0x1000e76c (orig FUN_1000e76c)
// Zero 0x1c bytes (ordinal-232 memset) when the pointer is non-null; a null
// pointer returns without touching memory.
std::uint32_t GK_CDECL afp_obj_zero_0x1c_guarded(std::uint8_t *obj) {
if (obj != nullptr) {
std::memset(obj, 0, 0x1c);
}
return 0;
}
// rva=0x1000e7a4 (orig FUN_1000e7a4)
// Zero 0x28 bytes (ordinal-232 memset).
std::uint32_t GK_CDECL afp_obj_zero_0x28(std::uint8_t *obj) {
std::memset(obj, 0, 0x28);
return 0;
}
// rva=0x1000e934 (orig FUN_1000e934)
// Zero 0x60 bytes (ordinal-232 memset).
std::uint32_t GK_CDECL afp_obj_zero_0x60(std::uint8_t *obj) {
std::memset(obj, 0, 0x60);
return 0;
}
// rva=0x1000e8ac (orig FUN_1000e8ac)
// Zero 0x20 bytes (ordinal-232 memset) then build the white colour block through
// the verified afp_color_init_white (0xa60c).
std::uint32_t GK_CDECL afp_color_zero_init(std::uint8_t *obj) {
std::memset(obj, 0, 0x20);
afp_color_init_white(reinterpret_cast<std::uint32_t *>(obj));
return 0;
}
// rva=0x1000e8cc (orig FUN_1000e8cc)
// Thin wrapper delegating to afp_color_zero_init (0xe8ac).
void GK_CDECL afp_color_zero_init_wrap(std::uint8_t *obj) {
afp_color_zero_init(obj);
}
// rva=0x1000e7b8 (orig afp_matrix44_finish)
// Zero the 0x40-byte 4x4 matrix (ordinal-232 memset) when non-null then set it to
// identity through the verified afp_matrix44_identity (0xc1f0).
std::uint32_t GK_CDECL afp_matrix44_finish(std::uint8_t *out) {
if (out == nullptr) {
return 0;
}
std::memset(out, 0, 0x40);
afp_matrix44_identity(reinterpret_cast<std::uint32_t *>(out));
return 0;
}
// rva=0x1000e7e0 (orig afp_matrix44_init)
// Same as afp_matrix44_finish: zero 0x40 bytes and set identity when non-null.
std::uint32_t GK_CDECL afp_matrix44_init(std::uint8_t *out) {
if (out != nullptr) {
std::memset(out, 0, 0x40);
afp_matrix44_identity(reinterpret_cast<std::uint32_t *>(out));
}
return 0;
}
// rva=0x1000e840 (orig afp_matrix_finish)
// Zero the 0x18-byte 2x3 matrix (ordinal-232 memset) when non-null then set it to
// identity through the verified afp_matrix_identity (0xae48).
std::uint32_t GK_CDECL afp_matrix_finish(std::uint8_t *out) {
if (out == nullptr) {
return 0;
}
std::memset(out, 0, 0x18);
afp_matrix_identity(reinterpret_cast<std::uint32_t *>(out));
return 0;
}
// rva=0x1000e868 (orig afp_matrix_init)
// Same as afp_matrix_finish: zero 0x18 bytes and set identity when non-null.
std::uint32_t GK_CDECL afp_matrix_init(std::uint8_t *out) {
if (out != nullptr) {
std::memset(out, 0, 0x18);
afp_matrix_identity(reinterpret_cast<std::uint32_t *>(out));
}
return 0;
}
// rva=0x1000e788 (orig FUN_1000e788)
// Store the projection extent words at obj[+0x18]/[+0x1c] (raw dwords) then
// recompute the focal term through the verified afp_proj_focal_from_fov (0xe064).
std::uint32_t GK_CDECL afp_proj_set_extent(std::uint8_t *obj, std::uint32_t extent_bits,
std::uint32_t field1c_bits) {
std::memcpy(obj + 0x18, &extent_bits, 4);
std::memcpy(obj + 0x1c, &field1c_bits, 4);
afp_proj_focal_from_fov(obj);
return 0;
}
// rva=0x1000e024 (orig FUN_1000e024)
// Projection init: obj[+0xc] = fov_h / 2.0, obj[+0x10] = fov_v / 2.0 (x87 FDIV by
// const 0xec09c, kept in 80-bit long double and rounded at the float32 store),
// obj[+4] = raw 0x3f75be0b, then afp_proj_set_extent(obj, fov_h, fov_v).
std::uint32_t GK_CDECL afp_proj_init_fov(std::uint8_t *obj, float fov_h, float fov_v) {
const float half_h =
static_cast<float>(static_cast<ld>(fov_h) / static_cast<ld>(g_const_ec09c));
const float half_v =
static_cast<float>(static_cast<ld>(fov_v) / static_cast<ld>(g_const_ec09c));
std::memcpy(obj + 0xc, &half_h, 4);
std::memcpy(obj + 0x10, &half_v, 4);
const std::uint32_t field4 = 0x3f75be0bu;
std::memcpy(obj + 4, &field4, 4);
std::uint32_t h_bits;
std::uint32_t v_bits;
std::memcpy(&h_bits, &fov_h, 4);
std::memcpy(&v_bits, &fov_v, 4);
afp_proj_set_extent(obj, h_bits, v_bits);
return 0;
}
// rva=0x1000e008 (orig FUN_1000e008)
// Projection init with the default 500.0f / 500.0f field of view.
std::uint32_t GK_CDECL afp_proj_init_default(std::uint8_t *obj) {
afp_proj_init_fov(obj, 500.0f, 500.0f);
return 0;
}
} // namespace afp
} // namespace gk
+4
View File
@@ -53,6 +53,10 @@ const float g_const_ec008 = std::bit_cast<float>(0x3F800000u); // 1.0f
const float g_const_ec00c = std::bit_cast<float>(0x00000000u); // 0.0f
const float g_const_ec010 = std::bit_cast<float>(0x33D6BF95u); // 1e-7f
// wave-11 projection init divisor (0xe024), read byte-identically from the
// oracle .data at this RVA.
const float g_const_ec09c = std::bit_cast<float>(0x40000000u); // 2.0f
// wave-9 projection accessor constants (0xe064 / 0xe0b0), read byte-identically
// from the oracle .data at these RVAs.
const float g_const_ec0a4 = std::bit_cast<float>(0x00000000u); // 0.0f