Small optimisations.
This commit is contained in:
parent
02daff44b5
commit
4aa3e39d7d
13
grmn/gcd.py
13
grmn/gcd.py
@ -12,6 +12,9 @@ DEFAULT_ALIGN = 0x1000 # second padding block pads until 0x1000
|
||||
# first 0x1000 Bytes: GCD_SIG > 0x0001 > 0x0002 > 0x0003 > 0x0005 > 0x0001 > 0x0002
|
||||
# then: 0x0001 > ( 0x0006 > 0x0007 > 0x???? > 0x0001 ... ) > 0xffff
|
||||
|
||||
class ParseException(Exception):
|
||||
pass
|
||||
|
||||
class Gcd:
|
||||
def __init__(self, filename: str=None):
|
||||
self.filename = filename
|
||||
@ -26,12 +29,12 @@ class Gcd:
|
||||
with open(self.filename, "rb") as f:
|
||||
sig = f.read(8)
|
||||
if sig != GCD_SIG:
|
||||
raise Exception("Signature mismatch ({}, should be {})!".format(repr(sig), repr(GCD_SIG)))
|
||||
raise ParseException("Signature mismatch ({}, should be {})!".format(repr(sig), repr(GCD_SIG)))
|
||||
while True:
|
||||
cur_offset = f.tell()
|
||||
header = f.read(4)
|
||||
tlv = TLV.factory(header, offset=cur_offset)
|
||||
self.struct.append(tlv)
|
||||
self.add_tlv(tlv)
|
||||
if tlv.type_id == 0xFFFF:
|
||||
# End of file reached
|
||||
break
|
||||
@ -44,7 +47,13 @@ class Gcd:
|
||||
tlv.set_tlv6(last_tlv6)
|
||||
f.close()
|
||||
|
||||
def add_tlv(self, new_tlv: TLV):
|
||||
self.struct.append(new_tlv)
|
||||
|
||||
def print_struct(self):
|
||||
"""
|
||||
Prints the structure of the parsed GCD file
|
||||
"""
|
||||
last_tlv = 0xffff
|
||||
tlv_count = 0
|
||||
tlv_length = 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user