Created
February 26, 2024 08:14
-
-
Save m0001a/be7cd1fd72cb245ffdf8a0585aaf5fe8 to your computer and use it in GitHub Desktop.
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
import argparse | |
from pathlib import Path | |
from machfs import Volume | |
from machfs.directory import File | |
PARSER = argparse.ArgumentParser( | |
description="set the copy protection bit on a file", | |
) | |
PARSER.add_argument("input_image", | |
type=Path, | |
help="the input HFS image") | |
PARSER.add_argument("mac_path", | |
help="the Macintosh path of the file to copy protect with " | |
"the usual colon separator; don't include the volume name " | |
"(e.g. if the disk is called 'Untitled', and you want to " | |
"patch 'Untitled:File', provide only 'File')") | |
PARSER.add_argument("output_image", | |
type=Path, | |
help="the output HFS image, with thee copy protected file") | |
args = PARSER.parse_args() | |
original = args.input_image.read_bytes() | |
mac_volume = Volume() | |
mac_volume.read(original) | |
mac_file = mac_volume | |
for part in args.mac_path.split(':'): | |
mac_file = mac_file[part] | |
if not isinstance(mac_file, File): | |
PARSER.exit(1, message="mac_path is not a file") | |
# copy protection is bit 6 | |
mac_file.filFlags |= (1 << 6) | |
patched = mac_volume.write(size=len(original)) | |
args.output_image.write_bytes(patched) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment