Files
cursornew2026/convert_unicode.js

66 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 安全转换 Unicode 转义序列为中文
* 只处理字符串字面量,不破坏正则表达式
*/
const fs = require('fs');
const babel = require('@babel/core');
const traverse = require('@babel/traverse').default;
const generate = require('@babel/generator').default;
const t = require('@babel/types');
const inputPath = 'D:/temp/破解/cursorpro-0.4.5/deobfuscated_full/extension/out/webview/provider.js';
const code = fs.readFileSync(inputPath, 'utf8');
console.log('安全转换 Unicode...');
let ast;
try {
ast = babel.parseSync(code, { sourceType: 'script' });
} catch (e) {
console.error('解析失败:', e.message);
process.exit(1);
}
let converted = 0;
traverse(ast, {
StringLiteral(path) {
const value = path.node.value;
// 检查是否包含 Unicode 转义(已解码的中文字符)
// 或者检查原始值是否有 \u
if (path.node.extra && path.node.extra.raw) {
const raw = path.node.extra.raw;
if (raw.includes('\\u')) {
// 保持已解码的 value只是清除 extra 让生成器使用 value
delete path.node.extra;
converted++;
}
}
}
});
console.log(`处理了 ${converted} 个字符串`);
const output = generate(ast, {
comments: false,
compact: false,
jsescOption: {
minimal: true // 最小转义,保留中文
}
}, code);
fs.writeFileSync(inputPath, output.code);
// 验证
try {
babel.parseSync(output.code, { sourceType: 'script' });
console.log('✅ 语法正确');
} catch (e) {
console.error('❌ 语法错误:', e.message);
}
// 统计
const unicodeRemaining = (output.code.match(/\\u[0-9a-fA-F]{4}/g) || []).length;
console.log(`剩余 Unicode 转义: ${unicodeRemaining}`);
console.log(`文件大小: ${(output.code.length / 1024).toFixed(2)} KB`);