js-confuser 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/ISSUE_TEMPLATE/bug_report.md +43 -43
- package/.github/ISSUE_TEMPLATE/feature_request.md +20 -20
- package/.github/workflows/node.js.yml +28 -28
- package/.prettierrc +4 -4
- package/CHANGELOG.md +1015 -987
- package/CODE_OF_CONDUCT.md +131 -131
- package/CONTRIBUTING.md +52 -52
- package/LICENSE +21 -21
- package/Migration.md +72 -72
- package/README.md +86 -86
- package/dist/constants.js +43 -43
- package/dist/index.js +14 -23
- package/dist/obfuscator.js +31 -25
- package/dist/order.js +4 -4
- package/dist/presets.js +31 -31
- package/dist/templates/integrityTemplate.js +4 -4
- package/dist/templates/template.js +1 -2
- package/dist/transforms/astScrambler.js +1 -2
- package/dist/transforms/calculator.js +1 -2
- package/dist/transforms/controlFlowFlattening.js +60 -41
- package/dist/transforms/deadCode.js +1 -2
- package/dist/transforms/dispatcher.js +4 -5
- package/dist/transforms/extraction/duplicateLiteralsRemoval.js +1 -2
- package/dist/transforms/extraction/objectExtraction.js +1 -2
- package/dist/transforms/finalizer.js +1 -2
- package/dist/transforms/flatten.js +1 -2
- package/dist/transforms/identifier/globalConcealing.js +15 -2
- package/dist/transforms/identifier/movedDeclarations.js +8 -7
- package/dist/transforms/identifier/renameVariables.js +7 -7
- package/dist/transforms/lock/integrity.js +8 -9
- package/dist/transforms/lock/lock.js +1 -2
- package/dist/transforms/minify.js +11 -29
- package/dist/transforms/opaquePredicates.js +1 -2
- package/dist/transforms/pack.js +1 -2
- package/dist/transforms/plugin.js +18 -19
- package/dist/transforms/preparation.js +16 -16
- package/dist/transforms/renameLabels.js +1 -2
- package/dist/transforms/rgf.js +8 -9
- package/dist/transforms/shuffle.js +1 -2
- package/dist/transforms/string/encoding.js +1 -2
- package/dist/transforms/string/stringCompression.js +3 -4
- package/dist/transforms/string/stringConcealing.js +1 -2
- package/dist/transforms/string/stringEncoding.js +1 -2
- package/dist/transforms/variableMasking.js +1 -2
- package/dist/utils/NameGen.js +2 -2
- package/dist/utils/PredicateGen.js +1 -2
- package/dist/utils/ast-utils.js +87 -88
- package/dist/utils/function-utils.js +8 -8
- package/dist/utils/node.js +5 -6
- package/dist/utils/object-utils.js +4 -4
- package/dist/utils/random-utils.js +20 -20
- package/dist/utils/static-utils.js +1 -2
- package/dist/validateOptions.js +4 -7
- package/index.d.ts +17 -17
- package/package.json +61 -59
- package/src/constants.ts +168 -168
- package/src/index.ts +118 -118
- package/src/obfuscationResult.ts +49 -49
- package/src/obfuscator.ts +501 -497
- package/src/options.ts +407 -407
- package/src/order.ts +54 -54
- package/src/presets.ts +125 -125
- package/src/templates/bufferToStringTemplate.ts +57 -57
- package/src/templates/deadCodeTemplates.ts +1185 -1185
- package/src/templates/getGlobalTemplate.ts +76 -76
- package/src/templates/integrityTemplate.ts +64 -64
- package/src/templates/setFunctionLengthTemplate.ts +11 -11
- package/src/templates/stringCompressionTemplate.ts +20 -20
- package/src/templates/tamperProtectionTemplates.ts +120 -120
- package/src/templates/template.ts +224 -224
- package/src/transforms/astScrambler.ts +99 -99
- package/src/transforms/calculator.ts +99 -99
- package/src/transforms/controlFlowFlattening.ts +1716 -1680
- package/src/transforms/deadCode.ts +82 -82
- package/src/transforms/dispatcher.ts +450 -450
- package/src/transforms/extraction/duplicateLiteralsRemoval.ts +156 -158
- package/src/transforms/extraction/objectExtraction.ts +186 -186
- package/src/transforms/finalizer.ts +74 -74
- package/src/transforms/flatten.ts +421 -418
- package/src/transforms/identifier/globalConcealing.ts +315 -295
- package/src/transforms/identifier/movedDeclarations.ts +252 -251
- package/src/transforms/identifier/renameVariables.ts +328 -321
- package/src/transforms/lock/integrity.ts +117 -117
- package/src/transforms/lock/lock.ts +418 -418
- package/src/transforms/minify.ts +615 -629
- package/src/transforms/opaquePredicates.ts +100 -100
- package/src/transforms/pack.ts +239 -239
- package/src/transforms/plugin.ts +173 -173
- package/src/transforms/preparation.ts +349 -347
- package/src/transforms/renameLabels.ts +175 -175
- package/src/transforms/rgf.ts +322 -322
- package/src/transforms/shuffle.ts +82 -82
- package/src/transforms/string/encoding.ts +144 -144
- package/src/transforms/string/stringCompression.ts +128 -128
- package/src/transforms/string/stringConcealing.ts +312 -312
- package/src/transforms/string/stringEncoding.ts +80 -80
- package/src/transforms/string/stringSplitting.ts +77 -77
- package/src/transforms/variableMasking.ts +257 -257
- package/src/utils/IntGen.ts +33 -33
- package/src/utils/NameGen.ts +116 -116
- package/src/utils/PredicateGen.ts +61 -61
- package/src/utils/ast-utils.ts +663 -663
- package/src/utils/function-utils.ts +50 -50
- package/src/utils/gen-utils.ts +48 -48
- package/src/utils/node.ts +78 -78
- package/src/utils/object-utils.ts +21 -21
- package/src/utils/random-utils.ts +93 -93
- package/src/utils/static-utils.ts +66 -66
- package/src/validateOptions.ts +256 -259
- package/tsconfig.json +13 -14
- package/dist/probability.js +0 -1
- package/dist/transforms/functionOutlining.js +0 -230
- package/dist/utils/ControlObject.js +0 -125
|
@@ -1,175 +1,175 @@
|
|
|
1
|
-
import * as t from "@babel/types";
|
|
2
|
-
import { NodePath } from "@babel/traverse";
|
|
3
|
-
import { PluginArg, PluginObject } from "./plugin";
|
|
4
|
-
import { Order } from "../order";
|
|
5
|
-
import { NameGen } from "../utils/NameGen";
|
|
6
|
-
import { ok } from "assert";
|
|
7
|
-
|
|
8
|
-
const LABEL = Symbol("label");
|
|
9
|
-
|
|
10
|
-
interface LabelInterface {
|
|
11
|
-
label?: string;
|
|
12
|
-
renamed?: string;
|
|
13
|
-
removed: boolean;
|
|
14
|
-
required: boolean;
|
|
15
|
-
paths: NodePath<t.BreakStatement | t.ContinueStatement>[];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
interface NodeLabel {
|
|
19
|
-
[LABEL]?: LabelInterface;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export default function ({ Plugin }: PluginArg): PluginObject {
|
|
23
|
-
const me = Plugin(Order.RenameLabels, {
|
|
24
|
-
changeData: {
|
|
25
|
-
labelsRenamed: 0,
|
|
26
|
-
labelsRemoved: 0,
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
return {
|
|
31
|
-
visitor: {
|
|
32
|
-
Program(path) {
|
|
33
|
-
const allLabelInterfaces: LabelInterface[] = [];
|
|
34
|
-
|
|
35
|
-
// First pass: Collect all label usages
|
|
36
|
-
path.traverse({
|
|
37
|
-
LabeledStatement(labelPath) {
|
|
38
|
-
const labelInterface = {
|
|
39
|
-
label: labelPath.node.label.name,
|
|
40
|
-
removed: false,
|
|
41
|
-
required: false,
|
|
42
|
-
paths: [],
|
|
43
|
-
};
|
|
44
|
-
allLabelInterfaces.push(labelInterface);
|
|
45
|
-
(labelPath.node as NodeLabel)[LABEL] = labelInterface;
|
|
46
|
-
},
|
|
47
|
-
"BreakStatement|ContinueStatement"(_path) {
|
|
48
|
-
const path = _path as NodePath<
|
|
49
|
-
t.BreakStatement | t.ContinueStatement
|
|
50
|
-
>;
|
|
51
|
-
|
|
52
|
-
if (path.node.label) {
|
|
53
|
-
const labelName = path.node.label.name;
|
|
54
|
-
let targets: NodePath<
|
|
55
|
-
t.For | t.While | t.BlockStatement | t.SwitchStatement
|
|
56
|
-
>[] = [];
|
|
57
|
-
|
|
58
|
-
let onlySearchLoops = path.isContinueStatement();
|
|
59
|
-
|
|
60
|
-
let currentPath: NodePath = path;
|
|
61
|
-
while (currentPath) {
|
|
62
|
-
if (
|
|
63
|
-
currentPath.isFor() ||
|
|
64
|
-
currentPath.isWhile() ||
|
|
65
|
-
currentPath.isSwitchStatement()
|
|
66
|
-
) {
|
|
67
|
-
targets.push(currentPath);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (
|
|
71
|
-
currentPath.isBlockStatement() &&
|
|
72
|
-
currentPath.parentPath.isLabeledStatement()
|
|
73
|
-
) {
|
|
74
|
-
targets.push(currentPath);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
currentPath = currentPath.parentPath;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const target = targets.find(
|
|
81
|
-
(label) =>
|
|
82
|
-
label.parentPath &&
|
|
83
|
-
label.parentPath.isLabeledStatement() &&
|
|
84
|
-
label.parentPath.node.label.name === labelName
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
if (onlySearchLoops) {
|
|
88
|
-
// Remove BlockStatements and SwitchStatements from the list of targets
|
|
89
|
-
// a continue statement only target loops
|
|
90
|
-
// This helps remove unnecessary labels when a continue is nested with a block statement
|
|
91
|
-
// ex: for-loop with if-statement continue
|
|
92
|
-
targets = targets.filter(
|
|
93
|
-
(target) =>
|
|
94
|
-
!target.isBlockStatement() && !target.isSwitchStatement()
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
ok(target);
|
|
99
|
-
|
|
100
|
-
const isRequired =
|
|
101
|
-
target.isBlockStatement() || targets[0] !== target;
|
|
102
|
-
|
|
103
|
-
const labelInterface = (target.parentPath.node as NodeLabel)[
|
|
104
|
-
LABEL
|
|
105
|
-
];
|
|
106
|
-
|
|
107
|
-
if (isRequired) {
|
|
108
|
-
labelInterface.required = true;
|
|
109
|
-
} else {
|
|
110
|
-
// Label is not required here, remove it for this particular break/continue statement
|
|
111
|
-
path.node.label = null;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (!labelInterface.paths) {
|
|
115
|
-
labelInterface.paths = [];
|
|
116
|
-
}
|
|
117
|
-
labelInterface.paths.push(path);
|
|
118
|
-
}
|
|
119
|
-
},
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
const nameGen = new NameGen(me.options.identifierGenerator);
|
|
123
|
-
|
|
124
|
-
for (var labelInterface of allLabelInterfaces) {
|
|
125
|
-
const isRequired = labelInterface.required;
|
|
126
|
-
if (isRequired) {
|
|
127
|
-
var newName = labelInterface.label;
|
|
128
|
-
if (
|
|
129
|
-
me.computeProbabilityMap(
|
|
130
|
-
me.options.renameLabels,
|
|
131
|
-
labelInterface.label
|
|
132
|
-
)
|
|
133
|
-
) {
|
|
134
|
-
newName = nameGen.generate();
|
|
135
|
-
}
|
|
136
|
-
labelInterface.renamed = newName;
|
|
137
|
-
me.changeData.labelsRenamed++;
|
|
138
|
-
} else {
|
|
139
|
-
labelInterface.removed = true;
|
|
140
|
-
me.changeData.labelsRemoved++;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// Second pass: Rename labels and remove unused ones
|
|
145
|
-
path.traverse({
|
|
146
|
-
LabeledStatement(labelPath) {
|
|
147
|
-
const labelInterface = (labelPath.node as NodeLabel)[LABEL];
|
|
148
|
-
if (labelInterface) {
|
|
149
|
-
// Remove label but replace it with its body
|
|
150
|
-
if (labelInterface.removed) {
|
|
151
|
-
labelPath.replaceWith(labelPath.node.body);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// Else keep the label but rename it
|
|
155
|
-
if (typeof labelInterface.renamed === "string") {
|
|
156
|
-
labelPath.node.label.name = labelInterface.renamed;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// Update all break/continue statements
|
|
160
|
-
for (var breakPath of labelInterface.paths) {
|
|
161
|
-
// Remove label from break/continue statement
|
|
162
|
-
if (labelInterface.removed) {
|
|
163
|
-
breakPath.node.label = null;
|
|
164
|
-
} else {
|
|
165
|
-
// Update label name
|
|
166
|
-
breakPath.node.label = t.identifier(labelInterface.renamed);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
},
|
|
171
|
-
});
|
|
172
|
-
},
|
|
173
|
-
},
|
|
174
|
-
};
|
|
175
|
-
}
|
|
1
|
+
import * as t from "@babel/types";
|
|
2
|
+
import { NodePath } from "@babel/traverse";
|
|
3
|
+
import { PluginArg, PluginObject } from "./plugin";
|
|
4
|
+
import { Order } from "../order";
|
|
5
|
+
import { NameGen } from "../utils/NameGen";
|
|
6
|
+
import { ok } from "assert";
|
|
7
|
+
|
|
8
|
+
const LABEL = Symbol("label");
|
|
9
|
+
|
|
10
|
+
interface LabelInterface {
|
|
11
|
+
label?: string;
|
|
12
|
+
renamed?: string;
|
|
13
|
+
removed: boolean;
|
|
14
|
+
required: boolean;
|
|
15
|
+
paths: NodePath<t.BreakStatement | t.ContinueStatement>[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface NodeLabel {
|
|
19
|
+
[LABEL]?: LabelInterface;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default function ({ Plugin }: PluginArg): PluginObject {
|
|
23
|
+
const me = Plugin(Order.RenameLabels, {
|
|
24
|
+
changeData: {
|
|
25
|
+
labelsRenamed: 0,
|
|
26
|
+
labelsRemoved: 0,
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
visitor: {
|
|
32
|
+
Program(path) {
|
|
33
|
+
const allLabelInterfaces: LabelInterface[] = [];
|
|
34
|
+
|
|
35
|
+
// First pass: Collect all label usages
|
|
36
|
+
path.traverse({
|
|
37
|
+
LabeledStatement(labelPath) {
|
|
38
|
+
const labelInterface = {
|
|
39
|
+
label: labelPath.node.label.name,
|
|
40
|
+
removed: false,
|
|
41
|
+
required: false,
|
|
42
|
+
paths: [],
|
|
43
|
+
};
|
|
44
|
+
allLabelInterfaces.push(labelInterface);
|
|
45
|
+
(labelPath.node as NodeLabel)[LABEL] = labelInterface;
|
|
46
|
+
},
|
|
47
|
+
"BreakStatement|ContinueStatement"(_path) {
|
|
48
|
+
const path = _path as NodePath<
|
|
49
|
+
t.BreakStatement | t.ContinueStatement
|
|
50
|
+
>;
|
|
51
|
+
|
|
52
|
+
if (path.node.label) {
|
|
53
|
+
const labelName = path.node.label.name;
|
|
54
|
+
let targets: NodePath<
|
|
55
|
+
t.For | t.While | t.BlockStatement | t.SwitchStatement
|
|
56
|
+
>[] = [];
|
|
57
|
+
|
|
58
|
+
let onlySearchLoops = path.isContinueStatement();
|
|
59
|
+
|
|
60
|
+
let currentPath: NodePath = path;
|
|
61
|
+
while (currentPath) {
|
|
62
|
+
if (
|
|
63
|
+
currentPath.isFor() ||
|
|
64
|
+
currentPath.isWhile() ||
|
|
65
|
+
currentPath.isSwitchStatement()
|
|
66
|
+
) {
|
|
67
|
+
targets.push(currentPath);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (
|
|
71
|
+
currentPath.isBlockStatement() &&
|
|
72
|
+
currentPath.parentPath.isLabeledStatement()
|
|
73
|
+
) {
|
|
74
|
+
targets.push(currentPath);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
currentPath = currentPath.parentPath;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const target = targets.find(
|
|
81
|
+
(label) =>
|
|
82
|
+
label.parentPath &&
|
|
83
|
+
label.parentPath.isLabeledStatement() &&
|
|
84
|
+
label.parentPath.node.label.name === labelName
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
if (onlySearchLoops) {
|
|
88
|
+
// Remove BlockStatements and SwitchStatements from the list of targets
|
|
89
|
+
// a continue statement only target loops
|
|
90
|
+
// This helps remove unnecessary labels when a continue is nested with a block statement
|
|
91
|
+
// ex: for-loop with if-statement continue
|
|
92
|
+
targets = targets.filter(
|
|
93
|
+
(target) =>
|
|
94
|
+
!target.isBlockStatement() && !target.isSwitchStatement()
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
ok(target);
|
|
99
|
+
|
|
100
|
+
const isRequired =
|
|
101
|
+
target.isBlockStatement() || targets[0] !== target;
|
|
102
|
+
|
|
103
|
+
const labelInterface = (target.parentPath.node as NodeLabel)[
|
|
104
|
+
LABEL
|
|
105
|
+
];
|
|
106
|
+
|
|
107
|
+
if (isRequired) {
|
|
108
|
+
labelInterface.required = true;
|
|
109
|
+
} else {
|
|
110
|
+
// Label is not required here, remove it for this particular break/continue statement
|
|
111
|
+
path.node.label = null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (!labelInterface.paths) {
|
|
115
|
+
labelInterface.paths = [];
|
|
116
|
+
}
|
|
117
|
+
labelInterface.paths.push(path);
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
const nameGen = new NameGen(me.options.identifierGenerator);
|
|
123
|
+
|
|
124
|
+
for (var labelInterface of allLabelInterfaces) {
|
|
125
|
+
const isRequired = labelInterface.required;
|
|
126
|
+
if (isRequired) {
|
|
127
|
+
var newName = labelInterface.label;
|
|
128
|
+
if (
|
|
129
|
+
me.computeProbabilityMap(
|
|
130
|
+
me.options.renameLabels,
|
|
131
|
+
labelInterface.label
|
|
132
|
+
)
|
|
133
|
+
) {
|
|
134
|
+
newName = nameGen.generate();
|
|
135
|
+
}
|
|
136
|
+
labelInterface.renamed = newName;
|
|
137
|
+
me.changeData.labelsRenamed++;
|
|
138
|
+
} else {
|
|
139
|
+
labelInterface.removed = true;
|
|
140
|
+
me.changeData.labelsRemoved++;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Second pass: Rename labels and remove unused ones
|
|
145
|
+
path.traverse({
|
|
146
|
+
LabeledStatement(labelPath) {
|
|
147
|
+
const labelInterface = (labelPath.node as NodeLabel)[LABEL];
|
|
148
|
+
if (labelInterface) {
|
|
149
|
+
// Remove label but replace it with its body
|
|
150
|
+
if (labelInterface.removed) {
|
|
151
|
+
labelPath.replaceWith(labelPath.node.body);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Else keep the label but rename it
|
|
155
|
+
if (typeof labelInterface.renamed === "string") {
|
|
156
|
+
labelPath.node.label.name = labelInterface.renamed;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Update all break/continue statements
|
|
160
|
+
for (var breakPath of labelInterface.paths) {
|
|
161
|
+
// Remove label from break/continue statement
|
|
162
|
+
if (labelInterface.removed) {
|
|
163
|
+
breakPath.node.label = null;
|
|
164
|
+
} else {
|
|
165
|
+
// Update label name
|
|
166
|
+
breakPath.node.label = t.identifier(labelInterface.renamed);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
}
|