diff --git a/grmn/gcd.py b/grmn/gcd.py index 8fbb4a6..875ddff 100644 --- a/grmn/gcd.py +++ b/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