diff --git a/index.js b/index.js index b703a9a3..644c48d5 100644 --- a/index.js +++ b/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; diff --git a/index.ts b/index.ts index 4f898d3a..7f4d8d28 100644 --- a/index.ts +++ b/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; } diff --git a/package.json b/package.json index bfd0ecd3..05244365 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "javascript-obfuscator", - "version": "0.2.1", + "version": "0.3.0", "description": "JavaScript obfuscator", "main": "index.js", "dependencies": { diff --git a/readme.md b/readme.md index 766a2215..1218d03b 100644 --- a/readme.md +++ b/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`