From 347333f2edd964e0dd258faa1549cb4d67471db9 Mon Sep 17 00:00:00 2001 From: Andy Wortman Date: Tue, 6 Aug 2019 20:53:45 -0700 Subject: script to read bits of fx3 firmware --- fx3parse.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 fx3parse.py diff --git a/fx3parse.py b/fx3parse.py new file mode 100644 index 0000000..8ff08e4 --- /dev/null +++ b/fx3parse.py @@ -0,0 +1,33 @@ +import binascii +import struct + +data = open("firmware/qhy/QHY367.img").read() + +if data[0:3] == [0x43, 0x59, 0x1c, 0xb0]: + print("looks like an fx3 image to me!") + +def read_section(data, offset): + length = struct.unpack_from("i", data, offset=offset)[0] + addr = struct.unpack_from("i", data, offset=offset + 4)[0] + return (data[offset + 8:offset + 8 + length * 4], addr) + +offset = 4 + +sections = [] + +while True: + (section, addr) = read_section(data, offset) + sections.append((section, addr, offset)) + print("read section at addr {}, length {}, file offset {}".format(hex(addr), hex(len(section)), hex(offset))) + offset = offset + 8 + len(section) + if len(section) == 0: + break + +def offsetof(sections, addr): + for (section, start, offset) in sections: + print("considering section {} +{}".format(hex(start), hex(offset))) + if addr >= start and addr < start + len(section): + sec_addr = addr - start + print("file offset of {}: {}".format(hex(addr), hex(sec_addr + offset + 8))) + +offsetof(sections, 0x40010a30) -- cgit v1.1