-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdrop.py
54 lines (44 loc) · 1.33 KB
/
drop.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#
#
# OpenOCD library: https://github.com/screwer/OpenOCD
#
# change line 193
# if not self.Name:
#
# to run: python2 drop.py
#
from OpenOCD import OpenOCD
ocd = OpenOCD()
ocd.Reset(Halt=True)
pc = ocd.Reg('pc')
reg = []
# create r0 through r12 register objects to read
for i in range(0,13):
reg.append(ocd.Reg("r%d" % i))
# Read() returns a number
pc_reset_val = pc.Read()
# run first 10 instructions trying to find a suitable instruction
for run in range(10):
# loop over all registers, calling Write(4) to set all registers to a value of 4
for i in range(len(reg)):
reg[i].Write(4)
print("Step %d, [pc:0x%08X]" % (run, pc.Read()))
ocd.Step()
for i in range(len(reg)):
reg_val = reg[i].Read()
if not reg_val:
print("reg[%d]"%i, "is None")
continue
print("reg_val:", reg_val)
print("pc_reset_val:", pc_reset_val)
if abs(reg_val - pc_reset_val) < 2:
print("found possible instruction at 0x%08X" % (pc.Read()))
print("r%d = 0x%08X, pc = 0x%08X" % (i, reg_val, pc_reset_val))
break
########## GOODIES ########################
# found possible instruction at 0x000006D6
# r4 = 0x000006D1, pc = 0x000006D0
#
# found possible instruction at 0x000006DE
# r3 = 0x000006D1, pc = 0x000006D0
###########################################