"""IGAntiTamper 宿主自测:cryptid 核心逻辑(合成 Mach-O 头)。 真机的 csops 代码签名检查与真实主镜像 cryptid 由设备测试覆盖;此处固化可复现的 cryptid 判定基线(加密正常/脱壳/剥除/非分发跳过/NULL),退出码 0 = 全过。 """ from pathlib import Path import os import shutil import subprocess import sys import tempfile import unittest ROOT = Path(__file__).resolve().parents[1] SOURCES = ['anti_tamper/IGAntiTamper.c'] @unittest.skipUnless(sys.platform == 'darwin' and shutil.which('xcrun'), '需要 Xcode/macOS') class AntiTamperCryptidTests(unittest.TestCase): def test_cryptid_core(self): with tempfile.TemporaryDirectory() as d: exe = Path(d) / 'anti-tamper-host' env = dict(os.environ) env.pop('DYLD_INSERT_LIBRARIES', None) args = ['xcrun', '--sdk', 'macosx', 'clang', '-O2', '-I', str(ROOT / 'defender/include'), '-I', str(ROOT / 'defender'), str(ROOT / 'tests/fixtures/anti_tamper_host.c'), *(str(ROOT / 'defender' / p) for p in SOURCES), '-o', str(exe)] build = subprocess.run(args, capture_output=True, text=True, env=env) self.assertEqual(build.returncode, 0, build.stdout + build.stderr) run = subprocess.run([str(exe)], capture_output=True, text=True, env=env) self.assertEqual(run.returncode, 0, run.stdout + run.stderr) self.assertIn('PASSED', run.stdout) if __name__ == '__main__': unittest.main()