Created
May 25, 2015 16:53
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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