Skip to content

Instantly share code, notes, and snippets.

@dmlary
Created January 18, 2024 00:38
Show Gist options
  • Save dmlary/1ffe294c351194c52fd0224d5e609210 to your computer and use it in GitHub Desktop.
Save dmlary/1ffe294c351194c52fd0224d5e609210 to your computer and use it in GitHub Desktop.
python script using pyfshfs to dump a hfs disk image that macos could not mount
# used this on an ubuntu docker image with `apt install python3-libfshfs`
import pyfshfs
import os
def export_file(entry, dest):
print(f'export {dest}')
dir = os.path.dirname(dest)
if not os.path.exists(dir):
os.makedirs(dir)
with open(dest, "wb") as file:
file.write(entry.read())
def export_dir(entry, dest):
print(f'export dir {dest} (id {entry.identifier:X}, file_mode {entry.file_mode & 0xf000:X})')
dirs = []
for i in range(entry.get_number_of_sub_file_entries()):
child = entry.get_sub_file_entry(i)
if child.file_mode & 0x4000:
export_dir(child, f'{dest}/{child.name}')
elif child.file_mode & 0x8000:
export_file(child, f'{dest}/{child.name}')
else:
print(f'error: unsupported file type {dest}: {entry.file_mode}')
volume = pyfshfs.open("/data/store.img")
root = volume.get_root_directory()
export_dir(root, "/data/store-export")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment