mirror of
https://github.com/sp00nznet/xboxrecomp.git
synced 2026-12-06 02:22:30 +00:00
0c3a00bbd4
Adds map_pairs()/host_of() to FusionModule and lifter_diff.py, which disassembles Microsoft's recompiled host x86-64 for a named function and rewrites it back into guest terms using their documented register model ([greg+r15+d] -> guest [greg+d], r14=esp, r15=RAM base). Validated: the dump of _SetEvent@4 matches the single-title report's hand-analysis exactly. The automated lifter-diff I planned is NOT achievable and I'm not shipping a tool that pretends otherwise: a clean diff needs both sides to lift the identical guest bytes, which needs Microsoft's exact source XBE. The BC package XBE is a subtly different build from a retail-disc XBE -- Crimson's guest 0x1C448A is a thunk in the disc build we recompile but an inlined body in Microsoft's -- so an address-matched offset diff conflates build differences with lifter bugs. `diff` is therefore a labelled side-by-side reading aid, not an oracle. What ships is the validated part: a reference dumper for studying how Microsoft handled a given function (the hard x87/flags/SEH cases), which is how the codegen teardown used it manually. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
"""The guest-term rewrite of Microsoft's host operands is the load-bearing logic:
|
|
[greg + r15 + disp] must read as guest [greg + disp], [r15 + disp] as a guest
|
|
global, and emulator-scratch accesses (rbx/r12/r13 state blocks) must NOT be
|
|
reported as guest memory."""
|
|
from capstone import Cs, CS_ARCH_X86, CS_MODE_64
|
|
from capstone.x86 import X86_OP_MEM
|
|
|
|
from tools.fusion import lifter_diff
|
|
|
|
_md = Cs(CS_ARCH_X86, CS_MODE_64)
|
|
_md.detail = True
|
|
|
|
|
|
def _one(code):
|
|
insn = next(_md.disasm(code, 0x1000))
|
|
for op in insn.operands:
|
|
if op.type == X86_OP_MEM:
|
|
return lifter_diff._guest_mem(insn, op)
|
|
return insn.op_str, None
|
|
|
|
|
|
def test_guest_field_access():
|
|
# mov ebp, [rsi + r15 + 0x18] -> guest [esi+0x18], offset 0x18
|
|
txt, off = _one(b"\x42\x8B\x6C\x3E\x18")
|
|
assert off == 0x18 and "guest mem" in txt and "esi" in txt
|
|
|
|
|
|
def test_guest_global_access():
|
|
# mov ebp, [r15 + 0x32dd8c] -> guest global, offset 0x32dd8c
|
|
txt, off = _one(b"\x41\x8B\xAF\x8C\xDD\x32\x00")
|
|
assert off == 0x32dd8c and "guest global" in txt
|
|
|
|
|
|
def test_emulator_scratch_not_guest():
|
|
# movzx ecx, byte [r12 - 0x3c] -> emulator state block, NOT guest memory
|
|
txt, off = _one(b"\x41\x0F\xB6\x4C\x24\xC4")
|
|
assert off is None
|
|
|
|
|
|
if __name__ == "__main__":
|
|
for k, v in sorted(globals().items()):
|
|
if k.startswith("test_"):
|
|
v(); print("ok", k)
|