Spiced up kunix's tool a bit.
This commit is contained in:
parent
d973ba9475
commit
ce673398c9
@ -12,17 +12,18 @@ import os.path
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
FILE = sys.argv[1]
|
FILE = sys.argv[1]
|
||||||
|
OFFSET = 0
|
||||||
|
if len(sys.argv) > 2:
|
||||||
|
OFFSET = int(sys.argv[2])
|
||||||
BLOCKSIZE = 4096
|
BLOCKSIZE = 4096
|
||||||
|
|
||||||
END_MARKER = b"\xff\xff\x5a\xa5"
|
END_MARKER = b"\xff\xff\x5a\xa5"
|
||||||
|
|
||||||
first_block = True
|
first_block = True
|
||||||
past_end = False
|
end_marker_pos = 0xffffffff
|
||||||
trailer = bytes()
|
|
||||||
trailer_pos = -1
|
|
||||||
|
|
||||||
print("Reading {} ...".format(FILE))
|
print("Reading {} ...".format(FILE))
|
||||||
with open(FILE, "rb") as f:
|
with open(FILE, "rb") as f:
|
||||||
|
f.read(OFFSET)
|
||||||
while True:
|
while True:
|
||||||
block = f.read(BLOCKSIZE)
|
block = f.read(BLOCKSIZE)
|
||||||
if first_block:
|
if first_block:
|
||||||
@ -30,37 +31,43 @@ with open(FILE, "rb") as f:
|
|||||||
first_block = False
|
first_block = False
|
||||||
if END_MARKER in block:
|
if END_MARKER in block:
|
||||||
end_pos = block.find(END_MARKER)
|
end_pos = block.find(END_MARKER)
|
||||||
marker_end = f.tell() - len(block) + end_pos + 2
|
found_pos = f.tell() - len(block) + end_pos + 2
|
||||||
break
|
if found_pos > end_marker_pos:
|
||||||
|
print("Found a second endmarker! Using that one.")
|
||||||
|
end_marker_pos = found_pos
|
||||||
|
#break
|
||||||
if len(block) < BLOCKSIZE:
|
if len(block) < BLOCKSIZE:
|
||||||
break
|
break
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
size = os.path.getsize(FILE)
|
size = os.path.getsize(FILE)
|
||||||
|
|
||||||
print("File is {} Bytes.".format(size))
|
print("File is {} (0x{:x}) Bytes.".format(size, size))
|
||||||
print("First double-words: 0x{:x} / 0x{:x} / 0x{:x} / 0x{:x} / 0x{:x}".format(dw[0], dw[1], dw[2], dw[3], dw[4]))
|
print("First double-words: 0x{:x} / 0x{:x} / 0x{:x} / 0x{:x} / 0x{:x}".format(dw[0], dw[1], dw[2], dw[3], dw[4]))
|
||||||
print("Found end marker at: 0x{:x}".format(marker_end))
|
print("Assuming this is end marker location in memory: 0x{:x}".format(dw[1]))
|
||||||
|
print("Found end marker in file at: 0x{:x}".format(end_marker_pos))
|
||||||
|
|
||||||
base_addr = dw[1] - marker_end
|
base_addr = dw[1] - (end_marker_pos - OFFSET)
|
||||||
|
if base_addr < 0:
|
||||||
|
base_addr += 0xffffffff
|
||||||
|
|
||||||
|
print("This would make Base address probably 0x{:x}".format(base_addr))
|
||||||
|
|
||||||
if base_addr % 4 != 0:
|
if base_addr % 4 != 0:
|
||||||
print("Bad alignment. Calculated base address not aligned to doublewords.")
|
print("However, bad alignment. Calculated base address not aligned to doublewords.")
|
||||||
#sys.exit(1)
|
|
||||||
|
|
||||||
if base_addr + size > 0xffffffff:
|
if base_addr + size > 0xffffffff:
|
||||||
print("Overflow")
|
print("However, base address can't fit whole file.")
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
if dw[2] % 2 != 0 or dw[2] - base_addr >= marker_end - 3:
|
# Assumes second dword points to hwid
|
||||||
print("Align & Bounds dw2 wrong.")
|
#if dw[2] % 2 != 0 or dw[2] - base_addr >= end_marker_pos - 3:
|
||||||
|
# print("Align & Bounds dw2 wrong.")
|
||||||
# sys.exit(1)
|
# sys.exit(1)
|
||||||
|
|
||||||
if dw[3] % 2 != 0 or dw[3] - base_addr >= marker_end - 3:
|
# Assumes third dword points to fwid
|
||||||
print("Align & Bounds dw3 wrong.")
|
#if dw[3] % 2 != 0 or dw[3] - base_addr >= end_marker_pos - 3:
|
||||||
|
# print("Align & Bounds dw3 wrong.")
|
||||||
# sys.exit(1)
|
# sys.exit(1)
|
||||||
|
|
||||||
print("Base address is probably 0x{:x}".format(base_addr))
|
|
||||||
|
|
||||||
# hwid = dw[2] - base_addr
|
# hwid = dw[2] - base_addr
|
||||||
# fwid = dw[3] - base_addr
|
# fwid = dw[3] - base_addr
|
||||||
|
Loading…
x
Reference in New Issue
Block a user