Browse Source

refactoring

sanex3339 9 years ago
parent
commit
f25781d6f6

+ 1 - 118
bin/javascript-obfuscator.js

@@ -1,120 +1,3 @@
 #!/usr/bin/env node
 #!/usr/bin/env node
 
 
-var commands = require('commander'),
-    fs = require('fs'),
-    path = require('path'),
-    JavaScriptObfuscator = require('../dist/index'),
-    data = '',
-    defaultOptions = {
-        compact: true,
-        debugProtection: false,
-        debugProtectionInterval: false,
-        disableConsoleOutput: true,
-        encodeUnicodeLiterals: false,
-        reservedNames: [],
-        rotateUnicodeArray: true,
-        selfDefending: true,
-        unicodeArray: true,
-        unicodeArrayThreshold: 0.8,
-        wrapUnicodeArrayCalls: true
-    };
-
-configureProcess();
-configureCommands();
-
-if (!isDataExist()) {
-    commands.outputHelp();
-
-    return 0;
-}
-
-function buildOptions () {
-    var options = {},
-        availableOptions = Object.keys(defaultOptions);
-
-    for (var option in commands) {
-        if (availableOptions.indexOf(option) === -1) {
-            continue;
-        }
-
-        options[option] = commands[option];
-    }
-
-    return Object.assign({}, defaultOptions, options);
-}
-
-function configureCommands () {
-    commands
-        .version(getBuildVersion(), '-v, --version')
-        .usage('[options] STDIN STDOUT')
-        .option('--compact <boolean>', 'Disable one line output code compacting', parseBoolean)
-        .option('--debugProtection <boolean>', 'Disable browser Debug panel (can cause DevTools enabled browser freeze)', parseBoolean)
-        .option('--debugProtectionInterval <boolean>', 'Disable browser Debug panel even after page was loaded (can cause DevTools enabled browser freeze)', parseBoolean)
-        .option('--disableConsoleOutput <boolean>', 'Allow console.log, console.info, console.error and console.warn messages output into browser console', parseBoolean)
-        .option('--encodeUnicodeLiterals <boolean>', 'All literals in Unicode array become encoded in Base64 (this option can slightly slow down your code speed)', parseBoolean)
-        .option('--reservedNames <list>', 'Disable obfuscation of variable names, function names and names of function parameters that match the passed RegExp patterns (comma separated)', (val) => val.split(','))
-        .option('--rotateUnicodeArray <boolean>', 'Disable rotation of unicode array values during obfuscation', parseBoolean)
-        .option('--selfDefending <boolean>', 'Disables self-defending for obfuscated code', parseBoolean)
-        .option('--unicodeArray <boolean>', 'Disables gathering of all literal strings into an array and replacing every literal string with an array call', parseBoolean)
-        .option('--unicodeArrayThreshold <number>', 'The probability that the literal string will be inserted into unicodeArray (Default: 0.8, Min: 0, Max: 1)', parseFloat)
-        .option('--wrapUnicodeArrayCalls <boolean>', 'Disables usage of special access function instead of direct array call', parseBoolean)
-        .parse(process.argv);
-
-    commands.on('--help', function () {
-        var isWindows = process.platform == 'win32';
-
-        console.log('  Examples:\n');
-        console.log('    %> javascript-obfuscator < in.js > out.js');
-
-        if (isWindows) {
-            console.log('    %> type in1.js in2.js | javascript-obfuscator > out.js');
-        } else {
-            console.log('    %> cat in1.js in2.js | javascript-obfuscator > out.js');
-        }
-
-        console.log('');
-
-        process.exit();
-    });
-}
-
-function configureProcess () {
-    process.stdin.setEncoding('utf-8');
-
-    process.stdin.on('readable', function () {
-        var chunk;
-
-        while (chunk = process.stdin.read()) {
-            data += chunk;
-        }
-    });
-
-    process.stdin.on('end', processData);
-}
-
-function getBuildVersion () {
-    var packageConfig = fs.readFileSync(
-        path.join(
-            path.dirname(
-                fs.realpathSync(process.argv[1])
-            ),
-            '../package.json'
-        )
-    );
-
-    return JSON.parse(packageConfig).version;
-}
-
-function isDataExist () {
-    return !process.env.__DIRECT__ && !process.stdin.isTTY;
-}
-
-function parseBoolean (value) {
-    return value === 'true' || value === '1';
-}
-
-function processData() {
-    process.stdout.write(
-        JavaScriptObfuscator.obfuscate(data, buildOptions())
-    );
-}
+require('../dist/index').runCLI();

+ 265 - 131
dist/index.js

@@ -79,7 +79,7 @@ module.exports =
 /******/ 	__webpack_require__.p = "";
 /******/ 	__webpack_require__.p = "";
 /******/
 /******/
 /******/ 	// Load entry module and return exports
 /******/ 	// Load entry module and return exports
