#!/usr/bin/env python3 # -*- coding: utf-8 -*- # Many thanks to kunix! """ Calculates possible base address. """ from struct import unpack import os.path import sys FILE = sys.argv[1] BLOCKSIZE = 4096 END_MARKER = b"\xff\xff\x5a\xa5" first_block = True past_end = False trailer = bytes() trailer_pos = -1 print("Reading {} ...".format(FILE)) with open(FILE, "rb") as f: while True: block = f.read(BLOCKSIZE) if first_block: dw = unpack(" 0xffffffff: print("Overflow") sys.exit(1) if dw[2] % 2 != 0 or dw[2] - base_addr >= marker_end - 3: print("Align & Bounds dw2 wrong.") #sys.exit(1) if dw[3] % 2 != 0 or dw[3] - base_addr >= marker_end - 3: print("Align & Bounds dw3 wrong.") #sys.exit(1) print("Base address is probably 0x{:x}".format(base_addr)) # hwid = dw[2] - base_addr # fwid = dw[3] - base_addr