Ver Fonte

Added `mangleProperties` option

sanex3339 há 5 anos atrás
pai
commit
f5e06fcfed

+ 13 - 0
README.md

@@ -329,6 +329,7 @@ Following options are available for the JS Obfuscator:
     identifiersPrefix: '',
     inputFileName: '',
     log: false,
+    mangleProperties: false,
     renameGlobals: false,
     reservedNames: [],
     reservedStrings: [],
@@ -373,6 +374,7 @@ Following options are available for the JS Obfuscator:
     --identifiers-dictionary '<list>' (comma separated)
     --identifiers-prefix <string>
     --log <boolean>
+    --mangle-properties <boolean>
     --rename-globals <boolean>
     --reserved-names '<list>' (comma separated)
     --reserved-strings '<list>' (comma separated)
@@ -662,6 +664,17 @@ Type: `boolean` Default: `false`
 
 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`
 Type: `boolean` Default: `false`
 

Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
dist/index.browser.js


Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 21086
dist/index.cli.js


Diff do ficheiro suprimidas por serem muito extensas
+ 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.MangleProperties);
+        if (this.options.mangleProperties) {
+            astTree = this.runNodeTransformationStage(astTree, NodeTransformationStage.MangleProperties);
+        }
+
         astTree = this.runNodeTransformationStage(astTree, NodeTransformationStage.Converting);
         astTree = this.runNodeTransformationStage(astTree, NodeTransformationStage.Obfuscating);
         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',
                 BooleanSanitizer
             )
+            .option(
+                '--mangle-properties <boolean>', 'UNSAFE: Enables mangling property names',
+                BooleanSanitizer
+            )
             .option(
                 '--reserved-names <list> (comma separated, without whitespaces)',
                 '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 inputFileName: string;
     readonly log: boolean;
+    readonly mangleProperties: boolean;
     readonly renameGlobals: boolean;
     readonly reservedNames: string[];
     readonly reservedStrings: string[];

+ 6 - 0
src/options/Options.ts

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

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

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

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

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

Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff