forked from c-jo/adfs-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
claim_frags.py
executable file
·70 lines (47 loc) · 1.68 KB
/
claim_frags.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
#! /usr/bin/python
import sys
from objects import Map
from utils import find_map
fd = open("Loader", "r")
fd.seek(0,2)
loader_len = fd.tell()
fd.close()
print "Loader is {0} bytes long.".format(loader_len)
if len(sys.argv) != 2:
print("Usage: claim_frags <device>")
exit(1)
fd = open(sys.argv[1], "r+b")
map_address, map_length = find_map(fd)
fd.seek(map_address)
fs_map = Map(fd.read(map_length))
loader_start = (fs_map.disc_record.idlen+1) * fs_map.disc_record.bpmb
bits_needed = loader_len / fs_map.disc_record.bpmb
start_bit = loader_start / fs_map.disc_record.bpmb
last_bit = start_bit + bits_needed
while start_bit * fs_map.disc_record.bpmb < loader_start:
start_bit += 1
while bits_needed * fs_map.disc_record.bpmb < loader_len:
bits_needed += 1
print "{0} map bits required for loader, from bit {1} to {2}.".format(bits_needed,start_bit,last_bit)
zone = 0
while True:
zone_start, zone_end = fs_map.zone_range(zone)
first_in_zone = zone_start
last_in_zone = zone_end
if zone_start < start_bit:
first_in_zone = start_bit
if last_bit < last_in_zone:
last_in_zone = last_bit
#note = ""
#if first_in_zone > zone_start:
# note = " ** {0} bits not used at start of zone".format(first_in_zone-zone_start)
#if last_in_zone < zone_end:
# note = " ** {0} bits not used at end of zone".format(zone_end-last_in_zone)
#print "Zone {0} - bits {1} to {2}{3}".format(zone,first_in_zone,last_in_zone,note)
#print zone_start
fs_map.allocate(zone, 3, first_in_zone-zone_start, last_in_zone-zone_start)
if zone_end > last_bit:
break
zone += 1
fd.seek(map_address)
fd.write(fs_map.data.tostring())