summaryrefslogtreecommitdiff
path: root/fx3parse.py
diff options
context:
space:
mode:
Diffstat (limited to 'fx3parse.py')
-rw-r--r--fx3parse.py33
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)