mirror of
https://git.k-space.ee/arti/vt1200.git
synced 2026-10-31 12:05:05 +02:00
38 lines
878 B
Python
38 lines
878 B
Python
#!/usr/bin/env python3
|
|
"""For each ROM string matching a regex, find 32-bit bit-address refs.
|
|
|
|
Usage: scan_str.py IMAGE REGEX
|
|
"""
|
|
import re
|
|
import struct
|
|
import sys
|
|
|
|
ROM_BASE = 0x07E40000
|
|
|
|
|
|
def main():
|
|
image = open(sys.argv[1], "rb").read()
|
|
pat = re.compile(sys.argv[2])
|
|
# enumerate strings
|
|
strings = []
|
|
for m in re.finditer(rb"[\x20-\x7e]{4,}", image):
|
|
s = m.group().decode("latin1")
|
|
if pat.search(s):
|
|
strings.append((m.start(), s))
|
|
for off, s in strings:
|
|
val = (ROM_BASE + off) << 3
|
|
p = struct.pack("<I", val)
|
|
refs = []
|
|
start = 0
|
|
while True:
|
|
i = image.find(p, start)
|
|
if i < 0:
|
|
break
|
|
refs.append(i)
|
|
start = i + 1
|
|
print(f"0x{off:06X} refs={[hex(r) for r in refs]} {s!r}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|