diff --git a/idtconfig.py b/idtconfig.py index 224ad09..87cfd00 100755 --- a/idtconfig.py +++ b/idtconfig.py @@ -10,8 +10,11 @@ from lxml import etree -def get_images(xml: bytes): - tree = etree.fromstring(xml) +def get_images(cfg: bytes): + try: + tree = etree.fromstring(cfg) + except: + return get_simple(cfg.decode("utf-8")) ddr_images = tree.xpath("(//configurations/configuration)[1]/bootloaderimage_ddr/image") std_images = tree.xpath("(//configurations/configuration)[1]/bootloaderimage/image") images = {int(img.get("address"), 0):img.text for img in ddr_images} @@ -21,3 +24,14 @@ def get_images(xml: bytes): images[int(img.get("address"), 0)] = img.text print(images) return images + +def get_simple(cfg): + ret = {} + for line in cfg.readlines: + match = re.fullmatch(r"(\w+)(?:\W+)(.+)") + if not match: + return None + addr = int(match[1], 0) + file = match[2] + ret[addr] = file + return ret