Skip to content

Instantly share code, notes, and snippets.

@heyjoeway
Created December 26, 2021 02:13
Show Gist options
  • Save heyjoeway/3b4a4597a37fc45c5d8c16994c13ce5c to your computer and use it in GitHub Desktop.
Save heyjoeway/3b4a4597a37fc45c5d8c16994c13ce5c to your computer and use it in GitHub Desktop.
Recover JPG images from a raw disk image
path = r'C:\Users\Joseph\Desktop\image.img'
HEADER_START = [b'\xff', b'\xd8', b'\xff', b'\xe1']
# HEADER_END = [b'\xff', b'\xd9']
header_start_index = 0
outfile_index = 0
outfile = None
with open(path, 'rb') as f:
while True:
b = f.read(1)
if not b:
break
if not (outfile is None):
outfile.write(b)
if b == HEADER_START[header_start_index]:
header_start_index += 1
else:
header_start_index = 0
if header_start_index >= len(HEADER_START):
print(f"Start Found: 0x{f.tell():1x}")
if not (outfile is None):
outfile.close()
outfile_index += 1
outfile = open(f"found_{outfile_index}.jpg", "wb")
for ob in HEADER_START:
outfile.write(ob)
header_start_index = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment