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 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
| #!/usr/bin/env node
const crypto = require('crypto'); const fs = require('fs'); const path = require('path'); const { spawnSync } = require('child_process'); const readlineSync = require('readline-sync'); const os = require('os');
const CONFIG_FILE = path.join(os.homedir(), '.typora_crack_config.json'); const DEFAULT_APP_PATH = '/Applications/Typora.app'; const ORIGINAL_PUB_KEY = `-----BEGIN PUBLIC KEY----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA7nVoGCHqIMJyqgALEUrc 5JJhap0+HtJqzPE04pz4y+nrOmY7/12f3HvZyyoRsxKdXTZbO0wEHFIh0cRqsuaJ PyaOOPbA0BsalofIAY3mRhQQ3vSf+rn3g+w0S+udWmKV9DnmJlpWqizFajU4T/E4 5ZgMNcXt3E1ips32rdbTR0Nnen9PVITvrbJ3l6CI2BFBImZQZ2P8N+LsqfJsqyVV wDkt3mHAVxV7FZbfYWG+8FDSuKQHaCmvgAtChx9hwl3J6RekkqDVa6GIV13D23LS qdk0Jb521wFJi/V6QAK6SLBiby5gYN6zQQ5RQpjXtR53MwzTdiAzGEuKdOtrY2Me DwIDAQAB -----END PUBLIC KEY-----`;
function getBinaryPath(appPath) { return path.join(appPath, 'Contents', 'MacOS', 'Typora'); }
function readCache() { try { if (fs.existsSync(CONFIG_FILE)) { const data = JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8')); if (data.path && fs.existsSync(getBinaryPath(data.path))) { return data; } } } catch (e) {} return { path: null, machineCode: null, email: null }; }
function saveCache(obj) { try { fs.writeFileSync(CONFIG_FILE, JSON.stringify(obj, null, 2), 'utf8'); } catch (e) {} }
function getNowDateStr() { const now = new Date(); const dd = String(now.getDate()).padStart(2, '0'); const mm = String(now.getMonth() + 1).padStart(2, '0'); return `${mm}/${dd}/${now.getFullYear()}`; }
function chooseTyporaPath() { const cache = readCache();
if (cache.path) { console.log(`\n✅ 检测到缓存路径: ${cache.path}`); const use = readlineSync.question('是否使用此路径?[Y/n]:').trim().toLowerCase(); if (use !== 'n' && use !== 'no') return cache.path; }
if (fs.existsSync(getBinaryPath(DEFAULT_APP_PATH))) { console.log(`\n✅ 检测到默认路径: ${DEFAULT_APP_PATH}`); const use = readlineSync.question('是否使用此路径?[Y/n]:').trim().toLowerCase(); if (use !== 'n' && use !== 'no') { saveCache({ ...cache, path: DEFAULT_APP_PATH }); return DEFAULT_APP_PATH; } }
try { const output = spawnSync('osascript', ['-e', 'POSIX path of (choose folder with prompt "请选择 Typora.app 所在目录")' ], { encoding: 'utf8' }).stdout.trim(); if (output) { let p = path.resolve(output.replace(/\/$/, '')); if (!p.endsWith('.app')) p = path.join(p, 'Typora.app'); if (fs.existsSync(getBinaryPath(p))) { saveCache({ ...cache, path: p }); return p; } } } catch (e) {}
while (true) { const input = readlineSync.question('请输入 Typora.app 路径:').trim(); if (!input) continue; const p = path.resolve(input); if (fs.existsSync(getBinaryPath(p))) { saveCache({ ...cache, path: p }); return p; } console.log('❌ 路径无效,未找到 Typora 二进制'); } }
function getMachineCodeAndEmail() { const cache = readCache();
if (cache.machineCode && cache.email) { console.log(`\n✅ 检测到缓存的激活信息:`); console.log(` 机器码: ${cache.machineCode.substring(0, 30)}...`); console.log(` 邮箱: ${cache.email}`); const use = readlineSync.question('是否使用此信息?[Y/n]:').trim().toLowerCase(); if (use !== 'n' && use !== 'no') { return { machineCode: cache.machineCode, email: cache.email }; } }
let machineCode, email; while (true) { machineCode = readlineSync.question('\n请输入机器码: ').trim(); email = readlineSync.question('请输入邮箱: ').trim(); if (!machineCode) { console.log('❌ 机器码不能为空'); continue; } if (!email) { console.log('❌ 邮箱不能为空'); continue; } break; }
saveCache({ ...cache, machineCode, email }); return { machineCode, email }; }
function rollback(appPath) { console.log('\n🔄 开始回滚还原...'); const binPath = getBinaryPath(appPath); const bakPath = binPath + '.bak';
spawnSync('killall', ['Typora'], { stdio: 'ignore' });
if (fs.existsSync(bakPath)) { fs.copyFileSync(bakPath, binPath); fs.rmSync(bakPath, { force: true }); console.log('✅ 已还原 Typora 二进制'); } else { console.log('⚠️ 未找到备份文件,无需回滚'); return; }
spawnSync('defaults', ['delete', 'abnerworks.Typora', 'typora-license'], { stdio: 'ignore' }); spawnSync('codesign', ['--force', '--deep', '-s', '-', appPath], { stdio: 'ignore' }); console.log('✅ 已清理授权信息并重新签名'); console.log('\n🎉 回滚完成!'); }
(function main() { process.stdout.write('\x1Bc'); console.log('================================='); console.log(' Typora macOS 激活脚本'); console.log('=================================');
const appPath = chooseTyporaPath(); const binPath = getBinaryPath(appPath); const bakPath = binPath + '.bak';
if (fs.existsSync(bakPath)) { console.log('\n⚠️ 检测到已激活过(二进制已 patch)'); const choice = readlineSync.question('[R]回滚还原 / [P]重新Patch / [Q]退出:').trim().toUpperCase(); if (choice === 'R') { rollback(appPath); process.exit(0); } if (choice !== 'P') { process.exit(0); } console.log('还原原始二进制...'); fs.copyFileSync(bakPath, binPath); fs.rmSync(bakPath, { force: true }); spawnSync('defaults', ['delete', 'abnerworks.Typora', 'typora-license'], { stdio: 'ignore' }); }
const { machineCode, email } = getMachineCodeAndEmail(); const mc = JSON.parse(Buffer.from(machineCode, 'base64').toString('utf8')); console.log(`\ndeviceId: ${mc.l}`); console.log(`fingerprint: ${mc.i}`); console.log(`version: ${mc.v}`);
spawnSync('killall', ['Typora'], { stdio: 'ignore' });
const nowDateStr = getNowDateStr();
console.log('\n一、生成密钥对...'); const { publicKey, privateKey } = crypto.generateKeyPairSync('rsa', { modulusLength: 2048, publicKeyEncoding: { type: 'spki', format: 'pem' }, privateKeyEncoding: { type: 'pkcs8', format: 'pem' } });
const pubKeyBase64 = publicKey .replace('-----BEGIN PUBLIC KEY-----', '') .replace('-----END PUBLIC KEY-----', '') .replace(/\s/g, ''); const lines = []; for (let i = 0; i < pubKeyBase64.length; i += 64) { lines.push(pubKeyBase64.slice(i, i + 64)); } const formattedPubKey = '-----BEGIN PUBLIC KEY-----\n' + lines.join('\n') + '\n-----END PUBLIC KEY-----'; const newKeyBuf = Buffer.from(formattedPubKey, 'utf8'); const originalKeyBuf = Buffer.from(ORIGINAL_PUB_KEY, 'utf8');
if (newKeyBuf.length !== originalKeyBuf.length) { console.log(`❌ 公钥长度不匹配: 期望 ${originalKeyBuf.length}, 实际 ${newKeyBuf.length}`); process.exit(1); } console.log(`✅ 密钥对生成成功 (${newKeyBuf.length} 字节)`);
console.log('\n二、Patch 二进制...'); fs.copyFileSync(binPath, bakPath);
let binaryData = fs.readFileSync(binPath); let offset = 0, replacements = 0; while (true) { const idx = binaryData.indexOf(originalKeyBuf, offset); if (idx === -1) break; newKeyBuf.copy(binaryData, idx); offset = idx + newKeyBuf.length; replacements++; }
if (replacements === 0) { console.log('❌ 未在二进制中找到原始公钥,可能版本不兼容'); fs.copyFileSync(bakPath, binPath); fs.rmSync(bakPath, { force: true }); process.exit(1); }
const urlReplacements = [ { from: 'https://store.typora.io', to: 'https://127.0.0.1' }, { from: 'https://dian.typora.com.cn', to: 'https://127.0.0.1' } ]; let urlPatched = 0; for (const { from, to } of urlReplacements) { const fromBuf = Buffer.from(from, 'utf8'); const toBuf = Buffer.alloc(fromBuf.length, 0); Buffer.from(to, 'utf8').copy(toBuf); let off = 0; while (true) { const idx = binaryData.indexOf(fromBuf, off); if (idx === -1) break; toBuf.copy(binaryData, idx); off = idx + toBuf.length; urlPatched++; } }
fs.writeFileSync(binPath, binaryData); console.log(`✅ 已替换 ${replacements} 处公钥, ${urlPatched} 处服务器地址`);
console.log('\n三、生成 Activation Token...');
const ACT_ENTITY = { deviceId: mc.l, fingerprint: mc.i, email: email, license: "Cracked_By_DreamNya&Letr", version: mc.v, date: nowDateStr, type: "DreamNya" };
const licenseJSON = JSON.stringify(ACT_ENTITY); const jsonBase64 = Buffer.from(licenseJSON, 'utf8').toString('base64');
const atobResult = Buffer.from(jsonBase64, 'base64').toString('latin1'); const parsedAfterAtob = JSON.parse(atobResult);
const skipKeys = new Set(['sig', 'oldSig', 'oldFinger']); const sortedKeys = Object.keys(parsedAfterAtob).filter(k => !skipKeys.has(k)).sort(); const dataToSign = sortedKeys.map(k => String(parsedAfterAtob[k])).join('');
const signature = crypto.sign('SHA256', Buffer.from(dataToSign, 'utf8'), { key: privateKey, padding: crypto.constants.RSA_PKCS1_PADDING });
const activationToken = '+' + jsonBase64 + '|' + signature.toString('base64') + '#'; console.log('✅ Token 生成成功');
console.log('\n四、重新签名应用...'); const signResult = spawnSync('codesign', ['--force', '--deep', '-s', '-', appPath], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }); if (signResult.status !== 0) { console.log(`⚠️ 签名警告: ${(signResult.stderr || '').trim()}`); } else { console.log('✅ 应用重新签名成功'); }
console.log('\n🎉 全部完成!'); console.log('\n使用方法:'); console.log('1. 打开 Typora → 帮助 → 我的许可证'); console.log('2. 点击「获取 Activation Token」进入离线激活页面'); console.log('3. 在 Activation Token 框中粘贴以下内容:\n'); console.log(activationToken); console.log('\n(Token 已复制到剪贴板)');
try { spawnSync('pbcopy', [], { input: activationToken, encoding: 'utf8' }); } catch (e) {} })();
|