Skip to content

Instantly share code, notes, and snippets.

@oPromessa
Created January 4, 2026 01:24
Show Gist options
  • Select an option

  • Save oPromessa/1c4bc8d62cbdd3a6795ced7badd2122e to your computer and use it in GitHub Desktop.

Select an option

Save oPromessa/1c4bc8d62cbdd3a6795ced7badd2122e to your computer and use it in GitHub Desktop.
Read, Decode and prints bynary adjustmentData field from a Mac Photos AAE file.
import base64
import json
import sys
import xml.etree.ElementTree as ET
import zlib
def read_aae_file(filename: str, verbosebinary: bool = False) -> None:
"""Read, Decode and prints bynary adjustmentData field from an AAE file.
Args:
filename (str): Mac Photos AAE filename to process.
verbosebinary (bool, optional): verbosely show data. Defaults to False.
"""
try:
# Parse the XML file
tree = ET.parse(filename)
root = tree.getroot()
# Find all data fields (assuming they are stored in elements with a tag 'data')
data_elements = root.findall(".//data")
if not data_elements:
print("No data fields found in the XML file.", file=sys.stderr)
return
for idx, data_elem in enumerate(data_elements):
binary_data = data_elem.text
# Print the raw binary data
if verbosebinary:
print(
f"Data field {idx+1} "
f"(raw): {binary_data=} {len({binary_data})=}"
f"{type({binary_data})=}",
file=sys.stderr
)
# If the binary data is base64 encoded, decode it
try:
decoded_data = base64.b64decode(binary_data)
# print(f"Data field {idx+1} (decoded):")
# print(decoded_data)
adjustmentData_decompressed = zlib.decompress(
decoded_data, -zlib.MAX_WBITS
)
adjustmentData_json = json.loads(adjustmentData_decompressed)
print(json.dumps(adjustmentData_json, indent=2))
except base64.binascii.Error:
print("Data is not base64 encoded.", file=sys.stderr)
except ET.ParseError:
print(f"Failed to parse the XML file: {filename}", file=sys.stderr)
except FileNotFoundError:
print(f"File not found: {filename}", file=sys.stderr)
except Exception as err:
print(f"An error occurred: {err}", file=sys.stderr)
def main():
if len(sys.argv) != 2:
print("Usage: python script.py <filename>", file=sys.stderr)
else:
filename = sys.argv[1]
read_aae_file(filename)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment