forked from c-jo/adfs-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_loader.py
executable file
·42 lines (27 loc) · 762 Bytes
/
get_loader.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
#! /usr/bin/python
import sys
import struct
SECSIZE = 512
if len(sys.argv) != 3:
print("Usage: get_loader <device> <loader file>")
exit(1)
fd = open(sys.argv[1], "rb")
fd.seek(0, 0)
part_table = fd.read(512)
p1 = part_table[0x1be:0x1be+16]
p2 = part_table[0x1ce:0x1ce+16]
p3 = part_table[0x1de:0x1de+16]
p4 = part_table[0x1ee:0x1ee+16]
p1_data = struct.unpack("BBBBBBBBII",p1)
start_sec = p1_data[8]
length_sec = p1_data[9]
start = start_sec * SECSIZE
length = length_sec * SECSIZE
print "Loader starts at sector {0} and is {1} sector ({2} bytes) long.".format(start_sec,length_sec,length)
fd.seek(start)
data = fd.read(length)
fd.close()
print "Saving 'Loader' file to",sys.argv[2]
fd = open(sys.argv[2],"wb")
fd.write(data)
fd.close()