Files
wii-ipl/tools/decomp-assist/export_pyghidra.py
coah f8d83e5ff2 Fork for AI-assisted matching work
Personal fork so AI-assisted decomp work has a home without disturbing
upstream. README explains the fork; AGENTS.md documents the method and
forbids ever opening a PR against koopthekoopa/wii-ipl.

Matching progress: +9 exact functions, 0 regressions, main.dol still
byte-identical (26116613f624061ba99c8d1a299aaa6efa85670d).

iplESMisc gains CheckTmdParentalControl, CheckSafeDeleteTitle,
NumPrivateContents, checkContentsNum and GetValidTicketIndex, plus the
other functions matched in the previous pass.

The load-bearing finding, written up in AGENTS.md: MWCC emits a
translation unit's string literals in source-token order. A missing
function, or an inverted if/else, shifts every later string offset and
breaks functions that were never edited. Fixing that pool ordering lifted
TMDFile::Open from 99.92 to 99.96 without touching Open.

Adds tools/decomp-assist/ with pool_diff.py, ctxdiff.py, disasm_fn.py,
export_pyghidra.py and the Ghidra decompilation dump.
2026-09-19 13:19:34 +00:00

38 lines
1.3 KiB
Python

import os
os.environ.setdefault("GHIDRA_INSTALL_DIR", "/tmp/opencode/ghidra_12.1.3_PUBLIC")
os.environ.setdefault("JAVA_HOME", "/tmp/opencode/jdk")
import pyghidra
pyghidra.start()
from java.io import File
from ghidra.base.project import GhidraProject
from ghidra.app.decompiler import DecompInterface
from ghidra.util.task import ConsoleTaskMonitor
proj = GhidraProject.openProject("/tmp/opencode/gproj", "wii", True)
prog = proj.openProgram("/", "ipl.bin", True)
iface = DecompInterface()
iface.openProgram(prog)
mon = ConsoleTaskMonitor()
addrs = [0x81365C40, 0x81365EDC, 0x81366A2C, 0x81366C7C, 0x81366EE4, 0x813670A0, 0x813671C4, 0x813673E0]
out = open("/tmp/opencode/ghidra_decomp.txt", "w")
for a in addrs:
addr = prog.getAddressFactory().getDefaultAddressSpace().getAddress(a)
fn = prog.getFunctionManager().getFunctionAt(addr)
if fn is None:
fn = prog.getFunctionManager().getFunctionContaining(addr)
if fn is None:
out.write("=== %x NOT FOUND\n\n" % a)
continue
res = iface.decompileFunction(fn, 120, mon)
out.write("=== %s @ %x\n" % (fn.getName(), a))
if res and res.decompileCompleted():
out.write(res.getDecompiledFunction().getC())
else:
out.write("DECOMP FAILED: %s\n" % (res.getErrorMessage() if res else "?"))
out.write("\n\n")
out.close()
print("EXPORT DONE")
proj.close()