Skip to content

Commit d27165f

Browse files
committed
Remove eval and nameRecycling and slight tweaks to presets
1 parent 54a6953 commit d27165f

File tree

7 files changed

+15
-788
lines changed

7 files changed

+15
-788
lines changed

src/obfuscator.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import DeadCode from "./transforms/deadCode";
1515
import OpaquePredicates from "./transforms/opaquePredicates";
1616
import Calculator from "./transforms/calculator";
1717
import ControlFlowFlattening from "./transforms/controlFlowFlattening/controlFlowFlattening";
18-
import Eval from "./transforms/eval";
1918
import GlobalConcealing from "./transforms/identifier/globalConcealing";
2019
import StringSplitting from "./transforms/string/stringSplitting";
2120
import StringConcealing from "./transforms/string/stringConcealing";
@@ -30,7 +29,6 @@ import ES5 from "./transforms/es5/es5";
3029
import RGF from "./transforms/rgf";
3130
import Flatten from "./transforms/flatten";
3231
import Stack from "./transforms/stack";
33-
import NameRecycling from "./transforms/identifier/nameRecycling";
3432
import AntiTooling from "./transforms/antiTooling";
3533
import Finalizer from "./transforms/finalizer";
3634

@@ -78,7 +76,6 @@ export default class Obfuscator extends EventEmitter {
7876
test(options.deadCode, DeadCode);
7977
test(options.calculator, Calculator);
8078
test(options.controlFlowFlattening, ControlFlowFlattening);
81-
test(options.eval, Eval);
8279
test(options.globalConcealing, GlobalConcealing);
8380
test(options.opaquePredicates, OpaquePredicates);
8481
test(options.stringSplitting, StringSplitting);
@@ -87,7 +84,6 @@ export default class Obfuscator extends EventEmitter {
8784
test(options.stack, Stack);
8885
test(options.duplicateLiteralsRemoval, DuplicateLiteralsRemoval);
8986
test(options.shuffle, Shuffle);
90-
test(options.nameRecycling, NameRecycling);
9187
test(options.movedDeclarations, MovedDeclarations);
9288
test(options.minify, Minify);
9389
test(options.renameVariables, RenameVariables);

src/options.ts

Lines changed: 9 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -141,39 +141,6 @@ export interface ObfuscateOptions {
141141
"hexadecimal" | "randomized" | "zeroWidth" | "mangled" | "number"
142142
>;
143143

144-
/**
145-
* ### `nameRecycling`
146-
*
147-
* (Experimental feature)
148-
*
149-
* Attempts to reuse released names.
150-
*
151-
* - Potency Medium
152-
* - Resilience High
153-
* - Cost Low
154-
*
155-
* ```js
156-
* // Input
157-
* function percentage(x) {
158-
* var multiplied = x * 100;
159-
* var floored = Math.floor(multiplied);
160-
* var output = floored + "%"
161-
* return output;
162-
* }
163-
*
164-
* // Output
165-
* function percentage(x) {
166-
* var multiplied = x * 100;
167-
* var floored = Math.floor(multiplied);
168-
* multiplied = floored + "%";
169-
* return multiplied;
170-
* }
171-
* ```
172-
*
173-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
174-
*/
175-
nameRecycling?: ProbabilityMap<boolean>;
176-
177144
/**
178145
* ### `controlFlowFlattening`
179146
*
@@ -286,48 +253,15 @@ export interface ObfuscateOptions {
286253
*/
287254
dispatcher?: ProbabilityMap<boolean>;
288255

289-
/**
290-
* ### `eval`
291-
*
292-
* #### **`Security Warning`**
293-
*
294-
* From [MDN](<(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval)**>): Executing JavaScript from a string is an enormous security risk. It is far too easy
295-
* for a bad actor to run arbitrary code when you use eval(). Never use eval()!
296-
*
297-
* Wraps defined functions within eval statements.
298-
*
299-
* - **`false`** - Avoids using the `eval` function. _Default_.
300-
* - **`true`** - Wraps function's code into an `eval` statement.
301-
*
302-
* ```js
303-
* // Output.js
304-
* var Q4r1__ = {
305-
* Oo$Oz8t: eval(
306-
* "(function(YjVpAp){var gniSBq6=kHmsJrhOO;switch(gniSBq6){case'RW11Hj5x':return console;}});"
307-
* ),
308-
* };
309-
* Q4r1__.Oo$Oz8t("RW11Hj5x");
310-
* ```
311-
*
312-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
313-
*/
314-
eval?: ProbabilityMap<boolean>;
315-
316256
/**
317257
* ### `rgf`
318258
*
319259
* RGF (Runtime-Generated-Functions) uses the [`new Function(code...)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/Function) syntax to construct executable code from strings. (`"all"/true/false`)
320260
*
321-
* - **This can break your code. This is also as dangerous as `eval`.**
261+
* - **This can break your code.
322262
* - **Due to the security concerns of arbitrary code execution, you must enable this yourself.**
323263
* - The arbitrary code is also obfuscated.
324264
*
325-
* | Mode | Description |
326-
* | --- | --- |
327-
* | `"all"` | Recursively applies to every scope (slow) |
328-
* | `true` | Applies to the top level only |
329-
* | `false` | Feature disabled |
330-
*
331265
* ```js
332266
* // Input
333267
* function log(x){
@@ -342,7 +276,7 @@ export interface ObfuscateOptions {
342276
*
343277
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
344278
*/
345-
rgf?: ProbabilityMap<boolean | "all">;
279+
rgf?: ProbabilityMap<boolean>;
346280

347281
/**
348282
* ### `stack`
@@ -678,7 +612,6 @@ const validProperties = new Set([
678612
"renameVariables",
679613
"renameGlobals",
680614
"identifierGenerator",
681-
"nameRecycling",
682615
"controlFlowFlattening",
683616
"globalConcealing",
684617
"stringCompression",
@@ -687,7 +620,6 @@ const validProperties = new Set([
687620
"stringSplitting",
688621
"duplicateLiteralsRemoval",
689622
"dispatcher",
690-
"eval",
691623
"rgf",
692624
"objectExtraction",
693625
"flatten",
@@ -868,6 +800,10 @@ export async function correctOptions(
868800
"alert",
869801
"confirm",
870802
"location",
803+
"btoa",
804+
"atob",
805+
"unescape",
806+
"encodeURIComponent",
871807
].forEach((x) => options.globalVariables.add(x));
872808
} else {
873809
// node
@@ -876,6 +812,8 @@ export async function correctOptions(
876812
"Buffer",
877813
"require",
878814
"process",
815+
"exports",
816+
"module",
879817
"__dirname",
880818
"__filename",
881819
].forEach((x) => options.globalVariables.add(x));
@@ -887,6 +825,7 @@ export async function correctOptions(
887825
"parseInt",
888826
"parseFloat",
889827
"Math",
828+
"JSON",
890829
"Promise",
891830
"String",
892831
"Boolean",
@@ -906,8 +845,6 @@ export async function correctOptions(
906845
"setImmediate",
907846
"clearImmediate",
908847
"queueMicrotask",
909-
"exports",
910-
"module",
911848
"isNaN",
912849
"isFinite",
913850
"Set",

src/presets.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { ObfuscateOptions } from "./options";
1717
* 10. Minified output
1818
*
1919
* ## **`Disabled features`**
20-
* - `eval` Use at your own risk!
20+
* - `rgf` Use at your own risk!
2121
*
2222
* ### Potential Issues
2323
* 1. *String Encoding* can corrupt files. Disable `stringEncoding` manually if this happens.
@@ -51,7 +51,6 @@ const highPreset: ObfuscateOptions = {
5151
stringSplitting: 0.75,
5252

5353
// Use at own risk
54-
eval: false,
5554
rgf: false,
5655
};
5756

@@ -66,9 +65,9 @@ const mediumPreset: ObfuscateOptions = {
6665
calculator: true,
6766
compact: true,
6867
hexadecimalNumbers: true,
69-
controlFlowFlattening: 0.5,
68+
controlFlowFlattening: 0.25,
7069
deadCode: 0.025,
71-
dispatcher: 0.75,
70+
dispatcher: 0.5,
7271
duplicateLiteralsRemoval: 0.5,
7372
globalConcealing: true,
7473
identifierGenerator: "randomized",
@@ -95,10 +94,10 @@ const lowPreset: ObfuscateOptions = {
9594
calculator: true,
9695
compact: true,
9796
hexadecimalNumbers: true,
98-
controlFlowFlattening: 0.25,
97+
controlFlowFlattening: 0.1,
9998
deadCode: 0.01,
100-
dispatcher: 0.5,
101-
duplicateLiteralsRemoval: true,
99+
dispatcher: 0.25,
100+
duplicateLiteralsRemoval: 0.5,
102101
identifierGenerator: "randomized",
103102
minify: true,
104103
movedDeclarations: true,

src/transforms/eval.ts

Lines changed: 0 additions & 89 deletions
This file was deleted.

0 commit comments

Comments
 (0)