ast babeljs --1( 16进制 unicode 转正常)
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 = ["\x67\x65\x74\x41\x74\x74\x72\x69\x62\x75\x74\x65", "\x41\x63\x74\x69\x76\x65\x58\x4f\x62\x6a\x65\x63\x74"]
转变成
var _ac = ["getAttribute", "ActiveXObject"]