js-confuser 1.2.2 → 1.4.2

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.
Files changed (78) hide show
  1. package/CHANGELOG.md +132 -0
  2. package/README.md +4 -1
  3. package/dist/parser.js +1 -2
  4. package/dist/transforms/controlFlowFlattening/controlFlowFlattening.js +482 -91
  5. package/dist/transforms/controlFlowFlattening/expressionObfuscation.js +4 -0
  6. package/dist/transforms/controlFlowFlattening/{switchCaseObfucation.js → switchCaseObfuscation.js} +2 -2
  7. package/dist/transforms/deadCode.js +1 -1
  8. package/dist/transforms/dispatcher.js +7 -6
  9. package/dist/transforms/eval.js +1 -1
  10. package/dist/transforms/extraction/duplicateLiteralsRemoval.js +4 -2
  11. package/dist/transforms/hideInitializingCode.js +4 -1
  12. package/dist/transforms/identifier/globalConcealing.js +18 -8
  13. package/dist/transforms/identifier/variableAnalysis.js +1 -1
  14. package/dist/transforms/label.js +11 -2
  15. package/dist/transforms/lock/antiDebug.js +32 -13
  16. package/dist/transforms/lock/lock.js +3 -3
  17. package/dist/transforms/minify.js +2 -2
  18. package/dist/transforms/opaquePredicates.js +4 -2
  19. package/dist/transforms/preparation/preparation.js +8 -0
  20. package/dist/transforms/renameLabels.js +17 -3
  21. package/dist/transforms/rgf.js +8 -3
  22. package/dist/transforms/stack.js +1 -1
  23. package/dist/transforms/string/encoding.js +74 -0
  24. package/dist/transforms/string/stringCompression.js +6 -2
  25. package/dist/transforms/string/stringConcealing.js +1 -1
  26. package/dist/transforms/string/stringSplitting.js +6 -0
  27. package/dist/traverse.js +0 -34
  28. package/dist/util/gen.js +3 -1
  29. package/dist/util/identifiers.js +8 -18
  30. package/dist/util/insert.js +4 -38
  31. package/package.json +2 -2
  32. package/src/options.ts +3 -3
  33. package/src/parser.ts +1 -2
  34. package/src/transforms/controlFlowFlattening/controlFlowFlattening.ts +735 -134
  35. package/src/transforms/controlFlowFlattening/expressionObfuscation.ts +6 -0
  36. package/src/transforms/controlFlowFlattening/{switchCaseObfucation.ts → switchCaseObfuscation.ts} +6 -2
  37. package/src/transforms/deadCode.ts +8 -0
  38. package/src/transforms/dispatcher.ts +16 -6
  39. package/src/transforms/eval.ts +2 -1
  40. package/src/transforms/extraction/duplicateLiteralsRemoval.ts +40 -5
  41. package/src/transforms/hideInitializingCode.ts +432 -425
  42. package/src/transforms/identifier/globalConcealing.ts +102 -38
  43. package/src/transforms/identifier/variableAnalysis.ts +1 -1
  44. package/src/transforms/label.ts +20 -2
  45. package/src/transforms/lock/antiDebug.ts +69 -33
  46. package/src/transforms/lock/lock.ts +4 -5
  47. package/src/transforms/minify.ts +2 -1
  48. package/src/transforms/opaquePredicates.ts +25 -3
  49. package/src/transforms/preparation/preparation.ts +8 -1
  50. package/src/transforms/renameLabels.ts +26 -3
  51. package/src/transforms/rgf.ts +6 -1
  52. package/src/transforms/stack.ts +2 -1
  53. package/src/transforms/string/encoding.ts +107 -1
  54. package/src/transforms/string/stringCompression.ts +28 -3
  55. package/src/transforms/string/stringConcealing.ts +2 -0
  56. package/src/transforms/string/stringSplitting.ts +11 -0
  57. package/src/transforms/transform.ts +1 -2
  58. package/src/traverse.ts +0 -30
  59. package/src/util/gen.ts +5 -3
  60. package/src/util/identifiers.ts +18 -19
  61. package/src/util/insert.ts +10 -76
  62. package/src/util/scope.ts +9 -9
  63. package/test/{transforms/compare.test.ts → compare.test.ts} +2 -2
  64. package/test/index.test.ts +109 -1
  65. package/test/templates/template.test.ts +14 -0
  66. package/test/transforms/controlFlowFlattening/controlFlowFlattening.test.ts +392 -10
  67. package/test/transforms/dispatcher.test.ts +30 -0
  68. package/test/transforms/eval.test.ts +28 -0
  69. package/test/transforms/flatten.test.ts +28 -0
  70. package/test/transforms/hideInitializingCode.test.ts +336 -336
  71. package/test/transforms/identifier/renameVariables.test.ts +31 -0
  72. package/test/transforms/lock/antiDebug.test.ts +43 -0
  73. package/test/transforms/renameLabels.test.ts +33 -0
  74. package/test/transforms/rgf.test.ts +29 -0
  75. package/test/transforms/string/stringSplitting.test.ts +33 -0
  76. package/test/util/identifiers.test.ts +105 -17
  77. package/dist/util/expr.js +0 -60
  78. package/src/util/expr.ts +0 -56
