Skip to content

Commit

Permalink
15.AST代码还原案例
Browse files Browse the repository at this point in the history
  • Loading branch information
luzhisheng committed Aug 25, 2023
1 parent f58aecc commit b304f9f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
27 changes: 27 additions & 0 deletions AST抽象语法树/15.AST代码还原案例/1-2020-06-09.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const fs = require('fs');
const {parse} = require("@babel/parser");
const traverse = require("@babel/traverse").default;
const generator = require("@babel/generator").default;
const types = require('@babel/types');
let encode_file = "./1-encode-2020-06-09.js";

let js_code = fs.readFileSync(encode_file, {encoding: "utf-8"});
let ast = parse(js_code, {
sourceType: 'module',
});

const visitor = {
CallExpression: {
enter(path) {
let {node} = path
let arguments = node.arguments
if (arguments[1].value != 'Hello AST'){
path.remove()
}
}
}
}

traverse(ast, visitor);
let {code} = generator(ast);
console.log(code)
12 changes: 12 additions & 0 deletions AST抽象语法树/15.AST代码还原案例/1-encode-2020-06-09.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var s = {
'hello': function(_0x4c52de) {
(function(_0xea7649, _0x55a64b) {
return function(_0x46f67a, _0x29dec9) {
return function(_0x56ee68, _0x1607ce) {
return _0x56ee68(_0x1607ce);
}(_0x46f67a, _0x29dec9);
}(_0xea7649, _0x55a64b);
}
)(alert, "Hello AST");
},
}

0 comments on commit b304f9f

Please sign in to comment.