#!/usr/bin/env python3 """Check the shipped native ABI, ELF load alignment and APK zip alignment.""" from pathlib import Path import argparse import hashlib import json import re import struct import subprocess import zipfile def verify_package_version(badging, version_name, version_code): package = next((line for line in badging.splitlines() if line.startswith('package: ')), '') attributes = dict(re.findall(r"(\w+)='([^']*)'", package)) expected = {'name': 'cn.crossdesk.mobile', 'versionName': version_name, 'versionCode': str(version_code)} for key, value in expected.items(): if attributes.get(key) != value: raise ValueError(f'Unexpected APK {key}: expected {value!r}, got {attributes.get(key)!r}') def verify(path): with zipfile.ZipFile(path) as archive, open(path, 'rb') as raw: libraries = [i for i in archive.infolist() if i.filename.endswith('.so')] if [i.filename for i in libraries] != ['lib/arm64-v8a/libcrossdesk_android.so']: raise ValueError('APK must contain exactly the arm64 native controller library') library = libraries[0] data = archive.read(library) if data[:6] != b'\x7fELF\x02\x01' or struct.unpack_from('