-
Notifications
You must be signed in to change notification settings - Fork 7
/
rom.py
44 lines (38 loc) · 1.27 KB
/
rom.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
"""
ROM parser
"""
from cap import CAP
from ichdesc import ICHDesc
from fd import FD
from raw import RAW
class ROM(object):
def __init__(self, data, start=0, prefix=''):
self.start = start
self.prefix = prefix
self.data = data
self.size = len(data)
if CAP.check_sig(data):
self.contents = CAP(data, start)
elif ICHDesc.check_sig(data):
self.contents = ICHDesc(data, start)
else:
self.contents = FD(data, start, 'bios_', full_dump=False)
self.trailing = None
if self.size > self.contents.size:
cur_prefix = '%strl_' % prefix
self.trailing = RAW(data[self.contents.size:], start + self.contents.size, cur_prefix)
def __str__(self):
return '0x%08x+0x%08x: ROM' % (self.start, self.size)
def showinfo(self, ts=' '):
print ts + 'Size: 0x%x' % self.size
if self.trailing:
print ts + 'Trailing: 0x%x' % self.trailing.size
print ts + str(self.contents)
self.contents.showinfo(ts + ' ')
if self.trailing:
print ts + str(self.trailing)
self.trailing.showinfo(ts + ' ')
def dump(self):
self.contents.dump()
if self.trailing:
self.trailing.dump()