commit 138eeff898cc2bbc2942cd13cd7135982cf57240 Author: Hipstercat Date: Fri May 24 11:01:03 2019 +0200 initial diff --git a/extract.py b/extract.py new file mode 100644 index 0000000..adda7d9 --- /dev/null +++ b/extract.py @@ -0,0 +1,64 @@ +import zipfile +import argparse +import logging +import struct + + +def main(): + objects = [] + _ch = logging.StreamHandler() + _ch.setLevel("DEBUG") + _formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') + _ch.setFormatter(_formatter) + logger = logging.getLogger(__name__) + logger.addHandler(_ch) + logger.setLevel("DEBUG") + parser = argparse.ArgumentParser() + parser.add_argument("map_file") + args = parser.parse_args() + + map_file = args.map_file + logger.info("Opening %s", map_file) + zip_file = zipfile.ZipFile(map_file) + files = zip_file.namelist() + bin_filename = None + for file in files: + logger.info("Found file %s", file) + if file.endswith(".bin"): + bin_filename = file + logger.info("Found BIN file %s", bin_filename) + break + if not bin_filename: + logger.error("FATAL: BIN file not found") + zip_file.close() + exit(1) + + logger.info("Opening %s", bin_filename) + with zip_file.open(bin_filename) as bin_file: + byte = bin_file.read(1) + while byte != b"": + if byte == b'\x2a': # start object + # object is 20 bytes long + model = struct.unpack("