1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
| #!/usr/bin/env node
const fs = require('fs'); const path = require('path'); const os = require('os'); const { spawnSync } = require('child_process');
const DEFAULT_APP_PATH = '/Applications/Path Finder.app'; const CONFIG_FILE = path.join(os.homedir(), '.pathfinder_crack_config.json');
function run(bin, args, opts = {}) { return spawnSync(bin, args, { encoding: 'utf8', ...opts }); }
function fail(msg) { console.error(`❌ ${msg}`); process.exit(1); }
function getFrameworkPath(appPath) { return path.join(appPath, 'Contents', 'Frameworks', 'PathFinderLicense.framework', 'Versions', 'A', 'PathFinderLicense'); }
function loadConfig() { try { return JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8')); } catch { return {}; } }
function saveConfig(data) { try { fs.writeFileSync(CONFIG_FILE, JSON.stringify(data, null, 2)); } catch {} }
function resolveAppPath() { const config = loadConfig(); if (config.path && fs.existsSync(getFrameworkPath(config.path))) return config.path; if (fs.existsSync(getFrameworkPath(DEFAULT_APP_PATH))) { saveConfig({ ...config, path: DEFAULT_APP_PATH }); return DEFAULT_APP_PATH; } fail('未找到 Path Finder.app'); }
function requireR2() { if (run('which', ['r2']).status !== 0) { fail('需要先安装 radare2:brew install radare2'); } }
function parseArchOffsets(frameworkPath) { const out = run('lipo', ['-detailed_info', frameworkPath]).stdout; const arm64 = out.match(/architecture arm64[\s\S]*?offset (\d+)/); const x86_64 = out.match(/architecture x86_64[\s\S]*?offset (\d+)/); if (!arm64 || !x86_64) fail('无法解析 fat binary 架构偏移'); return { arm64: Number(arm64[1]), x86_64: Number(x86_64[1]) }; }
function r2FindMethod(binaryPath, methodName) { const out = run('r2', ['-q', '-c', `ic~${methodName}`, binaryPath], { timeout: 30000 }).stdout; const match = out.match(/0x([0-9a-f]+)/i); return match ? Number.parseInt(match[1], 16) : null; }
function r2FindPattern(binaryPath, hexBytes) { const out = run('r2', ['-q', '-c', `/x ${hexBytes}`, binaryPath], { timeout: 30000 }).stdout; const match = out.match(/0x([0-9a-f]+)/i); return match ? Number.parseInt(match[1], 16) : null; }
function extractSlices(frameworkPath) { const dir = path.join(os.tmpdir(), 'opencode', 'pf_crack'); fs.mkdirSync(dir, { recursive: true });
const arm64 = path.join(dir, 'PathFinderLicense.arm64'); const x86_64 = path.join(dir, 'PathFinderLicense.x86_64');
run('lipo', ['-thin', 'arm64', frameworkPath, '-output', arm64]); run('lipo', ['-thin', 'x86_64', frameworkPath, '-output', x86_64]);
if (!fs.existsSync(arm64) || !fs.existsSync(x86_64)) { fail('无法提取架构切片'); }
return { arm64, x86_64 }; }
function buildPatches(frameworkPath) { const offsets = parseArchOffsets(frameworkPath); const slices = extractSlices(frameworkPath);
const arm64IsActive = r2FindMethod(slices.arm64, 'isActive'); const arm64StatusBase = r2FindPattern(slices.arm64, '9c 48 00 94 60 01 00 34'); const x86IsActive = r2FindMethod(slices.x86_64, 'isActive'); const x86StatusBase = r2FindPattern(slices.x86_64, '41 ff d5 84 c0 74');
if (arm64IsActive == null || arm64StatusBase == null || x86IsActive == null || x86StatusBase == null) { fail('未找到完整补丁点,可能版本不兼容'); }
return [ { arch: 'arm64', desc: 'isActive -> true', offset: offsets.arm64 + arm64IsActive, original: Buffer.from([0xF6, 0x57, 0xBD, 0xA9, 0xF4, 0x4F, 0x01, 0xA9]), patched: Buffer.from([0x20, 0x00, 0x80, 0x52, 0xC0, 0x03, 0x5F, 0xD6]) }, { arch: 'arm64', desc: 'status check -> nop', offset: offsets.arm64 + arm64StatusBase + 4, original: Buffer.from([0x60, 0x01, 0x00, 0x34]), patched: Buffer.from([0x1F, 0x20, 0x03, 0xD5]) }, { arch: 'x86_64', desc: 'isActive -> true', offset: offsets.x86_64 + x86IsActive, original: Buffer.from([0x55, 0x48, 0x89, 0xE5]), patched: Buffer.from([0x31, 0xC0, 0xFF, 0xC0, 0xC3]) }, { arch: 'x86_64', desc: 'status check -> nop', offset: offsets.x86_64 + x86StatusBase + 5, original: Buffer.from([0x74]), patched: Buffer.from([0x90, 0x90]) } ]; }
function patch(appPath) { const frameworkPath = getFrameworkPath(appPath); const backupPath = `${frameworkPath}.bak`;
if (fs.existsSync(backupPath)) { console.log('⚠️ 检测到已有备份,先恢复原始文件后重新 patch'); fs.copyFileSync(backupPath, frameworkPath); fs.rmSync(backupPath, { force: true }); }
console.log('🔍 查找补丁点...'); const patches = buildPatches(frameworkPath); let binary = fs.readFileSync(frameworkPath);
for (const patch of patches) { const current = binary.slice(patch.offset, patch.offset + patch.original.length); if (!current.equals(patch.original)) { fail(`${patch.arch} ${patch.desc} 字节不匹配 @ 0x${patch.offset.toString(16)}`); } patch.patched.copy(binary, patch.offset); console.log(`✅ ${patch.arch} ${patch.desc} @ 0x${patch.offset.toString(16)}`); }
fs.copyFileSync(frameworkPath, backupPath); fs.writeFileSync(frameworkPath, binary); run('killall', ['Path Finder'], { stdio: 'ignore' }); run('codesign', ['--force', '--deep', '--sign', '-', appPath], { stdio: 'ignore' }); console.log('🎉 Patch 完成'); }
function rollback(appPath) { const frameworkPath = getFrameworkPath(appPath); const backupPath = `${frameworkPath}.bak`;
run('killall', ['Path Finder'], { stdio: 'ignore' });
if (!fs.existsSync(backupPath)) { console.log('⚠️ 未找到备份文件,无需回滚'); return; }
fs.copyFileSync(backupPath, frameworkPath); fs.rmSync(backupPath, { force: true }); run('codesign', ['--force', '--deep', '--sign', '-', appPath], { stdio: 'ignore' }); console.log('🎉 回滚完成'); }
(function main() { const appPath = resolveAppPath(); requireR2();
if (process.argv.includes('--rollback')) { rollback(appPath); return; }
patch(appPath); })();
|