#!/usr/bin/env python3 """Exhaustive reference finder for the RT-4D app image. Decodes one instruction at EVERY 2-byte alignment (linear sweep desyncs on Thumb), so nothing is missed. python refs.py addr <0xADDR> [ctx] who pc-relative-loads this address/constant python refs.py gpio full GPIO map: (port, register, mask) per site """ import sys, struct, re, capstone BASE = 0x08002800 IMG = open("/home/viktor/claude/rt-4d/stock-fw/rt4d_stock_v3.25_abs_0x08002800.bin", "rb").read() md = capstone.Cs(capstone.CS_ARCH_ARM, capstone.CS_MODE_THUMB) PORTS = {0x40020000: "GPIOA", 0x40020400: "GPIOB", 0x40020800: "GPIOC", 0x40020C00: "GPIOD", 0x40021000: "GPIOE", 0x40021400: "GPIOF"} # AT32F43x GPIO layout REG = {0x00: "CFGR", 0x10: "IDT", 0x14: "ODT", 0x18: "SCR(set)", 0x1C: "CLR16", 0x28: "CLR(clear)", 0x2C: "TOGR(toggle)"} def word(va): o = va - BASE return struct.unpack_from(" 3 else 8) elif sys.argv[1] == "gpio": cmd_gpio()