-
Notifications
You must be signed in to change notification settings - Fork 40
/
main.js
116 lines (61 loc) · 2.48 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*****************************************************
Module name:main.js
Author:悦来客栈的老板
Date:2022.08.15
混淆工具地址:https://obfuscator.io/
脚本仅用于被obfuscator混淆了的代码,不支持商业工具混淆的代码
声明:
脚本仅用于学习研究,禁止非法使用,否则后果自负!
使用方法可以观看在线视频:
https://www.bilibili.com/video/BV16V411H7yz
*****************************************************/
const fs = require('fs');
const usefulPlugins = require("./tools/babel_pack");
//js混淆代码读取
process.argv.length > 2 ? encodeFile = process.argv[2]: encodeFile ="./input/demo.js";
process.argv.length > 3 ? decodeFile = process.argv[3]: decodeFile ="./output/decodeResult.js";
//将源代码解析为AST
let sourceCode = fs.readFileSync(encodeFile, {encoding: "utf-8"});
let ast = parser.parse(sourceCode);
if(!sourceCode.includes("_0x"))
{
console.log("混淆代码非ob混淆,直接退出!");
process.exit(0);
}
console.time("处理完毕,耗时");
//字面量解混淆
console.log("traverse Hex or Unicode String.......");
traverse(ast, simplifyLiteral);
console.log("constantFold.......");
traverse(ast, constantFold);
console.log("delete Repeat Define.......");
traverse(ast, deleteRepeatDefine);
traverse(ast, SimplifyIfStatement);
traverse(ast, standardLoop);
console.log("resolve Sequence.......");
traverse(ast, resolveSequence);
console.log("traverse CallExpress To ToLiteral.......");
traverse(ast, CallExpressToLiteral);
console.log("constantFold.......");
traverse(ast, constantFold);
//object key值Literal
console.log("Object Preconditioning .......");
traverse(ast, keyToLiteral);
traverse(ast, preDecodeObject);
//处理object
console.log("Object Decode .......");
traverse(ast, decodeObject);
console.log("Control Flow Decoding.......\n");
traverse(ast, decodeControlFlow);
console.log("constantFold.......");
traverse(ast, constantFold);
console.log("remove Dead Code.......\n");
traverse(ast, removeDeadCode);
ast = parser.parse(generator(ast).code);
traverse(ast, removeDeadCode);
traverse(ast, simplifyLiteral);
//可能会误删一些代码,可屏蔽
traverse(ast, deleteObfuscatorCode);
console.timeEnd("处理完毕,耗时");
let {code} = generator(ast,opts = {jsescOption:{"minimal":true}});
fs.writeFile(decodeFile, code, (err) => {});