-
Notifications
You must be signed in to change notification settings - Fork 1
/
findgspinterrupt.py
47 lines (37 loc) · 1.13 KB
/
findgspinterrupt.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
#!/usr/bin/env python2
from common.constants import *
import sys
import struct
def is_valid_va(address):
return 0 <= (address - 0x00100000) < APPMEMALLOC
def findinterrupttable(file):
pos = file.tell()
data = file.read(0x90)
if data[-16:] != b'\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00':
file.seek(pos)
return False
# Now, that should be a table
data = file.read(4 * 6)
if len(data) != 4 * 6:
file.seek(pos)
return False
addresses = struct.unpack('<6I', data)
for address in addresses:
if not is_valid_va(address):
file.seek(pos)
return False
file.seek(pos)
return True
def main(path):
with open(path, 'rb') as file:
file.seek(0, 2)
file_size = file.tell()
file.seek(0)
while True:
if findinterrupttable(file):
candidate = file.tell()
print('Offset in file: %#08x' % candidate)
print('Address in RAM: %#08x' % (DUMPEND - file_size + candidate))
if len(file.read(4)) < 4:
break
main(*sys.argv[1:])