#!/usr/bin/env python3 """Find every GPIO-base literal load in the RT-4D app and show the surrounding code, so each (port, register-offset, bit-mask) access can be identified.""" import struct, re, sys, 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", 0x40021800: "GPIOG", 0x40021C00: "GPIOH"} def word(va): o = va - BASE return struct.unpack_from(" 1 else None main(only=only)