#!/usr/bin/env python3 # Print heap offsets of the entries of a xar archive (InstallAssistant.pkg) as JSON, # so SharedSupport.dmg can be exposed to the VM as a raw disk without extracting 18 GB. import json import struct import sys import xml.etree.ElementTree as ET toc_xml, archive = sys.argv[1], sys.argv[2] with open(archive, 'rb') as f: magic, hsize, ver, toc_c, toc_u, cksum = struct.unpack('>4sHHQQI', f.read(28)) assert magic == b'xar!', 'not a xar archive' heap = hsize + toc_c out = {} for entry in ET.parse(toc_xml).getroot().iter('file'): data = entry.find('data') if data is None: continue out[entry.findtext('name')] = { 'offset': heap + int(data.findtext('offset')), 'length': int(data.findtext('length')), 'size': int(data.findtext('size')), 'encoding': data.find('encoding').get('style'), } json.dump(out, sys.stdout, indent=2)