-/******/ 	return __webpack_require__(__webpack_require__.s = 15);
+/******/ 	return __webpack_require__(__webpack_require__.s = 16);
 /******/ })
 /******/ })
 /************************************************************************/
 /************************************************************************/
 /******/ ([
 /******/ ([
@@ -93,8 +93,8 @@ module.exports =
 	
 	
 	function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
 	function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
 	
 	
-	var chance_1 = __webpack_require__(40);
-	var JSFuck_1 = __webpack_require__(9);
+	var chance_1 = __webpack_require__(41);
+	var JSFuck_1 = __webpack_require__(10);
 	
 	
 	var Utils = function () {
 	var Utils = function () {
 	    function Utils() {
 	    function Utils() {
@@ -428,7 +428,7 @@ module.exports =
 	function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
 	function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
 	
 	
 	var estraverse = __webpack_require__(3);
 	var estraverse = __webpack_require__(3);
-	var JSFuck_1 = __webpack_require__(9);
+	var JSFuck_1 = __webpack_require__(10);
 	var Nodes_1 = __webpack_require__(8);
 	var Nodes_1 = __webpack_require__(8);
 	var Utils_1 = __webpack_require__(0);
 	var Utils_1 = __webpack_require__(0);
 	
 	
@@ -617,6 +617,61 @@ module.exports =
 
 
 /***/ },
 /***/ },
 /* 9 */
 /* 9 */
+/***/ function(module, exports, __webpack_require__) {
+
+	"use strict";
+	"use strict";
+	
+	var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
+	
+	function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
+	
+	var esprima = __webpack_require__(7);
+	var escodegen = __webpack_require__(11);
+	var JavaScriptObfuscatorCLI_1 = __webpack_require__(20);
+	var Obfuscator_1 = __webpack_require__(17);
+	var Options_1 = __webpack_require__(18);
+	
+	var JavaScriptObfuscator = function () {
+	    function JavaScriptObfuscator() {
+	        _classCallCheck(this, JavaScriptObfuscator);
+	    }
+	
+	    _createClass(JavaScriptObfuscator, null, [{
+	        key: 'obfuscate',
+	        value: function obfuscate(sourceCode, customOptions) {
+	            var astTree = esprima.parse(sourceCode),
+	                options = new Options_1.Options(customOptions),
+	                obfuscator = new Obfuscator_1.Obfuscator(options);
+	            astTree = obfuscator.obfuscateNode(astTree);
+	            return JavaScriptObfuscator.generateCode(astTree, options);
+	        }
+	    }, {
+	        key: 'runCLI',
+	        value: function runCLI() {
+	            new JavaScriptObfuscatorCLI_1.JavaScriptObfuscatorCLI().run();
+	        }
+	    }, {
+	        key: 'generateCode',
+	        value: function generateCode(astTree, options) {
+	            var escodegenParams = Object.assign({}, JavaScriptObfuscator.escodegenParams);
+	            escodegenParams.format = {
+	                compact: options.get('compact')
+	            };
+	            return escodegen.generate(astTree, escodegenParams);
+	        }
+	    }]);
+	
+	    return JavaScriptObfuscator;
+	}();
+	
+	JavaScriptObfuscator.escodegenParams = {
+	    verbatim: 'x-verbatim-property'
+	};
+	exports.JavaScriptObfuscator = JavaScriptObfuscator;
+
+/***/ },
+/* 10 */
 /***/ function(module, exports) {
 /***/ function(module, exports) {
 
 
 	"use strict";
 	"use strict";
@@ -681,60 +736,11 @@ module.exports =
 	};
 	};
 
 
 /***/ },
 /***/ },
-/* 10 */
+/* 11 */
 /***/ function(module, exports) {
 /***/ function(module, exports) {
 
 
 	module.exports = require("escodegen");
 	module.exports = require("escodegen");
 
 
-/***/ },
-/* 11 */
-/***/ function(module, exports, __webpack_require__) {
-
-	"use strict";
-	"use strict";
-	
-	var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
-	
-	function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
-	
-	var esprima = __webpack_require__(7);
-	var escodegen = __webpack_require__(10);
-	var Obfuscator_1 = __webpack_require__(16);
-	var Options_1 = __webpack_require__(17);
-	
-	var JavaScriptObfuscator = function () {
-	    function JavaScriptObfuscator() {
-	        _classCallCheck(this, JavaScriptObfuscator);
-	    }
-	
-	    _createClass(JavaScriptObfuscator, null, [{
-	        key: 'obfuscate',
-	        value: function obfuscate(sourceCode, customOptions) {
-	            var astTree = esprima.parse(sourceCode),
-	                options = new Options_1.Options(customOptions),
-	                obfuscator = new Obfuscator_1.Obfuscator(options);
-	            astTree = obfuscator.obfuscateNode(astTree);
-	            return JavaScriptObfuscator.generateCode(astTree, options);
-	        }
-	    }, {
-	        key: 'generateCode',
-	        value: function generateCode(astTree, options) {
-	            var escodegenParams = Object.assign({}, JavaScriptObfuscator.escodegenParams);
-	            escodegenParams.format = {
-	                compact: options.get('compact')
-	            };
-	            return escodegen.generate(astTree, escodegenParams);
-	        }
-	    }]);
-	
-	    return JavaScriptObfuscator;
-	}();
-	
-	JavaScriptObfuscator.escodegenParams = {
-	    verbatim: 'x-verbatim-property'
-	};
-	exports.JavaScriptObfuscator = JavaScriptObfuscator;
-
 /***/ },
 /***/ },
 /* 12 */
 /* 12 */
 /***/ function(module, exports) {
 /***/ function(module, exports) {
@@ -791,23 +797,44 @@ module.exports =
 /* 14 */
 /* 14 */
 /***/ function(module, exports) {
 /***/ function(module, exports) {
 
 
-	module.exports = require("babel-polyfill");
+	"use strict";
+	"use strict";
+	
+	exports.DEFAULT_PRESET = Object.freeze({
+	    compact: true,
+	    debugProtection: false,
+	    debugProtectionInterval: false,
+	    disableConsoleOutput: true,
+	    encodeUnicodeLiterals: false,
+	    reservedNames: [],
+	    rotateUnicodeArray: true,
+	    selfDefending: true,
+	    unicodeArray: true,
+	    unicodeArrayThreshold: 0.8,
+	    wrapUnicodeArrayCalls: true
+	});
 
 
 /***/ },
 /***/ },
 /* 15 */
 /* 15 */
+/***/ function(module, exports) {
+
+	module.exports = require("babel-polyfill");
+
+/***/ },
+/* 16 */
 /***/ function(module, exports, __webpack_require__) {
 /***/ function(module, exports, __webpack_require__) {
 
 
 	"use strict";
 	"use strict";
 	"use strict";
 	"use strict";
 	
 	
-	var JavaScriptObfuscator_1 = __webpack_require__(11);
+	var JavaScriptObfuscator_1 = __webpack_require__(9);
 	if (!global._babelPolyfill) {
 	if (!global._babelPolyfill) {
-	    __webpack_require__(14);
+	    __webpack_require__(15);
 	}
 	}
 	module.exports = JavaScriptObfuscator_1.JavaScriptObfuscator;
 	module.exports = JavaScriptObfuscator_1.JavaScriptObfuscator;
 
 
 /***/ },
 /***/ },
-/* 16 */
+/* 17 */
 /***/ function(module, exports, __webpack_require__) {
 /***/ function(module, exports, __webpack_require__) {
 
 
 	"use strict";
 	"use strict";
@@ -820,19 +847,19 @@ module.exports =
 	var estraverse = __webpack_require__(3);
 	var estraverse = __webpack_require__(3);
 	var AppendState_1 = __webpack_require__(6);
 	var AppendState_1 = __webpack_require__(6);
 	var NodeType_1 = __webpack_require__(2);
 	var NodeType_1 = __webpack_require__(2);
-	var CatchClauseObfuscator_1 = __webpack_require__(31);
-	var ConsoleOutputDisableExpressionNode_1 = __webpack_require__(19);
-	var DebugProtectionNodesGroup_1 = __webpack_require__(28);
-	var FunctionDeclarationObfuscator_1 = __webpack_require__(32);
-	var FunctionObfuscator_1 = __webpack_require__(33);
-	var LiteralObfuscator_1 = __webpack_require__(34);
-	var MemberExpressionObfuscator_1 = __webpack_require__(35);
-	var MethodDefinitionObfuscator_1 = __webpack_require__(36);
+	var CatchClauseObfuscator_1 = __webpack_require__(33);
+	var ConsoleOutputDisableExpressionNode_1 = __webpack_require__(21);
+	var DebugProtectionNodesGroup_1 = __webpack_require__(30);
+	var FunctionDeclarationObfuscator_1 = __webpack_require__(34);
+	var FunctionObfuscator_1 = __webpack_require__(35);
+	var LiteralObfuscator_1 = __webpack_require__(36);
+	var MemberExpressionObfuscator_1 = __webpack_require__(37);
+	var MethodDefinitionObfuscator_1 = __webpack_require__(38);
 	var NodeUtils_1 = __webpack_require__(1);
 	var NodeUtils_1 = __webpack_require__(1);
-	var ObjectExpressionObfuscator_1 = __webpack_require__(37);
-	var SelfDefendingNodesGroup_1 = __webpack_require__(29);
-	var UnicodeArrayNodesGroup_1 = __webpack_require__(30);
-	var VariableDeclarationObfuscator_1 = __webpack_require__(38);
+	var ObjectExpressionObfuscator_1 = __webpack_require__(39);
+	var SelfDefendingNodesGroup_1 = __webpack_require__(31);
+	var UnicodeArrayNodesGroup_1 = __webpack_require__(32);
+	var VariableDeclarationObfuscator_1 = __webpack_require__(40);
 	
 	
 	var Obfuscator = function () {
 	var Obfuscator = function () {
 	    function Obfuscator(options) {
 	    function Obfuscator(options) {
@@ -933,7 +960,7 @@ module.exports =
 	exports.Obfuscator = Obfuscator;
 	exports.Obfuscator = Obfuscator;
 
 
 /***/ },
 /***/ },
-/* 17 */
+/* 18 */
 /***/ function(module, exports, __webpack_require__) {
 /***/ function(module, exports, __webpack_require__) {
 
 
 	"use strict";
 	"use strict";
@@ -943,8 +970,8 @@ module.exports =
 	
 	
 	function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
 	function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
 	
 	
-	var OptionsNormalizer_1 = __webpack_require__(18);
-	var DefaultPreset_1 = __webpack_require__(39);
+	var OptionsNormalizer_1 = __webpack_require__(19);
+	var DefaultPreset_1 = __webpack_require__(14);
 	
 	
 	var Options = function () {
 	var Options = function () {
 	    function Options(options) {
 	    function Options(options) {
@@ -966,7 +993,7 @@ module.exports =
 	exports.Options = Options;
 	exports.Options = Options;
 
 
 /***/ },
 /***/ },
-/* 18 */
+/* 19 */
 /***/ function(module, exports) {
 /***/ function(module, exports) {
 
 
 	"use strict";
 	"use strict";
@@ -1033,7 +1060,117 @@ module.exports =
 	exports.OptionsNormalizer = OptionsNormalizer;
 	exports.OptionsNormalizer = OptionsNormalizer;
 
 
 /***/ },
 /***/ },
-/* 19 */
+/* 20 */
+/***/ function(module, exports, __webpack_require__) {
+
+	"use strict";
+	"use strict";
+	
+	var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
+	
+	function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
+	
+	var commands = __webpack_require__(42);
+	var fs = __webpack_require__(43);
+	var path = __webpack_require__(44);
+	var DefaultPreset_1 = __webpack_require__(14);
+	var JavaScriptObfuscator_1 = __webpack_require__(9);
+	
+	var JavaScriptObfuscatorCLI = function () {
+	    function JavaScriptObfuscatorCLI() {
+	        _classCallCheck(this, JavaScriptObfuscatorCLI);
+	
+	        this.data = '';
+	    }
+	
+	    _createClass(JavaScriptObfuscatorCLI, [{
+	        key: 'run',
+	        value: function run() {
+	            this.configureProcess();
+	            this.configureCommands();
+	            if (!JavaScriptObfuscatorCLI.isDataExist()) {
+	                commands.outputHelp();
+	            }
+	        }
+	    }, {
+	        key: 'configureCommands',
+	        value: function configureCommands() {
+	            commands.version(JavaScriptObfuscatorCLI.getBuildVersion(), '-v, --version').usage('[options] STDIN STDOUT').option('--compact <boolean>', 'Disable one line output code compacting', JavaScriptObfuscatorCLI.parseBoolean).option('--debugProtection <boolean>', 'Disable browser Debug panel (can cause DevTools enabled browser freeze)', JavaScriptObfuscatorCLI.parseBoolean).option('--debugProtectionInterval <boolean>', 'Disable browser Debug panel even after page was loaded (can cause DevTools enabled browser freeze)', JavaScriptObfuscatorCLI.parseBoolean).option('--disableConsoleOutput <boolean>', 'Allow console.log, console.info, console.error and console.warn messages output into browser console', JavaScriptObfuscatorCLI.parseBoolean).option('--encodeUnicodeLiterals <boolean>', 'All literals in Unicode array become encoded in Base64 (this option can slightly slow down your code speed)', JavaScriptObfuscatorCLI.parseBoolean).option('--reservedNames <list>', 'Disable obfuscation of variable names, function names and names of function parameters that match the passed RegExp patterns (comma separated)', function (val) {
+	                return val.split(',');
+	            }).option('--rotateUnicodeArray <boolean>', 'Disable rotation of unicode array values during obfuscation', JavaScriptObfuscatorCLI.parseBoolean).option('--selfDefending <boolean>', 'Disables self-defending for obfuscated code', JavaScriptObfuscatorCLI.parseBoolean).option('--unicodeArray <boolean>', 'Disables gathering of all literal strings into an array and replacing every literal string with an array call', JavaScriptObfuscatorCLI.parseBoolean).option('--unicodeArrayThreshold <number>', 'The probability that the literal string will be inserted into unicodeArray (Default: 0.8, Min: 0, Max: 1)', parseFloat).option('--wrapUnicodeArrayCalls <boolean>', 'Disables usage of special access function instead of direct array call', JavaScriptObfuscatorCLI.parseBoolean).parse(process.argv);
+	            commands.on('--help', function () {
+	                var isWindows = process.platform === 'win32';
+	                console.log('  Examples:\n');
+	                console.log('    %> javascript-obfuscator < in.js > out.js');
+	                if (isWindows) {
+	                    console.log('    %> type in1.js in2.js | javascript-obfuscator > out.js');
+	                } else {
+	                    console.log('    %> cat in1.js in2.js | javascript-obfuscator > out.js');
+	                }
+	                console.log('');
+	                process.exit();
+	            });
+	        }
+	    }, {
+	        key: 'configureProcess',
+	        value: function configureProcess() {
+	            var _this = this;
+	
+	            process.stdin.setEncoding('utf-8');
+	            process.stdin.on('readable', function () {
+	                var chunk = void 0;
+	                while (chunk = process.stdin.read()) {
+	                    _this.data += chunk;
+	                }
+	            });
+	            process.stdin.on('end', this.processData);
+	        }
+	    }, {
+	        key: 'processData',
+	        value: function processData() {
+	            process.stdout.write(JavaScriptObfuscator_1.JavaScriptObfuscator.obfuscate(this.data, JavaScriptObfuscatorCLI.buildOptions()));
+	        }
+	    }], [{
+	        key: 'buildOptions',
+	        value: function buildOptions() {
+	            var options = {},
+	                availableOptions = Object.keys(DefaultPreset_1.DEFAULT_PRESET);
+	            for (var option in commands) {
+	                if (!commands.hasOwnProperty(option)) {
+	                    continue;
+	                }
+	                if (availableOptions.indexOf(option) === -1) {
+	                    continue;
+	                }
+	                options[option] = commands[option];
+	            }
+	            return Object.assign({}, DefaultPreset_1.DEFAULT_PRESET, options);
+	        }
+	    }, {
+	        key: 'getBuildVersion',
+	        value: function getBuildVersion() {
+	            var packageConfig = fs.readFileSync(path.join(path.dirname(fs.realpathSync(process.argv[1])), '../package.json'));
+	            return JSON.parse(packageConfig).version;
+	        }
+	    }, {
+	        key: 'isDataExist',
+	        value: function isDataExist() {
+	            return !process.env.__DIRECT__ && !process.stdin.isTTY;
+	        }
+	    }, {
+	        key: 'parseBoolean',
+	        value: function parseBoolean(value) {
+	            return value === 'true' || value === '1';
+	        }
+	    }]);
+	
+	    return JavaScriptObfuscatorCLI;
+	}();
+	
+	exports.JavaScriptObfuscatorCLI = JavaScriptObfuscatorCLI;
+
+/***/ },
+/* 21 */
 /***/ function(module, exports, __webpack_require__) {
 /***/ function(module, exports, __webpack_require__) {
 
 
 	"use strict";
 	"use strict";
@@ -1081,7 +1218,7 @@ module.exports =
 	exports.ConsoleOutputDisableExpressionNode = ConsoleOutputDisableExpressionNode;
 	exports.ConsoleOutputDisableExpressionNode = ConsoleOutputDisableExpressionNode;
 
 
 /***/ },
 /***/ },
-/* 20 */
+/* 22 */
 /***/ function(module, exports, __webpack_require__) {
 /***/ function(module, exports, __webpack_require__) {
 
 
 	"use strict";
 	"use strict";
@@ -1140,7 +1277,7 @@ module.exports =
 	exports.DebugProtectionFunctionCallNode = DebugProtectionFunctionCallNode;
 	exports.DebugProtectionFunctionCallNode = DebugProtectionFunctionCallNode;
 
 
 /***/ },
 /***/ },
-/* 21 */
+/* 23 */
 /***/ function(module, exports, __webpack_require__) {
 /***/ function(module, exports, __webpack_require__) {
 
 
 	"use strict";
 	"use strict";
@@ -1224,7 +1361,7 @@ module.exports =
 	exports.DebugProtectionFunctionIntervalNode = DebugProtectionFunctionIntervalNode;
 	exports.DebugProtectionFunctionIntervalNode = DebugProtectionFunctionIntervalNode;
 
 
 /***/ },
 /***/ },
-/* 22 */
+/* 24 */
 /***/ function(module, exports, __webpack_require__) {
 /***/ function(module, exports, __webpack_require__) {
 
 
 	"use strict";
 	"use strict";
@@ -1284,7 +1421,7 @@ module.exports =
 	exports.DebugProtectionFunctionNode = DebugProtectionFunctionNode;
 	exports.DebugProtectionFunctionNode = DebugProtectionFunctionNode;
 
 
 /***/ },
 /***/ },
-/* 23 */
+/* 25 */
 /***/ function(module, exports, __webpack_require__) {
 /***/ function(module, exports, __webpack_require__) {
 
 
 	"use strict";
 	"use strict";
@@ -1300,9 +1437,9 @@ module.exports =
 	
 	
 	var esprima = __webpack_require__(7);
 	var esprima = __webpack_require__(7);
 	var AppendState_1 = __webpack_require__(6);
 	var AppendState_1 = __webpack_require__(6);
-	var JSFuck_1 = __webpack_require__(9);
+	var JSFuck_1 = __webpack_require__(10);
 	var NoCustomNodesPreset_1 = __webpack_require__(13);
 	var NoCustomNodesPreset_1 = __webpack_require__(13);
-	var JavaScriptObfuscator_1 = __webpack_require__(11);
+	var JavaScriptObfuscator_1 = __webpack_require__(9);
 	var Node_1 = __webpack_require__(4);
 	var Node_1 = __webpack_require__(4);
 	var NodeUtils_1 = __webpack_require__(1);
 	var NodeUtils_1 = __webpack_require__(1);
 	var Utils_1 = __webpack_require__(0);
 	var Utils_1 = __webpack_require__(0);
@@ -1348,7 +1485,7 @@ module.exports =
 	exports.SelfDefendingUnicodeNode = SelfDefendingUnicodeNode;
 	exports.SelfDefendingUnicodeNode = SelfDefendingUnicodeNode;
 
 
 /***/ },
 /***/ },
-/* 24 */
+/* 26 */
 /***/ function(module, exports, __webpack_require__) {
 /***/ function(module, exports, __webpack_require__) {
 
 
 	"use strict";
 	"use strict";
@@ -1422,7 +1559,7 @@ module.exports =
 	exports.UnicodeArrayCallsWrapper = UnicodeArrayCallsWrapper;
 	exports.UnicodeArrayCallsWrapper = UnicodeArrayCallsWrapper;
 
 
 /***/ },
 /***/ },
-/* 25 */
+/* 27 */
 /***/ function(module, exports, __webpack_require__) {
 /***/ function(module, exports, __webpack_require__) {
 
 
 	"use strict";
 	"use strict";
@@ -1439,9 +1576,9 @@ module.exports =
 	function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
 	function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
 	
 	
 	var esprima = __webpack_require__(7);
 	var esprima = __webpack_require__(7);
-	var JavaScriptObfuscator_1 = __webpack_require__(11);
+	var JavaScriptObfuscator_1 = __webpack_require__(9);
 	var AppendState_1 = __webpack_require__(6);
 	var AppendState_1 = __webpack_require__(6);
-	var JSFuck_1 = __webpack_require__(9);
+	var JSFuck_1 = __webpack_require__(10);
 	var NoCustomNodesPreset_1 = __webpack_require__(13);
 	var NoCustomNodesPreset_1 = __webpack_require__(13);
 	var Node_1 = __webpack_require__(4);
 	var Node_1 = __webpack_require__(4);
 	var NodeUtils_1 = __webpack_require__(1);
 	var NodeUtils_1 = __webpack_require__(1);
@@ -1502,7 +1639,7 @@ module.exports =
 	exports.UnicodeArrayDecodeNode = UnicodeArrayDecodeNode;
 	exports.UnicodeArrayDecodeNode = UnicodeArrayDecodeNode;
 
 
 /***/ },
 /***/ },
-/* 26 */
+/* 28 */
 /***/ function(module, exports, __webpack_require__) {
 /***/ function(module, exports, __webpack_require__) {
 
 
 	"use strict";
 	"use strict";
@@ -1518,7 +1655,7 @@ module.exports =
 	
 	
 	function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
 	function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
 	
 	
-	var escodegen = __webpack_require__(10);
+	var escodegen = __webpack_require__(11);
 	var AppendState_1 = __webpack_require__(6);
 	var AppendState_1 = __webpack_require__(6);
 	var NodeType_1 = __webpack_require__(2);
 	var NodeType_1 = __webpack_require__(2);
 	var Node_1 = __webpack_require__(4);
 	var Node_1 = __webpack_require__(4);
@@ -1612,7 +1749,7 @@ module.exports =
 	exports.UnicodeArrayNode = UnicodeArrayNode;
 	exports.UnicodeArrayNode = UnicodeArrayNode;
 
 
 /***/ },
 /***/ },
-/* 27 */
+/* 29 */
 /***/ function(module, exports, __webpack_require__) {
 /***/ function(module, exports, __webpack_require__) {
 
 
 	"use strict";
 	"use strict";
@@ -1630,9 +1767,9 @@ module.exports =
 	
 	
 	var esprima = __webpack_require__(7);
 	var esprima = __webpack_require__(7);
 	var AppendState_1 = __webpack_require__(6);
 	var AppendState_1 = __webpack_require__(6);
-	var JSFuck_1 = __webpack_require__(9);
+	var JSFuck_1 = __webpack_require__(10);
 	var NoCustomNodesPreset_1 = __webpack_require__(13);
 	var NoCustomNodesPreset_1 = __webpack_require__(13);
-	var JavaScriptObfuscator_1 = __webpack_require__(11);
+	var JavaScriptObfuscator_1 = __webpack_require__(9);
 	var Node_1 = __webpack_require__(4);
 	var Node_1 = __webpack_require__(4);
 	var NodeUtils_1 = __webpack_require__(1);
 	var NodeUtils_1 = __webpack_require__(1);
 	var Utils_1 = __webpack_require__(0);
 	var Utils_1 = __webpack_require__(0);
@@ -1692,7 +1829,7 @@ module.exports =
 	exports.UnicodeArrayRotateFunctionNode = UnicodeArrayRotateFunctionNode;
 	exports.UnicodeArrayRotateFunctionNode = UnicodeArrayRotateFunctionNode;
 
 
 /***/ },
 /***/ },
-/* 28 */
+/* 30 */
 /***/ function(module, exports, __webpack_require__) {
 /***/ function(module, exports, __webpack_require__) {
 
 
 	"use strict";
 	"use strict";
@@ -1704,9 +1841,9 @@ module.exports =
 	
 	
 	function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
 	function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
 	
 	
-	var DebugProtectionFunctionCallNode_1 = __webpack_require__(20);
-	var DebugProtectionFunctionIntervalNode_1 = __webpack_require__(21);
-	var DebugProtectionFunctionNode_1 = __webpack_require__(22);
+	var DebugProtectionFunctionCallNode_1 = __webpack_require__(22);
+	var DebugProtectionFunctionIntervalNode_1 = __webpack_require__(23);
+	var DebugProtectionFunctionNode_1 = __webpack_require__(24);
 	var NodesGroup_1 = __webpack_require__(12);
 	var NodesGroup_1 = __webpack_require__(12);
 	var Utils_1 = __webpack_require__(0);
 	var Utils_1 = __webpack_require__(0);
 	
 	
@@ -1733,7 +1870,7 @@ module.exports =
 	exports.DebugProtectionNodesGroup = DebugProtectionNodesGroup;
 	exports.DebugProtectionNodesGroup = DebugProtectionNodesGroup;
 
 
 /***/ },
 /***/ },
-/* 29 */
+/* 31 */
 /***/ function(module, exports, __webpack_require__) {
 /***/ function(module, exports, __webpack_require__) {
 
 
 	"use strict";
 	"use strict";
@@ -1746,7 +1883,7 @@ module.exports =
 	function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
 	function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
 	
 	
 	var NodesGroup_1 = __webpack_require__(12);
 	var NodesGroup_1 = __webpack_require__(12);
-	var SelfDefendingUnicodeNode_1 = __webpack_require__(23);
+	var SelfDefendingUnicodeNode_1 = __webpack_require__(25);
 	
 	
 	var SelfDefendingNodesGroup = function (_NodesGroup_1$NodesGr) {
 	var SelfDefendingNodesGroup = function (_NodesGroup_1$NodesGr) {
 	    _inherits(SelfDefendingNodesGroup, _NodesGroup_1$NodesGr);
 	    _inherits(SelfDefendingNodesGroup, _NodesGroup_1$NodesGr);
@@ -1766,7 +1903,7 @@ module.exports =
 	exports.SelfDefendingNodesGroup = SelfDefendingNodesGroup;
 	exports.SelfDefendingNodesGroup = SelfDefendingNodesGroup;
 
 
 /***/ },
 /***/ },
-/* 30 */
+/* 32 */
 /***/ function(module, exports, __webpack_require__) {
 /***/ function(module, exports, __webpack_require__) {
 
 
 	"use strict";
 	"use strict";
@@ -1779,10 +1916,10 @@ module.exports =
 	function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
 	function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
 	
 	
 	var NodesGroup_1 = __webpack_require__(12);
 	var NodesGroup_1 = __webpack_require__(12);
-	var UnicodeArrayCallsWrapper_1 = __webpack_require__(24);
-	var UnicodeArrayDecodeNode_1 = __webpack_require__(25);
-	var UnicodeArrayNode_1 = __webpack_require__(26);
-	var UnicodeArrayRotateFunctionNode_1 = __webpack_require__(27);
+	var UnicodeArrayCallsWrapper_1 = __webpack_require__(26);
+	var UnicodeArrayDecodeNode_1 = __webpack_require__(27);
+	var UnicodeArrayNode_1 = __webpack_require__(28);
+	var UnicodeArrayRotateFunctionNode_1 = __webpack_require__(29);
 	var Utils_1 = __webpack_require__(0);
 	var Utils_1 = __webpack_require__(0);
 	
 	
 	var UnicodeArrayNodesGroup = function (_NodesGroup_1$NodesGr) {
 	var UnicodeArrayNodesGroup = function (_NodesGroup_1$NodesGr) {
@@ -1824,7 +1961,7 @@ module.exports =
 	exports.UnicodeArrayNodesGroup = UnicodeArrayNodesGroup;
 	exports.UnicodeArrayNodesGroup = UnicodeArrayNodesGroup;
 
 
 /***/ },
 /***/ },
-/* 31 */
+/* 33 */
 /***/ function(module, exports, __webpack_require__) {
 /***/ function(module, exports, __webpack_require__) {
 
 
 	"use strict";
 	"use strict";
@@ -1895,7 +2032,7 @@ module.exports =
 	exports.CatchClauseObfuscator = CatchClauseObfuscator;
 	exports.CatchClauseObfuscator = CatchClauseObfuscator;
 
 
 /***/ },
 /***/ },
-/* 32 */
+/* 34 */
 /***/ function(module, exports, __webpack_require__) {
 /***/ function(module, exports, __webpack_require__) {
 
 
 	"use strict";
 	"use strict";
@@ -1972,7 +2109,7 @@ module.exports =
 	exports.FunctionDeclarationObfuscator = FunctionDeclarationObfuscator;
 	exports.FunctionDeclarationObfuscator = FunctionDeclarationObfuscator;
 
 
 /***/ },
 /***/ },
-/* 33 */
+/* 35 */
 /***/ function(module, exports, __webpack_require__) {
 /***/ function(module, exports, __webpack_require__) {
 
 
 	"use strict";
 	"use strict";
@@ -2049,7 +2186,7 @@ module.exports =
 	exports.FunctionObfuscator = FunctionObfuscator;
 	exports.FunctionObfuscator = FunctionObfuscator;
 
 
 /***/ },
 /***/ },
-/* 34 */
+/* 36 */
 /***/ function(module, exports, __webpack_require__) {
 /***/ function(module, exports, __webpack_require__) {
 
 
 	"use strict";
 	"use strict";
@@ -2065,7 +2202,7 @@ module.exports =
 	
 	
 	function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
 	function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
 	
 	
-	var escodegen = __webpack_require__(10);
+	var escodegen = __webpack_require__(11);
 	var NodeObfuscator_1 = __webpack_require__(5);
 	var NodeObfuscator_1 = __webpack_require__(5);
 	var Nodes_1 = __webpack_require__(8);
 	var Nodes_1 = __webpack_require__(8);
 	
 	
@@ -2114,7 +2251,7 @@ module.exports =
 	exports.LiteralObfuscator = LiteralObfuscator;
 	exports.LiteralObfuscator = LiteralObfuscator;
 
 
 /***/ },
 /***/ },
-/* 35 */
+/* 37 */
 /***/ function(module, exports, __webpack_require__) {
 /***/ function(module, exports, __webpack_require__) {
 
 
 	"use strict";
 	"use strict";
@@ -2130,7 +2267,7 @@ module.exports =
 	
 	
 	function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
 	function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
 	
 	
-	var escodegen = __webpack_require__(10);
+	var escodegen = __webpack_require__(11);
 	var estraverse = __webpack_require__(3);
 	var estraverse = __webpack_require__(3);
 	var NodeType_1 = __webpack_require__(2);
 	var NodeType_1 = __webpack_require__(2);
 	var NodeObfuscator_1 = __webpack_require__(5);
 	var NodeObfuscator_1 = __webpack_require__(5);
@@ -2207,7 +2344,7 @@ module.exports =
 	exports.MemberExpressionObfuscator = MemberExpressionObfuscator;
 	exports.MemberExpressionObfuscator = MemberExpressionObfuscator;
 
 
 /***/ },
 /***/ },
-/* 36 */
+/* 38 */
 /***/ function(module, exports, __webpack_require__) {
 /***/ function(module, exports, __webpack_require__) {
 
 
 	"use strict";
 	"use strict";
@@ -2273,7 +2410,7 @@ module.exports =
 	exports.MethodDefinitionObfuscator = MethodDefinitionObfuscator;
 	exports.MethodDefinitionObfuscator = MethodDefinitionObfuscator;
 
 
 /***/ },
 /***/ },
-/* 37 */
+/* 39 */
 /***/ function(module, exports, __webpack_require__) {
 /***/ function(module, exports, __webpack_require__) {
 
 
 	"use strict";
 	"use strict";
@@ -2289,7 +2426,7 @@ module.exports =
 	
 	
 	function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
 	function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
 	
 	
-	var escodegen = __webpack_require__(10);
+	var escodegen = __webpack_require__(11);
 	var estraverse = __webpack_require__(3);
 	var estraverse = __webpack_require__(3);
 	var NodeType_1 = __webpack_require__(2);
 	var NodeType_1 = __webpack_require__(2);
 	var NodeObfuscator_1 = __webpack_require__(5);
 	var NodeObfuscator_1 = __webpack_require__(5);
@@ -2365,7 +2502,7 @@ module.exports =
 	exports.ObjectExpressionObfuscator = ObjectExpressionObfuscator;
 	exports.ObjectExpressionObfuscator = ObjectExpressionObfuscator;
 
 
 /***/ },
 /***/ },
-/* 38 */
+/* 40 */
 /***/ function(module, exports, __webpack_require__) {
 /***/ function(module, exports, __webpack_require__) {
 
 
 	"use strict";
 	"use strict";
@@ -2459,31 +2596,28 @@ module.exports =
 	exports.VariableDeclarationObfuscator = VariableDeclarationObfuscator;
 	exports.VariableDeclarationObfuscator = VariableDeclarationObfuscator;
 
 
 /***/ },
 /***/ },
-/* 39 */
+/* 41 */
 /***/ function(module, exports) {
 /***/ function(module, exports) {
 
 
-	"use strict";
-	"use strict";
-	
-	exports.DEFAULT_PRESET = Object.freeze({
-	    compact: true,
-	    debugProtection: false,
-	    debugProtectionInterval: false,
-	    disableConsoleOutput: true,
-	    encodeUnicodeLiterals: false,
-	    reservedNames: [],
-	    rotateUnicodeArray: true,
-	    selfDefending: true,
-	    unicodeArray: true,
-	    unicodeArrayThreshold: 0.8,
-	    wrapUnicodeArrayCalls: true
-	});
+	module.exports = require("chance");
 
 
 /***/ },
 /***/ },
-/* 40 */
+/* 42 */
 /***/ function(module, exports) {
 /***/ function(module, exports) {
 
 
-	module.exports = require("chance");
+	module.exports = require("commander");
+
+/***/ },
+/* 43 */
+/***/ function(module, exports) {
+
+	module.exports = require("fs");
+
+/***/ },
+/* 44 */
+/***/ function(module, exports) {
+
+	module.exports = require("path");
 
 
 /***/ }
 /***/ }
 /******/ ]);
 /******/ ]);

+ 1 - 1
index.ts

@@ -2,7 +2,7 @@
 
 
 import { JavaScriptObfuscator } from './src/JavaScriptObfuscator';
 import { JavaScriptObfuscator } from './src/JavaScriptObfuscator';
 
 
-if (!global._babelPolyfill) {
+if (!(<any>global)._babelPolyfill) {
     require('babel-polyfill');
     require('babel-polyfill');
 }
 }
 
 

+ 1 - 1
package.json

@@ -57,7 +57,7 @@
     "test:mocha": "npm run test:compile && node_modules/.bin/mocha test-tmp/test/**/**.spec.js  && npm run test:removeTestTmpDir",
     "test:mocha": "npm run test:compile && node_modules/.bin/mocha test-tmp/test/**/**.spec.js  && npm run test:removeTestTmpDir",
     "test:removeTestTmpDir": "rm -rf test-tmp",
     "test:removeTestTmpDir": "rm -rf test-tmp",
     "test": "npm run test:dev && npm run test:full",
     "test": "npm run test:dev && npm run test:full",
-    "tslint": "tslint src/*.ts",
+    "tslint": "tslint src/**/*.ts",
     "travis": "npm run tslint && npm test",
     "travis": "npm run tslint && npm test",
     "typings": "node_modules/.bin/typings install"
     "typings": "node_modules/.bin/typings install"
   },
   },

+ 1 - 1
readme.md

@@ -213,7 +213,7 @@ Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are met:
 modification, are permitted provided that the following conditions are met:
 
 
   * Redistributions of source code must retain the above copyright
   * Redistributions of source code must retain the above copyright
-    notice, this list of conditions and the following disclaimer.
+    notice, this li	st of conditions and the following disclaimer.
   * Redistributions in binary form must reproduce the above copyright
   * Redistributions in binary form must reproduce the above copyright
     notice, this list of conditions and the following disclaimer in the
     notice, this list of conditions and the following disclaimer in the
     documentation and/or other materials provided with the distribution.
     documentation and/or other materials provided with the distribution.

+ 5 - 0
src/JavaScriptObfuscator.ts

@@ -8,6 +8,7 @@ import { IObfuscator } from "./interfaces/IObfuscator";
 import { IOptions } from './interfaces/IOptions';
 import { IOptions } from './interfaces/IOptions';
 import { IOptionsPreset } from "./interfaces/IOptionsPreset";
 import { IOptionsPreset } from "./interfaces/IOptionsPreset";
 
 
+import { JavaScriptObfuscatorCLI } from "./cli/JavaScriptObfuscatorCLI";
 import { Obfuscator } from "./Obfuscator";
 import { Obfuscator } from "./Obfuscator";
 import { Options } from "./Options";
 import { Options } from "./Options";
 
 
@@ -33,6 +34,10 @@ export class JavaScriptObfuscator {
         return JavaScriptObfuscator.generateCode(astTree, options);
         return JavaScriptObfuscator.generateCode(astTree, options);
     }
     }
 
 
+    public static runCLI (): void {
+        new JavaScriptObfuscatorCLI().run();
+    }
+
     /**
     /**
      * @param astTree
      * @param astTree
      * @param options
      * @param options

+ 136 - 0
src/cli/JavaScriptObfuscatorCLI.ts

@@ -0,0 +1,136 @@
+import * as commands from 'commander';
+import * as fs from 'fs';
+import * as path from 'path';
+import * as tty from 'tty';
+
+import { IOptionsPreset } from "../interfaces/IOptionsPreset";
+
+import { DEFAULT_PRESET } from "../preset-options/DefaultPreset";
+
+import { JavaScriptObfuscator } from "../JavaScriptObfuscator";
+
+export class JavaScriptObfuscatorCLI {
+    /**
+     * @type {string}
+     */
+    private data: string = '';
+
+    constructor () {}
+
+    /**
+     * @returns {IOptionsPreset}
+     */
+    private static buildOptions (): IOptionsPreset {
+        let options: IOptionsPreset = {},
+            availableOptions: string[] = Object.keys(DEFAULT_PRESET);
+
+        for (let option in commands) {
+            if (!commands.hasOwnProperty(option)) {
+                continue;
+            }
+
+            if (availableOptions.indexOf(option) === -1) {
+                continue;
+            }
+
+            options[option] = (<any>commands)[option];
+        }
+
+        return Object.assign({}, DEFAULT_PRESET, options);
+    }
+
+    /**
+     * @returns {string}
+     */
+    private static getBuildVersion (): string {
+        let packageConfig: any = fs.readFileSync(
+            path.join(
+                path.dirname(
+                    fs.realpathSync(process.argv[1])
+                ),
+                '../package.json'
+            )
+        );
+
+        return JSON.parse(packageConfig).version;
+    }
+
+    /**
+     * @returns {boolean}
+     */
+    private static isDataExist (): boolean {
+        return !process.env.__DIRECT__ && !(<tty.ReadStream>process.stdin).isTTY;
+    }
+
+    /**
+     * @param value
+     * @returns {boolean}
+     */
+    private static parseBoolean (value: string): boolean {
+        return value === 'true' || value === '1';
+    }
+
+    public run (): void {
+        this.configureProcess();
+        this.configureCommands();
+
+        if (!JavaScriptObfuscatorCLI.isDataExist()) {
+            commands.outputHelp();
+        }
+    }
+
+    private configureCommands (): void {
+        commands
+            .version(JavaScriptObfuscatorCLI.getBuildVersion(), '-v, --version')
+            .usage('[options] STDIN STDOUT')
+            .option('--compact <boolean>', 'Disable one line output code compacting', JavaScriptObfuscatorCLI.parseBoolean)
+            .option('--debugProtection <boolean>', 'Disable browser Debug panel (can cause DevTools enabled browser freeze)', JavaScriptObfuscatorCLI.parseBoolean)
+            .option('--debugProtectionInterval <boolean>', 'Disable browser Debug panel even after page was loaded (can cause DevTools enabled browser freeze)', JavaScriptObfuscatorCLI.parseBoolean)
+            .option('--disableConsoleOutput <boolean>', 'Allow console.log, console.info, console.error and console.warn messages output into browser console', JavaScriptObfuscatorCLI.parseBoolean)
+            .option('--encodeUnicodeLiterals <boolean>', 'All literals in Unicode array become encoded in Base64 (this option can slightly slow down your code speed)', JavaScriptObfuscatorCLI.parseBoolean)
+            .option('--reservedNames <list>', 'Disable obfuscation of variable names, function names and names of function parameters that match the passed RegExp patterns (comma separated)', (val: string) => val.split(','))
+            .option('--rotateUnicodeArray <boolean>', 'Disable rotation of unicode array values during obfuscation', JavaScriptObfuscatorCLI.parseBoolean)
+            .option('--selfDefending <boolean>', 'Disables self-defending for obfuscated code', JavaScriptObfuscatorCLI.parseBoolean)
+            .option('--unicodeArray <boolean>', 'Disables gathering of all literal strings into an array and replacing every literal string with an array call', JavaScriptObfuscatorCLI.parseBoolean)
+            .option('--unicodeArrayThreshold <number>', 'The probability that the literal string will be inserted into unicodeArray (Default: 0.8, Min: 0, Max: 1)', parseFloat)
+            .option('--wrapUnicodeArrayCalls <boolean>', 'Disables usage of special access function instead of direct array call', JavaScriptObfuscatorCLI.parseBoolean)
+            .parse(process.argv);
+
+        commands.on('--help', () => {
+            let isWindows: boolean = process.platform === 'win32';
+
+            console.log('  Examples:\n');
+            console.log('    %> javascript-obfuscator < in.js > out.js');
+
+            if (isWindows) {
+                console.log('    %> type in1.js in2.js | javascript-obfuscator > out.js');
+            } else {
+                console.log('    %> cat in1.js in2.js | javascript-obfuscator > out.js');
+            }
+
+            console.log('');
+
+            process.exit();
+        });
+    }
+
+    private configureProcess (): void {
+        process.stdin.setEncoding('utf-8');
+
+        process.stdin.on('readable', () => {
+            let chunk: string;
+
+            while (chunk = <string>process.stdin.read()) {
+                this.data += chunk;
+            }
+        });
+
+        process.stdin.on('end', this.processData);
+    }
+
+    private processData (): void {
+        process.stdout.write(
+            JavaScriptObfuscator.obfuscate(this.data, JavaScriptObfuscatorCLI.buildOptions())
+        );
+    }
+}

+ 1 - 1
src/interfaces/IObfuscator.d.ts

@@ -2,4 +2,4 @@ import { INode } from "./nodes/INode";
 
 
 export interface IObfuscator {
 export interface IObfuscator {
     obfuscateNode (node: INode): INode;
     obfuscateNode (node: INode): INode;
-}
+}

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

@@ -1,5 +1,3 @@
-import { IOptionsPreset } from "./IOptionsPreset";
-
 export interface IOptions {
 export interface IOptions {
     /**
     /**
      * @param optionName
      * @param optionName

+ 0 - 3
src/node-obfuscators/CatchClauseObfuscator.ts

@@ -4,9 +4,6 @@ import { ICatchClauseNode } from "../interfaces/nodes/ICatchClauseNode";
 import { INode } from '../interfaces/nodes/INode';
 import { INode } from '../interfaces/nodes/INode';
 
 
 import { NodeObfuscator } from './NodeObfuscator';
 import { NodeObfuscator } from './NodeObfuscator';
-import { Nodes } from "../Nodes";
-import { Utils } from '../Utils';
-import {IBlockStatementNode} from "../interfaces/nodes/IBlockStatementNode";
 
 
 /**
 /**
  * replaces:
  * replaces:

+ 0 - 3
src/node-obfuscators/FunctionObfuscator.ts

@@ -1,12 +1,9 @@
 import * as estraverse from 'estraverse';
 import * as estraverse from 'estraverse';
 
 
-import { IBlockStatementNode } from "../interfaces/nodes/IBlockStatementNode";
 import { IFunctionNode } from "../interfaces/nodes/IFunctionNode";
 import { IFunctionNode } from "../interfaces/nodes/IFunctionNode";
 import { INode } from "../interfaces/nodes/INode";
 import { INode } from "../interfaces/nodes/INode";
 
 
 import { NodeObfuscator } from './NodeObfuscator';
 import { NodeObfuscator } from './NodeObfuscator';
-import { Nodes } from "../Nodes";
-import { Utils } from '../Utils';
 
 
 /**
 /**
  * replaces:
  * replaces:

+ 0 - 1
src/node-obfuscators/VariableDeclarationObfuscator.ts

@@ -7,7 +7,6 @@ import { IVariableDeclaratorNode } from "../interfaces/nodes/IVariableDeclarator
 import { NodeType } from "../enums/NodeType";
 import { NodeType } from "../enums/NodeType";
 
 
 import { NodeObfuscator } from './NodeObfuscator';
 import { NodeObfuscator } from './NodeObfuscator';
-import { Nodes } from "../Nodes";
 import { NodeUtils } from "../NodeUtils";
 import { NodeUtils } from "../NodeUtils";
 import { Utils } from '../Utils';
 import { Utils } from '../Utils';
 
 

+ 1 - 1
src/types/TNodeObfuscator.d.ts

@@ -2,4 +2,4 @@ import { ICustomNode } from "../interfaces/ICustomNode";
 import { INodeObfuscator } from "../interfaces/INodeObfuscator";
 import { INodeObfuscator } from "../interfaces/INodeObfuscator";
 import { IOptions } from "../interfaces/IOptions";
 import { IOptions } from "../interfaces/IOptions";
 
 
-export type TNodeObfuscator =  (new (nodes: Map <string, ICustomNode>, options: IOptions) => INodeObfuscator);
+export type TNodeObfuscator =  (new (nodes: Map <string, ICustomNode>, options: IOptions) => INodeObfuscator);

+ 1 - 1
src/types/TNodeWithBlockStatement.d.ts

@@ -1,4 +1,4 @@
 import { IBlockStatementNode } from "../interfaces/nodes/IBlockStatementNode";
 import { IBlockStatementNode } from "../interfaces/nodes/IBlockStatementNode";
 import { IProgramNode } from "../interfaces/nodes/IProgramNode";
 import { IProgramNode } from "../interfaces/nodes/IProgramNode";
 
 
-export type TNodeWithBlockStatement = IBlockStatementNode|IProgramNode;
+export type TNodeWithBlockStatement = IBlockStatementNode|IProgramNode;

+ 2 - 2
test/JavaScriptObfuscator.spec.ts

@@ -27,7 +27,7 @@ describe('JavaScriptObfuscator', () => {
         });
         });
 
 
         it('should obfuscate simple code with literal variable value', () => {
         it('should obfuscate simple code with literal variable value', () => {
-            let pattern = /^var _0x(\w){4} *= *\['(\\[x|u]\d+)+'\]; *var *test *= *_0x(\w){4}\[0x0\];$/;
+            let pattern: RegExp = /^var _0x(\w){4} *= *\['(\\[x|u]\d+)+'\]; *var *test *= *_0x(\w){4}\[0x0\];$/;
 
 
             assert.match(
             assert.match(
                 JavaScriptObfuscator.obfuscate(
                 JavaScriptObfuscator.obfuscate(
@@ -52,4 +52,4 @@ describe('JavaScriptObfuscator', () => {
             );
             );
         });
         });
     });
     });
-});
+});

+ 55 - 0
test/JavaScriptObfuscatorCLI.spec.ts

@@ -0,0 +1,55 @@
+import { JavaScriptObfuscator } from "../src/JavaScriptObfuscator";
+
+import { NO_CUSTOM_NODES_PRESET } from "../src/preset-options/NoCustomNodesPreset";
+
+let assert: any = require('chai').assert;
+
+describe('JavaScriptObfuscator', () => {
+    describe('obfuscate (sourceCode: string, customOptions?: IOptionsPreset): string', () => {
+        it('should obfuscate simple code with variable inside global scope', () => {
+            assert.match(
+                JavaScriptObfuscator.obfuscate(
+                    `var test = 1;`,
+                    Object.assign({}, NO_CUSTOM_NODES_PRESET)
+                ),
+                /^var *test *= *0x\d+;$/
+            );
+        });
+
+        it('should obfuscate simple code with variable inside block-scope', () => {
+            assert.match(
+                JavaScriptObfuscator.obfuscate(
+                    `(function () {var test = 1;})()`,
+                    Object.assign({}, NO_CUSTOM_NODES_PRESET)
+                ),
+                /^\(function *\(\) *\{ *var *_0x[\w]+ *= *0x\d+; *\}(\(\)\)|\)\(\));?$/
+            );
+        });
+
+        it('should obfuscate simple code with literal variable value', () => {
+            let pattern: RegExp = /^var _0x(\w){4} *= *\['(\\[x|u]\d+)+'\]; *var *test *= *_0x(\w){4}\[0x0\];$/;
+
+            assert.match(
+                JavaScriptObfuscator.obfuscate(
+                    `var test = 'abc';`,
+                    Object.assign({}, NO_CUSTOM_NODES_PRESET, {
+                        unicodeArray: true,
+                        unicodeArrayThreshold: 1
+                    })
+                ),
+                pattern
+            );
+
+            assert.match(
+                JavaScriptObfuscator.obfuscate(
+                    `var test = 'абц';`,
+                    Object.assign({}, NO_CUSTOM_NODES_PRESET, {
+                        unicodeArray: true,
+                        unicodeArrayThreshold: 1
+                    })
+                ),
+                pattern
+            );
+        });
+    });
+});

+ 3 - 3
test/NodeUtils.spec.ts

@@ -80,7 +80,7 @@ describe('NodeUtils', () => {
             expectedLiteralNode = Object.assign({}, literalNode);
             expectedLiteralNode = Object.assign({}, literalNode);
             expectedLiteralNode['x-verbatim-property'] = `'string'`;
             expectedLiteralNode['x-verbatim-property'] = `'string'`;
 
 
-            NodeUtils.addXVerbatimPropertyToLiterals(literalNode)
+            NodeUtils.addXVerbatimPropertyToLiterals(literalNode);
         });
         });
 
 
         it('should add `x-verbatim-property` to `Literal` node', () => {
         it('should add `x-verbatim-property` to `Literal` node', () => {
@@ -308,7 +308,7 @@ describe('NodeUtils', () => {
             expectedBlockStatementNode = Object.assign({}, blockStatementNode);
             expectedBlockStatementNode = Object.assign({}, blockStatementNode);
             expectedBlockStatementNode['body'].unshift(literalNode);
             expectedBlockStatementNode['body'].unshift(literalNode);
 
 
-            NodeUtils.prependNode(blockStatementNode.body, literalNode)
+            NodeUtils.prependNode(blockStatementNode.body, literalNode);
         });
         });
 
 
         it('should prepend given node to a `BlockStatement` node body', () => {
         it('should prepend given node to a `BlockStatement` node body', () => {
@@ -329,4 +329,4 @@ describe('NodeUtils', () => {
             );
             );
         });
         });
     });
     });
-});
+});

+ 1 - 1
test/OptionsNormalizer.spec.ts

@@ -39,4 +39,4 @@ describe('OptionsNormalizer', () => {
             );
             );
         });
         });
     });
     });
-});
+});

+ 1 - 1
test/Utils.spec.ts

@@ -78,4 +78,4 @@ describe('Utils', () => {
             assert.equal(Utils.stringToUnicode('string'), expected);
             assert.equal(Utils.stringToUnicode('string'), expected);
         });
         });
     });
     });
-});
+});

+ 2 - 2
tslint.json

@@ -43,7 +43,7 @@
     "no-any": false,
     "no-any": false,
     "no-arg": true,
     "no-arg": true,
     "no-bitwise": true,
     "no-bitwise": true,
-    "no-conditional-assignment": true,
+    "no-conditional-assignment": false,
     "no-consecutive-blank-lines": false,
     "no-consecutive-blank-lines": false,
     "no-console": [
     "no-console": [
       true,
       true,
@@ -68,7 +68,7 @@
       "check-function-in-method"
       "check-function-in-method"
     ],
     ],
     "no-null-keyword": false,
     "no-null-keyword": false,
-    "no-reference": true,
+    "no-reference": false,
     "no-require-imports": false,
     "no-require-imports": false,
     "no-shadowed-variable": false,
     "no-shadowed-variable": false,
     "no-string-literal": false,
     "no-string-literal": false,

+ 2 - 1
typings.json

@@ -2,8 +2,9 @@
   "name": "javascript-obfuscator",
   "name": "javascript-obfuscator",
   "version": false,
   "version": false,
   "ambientDependencies": {
   "ambientDependencies": {
-    "node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts#6834f97fb33561a3ad40695084da2b660efaee29",
+    "node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts",
     "chance": "github:DefinitelyTyped/DefinitelyTyped/chance/chance.d.ts",
     "chance": "github:DefinitelyTyped/DefinitelyTyped/chance/chance.d.ts",
+    "commander": "github:DefinitelyTyped/DefinitelyTyped/commander/commander.d.ts",
     "estree": "github:DefinitelyTyped/DefinitelyTyped/estree/estree.d.ts",
     "estree": "github:DefinitelyTyped/DefinitelyTyped/estree/estree.d.ts",
     "esprima": "github:DefinitelyTyped/DefinitelyTyped/esprima/esprima.d.ts",
     "esprima": "github:DefinitelyTyped/DefinitelyTyped/esprima/esprima.d.ts",
     "escodegen": "github:DefinitelyTyped/DefinitelyTyped/escodegen/escodegen.d.ts",
     "escodegen": "github:DefinitelyTyped/DefinitelyTyped/escodegen/escodegen.d.ts",

+ 1 - 0
typings/browser.d.ts

@@ -1,5 +1,6 @@
 /// <reference path="browser/ambient/chai/index.d.ts" />
 /// <reference path="browser/ambient/chai/index.d.ts" />
 /// <reference path="browser/ambient/chance/index.d.ts" />
 /// <reference path="browser/ambient/chance/index.d.ts" />
+/// <reference path="browser/ambient/commander/index.d.ts" />
 /// <reference path="browser/ambient/escodegen/index.d.ts" />
 /// <reference path="browser/ambient/escodegen/index.d.ts" />
 /// <reference path="browser/ambient/esprima/index.d.ts" />
 /// <reference path="browser/ambient/esprima/index.d.ts" />
 /// <reference path="browser/ambient/estraverse/index.d.ts" />
 /// <reference path="browser/ambient/estraverse/index.d.ts" />

+ 13 - 0
typings/browser/ambient/chai/index.d.ts

@@ -380,7 +380,20 @@ declare namespace Chai {
     }
     }
 
 
     export interface Config {
     export interface Config {
+        /**
+         * Default: false
+         */
         includeStack: boolean;
         includeStack: boolean;
+
+        /**
+         * Default: true
+         */
+        showDiff: boolean;
+
+        /**
+         * Default: 40
+         */
+        truncateThreshold: number;
     }
     }
 
 
     export class AssertionError {
     export class AssertionError {

+ 1 - 0
typings/browser/ambient/esprima/index.d.ts

@@ -72,6 +72,7 @@ declare namespace esprima {
         LabeledStatement: string,
         LabeledStatement: string,
         LogicalExpression: string,
         LogicalExpression: string,
         MemberExpression: string,
         MemberExpression: string,
+        MetaProperty: string,
         MethodDefinition: string,
         MethodDefinition: string,
         NewExpression: string,
         NewExpression: string,
         ObjectExpression: string,
         ObjectExpression: string,

+ 1 - 0
typings/browser/ambient/mocha/index.d.ts

@@ -46,6 +46,7 @@ declare var it: Mocha.ITestDefinition;
 declare var xit: Mocha.ITestDefinition;
 declare var xit: Mocha.ITestDefinition;
 // alias for `it`
 // alias for `it`
 declare var test: Mocha.ITestDefinition;
 declare var test: Mocha.ITestDefinition;
+declare var specify: Mocha.ITestDefinition;
 
 
 declare function before(action: () => void): void;
 declare function before(action: () => void): void;
 
 

File diff suppressed because it is too large
+ 731 - 168
typings/browser/ambient/node/index.d.ts


+ 1 - 0
typings/main.d.ts

@@ -1,5 +1,6 @@
 /// <reference path="main/ambient/chai/index.d.ts" />
 /// <reference path="main/ambient/chai/index.d.ts" />
 /// <reference path="main/ambient/chance/index.d.ts" />
 /// <reference path="main/ambient/chance/index.d.ts" />
+/// <reference path="main/ambient/commander/index.d.ts" />
 /// <reference path="main/ambient/escodegen/index.d.ts" />
 /// <reference path="main/ambient/escodegen/index.d.ts" />
 /// <reference path="main/ambient/esprima/index.d.ts" />
 /// <reference path="main/ambient/esprima/index.d.ts" />
 /// <reference path="main/ambient/estraverse/index.d.ts" />
 /// <reference path="main/ambient/estraverse/index.d.ts" />

+ 13 - 0
typings/main/ambient/chai/index.d.ts

@@ -380,7 +380,20 @@ declare namespace Chai {
     }
     }
 
 
     export interface Config {
     export interface Config {
+        /**
+         * Default: false
+         */
         includeStack: boolean;
         includeStack: boolean;
+
+        /**
+         * Default: true
+         */
+        showDiff: boolean;
+
+        /**
+         * Default: 40
+         */
+        truncateThreshold: number;
     }
     }
 
 
     export class AssertionError {
     export class AssertionError {

+ 1 - 0
typings/main/ambient/esprima/index.d.ts

@@ -72,6 +72,7 @@ declare namespace esprima {
         LabeledStatement: string,
         LabeledStatement: string,
         LogicalExpression: string,
         LogicalExpression: string,
         MemberExpression: string,
         MemberExpression: string,
+        MetaProperty: string,
         MethodDefinition: string,
         MethodDefinition: string,
         NewExpression: string,
         NewExpression: string,
         ObjectExpression: string,
         ObjectExpression: string,

+ 1 - 0
typings/main/ambient/mocha/index.d.ts

@@ -46,6 +46,7 @@ declare var it: Mocha.ITestDefinition;
 declare var xit: Mocha.ITestDefinition;
 declare var xit: Mocha.ITestDefinition;
 // alias for `it`
 // alias for `it`
 declare var test: Mocha.ITestDefinition;
 declare var test: Mocha.ITestDefinition;
+declare var specify: Mocha.ITestDefinition;
 
 
 declare function before(action: () => void): void;
 declare function before(action: () => void): void;
 
 

File diff suppressed because it is too large
+ 731 - 168
typings/main/ambient/node/index.d.ts


Some files were not shown because too many files changed in this diff