Skip to content

Instantly share code, notes, and snippets.

@aerosoul94
Created November 24, 2022 00:00
Show Gist options
  • Save aerosoul94/fd2ebb3c9486719bb06d4728d8d86644 to your computer and use it in GitHub Desktop.
Save aerosoul94/fd2ebb3c9486719bb06d4728d8d86644 to your computer and use it in GitHub Desktop.
Finds xbe sections in an hdd image using the section hashes
import sys
import hashlib
def brutehash(path, start, end, size, secthash):
with open(path, 'rb') as fp:
fp.seek(start)
blocksize = 0x1000 # PAGE_SIZE
seed = size.to_bytes(4, byteorder='little')
for block in range(start, end, blocksize):
fp.seek(block)
data = fp.read(size)
ctx = hashlib.sha1()
ctx.update(seed)
ctx.update(data)
digest = ctx.digest()
if secthash != digest:
print(f"Nope at {block:X} ({secthash} != {digest})")
else:
print(f"Found at {block:X} ({secthash} == {digest})")
return
if __name__ == "__main__":
print(len(sys.argv))
if (len(sys.argv) != 6):
print(f"Usage: {sys.argv[0]} <image path> <start offset> <end offset> <size in hex> <section hash>")
quit()
imagepath = sys.argv[1]
start = int(sys.argv[2],16)
end = int(sys.argv[3],16)
size = int(sys.argv[4],16)
secthash = bytes.fromhex(sys.argv[5])
print(f"Start: {start}")
print(f"End: {end}")
print(f"Size: {size}")
print(f"SectHash: {secthash}")
brutehash(imagepath, start, end, size, secthash)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment