import sys
import json
import struct
file = open("lib_nx.bin", "rb")
if (file.read(4) != b"INIB"):
print("WRONG MAGIC")
sys.exit()
dummy = file.read(4)
entry_table_offset = int.from_bytes(file.read(4), byteorder="little")
entry_count = int.from_bytes(file.read(4), byteorder="little")
assert(file.tell() == entry_table_offset)
DUMP = []
offsets = []
for i in range(0, entry_count):
entry = {}
entry["CRC"] = file.read(4).hex().upper()
entry["type"] = int.from_bytes(file.read(4), byteorder="little")
offsets.append(int.from_bytes(file.read(4), byteorder="little"))
DUMP.append(entry)
assert(offsets[0] == file.tell())
for i in range(0, entry_count):
print(offsets[i])
file.seek(offsets[i])
match(DUMP[i]["type"]):
# Boolean
case 0:
data = int.from_bytes(file.read(4), byteorder="little")
if (data > 1):
print("ERROR")
sys.exit()
DUMP[i]["data"] = bool(data)
# Float
case 1:
DUMP[i]["data"] = round(struct.unpack('f', file.read(4))[0], 3)
# (Float, Float, Float)
case 2:
DUMP[i]["data"] = [round(struct.unpack('f', file.read(4))[0], 3), round(struct.unpack('f', file.read(4))[0], 3), round(struct.unpack('f', file.read(4))[0], 3)]
# (Float, Float, Float, Float)
case 3:
DUMP[i]["data"] = [round(struct.unpack('f', file.read(4))[0], 3), round(struct.unpack('f', file.read(4))[0], 3), round(struct.unpack('f', file.read(4))[0], 3), round(struct.unpack('f', file.read(4))[0], 3)]
case _:
print("UNKNOWN CASE")
sys.exit()
file.close()
new_file = open("dump.json", "w", encoding="UTF-8")
json.dump(DUMP, new_file, indent="\t", ensure_ascii=False)
new_file.close()