PulseCanvas / app · pulsecanvas.ai / scripts / verify-original-resources.py
| 1 | #!/usr/bin/env python3 |
| 2 | """Inspect an actual original-Metal app payload without requiring a signature.""" |
| 3 | import argparse |
| 4 | import hashlib |
| 5 | import json |
| 6 | from pathlib import Path |
| 7 | import plistlib |
| 8 | import subprocess |
| 9 | |
| 10 | parser = argparse.ArgumentParser() |
| 11 | parser.add_argument('app', type=Path) |
| 12 | args = parser.parse_args() |
| 13 | app = args.app.resolve() |
| 14 | root = Path(__file__).resolve().parent.parent |
| 15 | info = plistlib.loads((app / 'Contents/Info.plist').read_bytes()) |
| 16 | exe = app / 'Contents/MacOS' / info['CFBundleExecutable'] |
| 17 | resources = app / 'Contents/Resources' |
| 18 | catalogs = list(resources.rglob('NativeVisualizers.json')) |
| 19 | assert len(catalogs) == 1, 'Expected one native resource catalog' |
| 20 | catalog_path = catalogs[0] |
| 21 | shader_root = catalog_path.parent |
| 22 | catalog = json.loads(catalog_path.read_text()) |
| 23 | expected = json.loads(subprocess.check_output(['python3', str(root / 'scripts/native-visualizer-catalog.py')])) |
| 24 | assert catalog == expected, 'App catalog differs from current source' |
| 25 | assert catalog['schema'] == 2 |
| 26 | assert not set(catalog['retiredScenes']).intersection(effect['scene'] for effect in catalog['effects']) |
| 27 | for path in app.rglob('*'): |
| 28 | assert path.suffix.lower() not in ('.milk', '.ll'), f'Withdrawn source/preset bundled: {path}' |
| 29 | assert path.name != 'VisualShaders.metallib', 'Recovered shader binary bundled' |
| 30 | assert 'projectm' not in path.name.lower(), f'External engine resource bundled: {path}' |
| 31 | for name, digest in catalog['shaders'].items(): |
| 32 | assert hashlib.sha256((shader_root / name).read_bytes()).hexdigest() == digest, name |
| 33 | assert (resources / 'Legal/PulseCanvas-LICENSE.txt').read_bytes() == (root / 'LICENSE').read_bytes() |
| 34 | imports = subprocess.check_output(['otool', '-L', str(exe)], text=True) |
| 35 | assert not any(value in imports for value in ['OpenGL.framework', 'libprojectM']), imports |
| 36 | symbols = subprocess.check_output(['nm', '-u', str(exe)], text=True) |
| 37 | assert '_projectm_' not in symbols and '_CGLCreateContext' not in symbols |
| 38 | print(json.dumps({'app': str(app), 'activeNativeEffects': catalog['nativeCount'], |
| 39 | 'retiredNativeIDs': catalog['retiredScenes'], 'externalPresets': 0, |
| 40 | 'recoveredShaders': 0, 'openGLImports': False, 'shaderHashesMatch': True, |
| 41 | 'signatureChecked': False}, indent=2)) |