287
|
1 #!/usr/bin/env python
|
283
|
2
|
|
3 import argparse
|
|
4
|
287
|
5 __doc__ = """
|
283
|
6 ISO 9660 filesystem utility.
|
|
7 """
|
|
8
|
287
|
9
|
|
10 class VolumeDescriptor:
|
|
11 @classmethod
|
|
12 def FromData(cls, d):
|
|
13 ty = d[0]
|
|
14 Id = d[1:6]
|
|
15 assert Id == 'CD001'.encode('ascii')
|
|
16 ver = d[6]
|
|
17 assert ver == 1
|
|
18 cls = vol_desc_types[ty]
|
|
19 return cls(d)
|
|
20
|
283
|
21
|
287
|
22 vol_desc_types = {}
|
|
23 def vol_type(t):
|
|
24 def reg_func(cls):
|
|
25 vol_desc_types[t] = cls
|
|
26 return cls
|
|
27 return reg_func
|
|
28
|
|
29
|
|
30 @vol_type(0)
|
|
31 class BootRecordVolumeDescriptor(VolumeDescriptor):
|
|
32 def __init__(self, d):
|
|
33 boot_sys_id = d[7:39]
|
|
34 boot_id = d[39:71]
|
|
35 print(boot_sys_id)
|
|
36 print(boot_id)
|
|
37
|
283
|
38
|
287
|
39 @vol_type(1)
|
|
40 class PrimaryVolumeDescriptor(VolumeDescriptor):
|
|
41 def __init__(self, d):
|
|
42 sys_id = d[8:40]
|
|
43 vol_id = d[40:72]
|
|
44 print(sys_id)
|
|
45 print(vol_id)
|
|
46
|
|
47
|
|
48 @vol_type(255)
|
|
49 class VolumeDescriptorTerminator(VolumeDescriptor):
|
|
50 def __init__(self, d):
|
|
51 pass
|
|
52
|
283
|
53
|
287
|
54 class ISOfs:
|
|
55 def __init__(self):
|
|
56 self.vol_descriptors = []
|
|
57
|
|
58 def read(self, f):
|
|
59 # System area:
|
|
60 self.system_area = f.read(16 * 2048)
|
|
61 while True:
|
|
62 d = f.read(2048)
|
|
63 desc = VolumeDescriptor.FromData(d)
|
|
64 self.vol_descriptors.append(desc)
|
|
65 if type(desc) is VolumeDescriptorTerminator:
|
|
66 break
|
|
67
|
|
68 def dump(self):
|
|
69 for vd in self.vol_descriptors:
|
|
70 print(vd)
|
283
|
71
|
|
72
|
|
73 if __name__ == '__main__':
|
287
|
74 parser = argparse.ArgumentParser(description=__doc__)
|
|
75 parser.add_argument('filename')
|
|
76 args = parser.parse_args()
|
|
77 fs = ISOfs()
|
|
78 with open(args.filename, 'rb') as f:
|
|
79 fs.read(f)
|
|
80 fs.dump()
|
283
|
81
|
|
82
|