https://bbs.nightteam.cn/thread-423.htm
// 将js代码转换成AST const { parse } = require("@babel/parser"); // 用来遍历AST中的节点 const traverse = require("@babel/traverse").default; // AST转换成js const generator = require("@babel/generator").default; // 用来判断节点类型和生成新的节点 const t = require("@babel/types"); const fs = require("fs"); const jscode = fs.readFileSync("./demo.js", { encoding: "utf-8" }); let ast = parse(jscode); function delExtra(path) { var curNode = path.node; delete curNode.extra; }; traverse(ast, { StringLiteral: delExtra, NumericLiteral: delExtra } ); let code = generator(ast).code; fs.writeFile('./demoNew.js', code, (err) => { });
var _ac = ["x67x65x74x41x74x74x72x69x62x75x74x65", "x41x63x74x69x76x65x58x4fx62x6ax65x63x74"]
转变成
var _ac = ["getAttribute", "ActiveXObject"]