Media3 内核播放框架(player-api/core/media3/source/render/lifecycle/telemetry)、 WebDAV/SMB/Jellyfin 来源、DLNA/Google Cast 投屏、RTMP 原生库与完整 App。
45 lines
2.0 KiB
Python
45 lines
2.0 KiB
Python
"""检查 APK 中 native ELF 的 LOAD 对齐与 ZIP 存储对齐,不代替设备加载测试。
|
|
|
|
用法:python tools/verify_apk_native.py path/to/demo.apk
|
|
无需第三方 Python 依赖;构建产物有误时返回非零状态。
|
|
"""
|
|
import struct
|
|
import sys
|
|
import zipfile
|
|
from pathlib import Path
|
|
|
|
|
|
def verify(apk: Path) -> None:
|
|
abis = set()
|
|
with zipfile.ZipFile(apk) as archive, apk.open("rb") as raw:
|
|
for entry in archive.infolist():
|
|
if not entry.filename.endswith(".so"):
|
|
continue
|
|
data = archive.read(entry)
|
|
assert data[:4] == b"\x7fELF", entry.filename
|
|
is64 = data[4] == 2
|
|
endian = "<" if data[5] == 1 else ">"
|
|
offset = struct.unpack_from(endian + ("Q" if is64 else "I"), data, 32 if is64 else 28)[0]
|
|
size, count = struct.unpack_from(endian + "HH", data, 54 if is64 else 42)
|
|
alignments = []
|
|
for index in range(count):
|
|
header = offset + index * size
|
|
if struct.unpack_from(endian + "I", data, header)[0] == 1:
|
|
alignment = struct.unpack_from(endian + ("Q" if is64 else "I"), data, header + (48 if is64 else 28))[0]
|
|
assert alignment >= 16384, f"ELF alignment {alignment}: {entry.filename}"
|
|
alignments.append(alignment)
|
|
assert alignments, entry.filename
|
|
if entry.compress_type == zipfile.ZIP_STORED:
|
|
raw.seek(entry.header_offset + 26)
|
|
name_len, extra_len = struct.unpack("<HH", raw.read(4))
|
|
data_offset = entry.header_offset + 30 + name_len + extra_len
|
|
assert data_offset % 16384 == 0, f"ZIP alignment: {entry.filename}"
|
|
abis.add(entry.filename.split("/")[1])
|
|
print(entry.filename, "ELF LOAD:", alignments)
|
|
assert abis == {"armeabi-v7a", "arm64-v8a", "x86", "x86_64"}, abis
|
|
print("PASS: four ABIs, 16 KB ELF and uncompressed ZIP alignment")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
verify(Path(sys.argv[1]))
|