#!/usr/bin/env python3 """PyGhidra driver: map AIS sections, analyze, decompile checksum targets. Runs with the project venv (has pyghidra): ./venv/bin/python /tmp/opencode/ghidra-lab/pyais.py Env: GHIDRA_INSTALL_DIR + JAVA_HOME must be set (see launch command). Writes /tmp/opencode/ghidra-lab/out/{dis,dec}_.txt Stdlib + pyghidra + jpype only. """ import os import struct import sys UNPACK = "/tmp/ais-unpack" OUT = "/tmp/opencode/ghidra-lab/out" SECT_IMAGE = "/tmp/ais-unpack/ais_sect1_addrC7074800.bin" PROJ_LOC = "/tmp/opencode/ghidra-lab/pyproj" PROJ_NAME = "LofiPy" LANG = "C6000:LE:32:default" ENTRY = "C70A28A0" TARGETS = ["C70A0A60", "C708E4E4", "C7086400", "C70A28A0", "C707841C"] def parse_ais(path): d = open(path, "rb").read() assert d[:4] == b"TIPA", "bad AIS magic" segs, i, n = [], 4, len(d) entry = None while i + 12 <= n: op = d[i:i + 4] if op == bytes([0x01, 0x59, 0x53, 0x58]): addr, sz = struct.unpack(" " + OUT, flush=True) if __name__ == "__main__": sys.exit(main())