/**
 * 测试 _0x4ff4 数组内容
 */
const fs = require('fs');
const vm = require('vm');

const inputPath = 'D:/temp/破解/cursorpro-0.4.5/deobfuscated_full/extension/out/webview/provider_clean.js';

let code = fs.readFileSync(inputPath, 'utf8');

// 找到 _0x4ff4 函数的结束位置
const arrayFuncStart = code.indexOf('function _0x4ff4()');
let braceCount = 0;
let arrayFuncEnd = arrayFuncStart;
let started = false;
for (let i = arrayFuncStart; i < code.length; i++) {
    if (code[i] === '{') {
        braceCount++;
        started = true;
    } else if (code[i] === '}') {
        braceCount--;
        if (started && braceCount === 0) {
            arrayFuncEnd = i + 1;
            break;
        }
    }
}

const initCode = code.slice(0, arrayFuncEnd);

// 执行并获取数组
const vmCode = `
${initCode}

// 获取数组
var arr = _0x4ff4();
({
    length: arr.length,
    first10: arr.slice(0, 10),
    sample: arr.slice(100, 110),
    last10: arr.slice(-10)
});
`;

const sandbox = { vip: 'cursor' };
const context = vm.createContext(sandbox);
const script = new vm.Script(vmCode, { timeout: 60000 });
const result = script.runInContext(context, { timeout: 60000 });

console.log('数组长度:', result.length);
console.log('\n前10个元素:');
result.first10.forEach((item, i) => console.log(`  [${i}]: ${item.slice(0, 60)}${item.length > 60 ? '...' : ''}`));

console.log('\n100-109 元素:');
result.sample.forEach((item, i) => console.log(`  [${100+i}]: ${item.slice(0, 60)}${item.length > 60 ? '...' : ''}`));

console.log('\n最后10个元素:');
result.last10.forEach((item, i) => console.log(`  [${result.length - 10 + i}]: ${item.slice(0, 60)}${item.length > 60 ? '...' : ''}`));
