js逆向分析之acorn和escodegen的使用

替换之前的d形如

d("77696669")

执行代码

const fs = require('fs');
const acorn = require('acorn');
const walk = require("acorn-walk")
const escodegen = require('escodegen');

function d(b) {
    var a, c = "";
    for (a = 0; a < b.length; a += 2) c += String.fromCharCode(parseInt(b.slice(a, a + 2), 16));
    return c
}

const content = fs.readFileSync('m301650.js');
const ast = acorn.parse(content);
walk.simple(ast, {
    CallExpression(node) {
        if (node.callee.name === 'd' && node.arguments[0].type === 'Literal') {
            node.type = 'Literal';
            node.value = d(node.arguments[0].value);
        }
    }
});
const decodedContent = escodegen.generate(ast);
fs.writeFileSync('m301650.decoded.js', decodedContent);

替换之后的

就是一个字符串

script
posted @ 2019-12-09 18:14  公众号python学习开发  阅读(1697)  评论(0编辑  收藏  举报