js-confuser 1.5.3 → 1.5.5
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/CHANGELOG.md +19 -0
- package/dist/transforms/identifier/variableAnalysis.js +1 -1
- package/dist/transforms/opaquePredicates.js +1 -1
- package/dist/transforms/shuffle.js +2 -1
- package/dist/util/insert.js +29 -0
- package/package.json +1 -1
- package/src/transforms/identifier/variableAnalysis.ts +2 -1
- package/src/transforms/opaquePredicates.ts +2 -2
- package/src/transforms/shuffle.ts +9 -5
- package/src/util/insert.ts +27 -0
- package/test/transforms/identifier/renameVariables.test.ts +35 -0
- package/test/transforms/opaquePredicates.test.ts +25 -0
- package/test/transforms/shuffle.test.ts +35 -17
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
# `1.5.5`
|
|
2
|
+
Updates
|
|
3
|
+
|
|
4
|
+
- Fixed [#53](https://github.com/MichaelXF/js-confuser/issues/53)
|
|
5
|
+
- - Shuffle to not use common varialbe names like `x`
|
|
6
|
+
|
|
7
|
+
- Fixed [#60](https://github.com/MichaelXF/js-confuser/issues/60)
|
|
8
|
+
- - Rename Variables to properly handle function parameters
|
|
9
|
+
|
|
10
|
+
- Fixed [#62](https://github.com/MichaelXF/js-confuser/issues/62)
|
|
11
|
+
- - Rename Variables to properly handle catch-clause parameters
|
|
12
|
+
|
|
13
|
+
# `1.5.4`
|
|
14
|
+
Small fix
|
|
15
|
+
|
|
16
|
+
- Fixed [#45](https://github.com/MichaelXF/js-confuser/issues/45)
|
|
17
|
+
- - Opaque predicates fixed to not this cause error
|
|
18
|
+
|
|
19
|
+
|
|
1
20
|
# `1.5.3`
|
|
2
21
|
Shuffle fix
|
|
3
22
|
|
|
@@ -100,7 +100,7 @@ class VariableAnalysis extends _transform.default {
|
|
|
100
100
|
this.globals.add(o.name);
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
var definingContexts = info.spec.isDefined ?
|
|
103
|
+
var definingContexts = info.spec.isDefined ? (0, _insert.getAllDefiningContexts)(o, p) : (0, _insert.getReferencingContexts)(o, p, info);
|
|
104
104
|
(0, _assert.ok)(definingContexts.length);
|
|
105
105
|
definingContexts.forEach(definingContext => {
|
|
106
106
|
(0, _assert.ok)((0, _insert.isContext)(definingContext), "".concat(definingContext.type, " is not a context"));
|
|
@@ -132,7 +132,7 @@ class OpaquePredicates extends _transform.default {
|
|
|
132
132
|
|
|
133
133
|
var cloned = (0, _insert.clone)(expr);
|
|
134
134
|
|
|
135
|
-
if (object.type == "SwitchCase") {
|
|
135
|
+
if (object.type == "SwitchCase" && object.test) {
|
|
136
136
|
var matching = (0, _gen.Identifier)((0, _random.choice)(["undefined", "null"]));
|
|
137
137
|
var test = object.test;
|
|
138
138
|
|
|
@@ -139,7 +139,8 @@ class Shuffle extends _transform.default {
|
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
if (mode !== "hash") {
|
|
142
|
-
|
|
142
|
+
var varPrefix = this.getPlaceholder();
|
|
143
|
+
code.push((0, _template.default)("\n for ( var ".concat(varPrefix, "x = 16; ").concat(varPrefix, "x%4 === 0; ").concat(varPrefix, "x++) {\n var ").concat(varPrefix, "z = 0;\n ").concat(inPlace ? "".concat(inPlaceName, " = ").concat(name) : name, " = ").concat(name, ".concat((function(){\n ").concat(varPrefix, "z++;\n if(").concat(varPrefix, "z === 1){\n return [];\n }\n\n for( var ").concat(varPrefix, "i = ").concat((0, _random.getRandomInteger)(5, 105), "; ").concat(varPrefix, "i; ").concat(varPrefix, "i-- ){\n ").concat(name, ".unshift(").concat(name, ".pop());\n }\n return [];\n })());\n }\n ")).single());
|
|
143
144
|
}
|
|
144
145
|
|
|
145
146
|
code.push((0, _gen.ForStatement)((0, _gen.VariableDeclaration)((0, _gen.VariableDeclarator)(iName, expr)), (0, _gen.Identifier)(iName), (0, _gen.UpdateExpression)("--", (0, _gen.Identifier)(iName), false), [// ${name}.unshift(${name}.pop());
|
package/dist/util/insert.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.append = append;
|
|
|
7
7
|
exports.clone = clone;
|
|
8
8
|
exports.deleteDeclaration = deleteDeclaration;
|
|
9
9
|
exports.deleteDirect = deleteDirect;
|
|
10
|
+
exports.getAllDefiningContexts = getAllDefiningContexts;
|
|
10
11
|
exports.getBlockBody = getBlockBody;
|
|
11
12
|
exports.getContexts = getContexts;
|
|
12
13
|
exports.getDefiningContext = getDefiningContext;
|
|
@@ -149,6 +150,34 @@ function getDefiningContext(o, p) {
|
|
|
149
150
|
|
|
150
151
|
return getVarContext(o, p);
|
|
151
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* A more accurate context finding function.
|
|
155
|
+
* @param o Object
|
|
156
|
+
* @param p Parents
|
|
157
|
+
* @returns Contexts
|
|
158
|
+
*/
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
function getAllDefiningContexts(o, p) {
|
|
162
|
+
var contexts = [getDefiningContext(o, p)];
|
|
163
|
+
var info = (0, _identifiers.getIdentifierInfo)(o, p);
|
|
164
|
+
|
|
165
|
+
if (info.isFunctionParameter) {
|
|
166
|
+
// Get Function
|
|
167
|
+
var fn = getFunction(o, p);
|
|
168
|
+
contexts.push(fn.body);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (info.isClauseParameter) {
|
|
172
|
+
var catchClause = p.find(x => x.type === "CatchClause");
|
|
173
|
+
|
|
174
|
+
if (catchClause) {
|
|
175
|
+
contexts.push(catchClause.body);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return contexts;
|
|
180
|
+
}
|
|
152
181
|
|
|
153
182
|
function getReferencingContexts(o, p, info) {
|
|
154
183
|
(0, _identifiers.validateChain)(o, p);
|
package/package.json
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
getLexContext,
|
|
11
11
|
isContext,
|
|
12
12
|
getReferencingContexts,
|
|
13
|
+
getAllDefiningContexts,
|
|
13
14
|
} from "../../util/insert";
|
|
14
15
|
import Transform from "../transform";
|
|
15
16
|
|
|
@@ -86,7 +87,7 @@ export default class VariableAnalysis extends Transform {
|
|
|
86
87
|
}
|
|
87
88
|
|
|
88
89
|
var definingContexts = info.spec.isDefined
|
|
89
|
-
?
|
|
90
|
+
? getAllDefiningContexts(o, p)
|
|
90
91
|
: getReferencingContexts(o, p, info);
|
|
91
92
|
|
|
92
93
|
ok(definingContexts.length);
|
|
@@ -199,8 +199,8 @@ export default class OpaquePredicates extends Transform {
|
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
var cloned = clone(expr);
|
|
202
|
-
if (object.type == "SwitchCase") {
|
|
203
|
-
var matching = Identifier(choice(["undefined", "null"]));
|
|
202
|
+
if (object.type == "SwitchCase" && object.test) {
|
|
203
|
+
var matching: Node = Identifier(choice(["undefined", "null"]));
|
|
204
204
|
|
|
205
205
|
var test = object.test;
|
|
206
206
|
|
|
@@ -166,19 +166,23 @@ export default class Shuffle extends Transform {
|
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
if (mode !== "hash") {
|
|
169
|
+
var varPrefix = this.getPlaceholder();
|
|
169
170
|
code.push(
|
|
170
171
|
Template(`
|
|
171
|
-
for ( var x = 16; x%4 === 0; x++) {
|
|
172
|
-
var z = 0;
|
|
172
|
+
for ( var ${varPrefix}x = 16; ${varPrefix}x%4 === 0; ${varPrefix}x++) {
|
|
173
|
+
var ${varPrefix}z = 0;
|
|
173
174
|
${
|
|
174
175
|
inPlace ? `${inPlaceName} = ${name}` : name
|
|
175
176
|
} = ${name}.concat((function(){
|
|
176
|
-
z++;
|
|
177
|
-
if(z === 1){
|
|
177
|
+
${varPrefix}z++;
|
|
178
|
+
if(${varPrefix}z === 1){
|
|
178
179
|
return [];
|
|
179
180
|
}
|
|
180
181
|
|
|
181
|
-
for( var i = ${getRandomInteger(
|
|
182
|
+
for( var ${varPrefix}i = ${getRandomInteger(
|
|
183
|
+
5,
|
|
184
|
+
105
|
|
185
|
+
)}; ${varPrefix}i; ${varPrefix}i-- ){
|
|
182
186
|
${name}.unshift(${name}.pop());
|
|
183
187
|
}
|
|
184
188
|
return [];
|
package/src/util/insert.ts
CHANGED
|
@@ -125,6 +125,33 @@ export function getDefiningContext(o: Node, p: Node[]): Node {
|
|
|
125
125
|
return getVarContext(o, p);
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
+
/**
|
|
129
|
+
* A more accurate context finding function.
|
|
130
|
+
* @param o Object
|
|
131
|
+
* @param p Parents
|
|
132
|
+
* @returns Contexts
|
|
133
|
+
*/
|
|
134
|
+
export function getAllDefiningContexts(o: Node, p: Node[]): Node[] {
|
|
135
|
+
var contexts = [getDefiningContext(o, p)];
|
|
136
|
+
|
|
137
|
+
var info = getIdentifierInfo(o, p);
|
|
138
|
+
if (info.isFunctionParameter) {
|
|
139
|
+
// Get Function
|
|
140
|
+
var fn = getFunction(o, p);
|
|
141
|
+
|
|
142
|
+
contexts.push(fn.body);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (info.isClauseParameter) {
|
|
146
|
+
var catchClause = p.find((x) => x.type === "CatchClause");
|
|
147
|
+
if (catchClause) {
|
|
148
|
+
contexts.push(catchClause.body);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return contexts;
|
|
153
|
+
}
|
|
154
|
+
|
|
128
155
|
export function getReferencingContexts(
|
|
129
156
|
o: Node,
|
|
130
157
|
p: Node[],
|
|
@@ -401,3 +401,38 @@ test("Variant #16: Function with multiple parameters and a default value", async
|
|
|
401
401
|
|
|
402
402
|
expect(value).toStrictEqual("Success!");
|
|
403
403
|
});
|
|
404
|
+
|
|
405
|
+
// https://github.com/MichaelXF/js-confuser/issues/60
|
|
406
|
+
test("Variant #17: Function parameter and lexical variable clash", async () => {
|
|
407
|
+
var code = `
|
|
408
|
+
function fun1(a) {
|
|
409
|
+
let b;
|
|
410
|
+
}
|
|
411
|
+
`;
|
|
412
|
+
|
|
413
|
+
var output = await JsConfuser(code, {
|
|
414
|
+
target: "node",
|
|
415
|
+
renameVariables: true,
|
|
416
|
+
renameGlobals: true,
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
eval(output);
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
test("Variant #18: Catch parameter and lexical variable clash", async () => {
|
|
423
|
+
var code = `
|
|
424
|
+
try {
|
|
425
|
+
|
|
426
|
+
} catch (a){
|
|
427
|
+
let b;
|
|
428
|
+
}
|
|
429
|
+
`;
|
|
430
|
+
|
|
431
|
+
var output = await JsConfuser(code, {
|
|
432
|
+
target: "node",
|
|
433
|
+
renameVariables: true,
|
|
434
|
+
renameGlobals: true,
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
eval(output);
|
|
438
|
+
});
|
|
@@ -16,3 +16,28 @@ it("should append logical expressions", async () => {
|
|
|
16
16
|
|
|
17
17
|
expect(output).not.toContain("(test)");
|
|
18
18
|
});
|
|
19
|
+
|
|
20
|
+
// https://github.com/MichaelXF/js-confuser/issues/45
|
|
21
|
+
it("should work on default Switch cases", async ()=>{
|
|
22
|
+
var code = `
|
|
23
|
+
|
|
24
|
+
switch (0) {
|
|
25
|
+
default:
|
|
26
|
+
input(true);
|
|
27
|
+
}
|
|
28
|
+
`;
|
|
29
|
+
|
|
30
|
+
var output = await JsConfuser(code, {
|
|
31
|
+
target: "browser",
|
|
32
|
+
opaquePredicates: true,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
var value;
|
|
36
|
+
function input(valueIn){
|
|
37
|
+
value = valueIn;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
eval(output);
|
|
41
|
+
|
|
42
|
+
expect(value).toStrictEqual(true);
|
|
43
|
+
})
|
|
@@ -92,26 +92,44 @@ it("should shuffle arrays based on hash and unshuffle incorrect if changed", asy
|
|
|
92
92
|
|
|
93
93
|
// https://github.com/MichaelXF/js-confuser/issues/48
|
|
94
94
|
it("Should properly apply to const variables", async () => {
|
|
95
|
-
|
|
95
|
+
var code = `
|
|
96
96
|
const TEST_ARRAY = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
|
97
97
|
|
|
98
98
|
input(TEST_ARRAY);
|
|
99
99
|
`;
|
|
100
100
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
101
|
+
var output = await JsConfuser(code, {
|
|
102
|
+
target: "browser",
|
|
103
|
+
shuffle: true,
|
|
104
|
+
});
|
|
105
105
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
106
|
+
expect(output).toContain("TEST_ARRAY=function");
|
|
107
|
+
|
|
108
|
+
var value;
|
|
109
|
+
function input(valueIn) {
|
|
110
|
+
value = valueIn;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
eval(output);
|
|
114
|
+
|
|
115
|
+
expect(value).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// https://github.com/MichaelXF/js-confuser/issues/53
|
|
119
|
+
it("Should not use common variable names like x", async () => {
|
|
120
|
+
var code = `
|
|
121
|
+
let x = -999;
|
|
122
|
+
let a = [1, 2, 3, 4, 5, 6];
|
|
123
|
+
|
|
124
|
+
VALUE = a;
|
|
125
|
+
`;
|
|
126
|
+
|
|
127
|
+
var output = await JsConfuser(code, {
|
|
128
|
+
target: "browser",
|
|
129
|
+
shuffle: true,
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
var VALUE;
|
|
133
|
+
eval(output);
|
|
134
|
+
expect(VALUE).toEqual([1, 2, 3, 4, 5, 6]);
|
|
135
|
+
});
|