Skip to content

Commit c09df0a

Browse files
committed
fix(re): drop dead movw/movt scaffolding in xref.py (ruff F841)
The unused imm4i() helper computed i/imm4/imm8 then returned None; the real movw/movt decode is inline below it. Removed so ruff F841 passes CI. Assisted-by: AI
1 parent ee40737 commit c09df0a

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

reverse-engineering/tools/xref.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
99
Usage: xref.py <binfile> <base> <target_hex>
1010
"""
11+
1112
import sys
1213

14+
1315
def main():
1416
path, base, target = sys.argv[1], int(sys.argv[2], 16), int(sys.argv[3], 16)
1517
data = open(path, "rb").read()
@@ -28,28 +30,25 @@ def main():
2830
# literal pool entry address = base + i ; scan backwards up to 1024+4 bytes
2931
refs = []
3032
for j in range(max(0, i - 1050), i, 2):
31-
hw = int.from_bytes(data[j:j+2], "little")
33+
hw = int.from_bytes(data[j : j + 2], "little")
3234
# LDR Rt,[PC,#imm] T1: 01001tttiiiiiiii ; addr = (pc&~3)+imm*4, pc=j+4
3335
if (hw & 0xF800) == 0x4800:
3436
imm = hw & 0xFF
3537
addr = ((base + j + 4) & ~3) + imm * 4
3638
if addr == base + i:
3739
refs.append(j)
38-
print(f" pool @ file 0x{i:06x} xip 0x{base+i:08x} ldr-refs: "
39-
+ ", ".join(f"file 0x{r:06x} / 0x{base+r:08x}" for r in refs))
40+
print(
41+
f" pool @ file 0x{i:06x} xip 0x{base + i:08x} ldr-refs: "
42+
+ ", ".join(f"file 0x{r:06x} / 0x{base + r:08x}" for r in refs)
43+
)
4044
# movw/movt search
4145
lo = target & 0xFFFF
4246
hi = target >> 16
43-
def imm4i(hw):
44-
i = (hw >> 10) & 1
45-
imm4 = hw & 0xF
46-
imm8 = (hw >> 16) & 0xFF if False else None
47-
return None
4847
movts = {}
4948
movws = {}
5049
for j in range(0, len(data) - 4, 2):
51-
h1 = int.from_bytes(data[j:j+2], "little")
52-
h2 = int.from_bytes(data[j+2:j+4], "little")
50+
h1 = int.from_bytes(data[j : j + 2], "little")
51+
h2 = int.from_bytes(data[j + 2 : j + 4], "little")
5352
# MOVW: 11110 i 100100 imm4 | 0 imm3 Rd imm8 => 0xF240 pattern
5453
# MOVT: 11110 i 101100 imm4 | 0 imm3 Rd imm8 => 0xF2C0
5554
if (h1 & 0xFBF0) in (0xF240, 0xF2C0):
@@ -67,7 +66,10 @@ def imm4i(hw):
6766
for tj in movts.get(rd, []):
6867
for wj in locs:
6968
if 0 < tj - wj <= 24:
70-
print(f" movw/movt r{rd} @ file 0x{wj:06x} / xip 0x{base+wj:08x}")
69+
print(
70+
f" movw/movt r{rd} @ file 0x{wj:06x} / xip 0x{base + wj:08x}"
71+
)
72+
7173

7274
if __name__ == "__main__":
7375
main()

0 commit comments

Comments
 (0)