mirror of
https://github.com/luzhisheng/js_reverse.git
synced 2025-04-12 11:37:09 +08:00
15.AST代码还原案例
This commit is contained in:
parent
b304f9f37b
commit
c373c690cd
19
AST抽象语法树/15.AST代码还原案例/万能数组还原插件.js
Normal file
19
AST抽象语法树/15.AST代码还原案例/万能数组还原插件.js
Normal file
@ -0,0 +1,19 @@
|
||||
//这里填入 数组的声明与定义
|
||||
let arrName = "XXX"; //XXX 为你要还原的数组名
|
||||
|
||||
const replaceArrayElements =
|
||||
{
|
||||
MemberExpression: {
|
||||
exit(path) {
|
||||
let {object, property} = path.node;
|
||||
if (!types.isIdentifier(object, {name: arrName}) ||
|
||||
!types.isNumericLiteral(property)) {
|
||||
return;
|
||||
}
|
||||
let value = eval(path.toString());
|
||||
path.replaceWith(types.valueToNode(value));
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
traverse(ast, replaceArrayElements);
|
Loading…
x
Reference in New Issue
Block a user