{"id":8905,"date":"2023-09-07T14:09:55","date_gmt":"2023-09-07T06:09:55","guid":{"rendered":"\/?p=8905"},"modified":"2023-09-07T14:11:46","modified_gmt":"2023-09-07T06:11:46","slug":"ast%e8%bf%98%e5%8e%9f%e6%b7%b7%e6%b7%86%e5%ae%9e%e6%88%98","status":"publish","type":"post","link":"\/?p=8905","title":{"rendered":"AST\u8fd8\u539f\u6df7\u6dc6\u5b9e\u6218"},"content":{"rendered":"<h2>1.\u6574\u4f53\u4ee3\u7801\u7ed3\u6784<\/h2>\n<p>\u672c\u7ae0\u4ee5\u4e00\u4e2a\u5b9e\u9645\u6848\u4f8b\uff0c\u6765\u4ecb\u7ecd AST \u5728\u8fd8\u539f JavaScript (\u4ee5\u4e0b\u7b80\u79f0JS) \u6df7\u6dc6\u4e0a\u7684\u5e94\u7528\u3002<\/p>\n<p>\u5f53\u7136\u5728\u8fd8\u539f\u4e4b\u524d\uff0c\u5fc5\u8981\u7684\u534f\u8bae\u5206\u6790\u4ee5\u53ca\u7f51\u7ad9\u4f7f\u7528\u4e86\u54ea\u4e9b\u6df7\u6dc6\u65b9\u6848\uff0c\u8fd8\u662f\u8981\u5206\u6790\u6e05\u695a\u7684\u3002<\/p>\n<p>AST \u8fd8\u539f\u540e\u7684 JS \u6587\u4ef6\u5e76\u4e0d\u662f\u53ea\u80fd\u9759\u6001\u5206\u6790\uff0c\u5982\u679c\u8fd8\u539f\u505a\u7684\u8db3\u591f\u4f18\u79c0\uff0c\u8fd8\u53ef\u4ee5\u66ff\u6362\u5230\u539f\u7f51\u7ad9\u4e2d\u8fdb\u884c\u52a8\u6001\u8c03\u8bd5\u3002\u4e00\u8d77\u6765\u4f53\u9a8c\u4e00\u4e0bAST \u7684\u5f3a\u5927\u4e4b\u5904\u5427\u3002<\/p>\n<p><strong>\u6574\u4f53\u4ee3\u7801\u7ed3\u6784<\/strong>\uff1a<\/p>\n<pre><code class=\"language-javascript\">const parser = require(&quot;@babel\/parser&quot;);\nconst traverse = require(&quot;@babel\/traverse&quot;).default;\nconst t = require(&quot;@babel\/types&quot;);\nconst generator = require(&quot;@babel\/generator&quot;).default;\nconst fs = require(&#039;fs&#039;);\n\nconst jscode = fs.readFileSync(&quot;.\/demo.js&quot;, {\n    encoding: &quot;utf-8&quot;\n});\n\nlet ast = parser.parse(jscode);\n\/\/\u6b64\u5904\u5bf9AST\u8fdb\u884c\u4e00\u7cfb\u5217\u7684\u64cd\u4f5c\n\/*\n*\n* *\/\nlet code = generator(ast).code;\nfs.writeFile(&#039;.\/demoNew.js&#039;, code, (err)=&gt;{});<\/code><\/pre>\n<p>\u9996\u5148\u4f7f\u7528require\u52a0\u8f7d\u5fc5\u8981\u7684\u4ee5\u6765\uff0c\u7136\u540e\u8bfb\u53d6JS\u6587\u4ef6\u4e2d\u7684\u4ee3\u7801\uff0c\u7528parser\u7ec4\u4ef6\u89e3\u6790\u6210ast,\u63a5\u7740\u5bf9ast\u8fdb\u884c\u4e00\u7cfb\u5217\u7684\u64cd\u4f5c\uff0c\u6700\u540e\u628aast\u8f6c\u4e3a\u5b57\u7b26\u4e32\uff0c\u4fdd\u5b58\u5230\u65b0\u6587\u4ef6\u3002<\/p>\n<h2>2.\u5b57\u7b26\u4e32\u89e3\u5bc6\u4e0e\u53bb\u9664\u6570\u7ec4\u6df7\u6dc6<\/h2>\n<p>\u6839\u636e\u524d\u9762\u51e0\u5c0f\u8282\u7684\u5206\u6790\u53ef\u77e5\uff0c\u539f\u4ee3\u7801\u4e2d\u6700\u5f00\u59cb\u5904\u5b9a\u4e49\u4e86\u4e00\u4e2a\u5927\u6570\u7ec4\uff0c\u7d27\u63a5\u7740\u662f\u4e00\u4e2a\u7528\u4e8e\u8fd8\u539f\u6570\u7ec4\u987a\u5e8f\u7684\u533f\u540d\u81ea\u6267\u884c\u7684\u51fd\u6570\uff0c\u7136\u540e\u8ddf\u7740\u4e00\u4e2a\u5b57\u7b26\u4e32\u89e3\u5bc6\u7684\u51fd\u6570\u3002\u800c\u8981\u8c03\u7528\u5b57\u7b26\u4e32\u89e3\u5bc6\u51fd\u6570\uff0c\u53c8\u5fc5\u987b\u5148\u5f97\u5230\u5927\u6570\u7ec4\u548c\u7528\u4e8e\u8fd8\u539f\u6570\u7ec4\u987a\u5e8f\u7684\u533f\u540d\u81ea\u6267\u884c\u51fd\u6570\u3002\u6765\u770b\u4e00\u4e0b\u539f\u4ee3\u7801\u7684\u6574\u4f53\u7ed3\u6784:<\/p>\n<pre><code class=\"language-javascript\">console.log(ast.program.body):\n\/*\n    Node {type:&#039;VariableDeclaration&#039;, ... declarations: Array(1)}\n    Node {type:&#039;ExpressionStatement&#039;, ... expression: Node}\n    Node {type:&#039;Variablebeclaration&#039;, ... declarations: Array(l)}\n    Node {type:&#039;Expressionstatement&#039;, ... expression:Node}\n    Node {type:&#039;VariableDeclaration&#039;, ... declarations: Array(l)}\n    Node {type:&#039;VariableDeclaration&#039;, ... declarations: Array(l)}\n    Node {type:&#039;VariableDeclaration&#039;, ... declarations: Array(1)}\n    Node {type:&#039;ExpressionStatement&#039;, ... expression: Node}\n*\/<\/code><\/pre>\n<p>\u8981\u5b8c\u6210\u5b57\u7b26\u4e32\u89e3\u5bc6\uff0c\u5148\u8981\u5f97\u5230\u539f\u4ee3\u7801\u4e2d\u7684\u524d\u4e09\u90e8\u5206\u4ee3\u7801\uff0c\u5176\u4e2d\u7b2c\u4e09\u90e8\u5206\u4e3a\u5b57\u7b26\u4e32\u89e3\u5bc6\u51fd\u6570\uff0c\u8fd8\u9700\u8981\u62ff\u5230\u5b57\u7b26\u4e32\u89e3\u5bc6\u51fd\u6570\u7684\u540d\u5b57\u3002<\/p>\n<pre><code class=\"language-javascript\">\/\/\u62ff\u5230\u89e3\u5bc6\u51fd\u6570\u6240\u5728\u8282\u70b9\nlet stringDecryptFuncAst = ast.program.body[2];\n\/\/\u62ff\u5230\u89e3\u5bc6\u51fd\u6570\u7684\u540d\u5b57\nlet DecryptFuncName = stringDecryptFuncAst.declarations[0].id.name;\n\/\/\u65b0\u5efa\u4e00\u4e2a AST\uff0c\u628a\u539f\u4ee3\u7801\u4e2d\u7684\u524d\u4e09\u90e8\u5206\uff0c\u52a0\u5165\u5230 body \u8282\u70b9\u4e2d\nlet newAst = parser.parse(&#039;&#039;);\nnewAst.program.body.push(ast.program.body[0]);\nnewAst.program.body.push(ast.program.body[1]);\nnewAst.program.body.push(stringDecryptFuncAst);\n\/\/\u628a\u8fd9\u4e09\u90e8\u5206\u7684\u4ee3\u7801\u8f6c\u4e3a\u5b57\u7b26\u4e32\uff0c\u7531\u4e8e\u5b58\u5728\u683c\u5f0f\u5316\u68c0\u6d4b\uff0c\u9700\u8981\u6307\u5b9a\u9009\u9879\uff0c\u6765\u538b\u7f29\u4ee3\u7801\nlet stringDecryptFunc = generator(newAst, {compact: true}).code;\n\/\/\u5c06\u5b57\u7b26\u4e32\u5f62\u5f0f\u7684\u4ee3\u7801\u6267\u884c\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u5728 nodejs \u4e2d\u8fd0\u884c\u89e3\u5bc6\u51fd\u6570\u4e86\neval(stringDecryptFunc);<\/code><\/pre>\n<p>\u8fd9\u91cc\u518d\u6b21\u5f3a\u8c03\uff0c\u7531\u4e8e\u6e90\u4ee3\u7801\u4e2d\u5b58\u5728\u683c\u5f0f\u5316\u68c0\u6d4b\u548c\u5185\u5b58\u7206\u7834\u4ee3\u7801\uff0c\u6240\u4ee5\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u751f\u6210\u5b57\u7b26\u4e32\u4ee3\u7801\u7684\u65f6\u5019\uff0c\u9700\u8981\u6307\u5b9a\u9009\u9879\uff0c\u4f7f\u7528\u538b\u7f29\u540e\u7684\u4ee3\u7801\u6765\u6267\u884c\uff0c\u5426\u5219\u5185\u5b58\u4f1a\u6ea2\u51fa\u3002<\/p>\n<p>\u73b0\u5728nodejs\u4e2d\u5df2\u7ecf\u6709\u89e3\u5bc6\u51fd\u6570\u4e86\uff0c\u90a3\u4e48\u63a5\u4e0b\u53bb\u5c31\u53ef\u4ee5\u76f4\u63a5\u8ba1\u7b97\u7c7b\u4f3c<code>_0x2ba9(0x0)<\/code>\u8fd9\u79cd\u8282\u70b9\uff0c\u5e76\u7528\u7ed3\u679c\u66ff\u6362\u5b83\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-javascript\">traverse(ast, {\n    \/\/\u904d\u5386\u6240\u6709\u53d8\u91cf\n    VariableDeclarator(path){\n        \/\/\u5f53\u53d8\u91cf\u540d\u4e0e\u89e3\u5bc6\u51fd\u6570\u540d\u76f8\u540c\u65f6\uff0c\u5c31\u6267\u884c\u76f8\u5e94\u64cd\u4f5c\n        if(path.node.id.name == DecryptFuncName){\n            let binding = path.scope.getBinding(DecryptFuncName);\n            \/\/\u5982\u679cbinding\u5b58\u5728\uff0c\u5219\u6267\u884c...map\u904d\u5386\n            binding &amp;&amp; binding.referencePaths.map(function(v){\n                v.parentPath.isCallExpression() &amp;&amp;\n                v.parentPath.replaceWith(t.stringLiteral(\n                    \/\/\u8282\u70b9\u8f6c\u4ee3\u7801\uff0c\u5f97\u5230\u5b57\u7b26\u4e32\u89e3\u5bc6\u540e\u7684\u7ed3\u679c\n                    eval(v.parentPath + &#039;&#039;)));\n            });\n        }\n    }\n});\n\/\/\u5b57\u7b26\u4e32\u89e3\u5bc6\u4ee5\u540e\uff0c\u539f\u4ee3\u7801\u7684\u524d\u4e09\u90e8\u5206\u5c31\u6ca1\u7528\u4e86\uff0c\u53ef\u4ee5\u53bb\u6389\nast.program.body.shift();\nast.program.body.shift();\nast.program.body.shift();\n\/*_0x2ba9(0xa1) \u5728AST Explorer \u7f51\u7ad9\u4e2d\u89e3\u6790\u540e\u7684\u7ed3\u6784\u4e3a\n    Node{\n        type: &#039;CallExpression&#039;,\n        ...\n        callee: Node { type: &#039;Identifier&#039;, ... name: &#039;_0x2ba9&quot;},\n        arguments: [\n            Node { type: &#039;StringLiteral&#039;, ... value:  &#039;Oxal&#039; }\n        ]\n    }\n*\/<\/code><\/pre>\n<h2>3.\u5254\u9664\u82b1\u6307\u4ee4<\/h2>\n<h3>1.\u82b1\u6307\u4ee4\u5254\u9664\u601d\u8def<\/h3>\n<p>\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-javascript\">var _0x1f20d3 = { ...\n        &#039;ZFmTI&#039;: function (_0x4e4bbb, _0x19e1fa) {\n            return _0x4e4bbb + _0x19e1fa;\n        },\n        &#039;aOJeX&#039;: &quot;\/yzmtest\/get.php?t=&quot;,  ... \n}\nvar _0x22b277 = { ...\n        &#039;etrqc&#039;: function (_0x3fb552, _0x5f9394) {\n            return _0x1f20d3[&quot;ZFmTI&quot;](_0x3fb552, _0x5f9394);\n          },\n        &#039;oiFIc&#039;: _0x1f20d3[&quot;aOJeX&quot;], ...\n}\n\/\/ _0x22b277[&#039;oiFIc&#039;] \u5b57\u7b26\u4e32\u82b1\u6307\u4ee4&#039;\n\/\/ _0x22b277[&#039;etrqc&#039;] \u51fd\u6570\u82b1\u6307\u4ee4<\/code><\/pre>\n<p>\u7528\u4e0a\u8ff0\u4f8b\u5b50\u6765\u8bf4\u660e\u82b1\u6307\u4ee4\u5254\u9664\u7684\u601d\u8def\u3002\u5927\u4f53\u4e0a\u53ef\u4ee5\u5206\u4e3a\u4e24\u79cd\u60c5\u51b5\u3002<\/p>\n<h4>\u5b57\u7b26\u4e32\u82b1\u6307\u4ee4\u7684\u522b\u9664<\/h4>\n<p>\u5bf9\u4e8e\u5b57\u7b26\u4e32\u82b1\u6307\u4ee4 _0x22b277['oiFIc']\uff0c\u53ef\u4ee5\u8ffd\u5386\u6240\u6709 MemberExpression\u8282\u70b9\uff0c\u53d6\u51fa object \u8282\u70b9\u540d\u548c property \u8282\u70b9\u503c\u3002\u5728 ObjectExpression \u8282\u70b9\u4e2d\u627e\u5230\u5bf9\u5e94\u7684\u503c\uff0c\u5982\u679c\u7c7b\u578b\u8fd8\u662f\u4e3a <strong>MemberExpression<\/strong>\uff0c\u5c31\u8bf4\u660e\u8fd8\u9700\u8981\u7ee7\u7eed\u627e\uff0c\u7ee7\u7eed\u53d6\u51faobject \u8282\u70b9\u540d\u548c property \u8282\u70b9\u503c\uff0c\u7ee7\u7eed\u5728 ObjectExpression \u8282\u70b9\u4e2d\u627e\u5230\u5bf9\u5e94\u7684\u503c\uff0c\u76f4\u5230\u627e\u5230\u7684\u503c\u7c7b\u578b\u4e3a <strong>StringLiteral<\/strong>\uff0c\u5c31\u8fdb\u884c\u66ff\u6362\u5373\u53ef\u3002\u56e0\u6b64\u9700\u8981\u7528\u5230\u9012\u5f52\u3002<\/p>\n<h4>\u51fd\u6570\u82b1\u6307\u4ee4\u7684\u53bb\u9664<\/h4>\n<p>\u5bf9\u4e8e\u51fd\u6570\u82b1\u6307\u4ee4 _0x22b277['etrgc']\uff0c\u4e5f\u662f\u8ffd\u5386\u6240\u6709MemberExpression \u8282\u70b9\u53d6\u51fa object \u8282\u70b9\u540d\u548c property \u8282\u70b9\u503c\u3002\u5728 ObjectExpression \u8282\u70b9\u4e2d\u627e\u5230\u5bf9\u5e94\u7684\u503c\uff0c\u5982\u679c\u7c7b\u578b\u4e3a FunctionExpression \u5e76\u4e14\u51fd\u6570\u4f53\u5185\u90e8\u6709 <strong>Membertxpression<\/strong> \u8282\u70b9\uff0c\u5c31\u8bf4\u660e\u8fd8\u9700\u8981\u7ee7\u7eed\u627e\uff0c\u76f4\u5230\u627e\u5230\u7c7b\u578b\u4e3a <strong>FunctionExpression<\/strong> \u5e76\u4e14\u51fd\u6570\u4f53\u5185\u90e8\u6ca1MemberExpression \u8282\u70b9\uff0c\u624d\u662f\u6700\u7ec8\u9700\u8981\u7684\u8282\u70b9\u3002<\/p>\n<p>\u5728ObjectExpression\u8282\u70b9\u4e2d\u627e\u5230\u5bf9\u5e94\u7684\u503c\u6709\u4e00\u4e2a\u6bd4\u8f83\u7b80\u5355\u7684\u65b9\u5f0f\uff0c\u53ef\u4ee5\u5728nodejs\u4e2d\u5b9a\u4e49\u4e00\u4e2atotalObj\u5bf9\u8c61\uff0c\u7136\u540e\u89e3\u6790\u539f\u59cb\u4ee3\u7801\u4e2d\u6240\u6709\u7684ObjectExpression,\u52a0\u5165\u5230totalObj\u5bf9\u8c61\u4e2d\uff0c\u6700\u540e\u628atotalObj\u5bf9\u8c61\u53d8\u6210\u5982\u4e0b\u7ed3\u6784\uff1a<\/p>\n<pre><code class=\"language-javascript\">{\n    _0x1f20d3: {\n        &#039;ZFmTI&#039;: Node {...},\n        &#039;aOJex&#039;: Node {...},\n        &#039;EDRDI&#039;: Node {...},\n        ...\n    },\n    _0x22b277: {\n        &#039;etrqc&#039;: Node {...},\n        &#039;oiFIc&#039;: Node {...},\n        ...\n    },\n    ...\n}<\/code><\/pre>\n<p>\u5728nodejs\u4e2d\u7ec4\u5408\u51fa\u8fd9\u6837\u7684\u7ed3\u6784\u540e\uff0c\u5982\u679c\u8981\u83b7\u53d6 <code>_0x22b277[&#039;oiFIc&#039;]<\/code>\u7684\u5b9a\u4e49\u90e8\u5206\u7684\u8282\u70b9\uff0c\u53ea\u9700\u8981\u4f7f\u7528<code>totalObj[&#039;_0x22b277&#039;][&#039;oiFIc&#039;]<\/code>\u6765\u83b7\u53d6Node\u8282\u70b9\u3002\u751f\u6210totalObj\u5bf9\u8c61\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-javascript\">var totalObj = {};\nfunction generatorobj(ast) {\n    traverse(ast, {\n        VariableDeclarator(path) {\n            \/\/init \u8282\u70b9\u4e3aObjectExpression \u7684\u65f6\u5019\uff0c\u5c31\u662f\u9700\u8981\u5904\u7406\u7684\u5bf9\u8c61\n            if(t.isObjectExpression(path.node.init)){\n                \/\/\u53d6\u51fa\u5bf9\u8c61\u540d\n                let objName = path.node.id.name;\n                \/\/\u4ee5\u5bf9\u8c61\u540d\u4f5c\u4e3a\u5c5e\u6027\u540d\u5728 totalObj \u4e2d\u521b\u5efa\u5bf9\u8c61\n                objName &amp;&amp; (totalObj[objName] = totalObj[objname] || {});\n                \/\/\u89e3\u6790\u5bf9\u8c61\u4e2d\u7684\u6bcf\u4e00\u4e2a\u5c5e\u6027\uff0c\u52a0\u5165\u5230\u65b0\u5efa\u7684\u5bf9\u8c61\u4e2d\u53bb\uff0c\u6ce8\u610f\u5c5e\u6027\u503c\u4f9d\u7136\u662f Node \u7c7b\u578b\n                totalObj[objName] &amp;&amp; path.node.init.properties.map(\n                    function(p){\n                        totalObj[objName][p.key.value] = p.value;\n                                          });\n            }\n        }\n    });\n    return ast\n}\nast = generatorObj(ast);\n\nNode {\n    type: &#039;VariableDeclarator&#039;, ...\n    id: Node { type: &#039;Identifier&#039;, ...name: &#039;_x1f20d3&#039;},\n    init: Node {type: &#039;ObjcetExpression&#039;, ...\n                    properties: [[Node], [Node], [Node], ...]}\n}\n\/\/ properties\u4e2d\u7684\u6bcf\u4e00\u4e2aObjectProperty\u7ed3\u6784\u4e3a\nNode {\n    type: &#039;ObjectProperty&#039;, ...\n    method: false,\n    key: Node { type: &#039;StringLiteral&#039;, ...value: &#039;NmgQU&#039;},\n    computed: false,\n    shorthand: false,\n    value: {type: &#039;StringLiteral&#039;, value: &#039;submit&#039;, ...}\n}<\/code><\/pre>\n<h3>2.\u5b57\u7b26\u4e32\u82b1\u6307\u4ee4\u7684\u5254\u9664<\/h3>\n<p>\u73b0\u5728\u53ef\u4ee5\u7740\u624b\u53bb\u9664\u82b1\u6307\u4ee4\u4e86\uff0c\u5b57\u7b26\u4e32\u82b1\u6307\u4ee4\u6bd4\u8f83\u5bb9\u6613\u53bb\u9664\uff0c\u904d\u5386 ObjectExpression \u8282\u70b9\u7684properties \u5c5e\u6027\uff0c\u6bcf\u5f97\u5230\u4e00\u4e2a ObjectProperty\u7684 value \u503c\uff0c\u90fd\u9012\u5f52\u627e\u5230\u771f\u5b9e\u7684\u5b57\u7b26\u4e32\u540e\u8fdb\u884c\u66ff\u6362\u3002\u4ee3\u7801\u5982\u4e0b:<\/p>\n<pre><code class=\"language-javascript\">traverselast, {\n    VariableDeclarator (path) {\n        if(t.isObjectExpression (path ,node,init)) {\n            path.node.init.properties.map(function (p) {\n                let realNode = findRealValue(p.value);\n                realNode &amp;&amp; (p.value = realNode);\n            });\n        };\n    }\n});\n\/*\n    var _0x1f20d3 = { &#039;aOJex&#039;: \/yzmtest\/get.php?t=&quot;, ...}\n    var 0x22b277 = { &#039;oiFIc&#039;: _0x1r20d3{&#039;aOJex&#039;&#039;}, ... }\n    \/\/\u5904\u7406\u540e\u53d8\u4e3a\u5982\u4e0b\u5f62\u5f0f\uff0c\u4e0d\u7ba1\u4ee3\u7801\u4e2d\u8c03\u7528\u54ea\u4e2a\u5bf9\u8c61\u4e2d\u7684\u5c5e\u6027\uff0c\u90fd\u662f\u771f\u5b9e\u5b57\u7b26\u4e32\uff0c\u6700\u540e\u7edf\u4e00\u66ff\u6362\u5373\u53ef\n    var _0x1r20d3 = { &#039;aOJex&#039;: &#039;\/yzmtest\/get,php?t=&#039;, ... }\n    var _0x22b277 = { &#039;oiFIc&#039;: &#039;\/yzmtest\/get.php?t=&#039;, ... }\n*\/<\/code><\/pre>\n<p>\u90a3\u4e48 findRealValue \u51fd\u6570\u5982\u4f55\u5b9e\u73b0\u5462? \u6839\u636e\u524d\u9762\u5bf9\u539f\u4ee3\u7801\u7684\u5206\u6790\u53ef\u77e5\uff0cObjectProperty\u7684value \u503c\u6709\u4e09\u79cd\u7c7b\u578b,\u5206\u522b\u662fMemberExpression,FunctionExpression \u548c StringLiteral\u3002\u5148\u4e0d\u5904\u7406 FunctionExpression \u8282\u70b9\uff0c\u800c StringLiteral \u8282\u70b9\u5c31\u662f\u771f\u5b9e\u7684\u5b57\u7b26\u4e32\u4e5f\u4e0d\u7528\u5904\u7406\u6240\u4ee5\u53ea\u9700\u5904\u7406 MemberExpression \u8282\u70b9\u3002\u5b9e\u73b0\u7684\u4ee3\u7801\u5982\u4e0b:<\/p>\n<pre><code class=\"language-javascript\">function findRealValue(node) {\n    if (t.isMemberExpression(node)) {\n        let objName = node.object.name;\n        let propName = node.property.value;\n        if (totalObj[objName][propName]) {\n            \/\/\u9012\u5f52\n            return findRealValue(totalObj[objName][propName]);\n        } else {\n            return false;\n        }\n    } else {\n        return node;\n    }\n}\n\/\/\u5254\u9664\u5b57\u7b26\u4e32\u82b1\u6307\u4ee4\u4ee5\u540e\uff0c\u66f4\u65b0totalObj\u5bf9\u8c61\nast = generatorObj(ast);\n\n\/*\n    var _0x1f20d3 = { &#039;a0JeX&#039;: &#039;\/yzmtest\/get.php?t=&#039;, ...}\n    var _0x22b277 = { &#039;a0JeX&#039;: &#039;\/yzmtest\/get.php?t=&#039;, ...}\n*\/<\/code><\/pre>\n<p>\u4ee5\u4e0a\u8ff0\u4ee3\u7801\u4e2d\u7684\u6ce8\u91ca\u4e3a\u4f8b\uff0c\u5047\u5982\u4f20\u7ed9 findReaValue \u7684\u53c2\u6570\u4e3a _0x1f20d3['aoJex']\u8282\u70b9\uff0c\u8fd9\u662f\u4e00\u4e2a MemberExpression \u8282\u70b9\uff0c\u56e0\u6b64\u4f1a\u53d6\u51fa '_0x1f20d3'\uff0c\u8d4b\u503c\u7ed9 objName\uff0c\u53d6\u51fa'aoJeX'\u8d4b\u503c\u7ed9propName,\u7136\u540e\u83b7\u53d6<code>totalObj[&#039;0x1t20d3&#039;][&#039;aoJex&#039;]<\/code>\u4e2d\u5b58\u653e\u7684Node\u8282\u70b9\uff0c\u7ee7\u7eed\u4f20\u5165\u5230findRealValue \u4e2d\u8fdb\u884c\u9012\u5f52\u3002\u8fd9\u65f6\u5019\u4f20\u5165\u7684\u662f'\/yzmtest\/get.php?t='\uff0c\u5e76\u975e\u6210\u5458\u8868\u8fbe\u5f0f\uff0c\u56e0\u6b64\u76f4\u63a5\u8fd4\u56de\u539f\u8282\u70b9\u3002\u4e00\u8def\u8fd4\u56de\uff0c\u6700\u540e\u6267\u884c realNode &amp;&amp; (p.value = realNode)\u8fdb\u884c\u8282\u70b9\u66ff\u6362\u3002<br \/>\n\u4e0a\u8ff0\u8fc7\u7a0b\u53ea\u662f\u628a ObjectExpression \u8282\u70b9\u7684\u5c5e\u6027\u503c\u90fd\u5904\u7406\u4e86\u4e00\u4e0b\uff0c\u6700\u540e\u8fd8\u8981\u5bf9\u4ee3\u7801\u4e2d\u5f15\u7528\u7684\u5730\u65b9\u90fd\u8fdb\u884c\u66ff\u6362(\u66ff\u6362\u4e4b\u524d\u8bb0\u5f97\u66f4\u65b0 totalObj \u5bf9\u8c61)\u3002\u5b9e\u73b0\u7684\u4ee3\u7801\u5982\u4e0b:<\/p>\n<pre><code class=\"language-javascript\">traverse(ast, {\n    VariableDeclarator(path) {\n        if (t.isObjectExpression(path.node.init)) {\n            path.node.init.properties.map(function (p) {\n                let realNode = findRealValue(p.value);\n                realNode &amp;&amp; (p.value = realNode);\n            });\n        };\n    }\n});<\/code><\/pre>\n<p>\u904d\u5386\u6240\u6709MemberExpression\u8282\u70b9\uff0c\u53bb\u9664objName\u548cprop Name\uff0c\u53ea\u8981\u5bf9\u5e94\u8282\u70b9\u5728totalObj\u5bf9\u8c61\u4e2d\u5b58\u5728\uff0c\u5e76\u4e14\u7c7b\u578b\u4e3aStringLiteral\uff0c\u5c31\u8fdb\u884c\u4e86\u66ff\u6362\u3002<\/p>\n<p>\u4ee5\u539f\u59cb\u4ee3\u7801\u4e2d\u7ecf\u8fc7\u5b57\u7b26\u4e32\u89e3\u5bc6\u4ee5\u540e\u7684\u67d0\u6bb5\u4ee3\u7801\u4e3a\u4f8b\uff0c\u8fd8\u539f\u524d\u540e\u7684\u4ee3\u7801\u5206\u522b\u4e3a\uff1a<\/p>\n<pre><code class=\"language-javascript\">\/\/\u8fd8\u539f\u524d\nvar _0x167f85 = _0x120d3[&quot;oseqj&quot;][&quot;split&quot;](&#039;|&#039;), _0x57e351 = 0x0;\n\/\/\u8fd8\u539f\u540e\nvar 0x167E85 =&quot;2|9|3|10|12|0|15|7|6|4|1|8|16|5|11|17|13|14|18&quot;[&quot;split&quot;](&#039;|&#039;)<\/code><\/pre>\n<p>\u6b64\u65f6\u5b8c\u6574\u4ee3\u7801\uff1a<\/p>\n<pre><code class=\"language-javascript\">const parser = require(&quot;@babel\/parser&quot;);\nconst traverse = require(&quot;@babel\/traverse&quot;).default;\nconst t = require(&quot;@babel\/types&quot;);\nconst generator = require(&quot;@babel\/generator&quot;).default;\nconst fs = require(&#039;fs&#039;);\n\nconst jscode = fs.readFileSync(&quot;.\/demo.js&quot;, {\n    encoding: &quot;utf-8&quot;\n});\n\nlet ast = parser.parse(jscode);\n\n\/\/\u62ff\u5230\u89e3\u5bc6\u51fd\u6570\u6240\u5728\u8282\u70b9\nlet stringDecryptFuncAst = ast.program.body[2];\n\/\/\u62ff\u5230\u89e3\u5bc6\u51fd\u6570\u7684\u540d\u5b57\nlet DecryptFuncName = stringDecryptFuncAst.declarations[0].id.name;\n\/\/\u65b0\u5efa\u4e00\u4e2a AST\uff0c\u628a\u539f\u4ee3\u7801\u4e2d\u7684\u524d\u4e09\u90e8\u5206\uff0c\u52a0\u5165\u5230 body \u8282\u70b9\u4e2d\nlet newAst = parser.parse(&#039;&#039;);\nnewAst.program.body.push(ast.program.body[0]);\nnewAst.program.body.push(ast.program.body[1]);\nnewAst.program.body.push(stringDecryptFuncAst);\n\/\/\u628a\u8fd9\u4e09\u90e8\u5206\u7684\u4ee3\u7801\u8f6c\u4e3a\u5b57\u7b26\u4e32\uff0c\u7531\u4e8e\u5b58\u5728\u683c\u5f0f\u5316\u68c0\u6d4b\uff0c\u9700\u8981\u6307\u5b9a\u9009\u9879\uff0c\u6765\u538b\u7f29\u4ee3\u7801\nlet stringDecryptFunc = generator(newAst, {compact: true}).code;\n\/\/\u5c06\u5b57\u7b26\u4e32\u5f62\u5f0f\u7684\u4ee3\u7801\u6267\u884c\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u5728 nodejs \u4e2d\u8fd0\u884c\u89e3\u5bc6\u51fd\u6570\u4e86\neval(stringDecryptFunc);\n\ntraverse(ast, {\n    \/\/\u904d\u5386\u6240\u6709\u53d8\u91cf\n    VariableDeclarator(path){\n        \/\/\u5f53\u53d8\u91cf\u540d\u4e0e\u89e3\u5bc6\u51fd\u6570\u540d\u76f8\u540c\u65f6\uff0c\u5c31\u6267\u884c\u76f8\u5e94\u64cd\u4f5c\n        if(path.node.id.name == DecryptFuncName){\n            let binding = path.scope.getBinding(DecryptFuncName);\n            binding &amp;&amp; binding.referencePaths.map(function(v){\n                v.parentPath.isCallExpression() &amp;&amp;\n                v.parentPath.replaceWith(t.stringLiteral(eval(v.parentPath + &#039;&#039;)));\n            });\n        } \n    }\n});\n\nast.program.body.shift();\nast.program.body.shift();\nast.program.body.shift();\n\nvar totalObj = {};\nfunction generatorObj(ast){\n    traverse(ast, {\n        VariableDeclarator(path){\n            \/\/init \u8282\u70b9\u4e3a ObjectExpression \u7684\u65f6\u5019\uff0c\u5c31\u662f\u9700\u8981\u5904\u7406\u7684\u5bf9\u8c61\n            if(t.isObjectExpression(path.node.init)){\n                \/\/\u53d6\u51fa\u5bf9\u8c61\u540d\n                let objName = path.node.id.name;\n                \/\/\u4ee5\u5bf9\u8c61\u540d\u4f5c\u4e3a\u5c5e\u6027\u540d\u5728 totalObj \u4e2d\u521b\u5efa\u5bf9\u8c61\n                objName &amp;&amp; (totalObj[objName] = totalObj[objName] || {});\n                \/\/\u89e3\u6790\u5bf9\u8c61\u4e2d\u7684\u6bcf\u4e00\u4e2a\u5c5e\u6027\uff0c\u52a0\u5165\u5230\u65b0\u5efa\u7684\u5bf9\u8c61\u4e2d\u53bb\uff0c\u6ce8\u610f\u5c5e\u6027\u503c\u4f9d\u7136\u662f Node \u7c7b\u578b\n                totalObj[objName] &amp;&amp; path.node.init.properties.map(function(p){\n                    totalObj[objName][p.key.value] = p.value;\n                });\n            };\n        }\n    });\n    return ast;\n}\nast = generatorObj(ast);\n\ntraverse(ast, {\n    VariableDeclarator(path) {\n        if (t.isObjectExpression(path.node.init)) {\n            path.node.init.properties.map(function (p) {\n                let realNode = findRealValue(p.value);\n                realNode &amp;&amp; (p.value = realNode);\n            });\n        };\n    }\n});\n\nfunction findRealValue(node) {\n    if (t.isMemberExpression(node)) {\n        let objName = node.object.name;\n        let propName = node.property.value;\n        if (totalObj[objName][propName]) {\n            return findRealValue(totalObj[objName][propName]);\n        } else {\n            return false;\n        }\n    } else {\n        return node;\n    }\n}\n\nast = generatorObj(ast);\n\ntraverse(ast, {\n    MemberExpression(path) {\n        let objName = path.node.object.name;\n        let propName = path.node.property.value;\n        totalObj[objName] &amp;&amp; t.isStringLiteral(totalObj[objName][propName]) &amp;&amp;\n        path.replaceWith(totalObj[objName][propName]);\n    }\n});\n\nlet code = generator(ast).code;\nfs.writeFile(&#039;.\/demoNew.js&#039;, code, (err)=&gt;{});<\/code><\/pre>\n<h3>3.\u51fd\u6570\u82b1\u6307\u4ee4\u7684\u5254\u9664<\/h3>\n<p>\u51fd\u6570\u82b1\u6307\u4ee4\u7684\u5254\u9664\u539f\u7406\u4e0e\u5b57\u7b26\u4e32\u82b1\u6307\u4ee4\u7684\u5254\u9664\u76f8\u4f3c\uff0c\u53ea\u4e0d\u8fc7\u9700\u8981\u66f4\u6539\u9012\u5f52\u7684\u51fd\u6570\uff0c\u5b9e\u73b0\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-javascript\">traverse(ast, {\n    VariableDeclarator(path) {\n        if (t.isObjectExpression(path.node.init)) {\n            path.node.init.properties.map(function (p) {\n                let realNode = findRealFunc(p.value);\n                realNode &amp;&amp; (p.value = realNode);\n            });\n        };\n    }\n});\nfunction findRealFunc(node) {\n    if (t.isFunctionExpression(node) &amp;&amp; node.body.body.length == 1) {\n        let expr = node.body.body[0].argument.callee;\n        if (t.isMemberExpression(expr)) {\n            let objName = expr.object.name;\n            let propName = expr.property.value;\n            if (totalObj[objName]) {\n                return findRealFunc(totalObj[objName][propName]);\n            } else {\n                return false;\n            }\n        }\n        return node;\n    } else {\n        return node;\n    }\n}\n\/\/\u53bb\u9664\u51fd\u6570\u82b1\u6307\u4ee4\u4ee5\u540e\uff0c\u66f4\u65b0\u4e00\u4e0b totalObj \u5bf9\u8c61\nast = generatorObj(ast);<\/code><\/pre>\n<p><strong>\u4ee5\u4e0a\u8ff0\u4ee3\u7801\u4e2d\u7684\u6ce8\u91ca\u4e3a\u4f8b,\u5c06\u5b83\u4eec\u7684\u7279\u70b9\u5f52\u7eb3\u4e3a\u4ee5\u4e0b 4 \u70b9:<\/strong><\/p>\n<ol>\n<li>\u5b83\u4eec\u90fd\u662f FunctionExpression \u8282\u70b9\u3002<\/li>\n<li>\u51fd\u6570\u4f53\u53ea\u6709\u4e00\u4e2a ReturnStatement \u8282\u70b9<\/li>\n<li>ReturnStatement \u8282\u70b9\u7684 argument \u5c5e\u6027\u7c7b\u578b\u5982\u679c\u4e0d\u662f CallExpression,\u90a3\u4e48\u8be5\u8282\u70b9\u5c31\u662f\u6700\u7ec8\u9700\u8981\u7684\u8282\u70b9\uff0c\u4f8b\u5982\u4e0a\u8ff0\u6ce8\u91ca\u4e2d\u7684 ZFmTI\u51fd\u6570\u3002<\/li>\n<li>ReturnStatement \u8282\u70b9\u7684 argument \u5c5e\u6027\u7c7b\u578b\u5982\u679c\u662f CallExpression,\u4f46\u662f\u5176 calle\u5c5e\u6027\u7c7b\u578b\u4e0d\u662f MemberExpression,\u90a3\u4e48\u8be5\u8282\u70b9\u4e5f\u662f\u6700\u7ec8\u9700\u8981\u7684\u8282\u70b9\uff0c\u4f8b\u5982\u4e0a\u8ff0\u6ce8\u91ca\u4e2d\u7684EDRDI \u51fd\u6570\u3002<\/li>\n<\/ol>\n<p>\u7efc\u4e0a\u6240\u8ff0,findRealFunc \u51fd\u6570\u6700\u7ec8\u9700\u8981\u9012\u5f52\u7684\u8282\u70b9\u7684\u7279\u70b9\u4e3a: ReturnStatement \u8282\u70b9\u7684argument \u5c5e\u6027\u7c7b\u578b\u4e3a CallExpression,\u5e76\u4e14 CallExpression \u8282\u70b9\u7684 callee \u5c5e\u6027\u7c7b\u578b\u4e3aMemberExpression.<\/p>\n<p><strong>findRealFunc\u7684\u5b9e\u73b0\u65b9\u5f0f\u4e3a:<\/strong><\/p>\n<ol>\n<li>\u7b5b\u9009\u51fa\u7c7b\u578b\u4e3a FunctionExpression,\u4e14\u51fd\u6570\u4f53\u53ea\u6709\u4e00\u884c\u4ee3\u7801\u7684\u8282\u70b9,\u5176\u4f59\u8282\u70b9\u76f4\u63a5\u8fd4\u56de\u539f\u8282\u70b9\u3002<\/li>\n<li>\u53d6\u51fa ReturnStatement \u8282\u70b9\u7684 argument \u5c5e\u6027\u4e2d\u7684 callee\u3002<\/li>\n<li>\u5982\u679c\u7b2c 2\u6b65\u5f97\u5230\u7684\u8282\u70b9\u7c7b\u578b\u4e3a MemberExpression,\u5c31\u53d6\u51fa\u5bf9\u8c61\u540d\u548c\u5c5e\u6027\u540d\uff0c\u4ecetotalObi \u4e2d\u83b7\u53d6\u5bf9\u5e94\u7684\u8282\u70b9\uff0c\u4f20\u4eba findRealFunc \u51fd\u6570\u8fdb\u884c\u9012\u5f52\u3002<\/li>\n<li>\u5982\u679c\u7b2c2\u6b65\u5f97\u5230\u7684\u662f undefined,\u5c31\u8bf4\u660e\u4e0d\u662f CallExpression \u8282\u70b9\uff0c\u8be5\u8282\u70b9\u5df2\u7ecf\u662f\u6700\u7ec8\u9700\u8981\u7684\u8282\u70b9,\u76f4\u63a5\u8fd4\u56de\u539f\u8282\u70b9\u5373\u53ef\u3002<\/li>\n<li>\u5982\u679c\u7b2c 2 \u6b65\u5f97\u5230\u7684\u4e0d\u662f undefined,\u4e5f\u4e0d\u662f MemberExpression \u8282\u70b9,\u8be5\u8282\u70b9\u5df2\u7ecf\u662f\u6700\u7ec8\u9700\u8981\u7684\u8282\u70b9,\u76f4\u63a5\u8fd4\u56de\u539f\u8282\u70b9\u5373\u53ef\u3002<\/li>\n<li>\u4e00\u76f4\u8fd4\u56de,\u6267\u884c realNode &amp;&amp; (p.value = realNode)\u66ff\u6362\u8282\u70b9<\/li>\n<\/ol>\n<p>\u4e0a\u8ff0\u8fc7\u7a0b\u53ea\u5904\u7406 ObjectExpression \u8282\u70b9\u7684\u5c5e\u6027\u503c\uff0c\u5904\u7406\u540e\u7684\u6548\u679c\u5982\u4e0b:<\/p>\n<pre><code class=\"language-javascript\">var _0x1f20d3 ={\n    &#039;ZFmTI&#039;: function (_0x4e4bbb, _0x19elfa){\n        return  _0x4e4bbb + _0x19elfa;\n    }\n    &#039;EDRDI&#039;: function( _0x247161\uff0c_0x4c4leb){\n        return _0x247161(_0x4c4leb);\n    },\n    ...\n};\nvar _0x22b277 = {\n    &#039;etrqc&#039;: function (_0x3fb552,_0x5f9394) {\n        return _0x1f20d3[&#039;ZFmTI&#039;](_0x3fb552, _0x5f9394);\n    };\n    ...\n};\n\/*\u4e0a\u9762\u7684\u4ee3\u7801\u88ab\u4fee\u6539\u4e3a\nvar _0xlf20d3 = {\n    &#039;ZFmTI&#039;: function (_0x4e4bbb, _0x19elfa) {\n        return _0x4e4bbb + _0x19elfa;\n    },\n    &#039;EDRDI&#039;: function( _0x247161, _0x4c4leb) {\n        return _0x247161(_0x4c4leb);\n    },\n    ...\n};\n\nvar _0x22b277 = {\n    &#039;etrqc&#039;: function (_0x4e4bbb, _0x19elfa) {\n        return _0x4e4bbb, _0x19elfa;\n    },\n    ...\n};\n*\/<\/code><\/pre>\n<p>\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5047\u5982\u4ee3\u7801\u4e2d\u7684\u5f15\u7528\u4e3a<code>_0x22b277[&#039;etrqe&#039;](1000\uff0c2000)<\/code>\uff0c\u8fd9\u65f6\u5019\u5e94\u5f53\u904d\u5386CallExpression \u8282\u70b9\uff0c\u5224\u65ad callee \u7684\u8282\u70b9\u7c7b\u578b\u4e3aMemberExpression\uff0c\u5c31\u53bb totalObj\u5bf9\u8c61\u4e2d\u67e5\u627e\u5bf9\u5e94\u4ee3\u7801\u8282\u70b9\u3002\u53d6\u51fa\u8be5\u4ee3\u7801\u8282\u70b9\u91cc\u9762\u7684 ReturnStatement \u4e2d\u7684argument \u5c5e\u6027,\u7136\u540e\u5224\u65ad\u8282\u70b9\u7c7b\u578b\u4e3a BinaryExpression,\u5c31\u53d6\u51fa\u5176\u4e2d\u7684 operator \u5c5e\u6027,\u4e0e\u4f20\u5165\u7684\u5b9e\u53c21000\u548c2000\u6784\u5efa\u65b0\u7684 BinaryExpression \u8282\u70b9\uff0c\u66ff\u6362\u6574\u4e2a<code>_0x22b277[&#039;etrqe&#039;](1000, 2000)<\/code><\/p>\n<p>\u518d\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5047\u5982\u4ee3\u7801\u4e2d\u7684\u5f15\u7528\u4e3a<code>_0x1f20d3[&#039;EDRDI&#039;](0x247162, 2000)<\/code>\uff0c\u8fd9\u65f6\u5019\u5e94\u5f53\u904d\u5386CallExpression \u8282\u70b9,\u5224\u65ad callee \u7684\u8282\u70b9\u7c7b\u578b\u4e3a MemberExpression,\u5c31\u53bb totalObj\u5bf9\u8c61\u4e2d\u67e5\u627e\u5bf9\u5e94\u4ee3\u7801\u8282\u70b9\u3002\u53d6\u51fa\u8be5\u4ee3\u7801\u8282\u70b9\u91cc\u9762\u7684 ReturnStatement \u4e2d\u7684argument \u5c5e\u6027,\u7136\u540e\u5224\u65ad\u8282\u70b9\u7c7b\u578b\u548cCallExpression,\u5c31\u7528\u4f20\u5165\u7684\u5b9e\u53c2\u6784\u5efa\u4e00\u4e2a\u65b0\u7684CallExpression \u8282\u70b9\uff0c_0x247162 \u4f5c\u4e3acallee\uff0c2000\u4f5c\u4e3aargument\uff0c\u6765\u66ff\u6362\u6389\u539f\u5148\u7684\u6574\u4e2a\u8282\u70b9\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u6700\u540e\u5bf9\u4ee3\u7801\u4e2d\u5f15\u7528\u7684\u5730\u65b9\u8fdb\u884c\u66ff\u6362(\u66ff\u6362\u4e4b\u524d\u8bb0\u5f97\u66f4\u65b0 totalObj \u5bf9\u8c61)\u7684\u4ee3\u7801\u5982\u4e0b:<\/p>\n<pre><code class=\"language-javascript\">traverse(ast, {\n    CallExpression(path){\n    \/\/callee \u4e0d\u4e3aMemberExpression \u7684\u8282\u70b9\uff0c\u4e0d\u505a\u5904\u7406\n    if(!t.isMemberExpression(path.node.callee)) return;\n    \/\/\u53d6\u51fa\u5bf9\u8c61\u540d\u548c\u5c5e\u6027\u540d\n    let objName = path.node.callee.object.name;\n    let propertyName = path.node.callee.property.value;\n    \/\/\u5982\u679c\u5728 totalObj \u4e2d\u6709\u76f8\u5e94\u8282\u70b9\uff0c\u5c31\u662f\u9700\u8981\u8fdb\u884c\u66ff\u6362\u7684\n    if(totalObj[objName] &amp;&amp; totalObj[objName][propertyName]){\n        \/\/totalObj \u4e2d\u5b58\u653e\u7684\u662f\u51fd\u6570\u8282\u70b9\n        let myFunc = totalObj[objName][propertyName];\n        \/\/\u5728\u539f\u4ee3\u7801\u4e2d\uff0c\u51fd\u6570\u4f53\u5176\u5b9e\u5c31\u4e00\u884c return \u8bed\u53e5\uff0c\u53d6\u51fa\u5176\u4e2d\u7684argument\u8282\u70b9\n        let returnExpr = myFunc.body.body[0].argument;\n        \/\/\u5224\u65adargument \u8282\u70b9\u7c7b\u578b\uff0c\u5e76\u4e14\u7528\u76f8\u5e94\u7684\u5b9e\u53c2\u6765\u6784\u5efa\u4e8c\u9879\u5f0f\u6216\u8005\u8c03\u7528\u8868\u8fbe\u5f0f\n        \/\/\u7136\u540e\u66ff\u6362\u5f53\u524d\u904d\u5386\u5230\u7684\u6574\u4e2a CallExpression \u8282\u70b9\u5373\u53ef\n        if(t.isBinaryExpression(returnExpr)){\n            let binExpr = t.binaryExpression(returnExpr.operator,\n                      path.node.arguments[0], path.node.arguments[1]);\n            path.replaceWith(binExpr);\n        }else if(t.isCallExpression(returnExpr)){\n            \/\/\u628aarguments \u6570\u7ec4\u4e2d\u7684\u4e0b\u6807\u4e3a1\u548c\u4ee5\u540e\u7684\u6210\u5458\uff0c\u653e\u5165 newArray \u4e2d\n            let newArray = pathnode.arguments.slice(1);\n            let callExpr = t.callExpression(path.node.arguments[0],\n                                                        newArray);\n            path .replaceWith(callExpr);\n        }\n    }\n    }\n});\n\/\/\u82b1\u6307\u4ee4\u90fd\u522b\u9664\u540e\uff0c\u539f\u4ee3\u7801\u4e2d\u7684 bjectExpression \u5c31\u53ef\u4ee5\u5220\u9664\u4e86\u3002\u5f53\u7136\u6700\u597d\u662f\u5224\u65ad\u4e0b\uff0c\u6ca1\u6709\u5f15\u7528\uff0c\u518d\u5220\ntraverse(ast, {\n    VariableDeclarator(path){\n        if(t.isObjectExpression(path.node.init)){\n            path.remove();\n        };\n    }\n});<\/code><\/pre>\n<p>\u4ee5\u8fd8\u539f\u4ee3\u7801\u4e2d\uff0c\u7ecf\u5b57\u7b26\u4e32\u89e3\u5bc6\u4ee5\u540e\u7684\u67d0\u6bb5\u4ee3\u7801\u4e3a\u4f8b\uff0c\u8fd8\u539f\u524d\u540e\u7684\u4ee3\u7801\u5206\u522b\u4e3a\uff1a<\/p>\n<pre><code class=\"language-javascript\">\/\/\u8fd8\u539f\u524d\nthis[&quot;$strlen&quot;] = _0x22b277[&quot;hdoPm&quot;](Math[&quot;floor&quot;]( 0x22b277[&quot;cdTwA&quot;](Math[&quot;random&quot;](),0x5)), 0x5);\n\/\/\u8fd8\u539f\u540e\nthis[&quot;$strlen&quot;] = Math[&quot;floor&quot;](Math[&quot;random&quot;]() * 0x5) + 0x5;<\/code><\/pre>\n<p>\u200b                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <\/p>\n<h2>4.\u8fd8\u539f\u6d41\u7a0b\u5e73\u5766\u5316<\/h2>\n<h3>1.\u83b7\u53d6\u5206\u53d1\u5668<\/h3>\n<p>\u6ce8\u610f\uff0c\u8fd8\u539f\u6d41\u7a0b\u5e73\u5766\u5316\u4e4b\u524d\uff0c\u5e94\u5f53\u5148\u8fdb\u884c\u5b57\u7b26\u4e32\u89e3\u5bc6\u4ee5\u53ca\u5254\u9664\u82b1\u6307\u4ee4\u3002\u5728\u8fd8\u539f\u6d41\u7a0b\u5e73\u5766\u5316\u7684\u8fc7\u7a0b\u4e2d\uff0c\u9700\u8981\u5148\u83b7\u53d6\u5206\u53d1\u5668\uff0c\u56e0\u4e3a\u5206\u53d1\u5668\u4e2d\u8bb0\u5f55\u7740\u4ee3\u7801\u539f\u5148\u7684\u771f\u5b9e\u987a\u5e8f\u3002\u4ee5 1.5\u5c0f\u8282\u4e2d\u7684\u4ee3\u7801\u4e3a\u4f8b\uff0c\u6765\u770b\u4e00\u4e0b\u5206\u53d1\u5668\u5728 AST \u4e2d\u7684\u7ed3\u6784:<\/p>\n<pre><code class=\"language-javascript\">Node {\n    type:&#039;MemberExpression&#039;,\n    ...\n    object: Node{ type: &#039;stringLiteral&#039;, ... value:&#039;1|2|4|7|5|3|8|0|6&#039;},\n    property: Node { type: &#039;StringLiteral&#039;, ... value: &#039;split&#039;} \n    computed: true\n}<\/code><\/pre>\n<p>\u4ece\u4e0a\u8ff0\u7ed3\u6784\u4e2d\u53ef\u4ee5\u770b\u51fa\uff0c\u53ea\u8981\u904d\u5386 MemberExpression \u8282\u70b9\uff0c\u5982\u679c\u5176\u4e2d\u7684 object \u8282\u70b9\u4e3aStringLiteral\u7c7b\u578b\uff0cproperty \u8282\u70b9\u4e3aStringLiteral\u7c7b\u578b\u5e76\u4e14 value \u4e3a'split'\u5c31\u662f\u5206\u53d1\u5668\u6240\u5728\u7684 MemberExpression \u8282\u70b9\u3002\u5176\u4e2d path.node.object.value \u5c31\u662f\u8bb0\u5f55\u7740\u4ee3\u7801\u539f\u5148\u771f\u5b9e\u987a\u5e8f\u7684\u5b57\u7b26\u4e32\u3002\u56e0\u6b64\uff0c\u83b7\u53d6\u5206\u53d1\u5668\u7684\u4ee3\u7801\u5982\u4e0b:<\/p>\n<pre><code class=\"language-javascript\">traverse(ast, {\n    MemberExpression (path) {\n        if (t.isStringLiteral(path.node.object) &amp;&amp; \n                t.isStringLiteral(path.node.property, {value: &#039;split&#039;})){\n            console.log(path.node.object.value);\n        }\n    }\n});\n\/\/ &#039;1|2|4|7|5|3|8|0|6&#039;<\/code><\/pre>\n<h3>2.\u89e3\u6790\u6574\u4e2aswitch<\/h3>\n<p>\u628aAST \u4e2d\u7684 switch \u7ed3\u6784\uff0c\u89e3\u6790\u5230 nodejs \u7684\u6570\u7ec4\u4e2d\u3002\u8fd9\u6837\u5728\u590d\u539f\u4ee3\u7801\u987a\u5e8f\u7684\u65f6\u5019\uff0c\u5c31\u53ef\u4ee5\u5feb\u901f\u51c6\u786e\u5730\u53d6\u5230\u5bf9\u5e94\u7684\u4ee3\u7801\u8282\u70b9\u3002\u60f3\u8981\u89e3\u6790\u6574\u4e2a switch,\u9700\u8981\u5148\u6765\u5b66\u4e60\u4e0b WileStatement\u8282\u70b9\u548c SwitchStatement \u8282\u70b9\u7684\u7ed3\u6784\uff0c\u4ee5 1.5\u5c0f\u8282\u4e2d\u7684\u4ee3\u7801\u4e3a\u4f8b:<\/p>\n<pre><code class=\"language-javascript\">\/\/WhileStatement \u7684\u7ed3\u6784\nNode {\n    type: &#039;Whilestatement&#039;, ...\n    test: Node {\n        type: &#039;UnaryExpression&#039;, ...\n        operator: &#039;!&#039;,\n        prefix: true,\n        argument: Node {\n            type: &#039;UnaryExpression&#039;, ...\n            operator: &#039;!&#039;,\n            prefix: true,\n            argument : [Node]\n        }\n    },\n        body:Node { ... }\n}<\/code><\/pre>\n<p>WhileStatement \u8282\u70b9\u7684 test \u5c5e\u6027\u5c31\u662f while \u5faa\u73af\u7684\u6761\u4ef6,body \u5c5e\u6027\u5c31\u662f while \u5faa\u73af\u4f53\u4e2d\u7684\u4ee3\u7801\uff0c\u63a5\u7740\u6765\u89c2\u5bdf\u4e0b body \u4f53\u4e2d\u7684\u7ed3\u6784:<\/p>\n<pre><code class=\"language-javascript\">Node {\n    type: &#039;BlockStatement&#039; , ...\n    body: [Node {\n        type: &#039;SwitchStatement&#039;, ...\n        discriminant: Node { type: &#039;MemberExpression&#039;, ...\n            object: Node { type: &#039;identifier&#039;, ... name:  &#039;_0x27fd60&#039;},\n            property: Node {\n                type: &#039;UpdateExpression&#039;, ...\n                operator: &#039;++&#039;,\n                prerix: false,\n                argument : [Node]\n            },\n            computed: true\n        },\n        cases: [\n            Node {\n                type: &#039;witchCase&#039;, ...\n                consequent: [Array],\n                test: Node { type: &#039;stringLiteral&#039;, ... value: &#039;0&#039; }\n            },\n            ...\n        ]\n    },\n      Node { type &#039;BeakStatenent&#039;, ...label: null}\n  ],\n  directives: []\n}<\/code><\/pre>\n<p>SwitchStatement \u8282\u70b9\u4e2d\u7684 discriminant \u5c5e\u6027\uff0c\u5c31\u662f switch \u8bed\u53e5\u4e2d\u7528\u6765\u63a7\u5236\u8df3\u8f6c\u7684\u8868\u8fbe\u5f0f\uff0ccases \u5c5e\u6027\u4e2d\u5b58\u653e\u7740 switch \u4e2d\u6240\u6709\u7684 case\u4ee3\u7801\u5757\u3002SwitchCase \u8282\u70b9\u7684 test \u5c5e\u6027\u5c31\u662f case \u540e\u9762\u8ddf\u7684\u503c\uff0cconsequent \u5c5e\u6027\u5c31\u662f\u5177\u4f53\u7684\u4ee3\u7801\u5757\u3002<\/p>\n<p>\u719f\u6089\u4e86\u8fd9\u4e9b\u7ed3\u6784\u4ee5\u540e\uff0c\u6765\u770b\u4e00\u4e0b\u89e3\u6790\u6574\u4e2a switch \u7684\u4ee3\u7801:<\/p>\n<pre><code class=\"language-javascript\">traverse(ast, {\n    MemberExpression(path) {\n        if (t.isStringLiteral(path.node.object) &amp;&amp; \n            t.isStringLiteral(path.node.property, {value: &#039;split&#039;})) {\n            \/\/\u627e\u5230\u7c7b\u578b\u4e3a VariableDeclaration \u7684\u7236\u8282\u70b9\n            let varPath = path.findparent (function (p) {\n                return t.isVariableDeclaration(p);\n            });\n            \/\/\u83b7\u53d6\u4e0b\u4e00\u4e2a\u540c\u7ea7\u8282\u70b9\n            let whilePath = varPath.getsibling(varPath.key + 1);\n            \/\/\u89e3\u6790\u6574\u4e2a switch\n            let myArr = [];\n            whilePath.node.body.body[0].cases.map(function (p) {\n                myArr[p.test.value] = p.consequent[0];\n            });\n        }\n    }\n});<\/code><\/pre>\n<p>\u6765\u4ecb\u7ecd\u4e00\u4e0b\u4e0a\u8ff0\u4ee3\u7801\u7684\u5b9e\u73b0\u8fc7\u7a0b\uff0c\u9996\u5148\u662f\u6cbf\u75284.1 \u5c0f\u8282\u4e2d\u7684\u4ee3\u7801\uff0c\u5b9a\u4f4d\u5230\u5206\u53d1\u5668\u6240\u5728\u7684MemberExpression \u8282\u70b9\u3002\u63a5\u7740\u8981\u5b9a\u4f4d\u5230 switch \u8282\u70b9\uff0c\u624d\u80fd\u89e3\u6790\u6574\u4e2a switch \u8282\u70b9\u3002\u5148\u627e\u5230WhileStatement\u8282\u70b9\uff0c\u6765\u770b\u4e00\u4e0b\u6e90\u4ee3\u7801\u5728AST\u4e2d\u7684\u6574\u4f53\u7ed3\u6784\uff1a<\/p>\n<pre><code class=\"language-javascript\">Node {\n  type: &#039;variableDeclaration&#039;,\n  ...\n  declarations: [\n    Node {\n      type: &#039;VariableDeclarator&#039;,\n      ...\n      id: Node { type: &#039;Identifier&#039;, ... name:&#039;_0x27fd60&#039;,\n      init: Node { type: &#039;CallExpression&#039;, ...\n        callee: Node {\n          type:&#039;MemberExpression&#039;,\n          ...\n          object: Node { type:&#039;stringLiteral&#039;, ...value:&#039;1|2|4|7|5|3|8|0|6&#039;},\n          property: Node { type: &#039;stringLiteral&#039;, ... value: &#039;split&#039; },\n          computed: true\n        },\n        arguments: [ [Node] ]\n        }\n    },\n    Node { type: &#039;VariableDeclarator&#039; ...}\n    ],\n    kind: &#039;var&#039;\n}\nNode { type: &#039;WhileStatement&#039;, ...}           <\/code><\/pre>\n<p>\u4ece\u4e0a\u8ff0\u7ed3\u6784\u4e2d\u53ef\u4ee5\u770b\u51fa\uff0cWileStatement \u8282\u70b9\u662f VariableDeclaration \u8282\u70b9\u7684\u4e0b\u4e00\u4e2a\u540c\u7ea7\u8282\u70b9\uff0c\u800c\u5f53\u524d\u5b9a\u4f4d\u5230\u7684\u662f\u5206\u53d1\u5668\u6240\u5728\u7684 MemberExpression \u8282\u70b9\u3002\u56e0\u6b64\u5728\u672c\u5c0f\u8282\u6700\u5f00\u59cb\u7684\u4ee3\u7801\u4e2d,\u901a\u8fc7 path.findParent \u627e\u5230\u5206\u53d1\u5668\u6240\u5728\u8282\u70b9\u7684\u7c7b\u578b\u4e3a VariableDeclaration \u7684\u7236\u8282\u70b9\uff0c\u8d4b\u503c\u7ed9 varPath\u3002\u7136\u540e\u901a\u8fc7 varPath.getSibling \u83b7\u53d6\u5230\u4e0b\u4e00\u4e2a\u540c\u7ea7\u8282\u70b9\u5373\u53ef\u3002<\/p>\n<p>\u63a5\u7740\u901a\u8fc7 WhileStatement \u8282\u70b9\uff0c\u627e\u5230\u5176\u4e0b\u5c5e\u7684 switch \u8282\u70b9\u4e2d\u7684 cases \u6570\u7ec4\uff0c\u4e5f\u5c31\u662f\u5b58\u653e\u7740\u6240\u6709 case \u4ee3\u7801\u5757\u7684\u8282\u70b9\u3002\u6700\u540e\u904d\u5386 cases \u6570\u7ec4\uff0c\u7528 case \u540e\u9762\u7684\u503c\u4f5c\u4e3a\u6570\u7ec4\u7d22\u5f15\uff0ccase\u4e2d\u5177\u4f53\u7684\u4ee3\u7801\u8282\u70b9\u4f5c\u4e3a\u5bf9\u5e94\u7684\u6570\u7ec4\u7684\u6210\u5458,\u628a\u6574\u4e2a switch \u89e3\u6790\u5230\u9884\u5148\u5b9a\u4e49\u7684 myArr \u6570\u7ec4\u4e2d\u3002<\/p>\n<h3>3.\u590d\u539f\u8bed\u53e5\u987a\u5e8f<\/h3>\n<p>\u4e00\u5207\u51c6\u5907\u5de5\u4f5c\u90fd\u5df2\u5c31\u7eea\uff0c\u63a5\u4e0b\u53bb\u5c31\u53ef\u4ee5\u590d\u539f\u4ee3\u7801\u987a\u5e8f\u4e86\u3002\u5b9e\u73b0\u7684\u4ee3\u7801\u4e5f\u5f88\u7b80\u5355\uff1a<\/p>\n<pre><code class=\"language-javascript\">let parentPath = whilePath.parent;\nvarPath.remove ();\nwhilePath.remove();\n\/\/ path.node.object.value \u53d6\u5230\u7684\u662f1|2|4|7|5|3|8|0|6\nlet shufferArr = path.node.object.value.split (&quot;|&quot;);\nshufferArr.map (function (v) {\n    parentPath.body.push(myArr[v]);\n});<\/code><\/pre>\n<p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u5148\u627e\u5230 WhileStatement \u7684\u7236\u8282\u70b9\uff0c\u4e5f\u5c31\u662f BlockStatement \u8282\u70b9\u3002\u7136\u540e\u628a\u5206\u53d1\u5668\u6240\u5728\u7684\u8282\u70b9\u548cWhileStatement \u8282\u70b9\u6574\u4e2a\u79fb\u9664\uff0c\u5176\u5b9e\u5c31\u76f8\u5f53\u4e8e\u662f\u628a BlockStatement\u7684 body \u8282\u70b9\u6e05\u7a7a\u3002\u7136\u540e\u628a\u5b58\u6709\u4ee3\u7801\u771f\u5b9e\u987a\u5e8f\u7684\u5b57\u7b26\u4e32\uff0c\u5206\u5272\u6210\u6570\u7ec4 shufferArr\u3002\u904d\u5386\u8be5\u6570\u7ec4\uff0c\u4ece\u4e4b\u524d\u89e3\u6790\u597d\u7684 myArr \u4e2d\uff0c\u53d6\u51fa\u5bf9\u5e94\u7d22\u5f15\u7684\u4ee3\u7801\u8282\u70b9\uff0c\u585e\u56de\u5230 BlockStatement \u7684 body\u8282\u70b9\u4e2d\u3002<\/p>\n<p>\u5355\u4e2a switch \u6d41\u7a0b\u5e73\u5766\u5316\u8fd8\u539f\u5b8c\u6210\u4e86\uff0c\u73b0\u5728\u8981\u5e94\u7528\u5230\u6574\u4e2aJS \u6587\u4ef6\u4e2d\u53bb\u3002\u7531\u4e8e\u539f\u4ee3\u7801\u4e2d\u5b58\u5728\u5d4c\u5957\u7684 switch \u6d41\u7a0b\u5e73\u5766\u5316\uff0c\u4e3a\u4e86\u9632\u6b62\u987a\u5e8f\u9519\u4e71\uff0c\u7b14\u8005\u5728\u8fd9\u91cc\u91c7\u7528\u6bcf\u904d\u5386\u4e00\u8f6e ast\uff0c\u53ea\u5904\u7406\u4e00\u4e2a switch \u6d41\u7a0b\u5e73\u5766\u5316\u7684\u65b9\u6848\uff0c\u5b8c\u6574\u7684\u8fd8\u539f\u4ee3\u7801\u5982\u4e0b:<\/p>\n<pre><code class=\"language-javascript\">\/\/\u7c97\u66b4\u7684\u591a\u5faa\u73af\u51e0\u6b21\uff0c\u800c\u4e0d\u7528\u53bb\u5224\u65ad\u6e90\u4ee3\u7801\u4e2d\u5230\u5e95\u6709\u591a\u5c11\u4e2aswitch\u6d41\u7a0b\u5e73\u5766\u5316\nfor(let i = 0; i &lt; 20; i++){\n    traverse(ast, {\n        MemberExpression(path) {\n            if (t.isStringLiteral(path.node.object) &amp;&amp;\n                    t.isStringLiteral(path.node.property, {\n                        value: &#039;split&#039;\n                    })) {\n                \/\/\u627e\u5230\u7c7b\u578b\u4e3a VariableDeclaration \u7684\u7236\u8282\u70b9\n                let varPath = path.findParent(function (p) {\n                        return t.isVariableDeclaration(p);\n                    });\n                \/\/\u83b7\u53d6\u4e0b\u4e00\u4e2a\u540c\u7ea7\u8282\u70b9\n                let whilePath = varPath.getSibling(varPath.key + 1);\n                \/\/\u89e3\u6790\u6574\u4e2a switch\n                let myArr = [];\n                whilePath.node.body.body[0].cases.map(function (p) {\n                    myArr[p.test.value] = p.consequent[0];\n                });\n\n                let parentPath = whilePath.parent;\n                varPath.remove();\n                whilePath.remove();\n                \/\/ path.node.object.value \u53d6\u5230\u7684\u662f &#039;1|2|4|7|5|3|8|0|6&#039;\n                let shufferArr = path.node.object.value.split(&quot;|&quot;);\n                shufferArr.map(function (v) {\n                    parentPath.body.push(myArr[v]);\n                });\n                \/\/\u6bcf\u904d\u5386\u4e00\u8f6e ast\uff0c\u53ea\u5904\u7406\u4e00\u4e2a switch \u6d41\u7a0b\u5e73\u5766\u5316\u5c31\u505c\u6b62\u904d\u5386\n                path.stop();\n            }\n        }\n    });\n}<\/code><\/pre>\n<p>switch \u6d41\u7a0b\u5e73\u5766\u5316\uff0c\u8fd8\u539f\u524d\u540e\u7684\u6548\u679c\uff0c\u8bfb\u8005\u4eec\u53ef\u4ee5\u53c2\u8003 11.1.5 \u5c0f\u8282\u4e2d\u7684\u4ee3\u7801\u3002\u5176\u4e2d\u8fd8\u6709\u4e00\u4e9b\u5341\u516d\u8fdb\u5236\u5b57\u7b26\u4e32\u6ca1\u6709\u8fd8\u539f\u3002\u8fd8\u539f\u7684\u65b9\u6cd5\u5728\u7b2c 10 \u7ae0\u4e2d\u6709\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u8fd9\u91cc\u4e0d\u518d\u8d58\u8ff0\u3002\u8fd8\u539f switch \u6d41\u7a0b\u5e73\u5766\u5316\u7684\u4ee3\u7801\u5176\u5b9e\u6ca1\u6709\u591a\u5c11\u884c\uff0c\u76f8\u5bf9\u6bd4\u522b\u9664\u82b1\u6307\u4ee4\u8fd8\u8981\u5bb9\u6613\u4e00\u70b9\u3002\u5f53\u7136 switch \u6d41\u7a0b\u5e73\u5766\u5316\u6df7\u6dc6\u5e76\u4e0d\u662f\u53ea\u6709\u8fd9\u4e00\u79cd\u3002\u56e0\u6b64\u8bfb\u8005\u4eec\u5e94\u5f53\u638c\u63e1\u539f\u7406\uff0c\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u5177\u4f53\u60c5\u51b5\u5177\u4f53\u5206\u6790\u3002<\/p>\n<h2>5.\u6700\u7ec8\u4ee3\u7801<\/h2>\n<pre><code class=\"language-javascript\">const parser = require(&quot;@babel\/parser&quot;);\nconst traverse = require(&quot;@babel\/traverse&quot;).default;\nconst t = require(&quot;@babel\/types&quot;);\nconst generator = require(&quot;@babel\/generator&quot;).default;\nconst fs = require(&#039;fs&#039;);\n\nconst jscode = fs.readFileSync(&quot;.\/demo.js&quot;, {\n    encoding: &quot;utf-8&quot;\n});\n\nlet ast = parser.parse(jscode);\n\n\/\/\u62ff\u5230\u89e3\u5bc6\u51fd\u6570\u6240\u5728\u8282\u70b9\nlet stringDecryptFuncAst = ast.program.body[2];\n\/\/\u62ff\u5230\u89e3\u5bc6\u51fd\u6570\u7684\u540d\u5b57\nlet DecryptFuncName = stringDecryptFuncAst.declarations[0].id.name;\n\/\/\u65b0\u5efa\u4e00\u4e2a AST\uff0c\u628a\u539f\u4ee3\u7801\u4e2d\u7684\u524d\u4e09\u90e8\u5206\uff0c\u52a0\u5165\u5230 body \u8282\u70b9\u4e2d\nlet newAst = parser.parse(&#039;&#039;);\nnewAst.program.body.push(ast.program.body[0]);\nnewAst.program.body.push(ast.program.body[1]);\nnewAst.program.body.push(stringDecryptFuncAst);\n\/\/\u628a\u8fd9\u4e09\u90e8\u5206\u7684\u4ee3\u7801\u8f6c\u4e3a\u5b57\u7b26\u4e32\uff0c\u7531\u4e8e\u5b58\u5728\u683c\u5f0f\u5316\u68c0\u6d4b\uff0c\u9700\u8981\u6307\u5b9a\u9009\u9879\uff0c\u6765\u538b\u7f29\u4ee3\u7801\nlet stringDecryptFunc = generator(newAst, {compact: true}).code;\n\/\/\u5c06\u5b57\u7b26\u4e32\u5f62\u5f0f\u7684\u4ee3\u7801\u6267\u884c\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u5728 nodejs \u4e2d\u8fd0\u884c\u89e3\u5bc6\u51fd\u6570\u4e86\neval(stringDecryptFunc);\n\ntraverse(ast, {\n    \/\/\u904d\u5386\u6240\u6709\u53d8\u91cf\n    VariableDeclarator(path){\n        \/\/\u5f53\u53d8\u91cf\u540d\u4e0e\u89e3\u5bc6\u51fd\u6570\u540d\u76f8\u540c\u65f6\uff0c\u5c31\u6267\u884c\u76f8\u5e94\u64cd\u4f5c\n        if(path.node.id.name == DecryptFuncName){\n            let binding = path.scope.getBinding(DecryptFuncName);\n            binding &amp;&amp; binding.referencePaths.map(function(v){\n                v.parentPath.isCallExpression() &amp;&amp;\n                v.parentPath.replaceWith(t.stringLiteral(eval(v.parentPath + &#039;&#039;)));\n            });\n        } \n    }\n});\n\nast.program.body.shift();\nast.program.body.shift();\nast.program.body.shift();\n\nvar totalObj = {};\nfunction generatorObj(ast){\n    traverse(ast, {\n        VariableDeclarator(path){\n            \/\/init \u8282\u70b9\u4e3a ObjectExpression \u7684\u65f6\u5019\uff0c\u5c31\u662f\u9700\u8981\u5904\u7406\u7684\u5bf9\u8c61\n            if(t.isObjectExpression(path.node.init)){\n                \/\/\u53d6\u51fa\u5bf9\u8c61\u540d\n                let objName = path.node.id.name;\n                \/\/\u4ee5\u5bf9\u8c61\u540d\u4f5c\u4e3a\u5c5e\u6027\u540d\u5728 totalObj \u4e2d\u521b\u5efa\u5bf9\u8c61\n                objName &amp;&amp; (totalObj[objName] = totalObj[objName] || {});\n                \/\/\u89e3\u6790\u5bf9\u8c61\u4e2d\u7684\u6bcf\u4e00\u4e2a\u5c5e\u6027\uff0c\u52a0\u5165\u5230\u65b0\u5efa\u7684\u5bf9\u8c61\u4e2d\u53bb\uff0c\u6ce8\u610f\u5c5e\u6027\u503c\u4f9d\u7136\u662f Node \u7c7b\u578b\n                totalObj[objName] &amp;&amp; path.node.init.properties.map(function(p){\n                    totalObj[objName][p.key.value] = p.value;\n                });\n            };\n        }\n    });\n    return ast;\n}\nast = generatorObj(ast);\n\ntraverse(ast, {\n    VariableDeclarator(path) {\n        if (t.isObjectExpression(path.node.init)) {\n            path.node.init.properties.map(function (p) {\n                let realNode = findRealValue(p.value);\n                realNode &amp;&amp; (p.value = realNode);\n            });\n        };\n    }\n});\n\nfunction findRealValue(node) {\n    if (t.isMemberExpression(node)) {\n        let objName = node.object.name;\n        let propName = node.property.value;\n        if (totalObj[objName][propName]) {\n            return findRealValue(totalObj[objName][propName]);\n        } else {\n            return false;\n        }\n    } else {\n        return node;\n    }\n}\n\nast = generatorObj(ast);\n\ntraverse(ast, {\n    MemberExpression(path) {\n        let objName = path.node.object.name;\n        let propName = path.node.property.value;\n        totalObj[objName] &amp;&amp; t.isStringLiteral(totalObj[objName][propName]) &amp;&amp;\n        path.replaceWith(totalObj[objName][propName]);\n    }\n});\n\ntraverse(ast, {\n    VariableDeclarator(path) {\n        if (t.isObjectExpression(path.node.init)) {\n            path.node.init.properties.map(function (p) {\n                let realNode = findRealFunc(p.value);\n                realNode &amp;&amp; (p.value = realNode);\n            });\n        };\n    }\n});\nfunction findRealFunc(node) {\n    if (t.isFunctionExpression(node) &amp;&amp; node.body.body.length == 1) {\n        let expr = node.body.body[0].argument.callee;\n        if (t.isMemberExpression(expr)) {\n            let objName = expr.object.name;\n            let propName = expr.property.value;\n            if (totalObj[objName]) {\n                return findRealFunc(totalObj[objName][propName]);\n            } else {\n                return false;\n            }\n        }\n        return node;\n    } else {\n        return node;\n    }\n}\n\/\/\u53bb\u9664\u51fd\u6570\u82b1\u6307\u4ee4\u4ee5\u540e\uff0c\u66f4\u65b0\u4e00\u4e0b totalObj \u5bf9\u8c61\nast = generatorObj(ast);\n\ntraverse(ast, {\n    CallExpression(path) {\n        \/\/callee \u4e0d\u4e3a MemberExpression \u7684\u8282\u70b9\uff0c\u4e0d\u505a\u5904\u7406\n        if (!t.isMemberExpression(path.node.callee))\n            return;\n        \/\/\u53d6\u51fa\u5bf9\u8c61\u540d\u548c\u5c5e\u6027\u540d\n        let objName = path.node.callee.object.name;\n        let propertyName = path.node.callee.property.value;\n        \/\/\u5982\u679c\u5728 totalObj \u4e2d\u6709\u76f8\u5e94\u8282\u70b9\uff0c\u5c31\u662f\u9700\u8981\u8fdb\u884c\u66ff\u6362\u7684\n        if (totalObj[objName] &amp;&amp; totalObj[objName][propertyName]) {\n            \/\/totalObj \u4e2d\u5b58\u653e\u7684\u662f\u51fd\u6570\u8282\u70b9\n            let myFunc = totalObj[objName][propertyName];\n            \/\/\u5728\u539f\u4ee3\u7801\u4e2d\uff0c\u51fd\u6570\u4f53\u5176\u5b9e\u5c31\u4e00\u884c return \u8bed\u53e5\uff0c\u53d6\u51fa\u5176\u4e2d\u7684 argument \u8282\u70b9\n            let returnExpr = myFunc.body.body[0].argument;\n            \/\/\u5224\u65ad argument \u8282\u70b9\u7c7b\u578b\uff0c\u5e76\u4e14\u7528\u76f8\u5e94\u7684\u5b9e\u53c2\u6765\u6784\u5efa\u4e8c\u9879\u5f0f\u6216\u8005\u8c03\u7528\u8868\u8fbe\u5f0f\n            \/\/\u7136\u540e\u66ff\u6362\u5f53\u524d\u904d\u5386\u5230\u7684\u6574\u4e2a CallExpression \u8282\u70b9\u5373\u53ef\n            if (t.isBinaryExpression(returnExpr)) {\n                let binExpr = t.binaryExpression(returnExpr.operator,\n                        path.node.arguments[0], path.node.arguments[1]);\n                path.replaceWith(binExpr);\n            } else if (t.isCallExpression(returnExpr)) {\n                \/\/\u628a arguments \u6570\u7ec4\u4e2d\u7684\u4e0b\u6807\u4e3a 1 \u548c\u4ee5\u540e\u7684\u6210\u5458\uff0c\u653e\u5165 newArray \u4e2d\n                let newArray = path.node.arguments.slice(1);\n                let callExpr = t.callExpression(path.node.arguments[0],\n                        newArray);\n                path.replaceWith(callExpr);\n            }\n        }\n    }\n})\n\ntraverse(ast, {\n    VariableDeclarator(path) {\n        if (t.isObjectExpression(path.node.init)) {\n            path.remove();\n        };\n    }\n});\n\nfor(let i = 0; i &lt; 20; i++){\n    traverse(ast, {\n        MemberExpression(path) {\n            if (t.isStringLiteral(path.node.object) &amp;&amp;\n                    t.isStringLiteral(path.node.property, {\n                        value: &#039;split&#039;\n                    })) {\n                \/\/\u627e\u5230\u7c7b\u578b\u4e3a VariableDeclaration \u7684\u7236\u8282\u70b9\n                let varPath = path.findParent(function (p) {\n                        return t.isVariableDeclaration(p);\n                    });\n                \/\/\u83b7\u53d6\u4e0b\u4e00\u4e2a\u540c\u7ea7\u8282\u70b9\n                let whilePath = varPath.getSibling(varPath.key + 1);\n                \/\/\u89e3\u6790\u6574\u4e2a switch\n                let myArr = [];\n                whilePath.node.body.body[0].cases.map(function (p) {\n                    myArr[p.test.value] = p.consequent[0];\n                });\n\n                let parentPath = whilePath.parent;\n                varPath.remove();\n                whilePath.remove();\n                \/\/ path.node.object.value \u53d6\u5230\u7684\u662f &#039;1|2|4|7|5|3|8|0|6&#039;\n                let shufferArr = path.node.object.value.split(&quot;|&quot;);\n                shufferArr.map(function (v) {\n                    parentPath.body.push(myArr[v]);\n                });\n                path.stop();\n            }\n        }\n    });\n}\n\nlet code = generator(ast).code;\nfs.writeFile(&#039;.\/demoNew.js&#039;, code, (err)=&gt;{});\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1.\u6574\u4f53\u4ee3\u7801\u7ed3\u6784 \u672c\u7ae0\u4ee5\u4e00\u4e2a\u5b9e\u9645\u6848\u4f8b\uff0c\u6765\u4ecb\u7ecd AST \u5728\u8fd8\u539f JavaScript (\u4ee5\u4e0b\u7b80\u79f0JS) \u6df7\u6dc6\u4e0a\u7684\u5e94\u7528\u3002 \u5f53\u7136\u5728\u8fd8\u539f\u4e4b\u524d\uff0c\u5fc5   \u2026 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0},"categories":[194,189],"tags":[],"_links":{"self":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts\/8905"}],"collection":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8905"}],"version-history":[{"count":2,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/8905\/revisions"}],"predecessor-version":[{"id":8907,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/8905\/revisions\/8907"}],"wp:attachment":[{"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8905"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8905"},{"taxonomy":"post_tag","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8905"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}