Created
January 18, 2024 00:38
-
-
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
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
# 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