diff --git a/gcdcompile.py b/gcdcompile.py new file mode 100644 index 0000000..0f50395 --- /dev/null +++ b/gcdcompile.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +""" +Parses a recipe file and builds a GCD file from it. +""" + +from grmn import Gcd +import sys + +if len(sys.argv) < 3: + print("Syntax: {} RCPFILE GCDFILE".format(sys.argv[0])) + sys.exit(1) + +RECIPE = sys.argv[1] +OUTFILE = sys.argv[2] + +print("Opening recipe {}".format(RECIPE)) +gcd = Gcd.from_recipe(RECIPE) +gcd.print_struct() +#print("Dumping to {}".format(OUTFILE)) +#gcd.write_to_file(OUTFILE) diff --git a/gcddump.py b/gcddump.py index b1a24c0..7eda393 100644 --- a/gcddump.py +++ b/gcddump.py @@ -9,13 +9,13 @@ from grmn import Gcd import sys if len(sys.argv) < 3: - print("Syntax: {} GCDFILE DUMPFILE (extension .rcp will be added)".format(sys.argv[0])) + print("Syntax: {} GCDFILE OUTPUTBASENAME (extension .rcp will be added)".format(sys.argv[0])) sys.exit(1) FILE = sys.argv[1] -OUTFILE = sys.argv[2] +OUTBASENAME = sys.argv[2] print("Opening {}".format(FILE)) gcd = Gcd(FILE) -print("Dumping to {}.rcp".format(OUTFILE)) -gcd.dump(OUTFILE) +print("Dumping to {}.rcp".format(OUTBASENAME)) +gcd.dump_to_files(OUTBASENAME) diff --git a/grmn/gcd.py b/grmn/gcd.py index 3b5ea15..5264512 100644 --- a/grmn/gcd.py +++ b/grmn/gcd.py @@ -3,6 +3,8 @@ from .chksum import ChkSum from .tlv import TLV, TLV6, TLV7 +from struct import unpack +import configparser GCD_SIG = b"G\x41RM\x49Nd\00" DEFAULT_COPYRIGHT = b"Copyright 1996-2017 by G\x61rm\x69n Ltd. or its subsidiaries." @@ -36,7 +38,8 @@ class Gcd: while True: cur_offset = f.tell() header = f.read(4) - tlv = TLV.factory(header, offset=cur_offset) + (type_id, length) = unpack("