Преглед изворни кода

Applying optimize-js for obfuscated code

sanex3339 пре 8 година
родитељ
комит
7c23e9fc04

Разлика између датотеке није приказан због своје велике величине
+ 128 - 128
dist/index.js


+ 3 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "javascript-obfuscator",
-  "version": "0.8.0-dev.0",
+  "version": "0.8.0-dev.1",
   "description": "JavaScript obfuscator",
   "keywords": [
     "obfuscator",
@@ -29,6 +29,7 @@
     "estraverse": "^4.2.0",
     "format-unicorn": "^1.1.0",
     "mkdirp": "^0.5.1",
+    "optimize-js": "^1.0.1",
     "source-map-support": "^0.4.2"
   },
   "devDependencies": {
@@ -52,6 +53,7 @@
     "coveralls": "^2.11.14",
     "istanbul": "1.1.0-alpha.1",
     "mocha": "^3.0.2",
+    "optimize-js-plugin": "0.0.4",
     "sinon": "^2.0.0-pre.3",
     "ts-loader": "^0.8.2",
     "ts-node": "^1.3.0",

+ 6 - 0
src/JavaScriptObfuscatorInternal.ts

@@ -12,6 +12,8 @@ import { Obfuscator } from "./Obfuscator";
 import { Options } from "./options/Options";
 import { SourceMapCorrector } from "./SourceMapCorrector";
 
+const optimizeJs = require('optimize-js');
+
 export class JavaScriptObfuscatorInternal {
     /**
      * @type {GenerateOptions}
@@ -67,6 +69,10 @@ export class JavaScriptObfuscatorInternal {
 
         const generatorOutput: IGeneratorOutput = escodegen.generate(astTree, escodegenParams);
 
+        if (options.optimize) {
+            generatorOutput.code = optimizeJs(generatorOutput.code);
+        }
+
         generatorOutput.map = generatorOutput.map ? generatorOutput.map.toString() : '';
 
         return generatorOutput;

+ 1 - 0
src/interfaces/IObfuscatorOptions.d.ts

@@ -6,6 +6,7 @@ export interface IObfuscatorOptions {
     debugProtectionInterval?: boolean;
     disableConsoleOutput?: boolean;
     encodeUnicodeLiterals?: boolean;
+    optimize?: boolean;
     reservedNames?: string[];
     rotateUnicodeArray?: boolean;
     selfDefending?: boolean;

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

@@ -6,6 +6,7 @@ export interface IOptions {
     readonly debugProtectionInterval: boolean;
     readonly disableConsoleOutput: boolean;
     readonly encodeUnicodeLiterals: boolean;
+    readonly optimize: boolean;
     readonly reservedNames: string[];
     readonly rotateUnicodeArray: boolean;
     readonly selfDefending: boolean;

+ 6 - 0
src/options/Options.ts

@@ -72,6 +72,12 @@ export class Options implements IOptions {
     @IsBoolean()
     public readonly encodeUnicodeLiterals: boolean;
 
+    /**
+     * @type {boolean}
+     */
+    @IsBoolean()
+    public readonly optimize: boolean;
+
     /**
      * @type {string[]}
      */

+ 1 - 0
src/preset-options/DefaultPreset.ts

@@ -9,6 +9,7 @@ export const DEFAULT_PRESET: IObfuscatorOptions = Object.freeze({
     disableConsoleOutput: true,
     domainLock: [],
     encodeUnicodeLiterals: false,
+    optimize: true,
     reservedNames: [],
     rotateUnicodeArray: true,
     selfDefending: true,

+ 1 - 0
src/preset-options/NoCustomNodesPreset.ts

@@ -9,6 +9,7 @@ export const NO_CUSTOM_NODES_PRESET: IObfuscatorOptions = Object.freeze({
     disableConsoleOutput: false,
     domainLock: [],
     encodeUnicodeLiterals: false,
+    optimize: false,
     reservedNames: [],
     rotateUnicodeArray: false,
     selfDefending: false,

+ 6 - 2
webpack.config.js

@@ -2,7 +2,8 @@
 
 var fs = require("fs"),
     nodeExternals = require('webpack-node-externals'),
-    webpack = require('webpack');
+    webpack = require('webpack'),
+    OptimizeJSPlugin = require('optimize-js-plugin');
 
 function getLicenseText () {
     return "/*\nCopyright (C) 2016 Timofey Kachalov <[email protected]>\n\n" +
@@ -31,7 +32,10 @@ module.exports = {
                 raw: true,
                 entryOnly: false
             }
-        )
+        ),
+        /*new OptimizeJSPlugin({
+            sourceMap: true
+        })*/
     ],
     output: {
         path: './dist',

Неке датотеке нису приказане због велике количине промена