js-confuser 2.0.0-alpha.2 → 2.0.0-alpha.4
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/.prettierrc +4 -0
- package/CHANGELOG.md +42 -8
- package/Migration.md +23 -8
- package/README.md +2 -2
- package/dist/constants.js +11 -2
- package/dist/index.js +49 -6
- package/dist/obfuscator.js +121 -10
- package/dist/order.js +0 -1
- package/dist/probability.js +1 -96
- package/dist/templates/getGlobalTemplate.js +4 -1
- package/dist/templates/integrityTemplate.js +1 -1
- package/dist/templates/stringCompressionTemplate.js +3 -3
- package/dist/templates/tamperProtectionTemplates.js +1 -1
- package/dist/templates/template.js +17 -12
- package/dist/transforms/controlFlowFlattening.js +112 -83
- package/dist/transforms/deadCode.js +21 -22
- package/dist/transforms/dispatcher.js +62 -37
- package/dist/transforms/extraction/duplicateLiteralsRemoval.js +5 -0
- package/dist/transforms/extraction/objectExtraction.js +1 -2
- package/dist/transforms/finalizer.js +1 -1
- package/dist/transforms/flatten.js +2 -19
- package/dist/transforms/identifier/globalConcealing.js +3 -4
- package/dist/transforms/identifier/movedDeclarations.js +12 -5
- package/dist/transforms/identifier/renameVariables.js +40 -6
- package/dist/transforms/lock/integrity.js +9 -1
- package/dist/transforms/lock/lock.js +16 -9
- package/dist/transforms/minify.js +64 -27
- package/dist/transforms/opaquePredicates.js +6 -7
- package/dist/transforms/pack.js +32 -5
- package/dist/transforms/plugin.js +20 -39
- package/dist/transforms/preparation.js +25 -36
- package/dist/transforms/renameLabels.js +1 -2
- package/dist/transforms/rgf.js +36 -16
- package/dist/transforms/shuffle.js +10 -11
- package/dist/transforms/string/stringCompression.js +14 -10
- package/dist/transforms/string/stringConcealing.js +7 -5
- package/dist/transforms/string/stringEncoding.js +4 -2
- package/dist/transforms/string/stringSplitting.js +4 -2
- package/dist/transforms/variableMasking.js +3 -2
- package/dist/utils/NameGen.js +5 -2
- package/dist/utils/PredicateGen.js +62 -0
- package/dist/utils/ast-utils.js +24 -9
- package/dist/utils/random-utils.js +10 -0
- package/dist/validateOptions.js +2 -2
- package/index.d.ts +16 -2
- package/package.json +2 -2
- package/src/constants.ts +15 -5
- package/src/index.ts +15 -5
- package/src/obfuscationResult.ts +7 -1
- package/src/obfuscator.ts +152 -12
- package/src/options.ts +26 -8
- package/src/order.ts +0 -2
- package/src/templates/getGlobalTemplate.ts +5 -1
- package/src/templates/integrityTemplate.ts +14 -19
- package/src/templates/stringCompressionTemplate.ts +4 -28
- package/src/templates/tamperProtectionTemplates.ts +7 -3
- package/src/templates/template.ts +5 -3
- package/src/transforms/controlFlowFlattening.ts +139 -83
- package/src/transforms/deadCode.ts +27 -30
- package/src/transforms/dispatcher.ts +24 -5
- package/src/transforms/extraction/duplicateLiteralsRemoval.ts +10 -1
- package/src/transforms/extraction/objectExtraction.ts +1 -2
- package/src/transforms/finalizer.ts +1 -1
- package/src/transforms/flatten.ts +3 -22
- package/src/transforms/identifier/globalConcealing.ts +26 -17
- package/src/transforms/identifier/movedDeclarations.ts +18 -6
- package/src/transforms/identifier/renameVariables.ts +48 -6
- package/src/transforms/lock/integrity.ts +11 -1
- package/src/transforms/lock/lock.ts +26 -10
- package/src/transforms/minify.ts +85 -38
- package/src/transforms/opaquePredicates.ts +6 -9
- package/src/transforms/pack.ts +41 -5
- package/src/transforms/plugin.ts +47 -69
- package/src/transforms/preparation.ts +33 -46
- package/src/transforms/renameLabels.ts +1 -2
- package/src/transforms/rgf.ts +52 -23
- package/src/transforms/shuffle.ts +28 -26
- package/src/transforms/string/encoding.ts +1 -1
- package/src/transforms/string/stringCompression.ts +22 -13
- package/src/transforms/string/stringConcealing.ts +13 -7
- package/src/transforms/string/stringEncoding.ts +6 -2
- package/src/transforms/string/stringSplitting.ts +9 -4
- package/src/transforms/variableMasking.ts +2 -2
- package/src/utils/NameGen.ts +13 -3
- package/src/utils/PredicateGen.ts +61 -0
- package/src/utils/ast-utils.ts +16 -9
- package/src/utils/random-utils.ts +14 -0
- package/src/validateOptions.ts +7 -4
- package/src/probability.ts +0 -110
- package/src/transforms/functionOutlining.ts +0 -225
- package/src/utils/ControlObject.ts +0 -141
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { NodePath } from "@babel/traverse";
|
|
2
|
-
import * as t from "@babel/types";
|
|
3
|
-
import { PluginInstance } from "../transforms/plugin";
|
|
4
|
-
import { NameGen } from "./NameGen";
|
|
5
|
-
import { prepend } from "./ast-utils";
|
|
6
|
-
import { chance, choice } from "./random-utils";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* A Control Object is an object that is used to store properties that are used in multiple places.
|
|
10
|
-
*/
|
|
11
|
-
export default class ControlObject {
|
|
12
|
-
propertyNames = new Set<string>();
|
|
13
|
-
nameGen: NameGen;
|
|
14
|
-
objectName: string | null = null;
|
|
15
|
-
objectPath: NodePath<t.Declaration> | null = null;
|
|
16
|
-
objectExpression: t.ObjectExpression | null = null;
|
|
17
|
-
|
|
18
|
-
constructor(public me: PluginInstance, public blockPath: NodePath<t.Block>) {
|
|
19
|
-
this.nameGen = new NameGen(me.options.identifierGenerator, {
|
|
20
|
-
avoidReserved: true,
|
|
21
|
-
avoidObjectPrototype: true,
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
createMemberExpression(propertyName: string): t.MemberExpression {
|
|
26
|
-
return t.memberExpression(
|
|
27
|
-
t.identifier(this.objectName),
|
|
28
|
-
t.stringLiteral(propertyName),
|
|
29
|
-
true
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
createPredicate() {
|
|
34
|
-
this.ensureCreated();
|
|
35
|
-
|
|
36
|
-
var propertyName = choice(Array.from(this.propertyNames));
|
|
37
|
-
if (!propertyName || chance(50)) {
|
|
38
|
-
propertyName = this.nameGen.generate();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
node: t.binaryExpression(
|
|
43
|
-
"in",
|
|
44
|
-
t.stringLiteral(propertyName),
|
|
45
|
-
t.identifier(this.objectName)
|
|
46
|
-
),
|
|
47
|
-
value: this.propertyNames.has(propertyName),
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
createTruePredicate() {
|
|
52
|
-
var { node, value } = this.createPredicate();
|
|
53
|
-
if (value) {
|
|
54
|
-
return node;
|
|
55
|
-
}
|
|
56
|
-
return t.unaryExpression("!", node);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
createFalsePredicate() {
|
|
60
|
-
var { node, value } = this.createPredicate();
|
|
61
|
-
if (!value) {
|
|
62
|
-
return node;
|
|
63
|
-
}
|
|
64
|
-
return t.unaryExpression("!", node);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
private ensureCreated(node?: t.Node) {
|
|
68
|
-
if (!this.objectName) {
|
|
69
|
-
// Object hasn't been created yet
|
|
70
|
-
this.objectName = this.me.getPlaceholder() + "_controlObject";
|
|
71
|
-
|
|
72
|
-
if (node && t.isFunctionExpression(node) && !node.id) {
|
|
73
|
-
// Use function declaration as object
|
|
74
|
-
|
|
75
|
-
let newNode: t.FunctionDeclaration = node as any;
|
|
76
|
-
newNode.type = "FunctionDeclaration";
|
|
77
|
-
newNode.id = t.identifier(this.objectName);
|
|
78
|
-
|
|
79
|
-
let newPath = prepend(
|
|
80
|
-
this.blockPath,
|
|
81
|
-
newNode
|
|
82
|
-
)[0] as NodePath<t.FunctionDeclaration>;
|
|
83
|
-
this.me.skip(newPath);
|
|
84
|
-
|
|
85
|
-
this.objectPath = newPath;
|
|
86
|
-
|
|
87
|
-
return t.identifier(this.objectName);
|
|
88
|
-
} else {
|
|
89
|
-
// Create plain object
|
|
90
|
-
let newPath = prepend(
|
|
91
|
-
this.blockPath,
|
|
92
|
-
t.variableDeclaration("var", [
|
|
93
|
-
t.variableDeclarator(
|
|
94
|
-
t.identifier(this.objectName),
|
|
95
|
-
t.objectExpression([])
|
|
96
|
-
),
|
|
97
|
-
])
|
|
98
|
-
)[0] as NodePath<t.VariableDeclaration>;
|
|
99
|
-
this.me.skip(newPath);
|
|
100
|
-
|
|
101
|
-
this.objectPath = newPath;
|
|
102
|
-
|
|
103
|
-
var objectExpression = newPath.node.declarations[0]
|
|
104
|
-
.init as t.ObjectExpression;
|
|
105
|
-
|
|
106
|
-
this.objectExpression = objectExpression;
|
|
107
|
-
this.me.skip(this.objectExpression);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
addProperty(node: t.Expression) {
|
|
113
|
-
var initialNode = this.ensureCreated(node);
|
|
114
|
-
if (initialNode) return initialNode;
|
|
115
|
-
|
|
116
|
-
const propertyName = this.nameGen.generate();
|
|
117
|
-
this.propertyNames.add(propertyName);
|
|
118
|
-
|
|
119
|
-
// Add an initial property
|
|
120
|
-
if (this.objectExpression) {
|
|
121
|
-
this.objectExpression.properties.push(
|
|
122
|
-
t.objectProperty(t.identifier(propertyName), node)
|
|
123
|
-
);
|
|
124
|
-
} else {
|
|
125
|
-
// Add as assignment expression
|
|
126
|
-
|
|
127
|
-
let assignment = t.assignmentExpression(
|
|
128
|
-
"=",
|
|
129
|
-
this.createMemberExpression(propertyName),
|
|
130
|
-
node
|
|
131
|
-
);
|
|
132
|
-
|
|
133
|
-
var newPath = this.objectPath.insertAfter(
|
|
134
|
-
t.expressionStatement(assignment)
|
|
135
|
-
)[0];
|
|
136
|
-
this.me.skip(newPath);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return this.createMemberExpression(propertyName);
|
|
140
|
-
}
|
|
141
|
-
}
|