Files

25 lines
559 B
Python

#!/usr/bin/env python3
"""Find 32-bit constants whose target byte offset falls in [lo,hi).
Usage: near_refs.py IMAGE lo hi
"""
import struct
import sys
ROM_BASE = 0x07E40000
def main():
image = open(sys.argv[1], "rb").read()
lo = int(sys.argv[2], 0)
hi = int(sys.argv[3], 0)
for off in range(0, len(image) - 3):
v = struct.unpack_from("<I", image, off)[0]
tgt = (v >> 3) - ROM_BASE
if lo <= tgt < hi:
print(f"const@0x{off:06X} = 0x{v:08X} -> target 0x{tgt:06X}")
if __name__ == "__main__":
main()