/**
 * 继续批量修复
 */
const fs = require('fs');

const inputPath = 'D:/temp/破解/cursorpro-0.4.5/deobfuscated_full/extension/out/webview/provider.js';
let code = fs.readFileSync(inputPath, 'utf8');

const replacements = {
    // 模块辅助
    'var7': 'getOwnPropNames',
    'var9': 'propKey',

    // 循环/遍历变量
    'v97': 'lineItem',
    'v416': 'subDir',
    'v424': 'subItem',
    'v404': 'fileItem',
    'v396': 'dirEntry',
    'v409': 'childPath',
    'v513': 'appDir',
    'v528': 'subPath',

    // 路径变量
    'var167': 'dbPath',
    'var189': 'storagePath',
    'var201': 'machineIdPath',
    'var383': 'cursorDbPath',
    'var627': 'backupDir',
    'var623': 'originalCode',
    'var675': 'modifiedCode',
    'var582': 'seamlessPath',
    'var723': 'workbenchContent',
    'var794': 'newContent',

    // 其他
    'var605': 'resourcePath',
};

let count = 0;
for (const [oldName, newName] of Object.entries(replacements)) {
    const regex = new RegExp('\\b' + oldName + '\\b', 'g');
    const matches = code.match(regex);
    if (matches) {
        code = code.replace(regex, newName);
        console.log(`${oldName} -> ${newName} (${matches.length})`);
        count++;
    }
}

fs.writeFileSync(inputPath, code);
console.log(`\n替换了 ${count} 个`);

const remaining = [...new Set((code.match(/\b(var|arg|v)\d+\b/g) || []))];
console.log(`剩余: ${remaining.length} 个`);
