Skip to content

Instantly share code, notes, and snippets.

@bmaupin
Created May 25, 2015 16:53
Show Gist options
  • Save bmaupin/12ddf05a2fe974c36d1f to your computer and use it in GitHub Desktop.
Save bmaupin/12ddf05a2fe974c36d1f to your computer and use it in GitHub Desktop.
Get the start offset of an ext4 partition in a raw image file
search_bytes = b'\x53\xef'
with open('system.raw.img.tmp', 'rb') as f:
i = 0
while True:
byte = f.read(1)
if not byte:
break
elif byte == search_bytes[i:i+1]:
i += 1
elif byte == search_bytes[0:1]:
i = 1
else:
i = 0
if i == len(search_bytes):
print(f.tell() - len(search_bytes) - 1080)
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment