sanex3339 9 년 전
부모
커밋
19fe8255ef
4개의 변경된 파일24개의 추가작업 그리고 15개의 파일을 삭제
  1. 8 6
      index.js
  2. 10 6
      index.ts
  3. 1 1
      package.json
  4. 5 2
      readme.md

+ 8 - 6
index.js

@@ -3,23 +3,25 @@ const esprima = require('esprima');
 const escodegen = require('escodegen');
 const Obfuscator_1 = require('./src/Obfuscator');
 class JavaScriptObfuscator {
-    static obfuscate(sourceCode, options = {}) {
-        let astTree = esprima.parse(sourceCode), obfuscator = new Obfuscator_1.Obfuscator(options);
+    static obfuscate(sourceCode, customOptions) {
+        let astTree = esprima.parse(sourceCode), options = Object.assign(JavaScriptObfuscator.defaultOptions, customOptions), obfuscator = new Obfuscator_1.Obfuscator(options);
         obfuscator.obfuscateNode(astTree);
         return JavaScriptObfuscator.generateCode(astTree, options);
     }
-    static generateCode(astTree, options = {}) {
+    static generateCode(astTree, options) {
         let escodegenParams = Object.assign({}, JavaScriptObfuscator.escodegenParams);
         if (options.hasOwnProperty('compact')) {
+            escodegenParams.format = {};
             escodegenParams.format.compact = options.compact;
         }
         return escodegen.generate(astTree, escodegenParams);
     }
 }
+JavaScriptObfuscator.defaultOptions = {
+    compact: true,
+    rotateUnicodeArray: true
+};
 JavaScriptObfuscator.escodegenParams = {
-    format: {
-        compact: true
-    },
     verbatim: 'x-verbatim-property'
 };
 exports.JavaScriptObfuscator = JavaScriptObfuscator;

+ 10 - 6
index.ts

@@ -8,22 +8,25 @@ import { IProgramNode } from './src/interfaces/nodes/IProgramNode';
 import { Obfuscator } from './src/Obfuscator';
 
 export class JavaScriptObfuscator {
+    private static defaultOptions: any = {
+        compact: true,
+        rotateUnicodeArray: true
+    };
+
     /**
      * @type any
      */
     private static escodegenParams: any = {
-        format: {
-            compact: true
-        },
         verbatim: 'x-verbatim-property'
     };
 
     /**
      * @param sourceCode
-     * @param options
+     * @param customOptions
      */
-    public static obfuscate (sourceCode: string, options: any = {}): string {
+    public static obfuscate (sourceCode: string, customOptions: any): string {
         let astTree: IProgramNode = esprima.parse(sourceCode),
+            options: any = Object.assign(JavaScriptObfuscator.defaultOptions, customOptions),
             obfuscator: Obfuscator = new Obfuscator(options);
 
         obfuscator.obfuscateNode(astTree);
@@ -35,10 +38,11 @@ export class JavaScriptObfuscator {
      * @param astTree
      * @param options
      */
-    private static generateCode (astTree: IProgramNode, options: any = {}): string {
+    private static generateCode (astTree: IProgramNode, options: any): string {
         let escodegenParams: any = Object.assign({}, JavaScriptObfuscator.escodegenParams);
 
         if (options.hasOwnProperty('compact')) {
+            escodegenParams.format = {};
             escodegenParams.format.compact = options.compact;
         }
 

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "javascript-obfuscator",
-  "version": "0.2.1",
+  "version": "0.3.0",
   "description": "JavaScript obfuscator",
   "main": "index.js",
   "dependencies": {

+ 5 - 2
readme.md

@@ -5,8 +5,6 @@ Compatible with ES6.
 Tested on Angular2 bundle.
 https://gist.github.com/sanex3339/ffc2876123b52e6d11ce45369fd53acf
 
-##Important: right now obfuscation of code which was minimized with UglifyJS may not work  (tested on Angular 2 bundle). I will try to fix that soon or later.
-
 ###Installation
 
 Install the package with NPM and add it to your devDependencies:
@@ -62,6 +60,11 @@ Options for JavaScript obfuscator:
 ```
 
 ###Available options
+####compact
+Type: `boolean` Default: `true`
+
+Compact code output in one line.
+
 ####rotateUnicodeArray
 Type: `boolean` Default: `true`