-
Notifications
You must be signed in to change notification settings - Fork 2
/
rkos.py
92 lines (61 loc) · 1.81 KB
/
rkos.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/python
import sys, struct, os
## THIS FILE IS INTELLECTUAL PROPERTY OF B1N4R1 B01.
## REVIEW CONTACT OPTIONS IN THE README.
## THE MIT LICENSE OF THE PROJECT DOES NOT APPLY TO
## THIS FILE UNLESS LICENSED IN SUCH MANNER BY THE
## AUTHOR.
if __name__ == '__main__':
myint = 4
real_offset = 48
if len(sys.argv) != 2:
print 'Usage: {} Firmware.bin'.format(sys.argv[0])
sys.exit(1)
in_file = sys.argv[1]
fp = open(in_file,'rb')
fp.seek(32)
file_magic = fp.read(8)
if file_magic != "rkosftab":
print "Firmware Invalid :("
sys.exit(1)
os.system('mkdir extracted')
print "Extracting Firmware Blobs To Folder 'extracted'"
fp.seek(16)
le = fp.read(myint)
tick_offset = struct.unpack('<i',le)[0]
print tick_offset
fp.seek(20)
le = fp.read(myint)
tick_size = struct.unpack('<i',le)[0]
print tick_size
if tick_size != 0:
out_file = 'ticket'
dump = 'dd if={} of=extracted/{} skip={} count={} bs=1 >/dev/null 2>&1'.format(in_file,out_file,tick_offset,tick_size)
os.system(dump)
print "Ticket Dumped"
fp.seek(real_offset)
tag = fp.read(4)
fp.seek(real_offset+myint)
le = fp.read(myint)
tagoff = struct.unpack('<i',le)[0]
fp.seek(real_offset+(myint*2))
le = fp.read(myint)
tagsz = struct.unpack('<i',le)[0]
ftagoff = tagoff
while real_offset < ftagoff:
statement = "Tag:{} Offset:{} Size:{}".format(tag,hex(tagoff),hex(tagsz))
print statement
dump = 'dd if={} of=extracted/{} skip={} count={} bs=1 >/dev/null 2>&1'.format(in_file,tag,tagoff,tagsz)
os.system(dump)
real_offset = real_offset + 16
fp.seek(real_offset)
tag = fp.read(4)
fp.seek(real_offset+myint)
le = fp.read(myint)
tagoff = struct.unpack('<i',le)[0]
fp.seek(real_offset+(myint*2))
le = fp.read(myint)
tagsz = struct.unpack('<i',le)[0]
if real_offset == ftagoff:
fp.close()
break