From b79dd8ba2529552bcadce51c4dd7642e02fc0ce7 Mon Sep 17 00:00:00 2001 From: sanex3339 Date: Thu, 24 Nov 2016 18:46:20 +0300 Subject: [PATCH] refactoring: nodesGroups -> customNodesFactory change --- dist/index.js | 512 +++++++++--------- src/JavaScriptObfuscator.ts | 8 +- src/Obfuscator.ts | 31 +- src/cli/JavaScriptObfuscatorCLI.ts | 18 +- .../AbstractCustomNodesFactory.ts} | 4 +- .../ConsoleOutputCustomNodesFactory.ts} | 14 +- .../DebugProtectionCustomNodesFactory.ts} | 14 +- .../factory/DomainLockCustomNodesFactory.ts} | 14 +- .../SelfDefendingCustomNodesFactory.ts} | 16 +- .../factory/StringArrayCustomNodesFactory.ts} | 20 +- ...desGroup.d.ts => ICustomNodesFactory.d.ts} | 2 +- ...uscatorOptions.d.ts => IInputOptions.d.ts} | 2 +- src/options/Options.ts | 8 +- src/options/OptionsNormalizer.ts | 14 +- src/preset-options/DefaultPreset.ts | 4 +- src/preset-options/NoCustomNodesPreset.ts | 4 +- src/types/TCustomNodesFactory.d.ts | 5 + src/types/TNodeGroup.d.ts | 5 - test/unit-tests/OptionsNormalizer.spec.ts | 8 +- 19 files changed, 352 insertions(+), 351 deletions(-) rename src/{node-groups/AbstractNodesGroup.ts => custom-nodes/AbstractCustomNodesFactory.ts} (89%) rename src/{node-groups/ConsoleOutputNodesGroup.ts => custom-nodes/console-output-nodes/factory/ConsoleOutputCustomNodesFactory.ts} (68%) rename src/{node-groups/DebugProtectionNodesGroup.ts => custom-nodes/debug-protection-nodes/factory/DebugProtectionCustomNodesFactory.ts} (64%) rename src/{node-groups/DomainLockNodesGroup.ts => custom-nodes/domain-lock-nodes/factory/DomainLockCustomNodesFactory.ts} (69%) rename src/{node-groups/SelfDefendingNodesGroup.ts => custom-nodes/self-defending-nodes/factory/SelfDefendingCustomNodesFactory.ts} (68%) rename src/{node-groups/StringArrayNodesGroup.ts => custom-nodes/string-array-nodes/factory/StringArrayCustomNodesFactory.ts} (74%) rename src/interfaces/{INodesGroup.d.ts => ICustomNodesFactory.d.ts} (82%) rename src/interfaces/{IObfuscatorOptions.d.ts => IInputOptions.d.ts} (95%) create mode 100644 src/types/TCustomNodesFactory.d.ts delete mode 100644 src/types/TNodeGroup.d.ts diff --git a/dist/index.js b/dist/index.js index 41628e70..2ef43130 100644 --- a/dist/index.js +++ b/dist/index.js @@ -919,9 +919,9 @@ var JavaScriptObfuscator = function () { _createClass(JavaScriptObfuscator, null, [{ key: 'obfuscate', value: function obfuscate(sourceCode) { - var obfuscatorOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var inputOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - var javaScriptObfuscator = new JavaScriptObfuscatorInternal_1.JavaScriptObfuscatorInternal(new Options_1.Options(obfuscatorOptions)); + var javaScriptObfuscator = new JavaScriptObfuscatorInternal_1.JavaScriptObfuscatorInternal(new Options_1.Options(inputOptions)); return javaScriptObfuscator.obfuscate(sourceCode); } }, { @@ -955,16 +955,16 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons var AppendState_1 = __webpack_require__(1); -var AbstractNodesGroup = function () { - function AbstractNodesGroup(stackTraceData, options) { - _classCallCheck(this, AbstractNodesGroup); +var AbstractCustomNodesFactory = function () { + function AbstractCustomNodesFactory(stackTraceData, options) { + _classCallCheck(this, AbstractCustomNodesFactory); this.appendState = AppendState_1.AppendState.BeforeObfuscation; this.stackTraceData = stackTraceData; this.options = options; } - _createClass(AbstractNodesGroup, [{ + _createClass(AbstractCustomNodesFactory, [{ key: "syncCustomNodesWithNodesGroup", value: function syncCustomNodesWithNodesGroup(customNodes) { var _this = this; @@ -976,10 +976,10 @@ var AbstractNodesGroup = function () { } }]); - return AbstractNodesGroup; + return AbstractCustomNodesFactory; }(); -exports.AbstractNodesGroup = AbstractNodesGroup; +exports.AbstractCustomNodesFactory = AbstractCustomNodesFactory; /***/ }, /* 13 */ @@ -1597,17 +1597,17 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons var estraverse = __webpack_require__(4); var AppendState_1 = __webpack_require__(1); -var VisitorDirection_1 = __webpack_require__(46); -var ConsoleOutputNodesGroup_1 = __webpack_require__(47); -var DebugProtectionNodesGroup_1 = __webpack_require__(48); -var DomainLockNodesGroup_1 = __webpack_require__(49); -var Node_1 = __webpack_require__(2); +var VisitorDirection_1 = __webpack_require__(51); +var ConsoleOutputCustomNodesFactory_1 = __webpack_require__(35); +var DebugProtectionCustomNodesFactory_1 = __webpack_require__(42); +var DomainLockCustomNodesFactory_1 = __webpack_require__(44); var NodeControlFlowTransformersFactory_1 = __webpack_require__(55); var NodeObfuscatorsFactory_1 = __webpack_require__(65); +var SelfDefendingCustomNodesFactory_1 = __webpack_require__(46); +var StringArrayCustomNodesFactory_1 = __webpack_require__(50); +var Node_1 = __webpack_require__(2); var NodeUtils_1 = __webpack_require__(8); -var SelfDefendingNodesGroup_1 = __webpack_require__(50); var StackTraceAnalyzer_1 = __webpack_require__(70); -var StringArrayNodesGroup_1 = __webpack_require__(51); var Obfuscator = function () { function Obfuscator(options) { @@ -1656,7 +1656,7 @@ var Obfuscator = function () { var _this = this; var customNodes = []; - Obfuscator.nodeGroups.forEach(function (nodeGroupConstructor) { + Obfuscator.customNodesFactories.forEach(function (nodeGroupConstructor) { var nodeGroupNodes = new nodeGroupConstructor(stackTraceData, _this.options).getNodes(); if (!nodeGroupNodes) { return; @@ -1680,7 +1680,7 @@ var Obfuscator = function () { return Obfuscator; }(); -Obfuscator.nodeGroups = [DomainLockNodesGroup_1.DomainLockNodesGroup, SelfDefendingNodesGroup_1.SelfDefendingNodesGroup, ConsoleOutputNodesGroup_1.ConsoleOutputNodesGroup, DebugProtectionNodesGroup_1.DebugProtectionNodesGroup, StringArrayNodesGroup_1.StringArrayNodesGroup]; +Obfuscator.customNodesFactories = [DomainLockCustomNodesFactory_1.DomainLockCustomNodesFactory, SelfDefendingCustomNodesFactory_1.SelfDefendingCustomNodesFactory, ConsoleOutputCustomNodesFactory_1.ConsoleOutputCustomNodesFactory, DebugProtectionCustomNodesFactory_1.DebugProtectionCustomNodesFactory, StringArrayCustomNodesFactory_1.StringArrayCustomNodesFactory]; exports.Obfuscator = Obfuscator; /***/ }, @@ -1878,7 +1878,7 @@ var JavaScriptObfuscatorCLI = function () { }, { key: 'buildOptions', value: function buildOptions() { - var obfuscatorOptions = {}; + var inputOptions = {}; var availableOptions = Object.keys(DefaultPreset_1.DEFAULT_PRESET); for (var option in this.commands) { if (!this.commands.hasOwnProperty(option)) { @@ -1887,9 +1887,9 @@ var JavaScriptObfuscatorCLI = function () { if (!Utils_1.Utils.arrayContains(availableOptions, option)) { continue; } - obfuscatorOptions[option] = this.commands[option]; + inputOptions[option] = this.commands[option]; } - return Object.assign({}, DefaultPreset_1.DEFAULT_PRESET, obfuscatorOptions); + return Object.assign({}, DefaultPreset_1.DEFAULT_PRESET, inputOptions); } }, { key: 'configureCommands', @@ -2053,6 +2053,53 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen 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 ConsoleOutputDisableExpressionNode_1 = __webpack_require__(34); +var NodeCallsControllerFunctionNode_1 = __webpack_require__(17); +var AbstractCustomNodesFactory_1 = __webpack_require__(12); +var NodeAppender_1 = __webpack_require__(3); +var Utils_1 = __webpack_require__(0); + +var ConsoleOutputCustomNodesFactory = function (_AbstractCustomNodesF) { + _inherits(ConsoleOutputCustomNodesFactory, _AbstractCustomNodesF); + + function ConsoleOutputCustomNodesFactory() { + _classCallCheck(this, ConsoleOutputCustomNodesFactory); + + return _possibleConstructorReturn(this, (ConsoleOutputCustomNodesFactory.__proto__ || Object.getPrototypeOf(ConsoleOutputCustomNodesFactory)).apply(this, arguments)); + } + + _createClass(ConsoleOutputCustomNodesFactory, [{ + key: 'getNodes', + value: function getNodes() { + if (!this.options.disableConsoleOutput) { + return; + } + var callsControllerFunctionName = Utils_1.Utils.getRandomVariableName(); + var randomStackTraceIndex = NodeAppender_1.NodeAppender.getRandomStackTraceIndex(this.stackTraceData.length); + return this.syncCustomNodesWithNodesGroup(new Map([['consoleOutputDisableExpressionNode', new ConsoleOutputDisableExpressionNode_1.ConsoleOutputDisableExpressionNode(this.stackTraceData, callsControllerFunctionName, randomStackTraceIndex, this.options)], ['ConsoleOutputNodeCallsControllerFunctionNode', new NodeCallsControllerFunctionNode_1.NodeCallsControllerFunctionNode(this.stackTraceData, callsControllerFunctionName, randomStackTraceIndex, this.options)]])); + } + }]); + + return ConsoleOutputCustomNodesFactory; +}(AbstractCustomNodesFactory_1.AbstractCustomNodesFactory); + +exports.ConsoleOutputCustomNodesFactory = ConsoleOutputCustomNodesFactory; + +/***/ }, +/* 36 */ +/***/ 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"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +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 format = __webpack_require__(7); var AppendState_1 = __webpack_require__(1); var BinaryExpressionFunctionTemplate_1 = __webpack_require__(82); @@ -2091,7 +2138,7 @@ var BinaryExpressionFunctionNode = function (_AbstractCustomNode_) { exports.BinaryExpressionFunctionNode = BinaryExpressionFunctionNode; /***/ }, -/* 36 */ +/* 37 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -2150,7 +2197,7 @@ var ControlFlowStorageCallNode = function (_AbstractCustomNode_) { exports.ControlFlowStorageCallNode = ControlFlowStorageCallNode; /***/ }, -/* 37 */ +/* 38 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -2205,7 +2252,7 @@ var ControlFlowStorageNode = function (_AbstractCustomNode_) { exports.ControlFlowStorageNode = ControlFlowStorageNode; /***/ }, -/* 38 */ +/* 39 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -2258,7 +2305,7 @@ var DebugProtectionFunctionCallNode = function (_AbstractCustomNode_) { exports.DebugProtectionFunctionCallNode = DebugProtectionFunctionCallNode; /***/ }, -/* 39 */ +/* 40 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -2311,7 +2358,7 @@ var DebugProtectionFunctionIntervalNode = function (_AbstractCustomNode_) { exports.DebugProtectionFunctionIntervalNode = DebugProtectionFunctionIntervalNode; /***/ }, -/* 40 */ +/* 41 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -2367,7 +2414,57 @@ var DebugProtectionFunctionNode = function (_AbstractCustomNode_) { exports.DebugProtectionFunctionNode = DebugProtectionFunctionNode; /***/ }, -/* 41 */ +/* 42 */ +/***/ 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"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +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__(39); +var DebugProtectionFunctionIntervalNode_1 = __webpack_require__(40); +var DebugProtectionFunctionNode_1 = __webpack_require__(41); +var AbstractCustomNodesFactory_1 = __webpack_require__(12); +var Utils_1 = __webpack_require__(0); + +var DebugProtectionCustomNodesFactory = function (_AbstractCustomNodesF) { + _inherits(DebugProtectionCustomNodesFactory, _AbstractCustomNodesF); + + function DebugProtectionCustomNodesFactory() { + _classCallCheck(this, DebugProtectionCustomNodesFactory); + + return _possibleConstructorReturn(this, (DebugProtectionCustomNodesFactory.__proto__ || Object.getPrototypeOf(DebugProtectionCustomNodesFactory)).apply(this, arguments)); + } + + _createClass(DebugProtectionCustomNodesFactory, [{ + key: 'getNodes', + value: function getNodes() { + if (!this.options.debugProtection) { + return; + } + var debugProtectionFunctionName = Utils_1.Utils.getRandomVariableName(); + var customNodes = new Map([['debugProtectionFunctionNode', new DebugProtectionFunctionNode_1.DebugProtectionFunctionNode(debugProtectionFunctionName, this.options)], ['debugProtectionFunctionCallNode', new DebugProtectionFunctionCallNode_1.DebugProtectionFunctionCallNode(debugProtectionFunctionName, this.options)]]); + if (this.options.debugProtectionInterval) { + customNodes.set('debugProtectionFunctionIntervalNode', new DebugProtectionFunctionIntervalNode_1.DebugProtectionFunctionIntervalNode(debugProtectionFunctionName, this.options)); + } + return this.syncCustomNodesWithNodesGroup(customNodes); + } + }]); + + return DebugProtectionCustomNodesFactory; +}(AbstractCustomNodesFactory_1.AbstractCustomNodesFactory); + +exports.DebugProtectionCustomNodesFactory = DebugProtectionCustomNodesFactory; + +/***/ }, +/* 43 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -2433,7 +2530,54 @@ var DomainLockNode = function (_AbstractCustomNode_) { exports.DomainLockNode = DomainLockNode; /***/ }, -/* 42 */ +/* 44 */ +/***/ 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"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +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 DomainLockNode_1 = __webpack_require__(43); +var NodeCallsControllerFunctionNode_1 = __webpack_require__(17); +var AbstractCustomNodesFactory_1 = __webpack_require__(12); +var NodeAppender_1 = __webpack_require__(3); +var Utils_1 = __webpack_require__(0); + +var DomainLockCustomNodesFactory = function (_AbstractCustomNodesF) { + _inherits(DomainLockCustomNodesFactory, _AbstractCustomNodesF); + + function DomainLockCustomNodesFactory() { + _classCallCheck(this, DomainLockCustomNodesFactory); + + return _possibleConstructorReturn(this, (DomainLockCustomNodesFactory.__proto__ || Object.getPrototypeOf(DomainLockCustomNodesFactory)).apply(this, arguments)); + } + + _createClass(DomainLockCustomNodesFactory, [{ + key: 'getNodes', + value: function getNodes() { + if (!this.options.domainLock.length) { + return; + } + var callsControllerFunctionName = Utils_1.Utils.getRandomVariableName(); + var randomStackTraceIndex = NodeAppender_1.NodeAppender.getRandomStackTraceIndex(this.stackTraceData.length); + return this.syncCustomNodesWithNodesGroup(new Map([['DomainLockNode', new DomainLockNode_1.DomainLockNode(this.stackTraceData, callsControllerFunctionName, randomStackTraceIndex, this.options)], ['DomainLockNodeCallsControllerFunctionNode', new NodeCallsControllerFunctionNode_1.NodeCallsControllerFunctionNode(this.stackTraceData, callsControllerFunctionName, randomStackTraceIndex, this.options)]])); + } + }]); + + return DomainLockCustomNodesFactory; +}(AbstractCustomNodesFactory_1.AbstractCustomNodesFactory); + +exports.DomainLockCustomNodesFactory = DomainLockCustomNodesFactory; + +/***/ }, +/* 45 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -2494,7 +2638,58 @@ var SelfDefendingUnicodeNode = function (_AbstractCustomNode_) { exports.SelfDefendingUnicodeNode = SelfDefendingUnicodeNode; /***/ }, -/* 43 */ +/* 46 */ +/***/ 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"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +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 AppendState_1 = __webpack_require__(1); +var NodeCallsControllerFunctionNode_1 = __webpack_require__(17); +var SelfDefendingUnicodeNode_1 = __webpack_require__(45); +var AbstractCustomNodesFactory_1 = __webpack_require__(12); +var NodeAppender_1 = __webpack_require__(3); +var Utils_1 = __webpack_require__(0); + +var SelfDefendingCustomNodesFactory = function (_AbstractCustomNodesF) { + _inherits(SelfDefendingCustomNodesFactory, _AbstractCustomNodesF); + + function SelfDefendingCustomNodesFactory() { + _classCallCheck(this, SelfDefendingCustomNodesFactory); + + var _this = _possibleConstructorReturn(this, (SelfDefendingCustomNodesFactory.__proto__ || Object.getPrototypeOf(SelfDefendingCustomNodesFactory)).apply(this, arguments)); + + _this.appendState = AppendState_1.AppendState.AfterObfuscation; + return _this; + } + + _createClass(SelfDefendingCustomNodesFactory, [{ + key: 'getNodes', + value: function getNodes() { + if (!this.options.selfDefending) { + return; + } + var callsControllerFunctionName = Utils_1.Utils.getRandomVariableName(); + var randomStackTraceIndex = NodeAppender_1.NodeAppender.getRandomStackTraceIndex(this.stackTraceData.length); + return this.syncCustomNodesWithNodesGroup(new Map([['selfDefendingUnicodeNode', new SelfDefendingUnicodeNode_1.SelfDefendingUnicodeNode(this.stackTraceData, callsControllerFunctionName, randomStackTraceIndex, this.options)], ['SelfDefendingNodeCallsControllerFunctionNode', new NodeCallsControllerFunctionNode_1.NodeCallsControllerFunctionNode(this.stackTraceData, callsControllerFunctionName, randomStackTraceIndex, this.options)]])); + } + }]); + + return SelfDefendingCustomNodesFactory; +}(AbstractCustomNodesFactory_1.AbstractCustomNodesFactory); + +exports.SelfDefendingCustomNodesFactory = SelfDefendingCustomNodesFactory; + +/***/ }, +/* 47 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -2607,7 +2802,7 @@ var StringArrayCallsWrapper = function (_AbstractCustomNode_) { exports.StringArrayCallsWrapper = StringArrayCallsWrapper; /***/ }, -/* 44 */ +/* 48 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -2683,7 +2878,7 @@ StringArrayNode.ARRAY_RANDOM_LENGTH = 4; exports.StringArrayNode = StringArrayNode; /***/ }, -/* 45 */ +/* 49 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -2761,163 +2956,6 @@ var StringArrayRotateFunctionNode = function (_AbstractCustomNode_) { exports.StringArrayRotateFunctionNode = StringArrayRotateFunctionNode; -/***/ }, -/* 46 */ -/***/ function(module, exports, __webpack_require__) { - -"use strict"; -"use strict"; - -var Utils_1 = __webpack_require__(0); -exports.VisitorDirection = Utils_1.Utils.strEnumify({ - enter: 'enter', - leave: 'leave' -}); - -/***/ }, -/* 47 */ -/***/ 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"); } } - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -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 ConsoleOutputDisableExpressionNode_1 = __webpack_require__(34); -var NodeCallsControllerFunctionNode_1 = __webpack_require__(17); -var AbstractNodesGroup_1 = __webpack_require__(12); -var NodeAppender_1 = __webpack_require__(3); -var Utils_1 = __webpack_require__(0); - -var ConsoleOutputNodesGroup = function (_AbstractNodesGroup_) { - _inherits(ConsoleOutputNodesGroup, _AbstractNodesGroup_); - - function ConsoleOutputNodesGroup() { - _classCallCheck(this, ConsoleOutputNodesGroup); - - return _possibleConstructorReturn(this, (ConsoleOutputNodesGroup.__proto__ || Object.getPrototypeOf(ConsoleOutputNodesGroup)).apply(this, arguments)); - } - - _createClass(ConsoleOutputNodesGroup, [{ - key: 'getNodes', - value: function getNodes() { - if (!this.options.disableConsoleOutput) { - return; - } - var callsControllerFunctionName = Utils_1.Utils.getRandomVariableName(); - var randomStackTraceIndex = NodeAppender_1.NodeAppender.getRandomStackTraceIndex(this.stackTraceData.length); - return this.syncCustomNodesWithNodesGroup(new Map([['consoleOutputDisableExpressionNode', new ConsoleOutputDisableExpressionNode_1.ConsoleOutputDisableExpressionNode(this.stackTraceData, callsControllerFunctionName, randomStackTraceIndex, this.options)], ['ConsoleOutputNodeCallsControllerFunctionNode', new NodeCallsControllerFunctionNode_1.NodeCallsControllerFunctionNode(this.stackTraceData, callsControllerFunctionName, randomStackTraceIndex, this.options)]])); - } - }]); - - return ConsoleOutputNodesGroup; -}(AbstractNodesGroup_1.AbstractNodesGroup); - -exports.ConsoleOutputNodesGroup = ConsoleOutputNodesGroup; - -/***/ }, -/* 48 */ -/***/ 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"); } } - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -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__(38); -var DebugProtectionFunctionIntervalNode_1 = __webpack_require__(39); -var DebugProtectionFunctionNode_1 = __webpack_require__(40); -var AbstractNodesGroup_1 = __webpack_require__(12); -var Utils_1 = __webpack_require__(0); - -var DebugProtectionNodesGroup = function (_AbstractNodesGroup_) { - _inherits(DebugProtectionNodesGroup, _AbstractNodesGroup_); - - function DebugProtectionNodesGroup() { - _classCallCheck(this, DebugProtectionNodesGroup); - - return _possibleConstructorReturn(this, (DebugProtectionNodesGroup.__proto__ || Object.getPrototypeOf(DebugProtectionNodesGroup)).apply(this, arguments)); - } - - _createClass(DebugProtectionNodesGroup, [{ - key: 'getNodes', - value: function getNodes() { - if (!this.options.debugProtection) { - return; - } - var debugProtectionFunctionName = Utils_1.Utils.getRandomVariableName(); - var customNodes = new Map([['debugProtectionFunctionNode', new DebugProtectionFunctionNode_1.DebugProtectionFunctionNode(debugProtectionFunctionName, this.options)], ['debugProtectionFunctionCallNode', new DebugProtectionFunctionCallNode_1.DebugProtectionFunctionCallNode(debugProtectionFunctionName, this.options)]]); - if (this.options.debugProtectionInterval) { - customNodes.set('debugProtectionFunctionIntervalNode', new DebugProtectionFunctionIntervalNode_1.DebugProtectionFunctionIntervalNode(debugProtectionFunctionName, this.options)); - } - return this.syncCustomNodesWithNodesGroup(customNodes); - } - }]); - - return DebugProtectionNodesGroup; -}(AbstractNodesGroup_1.AbstractNodesGroup); - -exports.DebugProtectionNodesGroup = DebugProtectionNodesGroup; - -/***/ }, -/* 49 */ -/***/ 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"); } } - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -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 DomainLockNode_1 = __webpack_require__(41); -var NodeCallsControllerFunctionNode_1 = __webpack_require__(17); -var AbstractNodesGroup_1 = __webpack_require__(12); -var NodeAppender_1 = __webpack_require__(3); -var Utils_1 = __webpack_require__(0); - -var DomainLockNodesGroup = function (_AbstractNodesGroup_) { - _inherits(DomainLockNodesGroup, _AbstractNodesGroup_); - - function DomainLockNodesGroup() { - _classCallCheck(this, DomainLockNodesGroup); - - return _possibleConstructorReturn(this, (DomainLockNodesGroup.__proto__ || Object.getPrototypeOf(DomainLockNodesGroup)).apply(this, arguments)); - } - - _createClass(DomainLockNodesGroup, [{ - key: 'getNodes', - value: function getNodes() { - if (!this.options.domainLock.length) { - return; - } - var callsControllerFunctionName = Utils_1.Utils.getRandomVariableName(); - var randomStackTraceIndex = NodeAppender_1.NodeAppender.getRandomStackTraceIndex(this.stackTraceData.length); - return this.syncCustomNodesWithNodesGroup(new Map([['DomainLockNode', new DomainLockNode_1.DomainLockNode(this.stackTraceData, callsControllerFunctionName, randomStackTraceIndex, this.options)], ['DomainLockNodeCallsControllerFunctionNode', new NodeCallsControllerFunctionNode_1.NodeCallsControllerFunctionNode(this.stackTraceData, callsControllerFunctionName, randomStackTraceIndex, this.options)]])); - } - }]); - - return DomainLockNodesGroup; -}(AbstractNodesGroup_1.AbstractNodesGroup); - -exports.DomainLockNodesGroup = DomainLockNodesGroup; - /***/ }, /* 50 */ /***/ function(module, exports, __webpack_require__) { @@ -2934,71 +2972,20 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen 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 AppendState_1 = __webpack_require__(1); -var NodeCallsControllerFunctionNode_1 = __webpack_require__(17); -var SelfDefendingUnicodeNode_1 = __webpack_require__(42); -var AbstractNodesGroup_1 = __webpack_require__(12); -var NodeAppender_1 = __webpack_require__(3); -var Utils_1 = __webpack_require__(0); - -var SelfDefendingNodesGroup = function (_AbstractNodesGroup_) { - _inherits(SelfDefendingNodesGroup, _AbstractNodesGroup_); - - function SelfDefendingNodesGroup() { - _classCallCheck(this, SelfDefendingNodesGroup); - - var _this = _possibleConstructorReturn(this, (SelfDefendingNodesGroup.__proto__ || Object.getPrototypeOf(SelfDefendingNodesGroup)).apply(this, arguments)); - - _this.appendState = AppendState_1.AppendState.AfterObfuscation; - return _this; - } - - _createClass(SelfDefendingNodesGroup, [{ - key: 'getNodes', - value: function getNodes() { - if (!this.options.selfDefending) { - return; - } - var callsControllerFunctionName = Utils_1.Utils.getRandomVariableName(); - var randomStackTraceIndex = NodeAppender_1.NodeAppender.getRandomStackTraceIndex(this.stackTraceData.length); - return this.syncCustomNodesWithNodesGroup(new Map([['selfDefendingUnicodeNode', new SelfDefendingUnicodeNode_1.SelfDefendingUnicodeNode(this.stackTraceData, callsControllerFunctionName, randomStackTraceIndex, this.options)], ['SelfDefendingNodeCallsControllerFunctionNode', new NodeCallsControllerFunctionNode_1.NodeCallsControllerFunctionNode(this.stackTraceData, callsControllerFunctionName, randomStackTraceIndex, this.options)]])); - } - }]); - - return SelfDefendingNodesGroup; -}(AbstractNodesGroup_1.AbstractNodesGroup); - -exports.SelfDefendingNodesGroup = SelfDefendingNodesGroup; - -/***/ }, -/* 51 */ -/***/ 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"); } } - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -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 AppendState_1 = __webpack_require__(1); -var StringArrayCallsWrapper_1 = __webpack_require__(43); -var StringArrayNode_1 = __webpack_require__(44); -var StringArrayRotateFunctionNode_1 = __webpack_require__(45); -var AbstractNodesGroup_1 = __webpack_require__(12); +var StringArrayCallsWrapper_1 = __webpack_require__(47); +var StringArrayNode_1 = __webpack_require__(48); +var StringArrayRotateFunctionNode_1 = __webpack_require__(49); +var AbstractCustomNodesFactory_1 = __webpack_require__(12); var StringArrayStorage_1 = __webpack_require__(77); var Utils_1 = __webpack_require__(0); -var StringArrayNodesGroup = function (_AbstractNodesGroup_) { - _inherits(StringArrayNodesGroup, _AbstractNodesGroup_); +var StringArrayCustomNodesFactory = function (_AbstractCustomNodesF) { + _inherits(StringArrayCustomNodesFactory, _AbstractCustomNodesF); - function StringArrayNodesGroup() { - _classCallCheck(this, StringArrayNodesGroup); + function StringArrayCustomNodesFactory() { + _classCallCheck(this, StringArrayCustomNodesFactory); - var _this = _possibleConstructorReturn(this, (StringArrayNodesGroup.__proto__ || Object.getPrototypeOf(StringArrayNodesGroup)).apply(this, arguments)); + var _this = _possibleConstructorReturn(this, (StringArrayCustomNodesFactory.__proto__ || Object.getPrototypeOf(StringArrayCustomNodesFactory)).apply(this, arguments)); _this.appendState = AppendState_1.AppendState.AfterObfuscation; _this.stringArrayName = Utils_1.Utils.getRandomVariableName(StringArrayNode_1.StringArrayNode.ARRAY_RANDOM_LENGTH); @@ -3006,7 +2993,7 @@ var StringArrayNodesGroup = function (_AbstractNodesGroup_) { return _this; } - _createClass(StringArrayNodesGroup, [{ + _createClass(StringArrayCustomNodesFactory, [{ key: 'getNodes', value: function getNodes() { if (!this.options.stringArray) { @@ -3027,10 +3014,23 @@ var StringArrayNodesGroup = function (_AbstractNodesGroup_) { } }]); - return StringArrayNodesGroup; -}(AbstractNodesGroup_1.AbstractNodesGroup); + return StringArrayCustomNodesFactory; +}(AbstractCustomNodesFactory_1.AbstractCustomNodesFactory); -exports.StringArrayNodesGroup = StringArrayNodesGroup; +exports.StringArrayCustomNodesFactory = StringArrayCustomNodesFactory; + +/***/ }, +/* 51 */ +/***/ function(module, exports, __webpack_require__) { + +"use strict"; +"use strict"; + +var Utils_1 = __webpack_require__(0); +exports.VisitorDirection = Utils_1.Utils.strEnumify({ + enter: 'enter', + leave: 'leave' +}); /***/ }, /* 52 */ @@ -3052,7 +3052,7 @@ var NodeType_1 = __webpack_require__(6); var AbstractNodeTransformer_1 = __webpack_require__(9); var BinaryExpressionControlFlowReplacer_1 = __webpack_require__(54); var ControlFlowStorage_1 = __webpack_require__(76); -var ControlFlowStorageNode_1 = __webpack_require__(37); +var ControlFlowStorageNode_1 = __webpack_require__(38); var Node_1 = __webpack_require__(2); var NodeAppender_1 = __webpack_require__(3); var Utils_1 = __webpack_require__(0); @@ -3164,8 +3164,8 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function" var escodegen = __webpack_require__(11); var AbstractControlFlowReplacer_1 = __webpack_require__(53); -var BinaryExpressionFunctionNode_1 = __webpack_require__(35); -var ControlFlowStorageCallNode_1 = __webpack_require__(36); +var BinaryExpressionFunctionNode_1 = __webpack_require__(36); +var ControlFlowStorageCallNode_1 = __webpack_require__(37); var BinaryExpressionControlFlowReplacer = function (_AbstractControlFlowR) { _inherits(BinaryExpressionControlFlowReplacer, _AbstractControlFlowR); @@ -4012,10 +4012,10 @@ var DefaultPreset_1 = __webpack_require__(24); var OptionsNormalizer_1 = __webpack_require__(68); var ValidationErrorsFormatter_1 = __webpack_require__(69); -var Options = function Options(obfuscatorOptions) { +var Options = function Options(inputOptions) { _classCallCheck(this, Options); - Object.assign(this, DefaultPreset_1.DEFAULT_PRESET, obfuscatorOptions); + Object.assign(this, DefaultPreset_1.DEFAULT_PRESET, inputOptions); var errors = class_validator_1.validateSync(this, Options.validatorOptions); if (errors.length) { throw new ReferenceError("Validation failed. errors:\n" + ValidationErrorsFormatter_1.ValidationErrorsFormatter.format(errors)); diff --git a/src/JavaScriptObfuscator.ts b/src/JavaScriptObfuscator.ts index c4354131..fef76cc0 100644 --- a/src/JavaScriptObfuscator.ts +++ b/src/JavaScriptObfuscator.ts @@ -1,5 +1,5 @@ +import { IInputOptions } from './interfaces/IInputOptions'; import { IObfuscationResult } from './interfaces/IObfuscationResult'; -import { IObfuscatorOptions } from './interfaces/IObfuscatorOptions'; import { JavaScriptObfuscatorCLI } from './cli/JavaScriptObfuscatorCLI'; import { JavaScriptObfuscatorInternal } from './JavaScriptObfuscatorInternal'; @@ -8,12 +8,12 @@ import { Options } from './options/Options'; export class JavaScriptObfuscator { /** * @param sourceCode - * @param obfuscatorOptions + * @param inputOptions * @returns {string} */ - public static obfuscate (sourceCode: string, obfuscatorOptions: IObfuscatorOptions = {}): IObfuscationResult { + public static obfuscate (sourceCode: string, inputOptions: IInputOptions = {}): IObfuscationResult { const javaScriptObfuscator: JavaScriptObfuscatorInternal = new JavaScriptObfuscatorInternal( - new Options(obfuscatorOptions) + new Options(inputOptions) ); return javaScriptObfuscator.obfuscate(sourceCode); diff --git a/src/Obfuscator.ts b/src/Obfuscator.ts index a5aa7a23..8a91740b 100644 --- a/src/Obfuscator.ts +++ b/src/Obfuscator.ts @@ -1,7 +1,7 @@ import * as estraverse from 'estraverse'; import * as ESTree from 'estree'; -import { TNodeGroup } from './types/TNodeGroup'; +import { TCustomNodesFactory } from './types/TCustomNodesFactory'; import { TVisitorDirection } from './types/TVisitorDirection'; import { ICustomNode } from './interfaces/custom-nodes/ICustomNode'; @@ -14,27 +14,28 @@ import { IStackTraceData } from './interfaces/stack-trace-analyzer/IStackTraceDa import { AppendState } from './enums/AppendState'; import { VisitorDirection } from './enums/VisitorDirection'; -import { ConsoleOutputNodesGroup } from './node-groups/ConsoleOutputNodesGroup'; -import { DebugProtectionNodesGroup } from './node-groups/DebugProtectionNodesGroup'; -import { DomainLockNodesGroup } from './node-groups/DomainLockNodesGroup'; -import { Node } from './node/Node'; +import { ConsoleOutputCustomNodesFactory } from './custom-nodes/console-output-nodes/factory/ConsoleOutputCustomNodesFactory'; +import { DebugProtectionCustomNodesFactory } from './custom-nodes/debug-protection-nodes/factory/DebugProtectionCustomNodesFactory'; +import { DomainLockCustomNodesFactory } from './custom-nodes/domain-lock-nodes/factory/DomainLockCustomNodesFactory'; import { NodeControlFlowTransformersFactory } from './node-transformers/node-control-flow-transformers/factory/NodeControlFlowTransformersFactory'; import { NodeObfuscatorsFactory } from './node-transformers/node-obfuscators/factory/NodeObfuscatorsFactory'; +import { SelfDefendingCustomNodesFactory } from './custom-nodes/self-defending-nodes/factory/SelfDefendingCustomNodesFactory'; +import { StringArrayCustomNodesFactory } from './custom-nodes/string-array-nodes/factory/StringArrayCustomNodesFactory'; + +import { Node } from './node/Node'; import { NodeUtils } from './node/NodeUtils'; -import { SelfDefendingNodesGroup } from './node-groups/SelfDefendingNodesGroup'; import { StackTraceAnalyzer } from './stack-trace-analyzer/StackTraceAnalyzer'; -import { StringArrayNodesGroup } from './node-groups/StringArrayNodesGroup'; export class Obfuscator implements IObfuscator { /** - * @type {TNodeGroup[]} + * @type {TCustomNodesFactory[]} */ - private static readonly nodeGroups: TNodeGroup[] = [ - DomainLockNodesGroup, - SelfDefendingNodesGroup, - ConsoleOutputNodesGroup, - DebugProtectionNodesGroup, - StringArrayNodesGroup + private static readonly customNodesFactories: TCustomNodesFactory[] = [ + DomainLockCustomNodesFactory, + SelfDefendingCustomNodesFactory, + ConsoleOutputCustomNodesFactory, + DebugProtectionCustomNodesFactory, + StringArrayCustomNodesFactory ]; /** @@ -117,7 +118,7 @@ export class Obfuscator implements IObfuscator { private initializeCustomNodes (stackTraceData: IStackTraceData[]): void { const customNodes: [string, ICustomNode][] = []; - Obfuscator.nodeGroups.forEach((nodeGroupConstructor: TNodeGroup) => { + Obfuscator.customNodesFactories.forEach((nodeGroupConstructor: TCustomNodesFactory) => { const nodeGroupNodes: Map | undefined = new nodeGroupConstructor( stackTraceData, this.options ).getNodes(); diff --git a/src/cli/JavaScriptObfuscatorCLI.ts b/src/cli/JavaScriptObfuscatorCLI.ts index e29b6386..126185be 100644 --- a/src/cli/JavaScriptObfuscatorCLI.ts +++ b/src/cli/JavaScriptObfuscatorCLI.ts @@ -3,8 +3,8 @@ import * as path from 'path'; import { TStringArrayEncoding } from '../types/TStringArrayEncoding'; +import { IInputOptions } from '../interfaces/IInputOptions'; import { IObfuscationResult } from '../interfaces/IObfuscationResult'; -import { IObfuscatorOptions } from '../interfaces/IObfuscatorOptions'; import { SourceMapMode } from '../enums/SourceMapMode'; import { StringArrayEncoding } from '../enums/StringArrayEncoding'; @@ -118,10 +118,10 @@ export class JavaScriptObfuscatorCLI { } /** - * @returns {IObfuscatorOptions} + * @returns {IInputOptions} */ - private buildOptions (): IObfuscatorOptions { - const obfuscatorOptions: IObfuscatorOptions = {}; + private buildOptions (): IInputOptions { + const inputOptions: IInputOptions = {}; const availableOptions: string[] = Object.keys(DEFAULT_PRESET); for (const option in this.commands) { @@ -133,10 +133,10 @@ export class JavaScriptObfuscatorCLI { continue; } - obfuscatorOptions[option] = (this.commands)[option]; + inputOptions[option] = (this.commands)[option]; } - return Object.assign({}, DEFAULT_PRESET, obfuscatorOptions); + return Object.assign({}, DEFAULT_PRESET, inputOptions); } private configureCommands (): void { @@ -181,7 +181,7 @@ export class JavaScriptObfuscatorCLI { } private processData (): void { - const options: IObfuscatorOptions = this.buildOptions(); + const options: IInputOptions = this.buildOptions(); const outputCodePath: string = CLIUtils.getOutputCodePath((this.commands).output, this.inputPath); if (options.sourceMap) { @@ -195,7 +195,7 @@ export class JavaScriptObfuscatorCLI { * @param outputCodePath * @param options */ - private processDataWithoutSourceMap (outputCodePath: string, options: IObfuscatorOptions): void { + private processDataWithoutSourceMap (outputCodePath: string, options: IInputOptions): void { const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(this.data, options).getObfuscatedCode(); CLIUtils.writeFile(outputCodePath, obfuscatedCode); @@ -205,7 +205,7 @@ export class JavaScriptObfuscatorCLI { * @param outputCodePath * @param options */ - private processDataWithSourceMap (outputCodePath: string, options: IObfuscatorOptions): void { + private processDataWithSourceMap (outputCodePath: string, options: IInputOptions): void { const outputSourceMapPath: string = CLIUtils.getOutputSourceMapPath( outputCodePath, options.sourceMapFileName || '' diff --git a/src/node-groups/AbstractNodesGroup.ts b/src/custom-nodes/AbstractCustomNodesFactory.ts similarity index 89% rename from src/node-groups/AbstractNodesGroup.ts rename to src/custom-nodes/AbstractCustomNodesFactory.ts index eb6df4e4..c9a25b50 100644 --- a/src/node-groups/AbstractNodesGroup.ts +++ b/src/custom-nodes/AbstractCustomNodesFactory.ts @@ -1,11 +1,11 @@ import { ICustomNode } from '../interfaces/custom-nodes/ICustomNode'; -import { INodesGroup } from '../interfaces/INodesGroup'; +import { ICustomNodesFactory } from '../interfaces/ICustomNodesFactory'; import { IOptions } from '../interfaces/IOptions'; import { IStackTraceData } from '../interfaces/stack-trace-analyzer/IStackTraceData'; import { AppendState } from '../enums/AppendState'; -export abstract class AbstractNodesGroup implements INodesGroup { +export abstract class AbstractCustomNodesFactory implements ICustomNodesFactory { /** * @type {AppendState} */ diff --git a/src/node-groups/ConsoleOutputNodesGroup.ts b/src/custom-nodes/console-output-nodes/factory/ConsoleOutputCustomNodesFactory.ts similarity index 68% rename from src/node-groups/ConsoleOutputNodesGroup.ts rename to src/custom-nodes/console-output-nodes/factory/ConsoleOutputCustomNodesFactory.ts index b5e8aec0..1df0526d 100644 --- a/src/node-groups/ConsoleOutputNodesGroup.ts +++ b/src/custom-nodes/console-output-nodes/factory/ConsoleOutputCustomNodesFactory.ts @@ -1,13 +1,13 @@ -import { ICustomNode } from '../interfaces/custom-nodes/ICustomNode'; +import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode'; -import { ConsoleOutputDisableExpressionNode } from '../custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode'; -import { NodeCallsControllerFunctionNode } from '../custom-nodes/node-calls-controller-nodes/NodeCallsControllerFunctionNode'; +import { ConsoleOutputDisableExpressionNode } from '../ConsoleOutputDisableExpressionNode'; +import { NodeCallsControllerFunctionNode } from '../../node-calls-controller-nodes/NodeCallsControllerFunctionNode'; -import { AbstractNodesGroup } from './AbstractNodesGroup'; -import { NodeAppender } from '../node/NodeAppender'; -import { Utils } from '../Utils'; +import { AbstractCustomNodesFactory } from '../../AbstractCustomNodesFactory'; +import { NodeAppender } from '../../../node/NodeAppender'; +import { Utils } from '../../../Utils'; -export class ConsoleOutputNodesGroup extends AbstractNodesGroup { +export class ConsoleOutputCustomNodesFactory extends AbstractCustomNodesFactory { /** * @returns {Map} */ diff --git a/src/node-groups/DebugProtectionNodesGroup.ts b/src/custom-nodes/debug-protection-nodes/factory/DebugProtectionCustomNodesFactory.ts similarity index 64% rename from src/node-groups/DebugProtectionNodesGroup.ts rename to src/custom-nodes/debug-protection-nodes/factory/DebugProtectionCustomNodesFactory.ts index de8d93e0..87c73dd1 100644 --- a/src/node-groups/DebugProtectionNodesGroup.ts +++ b/src/custom-nodes/debug-protection-nodes/factory/DebugProtectionCustomNodesFactory.ts @@ -1,13 +1,13 @@ -import { ICustomNode } from '../interfaces/custom-nodes/ICustomNode'; +import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode'; -import { DebugProtectionFunctionCallNode } from '../custom-nodes/debug-protection-nodes/DebugProtectionFunctionCallNode'; -import { DebugProtectionFunctionIntervalNode } from '../custom-nodes/debug-protection-nodes/DebugProtectionFunctionIntervalNode'; -import { DebugProtectionFunctionNode } from '../custom-nodes/debug-protection-nodes/DebugProtectionFunctionNode'; +import { DebugProtectionFunctionCallNode } from '../DebugProtectionFunctionCallNode'; +import { DebugProtectionFunctionIntervalNode } from '../DebugProtectionFunctionIntervalNode'; +import { DebugProtectionFunctionNode } from '../DebugProtectionFunctionNode'; -import { AbstractNodesGroup } from './AbstractNodesGroup'; -import { Utils } from '../Utils'; +import { AbstractCustomNodesFactory } from '../../AbstractCustomNodesFactory'; +import { Utils } from '../../../Utils'; -export class DebugProtectionNodesGroup extends AbstractNodesGroup { +export class DebugProtectionCustomNodesFactory extends AbstractCustomNodesFactory { /** * @returns {Map | undefined} */ diff --git a/src/node-groups/DomainLockNodesGroup.ts b/src/custom-nodes/domain-lock-nodes/factory/DomainLockCustomNodesFactory.ts similarity index 69% rename from src/node-groups/DomainLockNodesGroup.ts rename to src/custom-nodes/domain-lock-nodes/factory/DomainLockCustomNodesFactory.ts index c7abe126..5d9e6089 100644 --- a/src/node-groups/DomainLockNodesGroup.ts +++ b/src/custom-nodes/domain-lock-nodes/factory/DomainLockCustomNodesFactory.ts @@ -1,13 +1,13 @@ -import { ICustomNode } from '../interfaces/custom-nodes/ICustomNode'; +import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode'; -import { DomainLockNode } from '../custom-nodes/domain-lock-nodes/DomainLockNode'; -import { NodeCallsControllerFunctionNode } from '../custom-nodes/node-calls-controller-nodes/NodeCallsControllerFunctionNode'; +import { DomainLockNode } from '../DomainLockNode'; +import { NodeCallsControllerFunctionNode } from '../../node-calls-controller-nodes/NodeCallsControllerFunctionNode'; -import { AbstractNodesGroup } from './AbstractNodesGroup'; -import { NodeAppender } from '../node/NodeAppender'; -import { Utils } from '../Utils'; +import { AbstractCustomNodesFactory } from '../../AbstractCustomNodesFactory'; +import { NodeAppender } from '../../../node/NodeAppender'; +import { Utils } from '../../../Utils'; -export class DomainLockNodesGroup extends AbstractNodesGroup { +export class DomainLockCustomNodesFactory extends AbstractCustomNodesFactory { /** * @returns {Map | undefined} */ diff --git a/src/node-groups/SelfDefendingNodesGroup.ts b/src/custom-nodes/self-defending-nodes/factory/SelfDefendingCustomNodesFactory.ts similarity index 68% rename from src/node-groups/SelfDefendingNodesGroup.ts rename to src/custom-nodes/self-defending-nodes/factory/SelfDefendingCustomNodesFactory.ts index d990143e..5d5e4de3 100644 --- a/src/node-groups/SelfDefendingNodesGroup.ts +++ b/src/custom-nodes/self-defending-nodes/factory/SelfDefendingCustomNodesFactory.ts @@ -1,15 +1,15 @@ -import { ICustomNode } from '../interfaces/custom-nodes/ICustomNode'; +import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode'; -import { AppendState } from '../enums/AppendState'; +import { AppendState } from '../../../enums/AppendState'; -import { NodeCallsControllerFunctionNode } from '../custom-nodes/node-calls-controller-nodes/NodeCallsControllerFunctionNode'; -import { SelfDefendingUnicodeNode } from '../custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode'; +import { NodeCallsControllerFunctionNode } from '../../node-calls-controller-nodes/NodeCallsControllerFunctionNode'; +import { SelfDefendingUnicodeNode } from '../SelfDefendingUnicodeNode'; -import { AbstractNodesGroup } from './AbstractNodesGroup'; -import { NodeAppender } from '../node/NodeAppender'; -import { Utils } from '../Utils'; +import { AbstractCustomNodesFactory } from '../../AbstractCustomNodesFactory'; +import { NodeAppender } from '../../../node/NodeAppender'; +import { Utils } from '../../../Utils'; -export class SelfDefendingNodesGroup extends AbstractNodesGroup { +export class SelfDefendingCustomNodesFactory extends AbstractCustomNodesFactory { /** * @type {AppendState} */ diff --git a/src/node-groups/StringArrayNodesGroup.ts b/src/custom-nodes/string-array-nodes/factory/StringArrayCustomNodesFactory.ts similarity index 74% rename from src/node-groups/StringArrayNodesGroup.ts rename to src/custom-nodes/string-array-nodes/factory/StringArrayCustomNodesFactory.ts index 96670cea..99a741f5 100644 --- a/src/node-groups/StringArrayNodesGroup.ts +++ b/src/custom-nodes/string-array-nodes/factory/StringArrayCustomNodesFactory.ts @@ -1,17 +1,17 @@ -import { ICustomNode } from '../interfaces/custom-nodes/ICustomNode'; +import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode'; -import { AppendState } from '../enums/AppendState'; +import { AppendState } from '../../../enums/AppendState'; -import { StringArrayCallsWrapper } from '../custom-nodes/string-array-nodes/StringArrayCallsWrapper'; -import { StringArrayNode } from '../custom-nodes/string-array-nodes/StringArrayNode'; -import { StringArrayRotateFunctionNode } from '../custom-nodes/string-array-nodes/StringArrayRotateFunctionNode'; +import { StringArrayCallsWrapper } from '../StringArrayCallsWrapper'; +import { StringArrayNode } from '../StringArrayNode'; +import { StringArrayRotateFunctionNode } from '../StringArrayRotateFunctionNode'; -import { AbstractNodesGroup } from './AbstractNodesGroup'; -import { StringArrayStorage } from '../storages/string-array/StringArrayStorage'; -import { Utils } from '../Utils'; -import { IStorage } from '../interfaces/IStorage'; +import { AbstractCustomNodesFactory } from '../../AbstractCustomNodesFactory'; +import { StringArrayStorage } from '../../../storages/string-array/StringArrayStorage'; +import { Utils } from '../../../Utils'; +import { IStorage } from '../../../interfaces/IStorage'; -export class StringArrayNodesGroup extends AbstractNodesGroup { +export class StringArrayCustomNodesFactory extends AbstractCustomNodesFactory { /** * @type {AppendState} */ diff --git a/src/interfaces/INodesGroup.d.ts b/src/interfaces/ICustomNodesFactory.d.ts similarity index 82% rename from src/interfaces/INodesGroup.d.ts rename to src/interfaces/ICustomNodesFactory.d.ts index be7ca0e7..3773d4e4 100644 --- a/src/interfaces/INodesGroup.d.ts +++ b/src/interfaces/ICustomNodesFactory.d.ts @@ -1,6 +1,6 @@ import { ICustomNode } from './custom-nodes/ICustomNode'; -export interface INodesGroup { +export interface ICustomNodesFactory { /** * @returns {Map | undefined} */ diff --git a/src/interfaces/IObfuscatorOptions.d.ts b/src/interfaces/IInputOptions.d.ts similarity index 95% rename from src/interfaces/IObfuscatorOptions.d.ts rename to src/interfaces/IInputOptions.d.ts index 90aeeb8d..733ccf0b 100644 --- a/src/interfaces/IObfuscatorOptions.d.ts +++ b/src/interfaces/IInputOptions.d.ts @@ -1,7 +1,7 @@ import { TSourceMapMode } from '../types/TSourceMapMode'; import { TStringArrayEncoding } from '../types/TStringArrayEncoding'; -export interface IObfuscatorOptions { +export interface IInputOptions { compact?: boolean; controlFlowFlattening?: boolean; debugProtection?: boolean; diff --git a/src/options/Options.ts b/src/options/Options.ts index 2c0f593f..c139d271 100644 --- a/src/options/Options.ts +++ b/src/options/Options.ts @@ -14,7 +14,7 @@ import { ValidatorOptions } from 'class-validator'; -import { IObfuscatorOptions } from '../interfaces/IObfuscatorOptions'; +import { IInputOptions } from '../interfaces/IInputOptions'; import { IOptions } from '../interfaces/IOptions'; import { TSourceMapMode } from '../types/TSourceMapMode'; @@ -159,10 +159,10 @@ export class Options implements IOptions { public readonly unicodeEscapeSequence: boolean; /** - * @param obfuscatorOptions + * @param inputOptions */ - constructor (obfuscatorOptions: IObfuscatorOptions) { - Object.assign(this, DEFAULT_PRESET, obfuscatorOptions); + constructor (inputOptions: IInputOptions) { + Object.assign(this, DEFAULT_PRESET, inputOptions); const errors: ValidationError[] = validateSync(this, Options.validatorOptions); diff --git a/src/options/OptionsNormalizer.ts b/src/options/OptionsNormalizer.ts index ea9efed1..ed972fa7 100644 --- a/src/options/OptionsNormalizer.ts +++ b/src/options/OptionsNormalizer.ts @@ -1,4 +1,4 @@ -import { IObfuscatorOptions } from '../interfaces/IObfuscatorOptions'; +import { IInputOptions } from '../interfaces/IInputOptions'; import { IOptions } from '../interfaces/IOptions'; import { TOptionsNormalizerRule } from '../types/TOptionsNormalizerRule'; @@ -7,9 +7,9 @@ import { Utils } from '../Utils'; export class OptionsNormalizer { /** - * @type {IObfuscatorOptions} + * @type {IInputOptions} */ - private static readonly DISABLED_UNICODE_ARRAY_OPTIONS: IObfuscatorOptions = { + private static readonly DISABLED_UNICODE_ARRAY_OPTIONS: IInputOptions = { rotateStringArray: false, stringArray: false, stringArrayEncoding: false, @@ -17,17 +17,17 @@ export class OptionsNormalizer { }; /** - * @type {IObfuscatorOptions} + * @type {IInputOptions} */ - private static readonly SELF_DEFENDING_OPTIONS: IObfuscatorOptions = { + private static readonly SELF_DEFENDING_OPTIONS: IInputOptions = { compact: true, selfDefending: true }; /** - * @type {IObfuscatorOptions} + * @type {IInputOptions} */ - private static readonly UNICODE_ARRAY_ENCODING_OPTIONS: IObfuscatorOptions = { + private static readonly UNICODE_ARRAY_ENCODING_OPTIONS: IInputOptions = { stringArrayEncoding: 'base64' }; diff --git a/src/preset-options/DefaultPreset.ts b/src/preset-options/DefaultPreset.ts index 7f35d55d..f765c99c 100644 --- a/src/preset-options/DefaultPreset.ts +++ b/src/preset-options/DefaultPreset.ts @@ -1,8 +1,8 @@ -import { IObfuscatorOptions } from '../interfaces/IObfuscatorOptions'; +import { IInputOptions } from '../interfaces/IInputOptions'; import { SourceMapMode } from '../enums/SourceMapMode'; -export const DEFAULT_PRESET: IObfuscatorOptions = Object.freeze({ +export const DEFAULT_PRESET: IInputOptions = Object.freeze({ compact: true, controlFlowFlattening: false, debugProtection: false, diff --git a/src/preset-options/NoCustomNodesPreset.ts b/src/preset-options/NoCustomNodesPreset.ts index fb5ad5f4..2a62063d 100644 --- a/src/preset-options/NoCustomNodesPreset.ts +++ b/src/preset-options/NoCustomNodesPreset.ts @@ -1,8 +1,8 @@ -import { IObfuscatorOptions } from '../interfaces/IObfuscatorOptions'; +import { IInputOptions } from '../interfaces/IInputOptions'; import { SourceMapMode } from '../enums/SourceMapMode'; -export const NO_CUSTOM_NODES_PRESET: IObfuscatorOptions = Object.freeze({ +export const NO_CUSTOM_NODES_PRESET: IInputOptions = Object.freeze({ compact: true, controlFlowFlattening: false, debugProtection: false, diff --git a/src/types/TCustomNodesFactory.d.ts b/src/types/TCustomNodesFactory.d.ts new file mode 100644 index 00000000..f95bfc8d --- /dev/null +++ b/src/types/TCustomNodesFactory.d.ts @@ -0,0 +1,5 @@ +import { ICustomNodesFactory } from '../interfaces/ICustomNodesFactory'; +import { IOptions } from '../interfaces/IOptions'; +import { IStackTraceData } from '../interfaces/stack-trace-analyzer/IStackTraceData'; + +export type TCustomNodesFactory = new (stackTraceData: IStackTraceData[], options: IOptions) => ICustomNodesFactory; diff --git a/src/types/TNodeGroup.d.ts b/src/types/TNodeGroup.d.ts deleted file mode 100644 index b72421e2..00000000 --- a/src/types/TNodeGroup.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { INodesGroup } from '../interfaces/INodesGroup'; -import { IOptions } from '../interfaces/IOptions'; -import { IStackTraceData } from '../interfaces/stack-trace-analyzer/IStackTraceData'; - -export type TNodeGroup = new (stackTraceData: IStackTraceData[], options: IOptions) => INodesGroup; diff --git a/test/unit-tests/OptionsNormalizer.spec.ts b/test/unit-tests/OptionsNormalizer.spec.ts index adbdf739..8cffac69 100644 --- a/test/unit-tests/OptionsNormalizer.spec.ts +++ b/test/unit-tests/OptionsNormalizer.spec.ts @@ -1,4 +1,4 @@ -import { IObfuscatorOptions } from '../../src/interfaces/IObfuscatorOptions'; +import { IInputOptions } from '../../src/interfaces/IInputOptions'; import { IOptions } from '../../src/interfaces/IOptions'; import { DEFAULT_PRESET } from '../../src/preset-options/DefaultPreset'; @@ -12,7 +12,7 @@ const assert: Chai.AssertStatic = require('chai').assert; * @param optionsPreset * @returns {IOptions} */ -function getNormalizedOptions (optionsPreset: IObfuscatorOptions): IObfuscatorOptions { +function getNormalizedOptions (optionsPreset: IInputOptions): IInputOptions { const options: IOptions = new Options(optionsPreset); return OptionsNormalizer.normalizeOptions(options); @@ -20,8 +20,8 @@ function getNormalizedOptions (optionsPreset: IObfuscatorOptions): IObfuscatorOp describe('OptionsNormalizer', () => { describe('normalizeOptions (options: IObfuscatorOptions): IObfuscatorOptions', () => { - let optionsPreset: IObfuscatorOptions, - expectedOptionsPreset: IObfuscatorOptions; + let optionsPreset: IInputOptions, + expectedOptionsPreset: IInputOptions; it('should normalize options preset: domainLockRule', () => { optionsPreset = Object.assign({}, DEFAULT_PRESET, {