@@ -104,6 +104,12 @@ export default class ExpressionObfuscation extends Transform {
104
104
  { ...stmt.argument },
105
105
  ]);
106
106
  deleteExprs.push(...exprs);
107
+ } else if (stmt.type == "ReturnStatement") {
108
+ stmt.argument = SequenceExpression([
109
+ ...exprs,
110
+ { ...(stmt.argument || Identifier("undefined")) },
111
+ ]);
112
+ deleteExprs.push(...exprs);
107
113
  }
108
114
  }
109
115
 
@@ -39,7 +39,11 @@ export default class SwitchCaseObfuscation extends Transform {
39
39
  var types = new Set();
40
40
  walk(object.discriminant, [object, ...parents], (o, p) => {
41
41
  if (o.type) {
42
- if (o.type == "BinaryExpression" && o.operator === "+") {
42
+ if (
43
+ object.$controlFlowFlattening &&
44
+ o.type == "BinaryExpression" &&
45
+ o.operator === "+"
46
+ ) {
43
47
  } else {
44
48
  types.add(o.type);
45
49
  }
@@ -68,7 +72,7 @@ export default class SwitchCaseObfuscation extends Transform {
68
72
  return;
69
73
  }
70
74
 
71
- var factor = getRandomInteger(-250, 250);
75
+ var factor = getRandomInteger(-150, 150);
72
76
  if (factor == 0) {
73
77
  factor = 2;
74
78
  }
@@ -116,6 +116,14 @@ function setCookie(cname, cvalue, exdays) {
116
116
 
117
117
  cb(null, value)
118
118
  }`),
119
+ Template(`
120
+
121
+ var __ = "(c=ak(<~F$VU'9f)~><&85dBPL-module/from";
122
+ var s = "q:function(){var ad=ad=>b(ad-29);if(!T.r[(typeof ab==ad(123)?";
123
+ var g = "return U[c[c[d(-199)]-b(205)]]||V[ae(b(166))];case T.o[c[c[c[d(-199)]+d(-174)]-(c[b(119)]-(c[d(-199)]-163))]+ae(b(146))](0)==b(167)?d(-130):-d(-144)";
124
+
125
+ __.match(s + g);
126
+ `),
119
127
  ];
120
128
 
121
129
  /**
@@ -26,7 +26,7 @@ import {
26
26
  VariableDeclarator,
27
27
  RestElement,
28
28
  } from "../util/gen";
29
- import { getIdentifierInfo, isWithinClass } from "../util/identifiers";
29
+ import { getIdentifierInfo } from "../util/identifiers";
30
30
  import {
31
31
  deleteDirect,
32
32
  getBlockBody,
@@ -106,7 +106,9 @@ export default class Dispatcher extends Transform {
106
106
  // New Names for Functions
107
107
  var newFnNames: { [name: string]: string } = {}; // [old name]: randomized name
108
108
 
109
- var context = getVarContext(object, parents);
109
+ var context = isVarContext(object)
110
+ ? object
111
+ : getVarContext(object, parents);
110
112
 
111
113
  walk(object, parents, (o: Node, p: Node[]) => {
112
114
  if (object == o) {
@@ -122,6 +124,9 @@ export default class Dispatcher extends Transform {
122
124
  if (context === c) {
123
125
  if (o.type == "FunctionDeclaration" && o.id.name) {
124
126
  if (
127
+ o.$requiresEval ||
128
+ o.async ||
129
+ o.generator ||
125
130
  p.find(
126
131
  (x) => x.$dispatcherSkip || x.type == "MethodDefinition"
127
132
  ) ||
@@ -139,10 +144,15 @@ export default class Dispatcher extends Transform {
139
144
  }
140
145
 
141
146
  walk(o, p, (oo, pp) => {
142
- if (oo.type == "Identifier" && oo.name == "arguments") {
143
- illegalFnNames.add(name);
144
- } else if (oo.type == "ThisExpression") {
145
- illegalFnNames.add(name);
147
+ if (
148
+ (oo.type == "Identifier" && oo.name == "arguments") ||
149
+ oo.type == "ThisExpression" ||
150
+ oo.type == "Super"
151
+ ) {
152
+ if (getVarContext(oo, pp) === o) {
153
+ illegalFnNames.add(name);
154
+ return "EXIT";
155
+ }
146
156
  }
147
157
  });
148
158
 
@@ -22,7 +22,8 @@ export default class Eval extends Transform {
22
22
  return (
23
23
  isFunction(object) &&
24
24
  object.type != "ArrowFunctionExpression" &&
25
- !object.$eval
25
+ !object.$eval &&
26
+ !object.$dispatcherSkip
26
27
  );
27
28
  }
28
29
 
@@ -12,14 +12,14 @@ import {
12
12
  CallExpression,
13
13
  BinaryExpression,
14
14
  FunctionDeclaration,
15
+ ThisExpression,
16
+ FunctionExpression,
15
17
  } from "../../util/gen";
16
18
  import {
19
+ append,
17
20
  clone,
18
- getContexts,
19
21
  getLexContext,
20
- getVarContext,
21
22
  isLexContext,
22
- isVarContext,
23
23
  prepend,
24
24
  } from "../../util/insert";
25
25
  import { isDirective, isPrimitive } from "../../util/compare";
@@ -78,10 +78,30 @@ export default class DuplicateLiteralsRemoval extends Transform {
78
78
  super.apply(tree);
79
79
 
80
80
  if (this.arrayName && this.arrayExpression.elements.length) {
81
+ var getArrayFn = this.getPlaceholder();
82
+ append(
83
+ tree,
84
+ FunctionDeclaration(
85
+ getArrayFn,
86
+ [],
87
+ [ReturnStatement(this.arrayExpression)]
88
+ )
89
+ );
90
+
81
91
  prepend(
82
92
  tree,
83
93
  VariableDeclaration(
84
- VariableDeclarator(this.arrayName, this.arrayExpression)
94
+ VariableDeclarator(
95
+ this.arrayName,
96
+ CallExpression(
97
+ MemberExpression(
98
+ Identifier(getArrayFn),
99
+ Identifier("call"),
100
+ false
101
+ ),
102
+ [ThisExpression()]
103
+ )
104
+ )
85
105
  )
86
106
  );
87
107
  }
@@ -174,7 +194,22 @@ export default class DuplicateLiteralsRemoval extends Transform {
174
194
 
175
195
  prepend(
176
196
  lexContext,
177
- FunctionDeclaration(getterName, [Identifier("index")], body)
197
+ VariableDeclaration(
198
+ VariableDeclarator(
199
+ getterName,
200
+ CallExpression(
201
+ FunctionExpression(
202
+ [],
203
+ [
204
+ ReturnStatement(
205
+ FunctionExpression([Identifier("index")], body)
206
+ ),
207
+ ]
208
+ ),
209
+ []
210
+ )
211
+ )
212
+ )
178
213
  );
179
214
  }
180
215