summaryrefslogtreecommitdiff
path: root/tools/find_bootsect.py
blob: f52e9102fc2ab1235958c7c12715c7bff165400f (plain)
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
#!/usr/bin/env python
import os, logging, binascii

disk_count = 15
disk_order = [ 0,1,2,4,5,6,7,8,9,10,11,12,13,14,15 ]
disk_paths = [ 'disk%02i.img'%d for d in disk_order ]
disks      = [ None for d in range(disk_count) ]
disks_size = [ 0 for d in range(disk_count) ]

for d in range(disk_count):
    path = disk_paths[d]
    logging.debug("Try to open disk #%2d"%d)
    try:
	disks[d] = open(path, "r")
	disks_size[d] = os.lstat(path).st_size
	logging.debug("Opened disk #%2d"%d)
    except IOError as e:
	logging.error("Can't open disk #%2d ('%s') : %s"%(d, path, e.strerror))
	disks_size[d] = 0
    except:
	logging.error("Can't open disk #%2d ('%s') : unhandled exception"%(d, path))
	disks_size[d] = 0
logging.debug("Exit. open_disks()")

ref_sig = binascii.unhexlify('55AA')

for offset in range(0, min(disks_size), 512):
    for disk_no in range(disk_count):
	disks[disk_no].seek(offset)
	data = disks[disk_no].read(512)
	sig = data[510:]
	if sig == ref_sig:
	    print "%s@%x:%s"%(disk_paths[disk_no],offset,binascii.hexlify(sig))