diff options
author | Andy Wortman <ixineeringeverywhere@gmail.com> | 2019-08-06 20:53:45 -0700 |
---|---|---|
committer | Andy Wortman <ixineeringeverywhere@gmail.com> | 2019-08-06 20:53:45 -0700 |
commit | 347333f2edd964e0dd258faa1549cb4d67471db9 (patch) | |
tree | 87085f0274b02762786aa25d5989988766c04b2b | |
parent | c79469d44ca83043e9c5d22509850293ed65507a (diff) |
script to read bits of fx3 firmware
-rw-r--r-- | fx3parse.py | 33 |
1 files changed, 33 insertions, 0 deletions
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) |