Jelajahi Sumber

Added `mangleProperties` option

sanex3339 5 tahun lalu
induk
melakukan
f5e06fcfed

+ 13 - 0
README.md

@@ -329,6 +329,7 @@ Following options are available for the JS Obfuscator:
     identifiersPrefix: '',
     identifiersPrefix: '',
     inputFileName: '',
     inputFileName: '',
     log: false,
     log: false,
+    mangleProperties: false,
     renameGlobals: false,
     renameGlobals: false,
     reservedNames: [],
     reservedNames: [],
     reservedStrings: [],
     reservedStrings: [],
@@ -373,6 +374,7 @@ Following options are available for the JS Obfuscator:
     --identifiers-dictionary '<list>' (comma separated)
     --identifiers-dictionary '<list>' (comma separated)
     --identifiers-prefix <string>
     --identifiers-prefix <string>
     --log <boolean>
     --log <boolean>
+    --mangle-properties <boolean>
     --rename-globals <boolean>
     --rename-globals <boolean>
     --reserved-names '<list>' (comma separated)
     --reserved-names '<list>' (comma separated)
     --reserved-strings '<list>' (comma separated)
     --reserved-strings '<list>' (comma separated)
@@ -662,6 +664,17 @@ Type: `boolean` Default: `false`
 
 
 Enables logging of the information to the console.
 Enables logging of the information to the console.
 
 
+### `mangleProperties`
+Type: `boolean` Default: `false`
+
+##### :warning: this option will break your code in most cases. Enable it only if you know what it does!
+
+Enables mangling property names. 
+
+Generated names are being controlled by [`identifierNamesGenerator`](#identifierNamesGenerator) option.
+
+It is possible to control which properties will be mangled with [`reservedNames`](#reservedNames) option.
+
 ### `renameGlobals`
 ### `renameGlobals`
 Type: `boolean` Default: `false`
 Type: `boolean` Default: `false`
 
 

File diff ditekan karena terlalu besar
+ 0 - 0
dist/index.browser.js


File diff ditekan karena terlalu besar
+ 0 - 21086
dist/index.cli.js


File diff ditekan karena terlalu besar
+ 0 - 20344
dist/index.js


+ 4 - 1
src/JavaScriptObfuscator.ts

@@ -209,7 +209,10 @@ export class JavaScriptObfuscator implements IJavaScriptObfuscator {
             astTree = this.runNodeTransformationStage(astTree, NodeTransformationStage.ControlFlowFlattening);
             astTree = this.runNodeTransformationStage(astTree, NodeTransformationStage.ControlFlowFlattening);
         }
         }
 
 
-        astTree = this.runNodeTransformationStage(astTree, NodeTransformationStage.MangleProperties);
+        if (this.options.mangleProperties) {
+            astTree = this.runNodeTransformationStage(astTree, NodeTransformationStage.MangleProperties);
+        }
+
         astTree = this.runNodeTransformationStage(astTree, NodeTransformationStage.Converting);
         astTree = this.runNodeTransformationStage(astTree, NodeTransformationStage.Converting);
         astTree = this.runNodeTransformationStage(astTree, NodeTransformationStage.Obfuscating);
         astTree = this.runNodeTransformationStage(astTree, NodeTransformationStage.Obfuscating);
         astTree = this.runNodeTransformationStage(astTree, NodeTransformationStage.Finalizing);
         astTree = this.runNodeTransformationStage(astTree, NodeTransformationStage.Finalizing);

+ 4 - 0
src/cli/JavaScriptObfuscatorCLI.ts

@@ -249,6 +249,10 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
                 '--log <boolean>', 'Enables logging of the information to the console',
                 '--log <boolean>', 'Enables logging of the information to the console',
                 BooleanSanitizer
                 BooleanSanitizer
             )
             )
+            .option(
+                '--mangle-properties <boolean>', 'UNSAFE: Enables mangling property names',
+                BooleanSanitizer
+            )
             .option(
             .option(
                 '--reserved-names <list> (comma separated, without whitespaces)',
                 '--reserved-names <list> (comma separated, without whitespaces)',
                 'Disables obfuscation and generation of identifiers, which being matched by passed RegExp patterns (comma separated)',
                 'Disables obfuscation and generation of identifiers, which being matched by passed RegExp patterns (comma separated)',

+ 1 - 0
src/interfaces/options/IOptions.ts

@@ -21,6 +21,7 @@ export interface IOptions {
     readonly identifiersPrefix: string;
     readonly identifiersPrefix: string;
     readonly inputFileName: string;
     readonly inputFileName: string;
     readonly log: boolean;
     readonly log: boolean;
+    readonly mangleProperties: boolean;
     readonly renameGlobals: boolean;
     readonly renameGlobals: boolean;
     readonly reservedNames: string[];
     readonly reservedNames: string[];
     readonly reservedStrings: string[];
     readonly reservedStrings: string[];

+ 6 - 0
src/options/Options.ts

@@ -150,6 +150,12 @@ export class Options implements IOptions {
     @IsBoolean()
     @IsBoolean()
     public readonly log!: boolean;
     public readonly log!: boolean;
 
 
+    /**
+     * @type {boolean}
+     */
+    @IsBoolean()
+    public readonly mangleProperties!: boolean;
+
     /**
     /**
      * @type {boolean}
      * @type {boolean}
      */
      */

+ 1 - 0
src/options/presets/Default.ts

@@ -21,6 +21,7 @@ export const DEFAULT_PRESET: TInputOptions = Object.freeze({
     identifiersDictionary: [],
     identifiersDictionary: [],
     inputFileName: '',
     inputFileName: '',
     log: false,
     log: false,
+    mangleProperties: false,
     renameGlobals: false,
     renameGlobals: false,
     reservedNames: [],
     reservedNames: [],
     reservedStrings: [],
     reservedStrings: [],

+ 1 - 0
src/options/presets/NoCustomNodes.ts

@@ -20,6 +20,7 @@ export const NO_ADDITIONAL_NODES_PRESET: TInputOptions = Object.freeze({
     identifiersDictionary: [],
     identifiersDictionary: [],
     inputFileName: '',
     inputFileName: '',
     log: false,
     log: false,
+    mangleProperties: false,
     renameGlobals: false,
     renameGlobals: false,
     reservedNames: [],
     reservedNames: [],
     reservedStrings: [],
     reservedStrings: [],

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini