From c1b3afa92c7a84034dc5a11e2680bd2004cb9b61 Mon Sep 17 00:00:00 2001 From: sanex3339 Date: Thu, 1 Dec 2016 20:57:05 +0300 Subject: [PATCH] refactoring --- dist/index.js | 738 +++++++++--------- src/JavaScriptObfuscator.ts | 2 +- src/JavaScriptObfuscatorInternal.ts | 31 +- src/Obfuscator.ts | 10 +- src/SourceMapCorrector.ts | 79 +- src/Utils.ts | 22 +- src/cli/JavaScriptObfuscatorCLI.ts | 4 +- src/container/InversifyContainerFacade.ts | 45 +- src/container/ServiceIdentifiers.ts | 2 + .../NodeControlFlowTransformersModule.ts | 2 +- .../NodeObfuscatorsModule.ts | 2 +- .../NodeTransformersModule.ts | 2 +- src/custom-nodes/AbstractCustomNode.ts | 6 +- .../AbstractCustomNodesFactory.ts | 4 +- .../ConsoleOutputDisableExpressionNode.ts | 6 +- .../BinaryExpressionFunctionNode.ts | 6 +- .../ControlFlowStorageCallNode.ts | 6 +- .../ControlFlowStorageNode.ts | 8 +- .../DebugProtectionFunctionCallNode.ts | 6 +- .../DebugProtectionFunctionIntervalNode.ts | 6 +- .../DebugProtectionFunctionNode.ts | 6 +- .../domain-lock-nodes/DomainLockNode.ts | 6 +- .../NodeCallsControllerFunctionNode.ts | 6 +- .../SelfDefendingUnicodeNode.ts | 6 +- .../SelfDefendingCustomNodesFactory.ts | 2 +- .../StringArrayCallsWrapper.ts | 10 +- .../string-array-nodes/StringArrayNode.ts | 10 +- .../StringArrayRotateFunctionNode.ts | 8 +- .../factory/StringArrayCustomNodesFactory.ts | 4 +- src/enums/ObfuscationEvents.ts | 2 +- src/event-emitters/ObfuscationEventEmitter.ts | 2 +- src/interfaces/IObfuscator.d.ts | 2 +- src/interfaces/ISourceMapCorrector.d.ts | 2 +- .../IContainerServiceIdentifiers.d.ts | 2 + .../container/IInversifyContainerFacade.d.ts | 1 - src/interfaces/custom-nodes/ICustomNode.d.ts | 4 +- .../IObfuscationEventEmitter.d.ts | 2 +- .../IControlFlowReplacer.d.ts | 4 +- .../INodeTransformer.d.ts | 0 .../{ => node-transformers}/IReplacer.d.ts | 0 .../{ => options}/IInputOptions.d.ts | 4 +- src/interfaces/{ => options}/IOptions.d.ts | 4 +- src/interfaces/{ => storages}/IStorage.d.ts | 0 .../AbstractNodeTransformer.ts | 6 +- .../FunctionControlFlowTransformer.ts | 8 +- .../AbstractControlFlowReplacer.ts | 6 +- .../BinaryExpressionControlFlowReplacer.ts | 8 +- .../node-obfuscators/CatchClauseObfuscator.ts | 6 +- .../FunctionDeclarationObfuscator.ts | 8 +- .../node-obfuscators/FunctionObfuscator.ts | 6 +- .../LabeledStatementObfuscator.ts | 6 +- .../node-obfuscators/LiteralObfuscator.ts | 6 +- .../MemberExpressionObfuscator.ts | 6 +- .../MethodDefinitionObfuscator.ts | 6 +- .../ObjectExpressionObfuscator.ts | 4 +- .../VariableDeclarationObfuscator.ts | 8 +- .../replacers/AbstractReplacer.ts | 6 +- .../replacers/BooleanLiteralReplacer.ts | 4 +- .../replacers/IdentifierReplacer.ts | 4 +- .../replacers/NumberLiteralReplacer.ts | 8 +- .../replacers/StringLiteralReplacer.ts | 7 +- src/node/Node.ts | 4 +- src/node/NodeAppender.ts | 4 +- src/node/NodeUtils.ts | 6 +- src/options/Options.ts | 6 +- src/options/OptionsNormalizer.ts | 6 +- src/preset-options/DefaultPreset.ts | 2 +- src/preset-options/NoCustomNodesPreset.ts | 2 +- .../StackTraceAnalyzer.ts | 64 +- .../ObjectExpressionCalleeDataExtractor.ts | 2 +- src/storages/ArrayStorage.ts | 2 +- src/storages/MapStorage.ts | 2 +- .../custom-nodes/CustomNodesStorage.ts | 4 +- src/types/TCalleeDataExtractorsFactory.d.ts | 5 - src/types/TControlFlowReplacer.d.ts | 6 - src/types/TCustomNodesFactory.d.ts | 4 - src/types/TNodeTransformer.d.ts | 6 - src/types/TNodeTransformersFactory.d.ts | 5 - .../TCalleeDataExtractorsFactory.d.ts | 5 + src/types/container/TCustomNodesFactory.d.ts | 4 + .../container/TNodeTransformersFactory.d.ts | 5 + .../container/TObfuscationResultFactory.d.ts | 3 + .../TObfuscationEvent.d.ts | 0 .../TControlFlowReplacer.d.ts | 6 + .../node-transformers/TNodeTransformer.d.ts | 6 + .../{ => node}/TNodeWithBlockStatement.d.ts | 0 src/types/{ => node}/TStatement.d.ts | 0 .../{ => options}/TOptionsNormalizerRule.d.ts | 2 +- .../{ => options}/TStringArrayEncoding.d.ts | 0 .../TObjectMembersCallsChain.d.ts | 0 .../StackTraceAnalyzer.spec.ts | 2 +- test/mocks/NodeMocks.ts | 2 +- test/unit-tests/OptionsNormalizer.spec.ts | 4 +- test/unit-tests/SourceMapCorrector.spec.ts | 45 +- test/unit-tests/node/NodeAppender.spec.ts | 2 +- test/unit-tests/node/NodeUtils.spec.ts | 82 ++ 96 files changed, 816 insertions(+), 669 deletions(-) rename src/interfaces/{ => event-emitters}/IObfuscationEventEmitter.d.ts (72%) rename src/interfaces/{ => node-transformers}/IControlFlowReplacer.d.ts (72%) rename src/interfaces/{ => node-transformers}/INodeTransformer.d.ts (100%) rename src/interfaces/{ => node-transformers}/IReplacer.d.ts (100%) rename src/interfaces/{ => options}/IInputOptions.d.ts (81%) rename src/interfaces/{ => options}/IOptions.d.ts (84%) rename src/interfaces/{ => storages}/IStorage.d.ts (100%) delete mode 100644 src/types/TCalleeDataExtractorsFactory.d.ts delete mode 100644 src/types/TControlFlowReplacer.d.ts delete mode 100644 src/types/TCustomNodesFactory.d.ts delete mode 100644 src/types/TNodeTransformer.d.ts delete mode 100644 src/types/TNodeTransformersFactory.d.ts create mode 100644 src/types/container/TCalleeDataExtractorsFactory.d.ts create mode 100644 src/types/container/TCustomNodesFactory.d.ts create mode 100644 src/types/container/TNodeTransformersFactory.d.ts create mode 100644 src/types/container/TObfuscationResultFactory.d.ts rename src/types/{ => event-emitters}/TObfuscationEvent.d.ts (100%) create mode 100644 src/types/node-transformers/TControlFlowReplacer.d.ts create mode 100644 src/types/node-transformers/TNodeTransformer.d.ts rename src/types/{ => node}/TNodeWithBlockStatement.d.ts (100%) rename src/types/{ => node}/TStatement.d.ts (100%) rename src/types/{ => options}/TOptionsNormalizerRule.d.ts (53%) rename src/types/{ => options}/TStringArrayEncoding.d.ts (100%) rename src/types/{ => stack-trace-analyzer}/TObjectMembersCallsChain.d.ts (100%) diff --git a/dist/index.js b/dist/index.js index d640bce9..1a9ca41f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -88,7 +88,7 @@ module.exports = /******/ __webpack_require__.p = ""; /******/ /******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = 113); +/******/ return __webpack_require__(__webpack_require__.s = 116); /******/ }) /************************************************************************/ /******/ ([ @@ -104,9 +104,9 @@ var _createClass = (function () { function defineProperties(target, props) { for function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } -var chance_1 = __webpack_require__(28); +var chance_1 = __webpack_require__(29); var JSFuck_1 = __webpack_require__(22); -var isEqual = __webpack_require__(109); +var isEqual = __webpack_require__(112); var Utils = function () { function Utils() { @@ -141,7 +141,7 @@ var Utils = function () { var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; var output = ''; string = encodeURIComponent(string).replace(/%([0-9A-F]{2})/g, function (match, p1) { - return String.fromCharCode(parseInt('0x' + p1)); + return String.fromCharCode(parseInt('' + Utils.hexadecimalPrefix + p1)); }); for (var block, charCode, idx = 0, map = chars; string.charAt(idx | 0) || (map = '=', idx % 1); output += map.charAt(63 & block >> 8 - idx % 1 * 8)) { charCode = string.charCodeAt(idx += 3 / 4); @@ -173,7 +173,7 @@ var Utils = function () { }, { key: 'getRandomFloat', value: function getRandomFloat(min, max) { - return Utils.getRandomGenerator().floating({ + return Utils.randomGenerator.floating({ min: min, max: max, fixed: 7 @@ -191,7 +191,7 @@ var Utils = function () { }, { key: 'getRandomInteger', value: function getRandomInteger(min, max) { - return Utils.getRandomGenerator().integer({ + return Utils.randomGenerator.integer({ min: min, max: max }); @@ -202,9 +202,8 @@ var Utils = function () { var length = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 6; var rangeMinInteger = 10000, - rangeMaxInteger = 99999999, - prefix = '_0x'; - return '' + prefix + Utils.decToHex(Utils.getRandomInteger(rangeMinInteger, rangeMaxInteger)).substr(0, length); + rangeMaxInteger = 99999999; + return '_' + Utils.hexadecimalPrefix + Utils.decToHex(Utils.getRandomInteger(rangeMinInteger, rangeMaxInteger)).substr(0, length); } }, { key: 'hideString', @@ -303,9 +302,9 @@ var Utils = function () { return result; } }, { - key: 'setRandomGenerator', - value: function setRandomGenerator(randomGenerator) { - Utils.randomGenerator = randomGenerator; + key: 'setRandomGeneratorSeed', + value: function setRandomGeneratorSeed(randomGeneratorSeed) { + Utils.randomGenerator = new chance_1.Chance(randomGeneratorSeed); } }, { key: 'strEnumify', @@ -342,6 +341,7 @@ var Utils = function () { return Utils; }(); +Utils.hexadecimalPrefix = '0x'; Utils.randomGeneratorPool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; Utils.randomGenerator = new chance_1.Chance(); exports.Utils = Utils; @@ -363,6 +363,7 @@ exports.ServiceIdentifiers = { 'Factory': Symbol('Factory'), 'Factory': Symbol('Factory'), 'Factory': Symbol('Factory'), + 'Factory': Symbol('Factory'), 'Factory': Symbol('Factory'), ICalleeDataExtractor: Symbol('ICalleeDataExtractor'), IControlFlowReplacer: Symbol('IControlFlowReplacer'), @@ -372,6 +373,7 @@ exports.ServiceIdentifiers = { IObfuscator: Symbol('IObfuscator'), IOptions: Symbol('IOptions'), IReplacer: Symbol('IReplacer'), + ISourceMapCorrector: Symbol('ISourceMapCorrector'), IStackTraceAnalyzer: Symbol('IStackTraceAnalyzer'), 'IStorage': Symbol('IStorage') }; @@ -768,7 +770,7 @@ var _createClass = (function () { function defineProperties(target, props) { for function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var escodegen = __webpack_require__(14); -var esprima = __webpack_require__(29); +var esprima = __webpack_require__(30); var estraverse = __webpack_require__(6); var NodeType_1 = __webpack_require__(9); var Node_1 = __webpack_require__(4); @@ -849,7 +851,7 @@ var NodeUtils = function () { if (Node_1.Node.isProgramNode(parentNode)) { return depth; } - if (Node_1.Node.isBlockStatementNode(node)) { + if (Node_1.Node.isBlockStatementNode(node) && Utils_1.Utils.arrayContains(NodeUtils.nodesWithBlockScope, parentNode.type)) { return NodeUtils.getNodeBlockScopeDepth(parentNode, ++depth); } return NodeUtils.getNodeBlockScopeDepth(parentNode, depth); @@ -972,12 +974,12 @@ var _createClass = (function () { function defineProperties(target, props) { for function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } -__webpack_require__(111); +__webpack_require__(114); if (!global._babelPolyfill) { - __webpack_require__(104); + __webpack_require__(107); } -var InversifyContainerFacade_1 = __webpack_require__(36); -var JavaScriptObfuscatorCLI_1 = __webpack_require__(35); +var InversifyContainerFacade_1 = __webpack_require__(38); +var JavaScriptObfuscatorCLI_1 = __webpack_require__(37); var ServiceIdentifiers_1 = __webpack_require__(2); var JavaScriptObfuscator = function () { @@ -1146,7 +1148,7 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function" var format = __webpack_require__(8); var ObfuscationEvents_1 = __webpack_require__(3); -var SingleNodeCallControllerTemplate_1 = __webpack_require__(87); +var SingleNodeCallControllerTemplate_1 = __webpack_require__(90); var NoCustomNodesPreset_1 = __webpack_require__(18); var AbstractCustomNode_1 = __webpack_require__(7); var JavaScriptObfuscator_1 = __webpack_require__(13); @@ -1213,44 +1215,32 @@ exports.StringArrayEncoding = { /***/ }, /* 21 */ -/***/ function(module, exports) { +/***/ 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; }; })(); +var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } -var ObfuscationResult = function () { - function ObfuscationResult(obfuscatedCode, sourceMap) { - _classCallCheck(this, ObfuscationResult); - - this.obfuscatedCode = obfuscatedCode; - this.sourceMap = sourceMap; - } - - _createClass(ObfuscationResult, [{ - key: "getObfuscatedCode", - value: function getObfuscatedCode() { - return this.obfuscatedCode; - } - }, { - key: "getSourceMap", - value: function getSourceMap() { - return this.sourceMap; - } - }, { - key: "toString", - value: function toString() { - return this.obfuscatedCode; - } - }]); - - return ObfuscationResult; -}(); - -exports.ObfuscationResult = ObfuscationResult; +var __decorate = undefined && undefined.__decorate || function (decorators, target, key, desc) { + var c = arguments.length, + r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, + d; + if ((typeof Reflect === "undefined" ? "undefined" : _typeof(Reflect)) === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) { + if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + }return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __metadata = undefined && undefined.__metadata || function (k, v) { + if ((typeof Reflect === "undefined" ? "undefined" : _typeof(Reflect)) === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); +}; +var inversify_1 = __webpack_require__(1); +var AbstractCalleeDataExtractor = function AbstractCalleeDataExtractor() { + _classCallCheck(this, AbstractCalleeDataExtractor); +}; +AbstractCalleeDataExtractor = __decorate([inversify_1.injectable(), __metadata('design:paramtypes', [])], AbstractCalleeDataExtractor); +exports.AbstractCalleeDataExtractor = AbstractCalleeDataExtractor; /***/ }, /* 22 */ @@ -1323,6 +1313,20 @@ exports.JSFuck = { "use strict"; "use strict"; +(function (CalleeDataExtractors) { + CalleeDataExtractors[CalleeDataExtractors["FunctionDeclarationCalleeDataExtractor"] = 0] = "FunctionDeclarationCalleeDataExtractor"; + CalleeDataExtractors[CalleeDataExtractors["FunctionExpressionCalleeDataExtractor"] = 1] = "FunctionExpressionCalleeDataExtractor"; + CalleeDataExtractors[CalleeDataExtractors["ObjectExpressionCalleeDataExtractor"] = 2] = "ObjectExpressionCalleeDataExtractor"; +})(exports.CalleeDataExtractors || (exports.CalleeDataExtractors = {})); +var CalleeDataExtractors = exports.CalleeDataExtractors; + +/***/ }, +/* 24 */ +/***/ function(module, exports) { + +"use strict"; +"use strict"; + (function (NodeTransformers) { NodeTransformers[NodeTransformers["FunctionControlFlowTransformer"] = 0] = "FunctionControlFlowTransformer"; NodeTransformers[NodeTransformers["CatchClauseObfuscator"] = 1] = "CatchClauseObfuscator"; @@ -1338,7 +1342,7 @@ exports.JSFuck = { var NodeTransformers = exports.NodeTransformers; /***/ }, -/* 24 */ +/* 25 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -1373,9 +1377,9 @@ var __param = undefined && undefined.__param || function (paramIndex, decorator) var inversify_1 = __webpack_require__(1); var ServiceIdentifiers_1 = __webpack_require__(2); var escodegen = __webpack_require__(14); -var AbstractControlFlowReplacer_1 = __webpack_require__(61); -var BinaryExpressionFunctionNode_1 = __webpack_require__(42); -var ControlFlowStorageCallNode_1 = __webpack_require__(43); +var AbstractControlFlowReplacer_1 = __webpack_require__(64); +var BinaryExpressionFunctionNode_1 = __webpack_require__(45); +var ControlFlowStorageCallNode_1 = __webpack_require__(46); var BinaryExpressionControlFlowReplacer_1 = function (_AbstractControlFlowR) { _inherits(BinaryExpressionControlFlowReplacer, _AbstractControlFlowR); @@ -1408,7 +1412,7 @@ BinaryExpressionControlFlowReplacer = BinaryExpressionControlFlowReplacer_1 = __ exports.BinaryExpressionControlFlowReplacer = BinaryExpressionControlFlowReplacer; /***/ }, -/* 25 */ +/* 26 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -1456,11 +1460,10 @@ var NumberLiteralReplacer = function (_AbstractReplacer_1$A) { _createClass(NumberLiteralReplacer, [{ key: "replace", value: function replace(nodeValue) { - var prefix = '0x'; if (!Utils_1.Utils.isInteger(nodeValue)) { return String(nodeValue); } - return "" + prefix + Utils_1.Utils.decToHex(nodeValue); + return "" + Utils_1.Utils.hexadecimalPrefix + Utils_1.Utils.decToHex(nodeValue); } }]); @@ -1470,7 +1473,7 @@ NumberLiteralReplacer = __decorate([inversify_1.injectable(), __param(0, inversi exports.NumberLiteralReplacer = NumberLiteralReplacer; /***/ }, -/* 26 */ +/* 27 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -1499,7 +1502,7 @@ exports.DEFAULT_PRESET = Object.freeze({ }); /***/ }, -/* 27 */ +/* 28 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -1571,25 +1574,25 @@ MapStorage = __decorate([inversify_1.injectable(), __metadata('design:paramtypes exports.MapStorage = MapStorage; /***/ }, -/* 28 */ +/* 29 */ /***/ function(module, exports) { module.exports = require("chance"); /***/ }, -/* 29 */ +/* 30 */ /***/ function(module, exports) { module.exports = require("esprima"); /***/ }, -/* 30 */ +/* 31 */ /***/ function(module, exports) { module.exports = require("path"); /***/ }, -/* 31 */ +/* 32 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -1619,17 +1622,15 @@ var __param = undefined && undefined.__param || function (paramIndex, decorator) }; var inversify_1 = __webpack_require__(1); var ServiceIdentifiers_1 = __webpack_require__(2); -var esprima = __webpack_require__(29); +var esprima = __webpack_require__(30); var escodegen = __webpack_require__(14); -var chance_1 = __webpack_require__(28); -var ObfuscationResult_1 = __webpack_require__(21); -var SourceMapCorrector_1 = __webpack_require__(33); var Utils_1 = __webpack_require__(0); var JavaScriptObfuscatorInternal_1 = function () { - function JavaScriptObfuscatorInternal(obfuscator, customNodesStorage, options) { + function JavaScriptObfuscatorInternal(obfuscator, sourceMapCorrector, customNodesStorage, options) { _classCallCheck(this, JavaScriptObfuscatorInternal); this.obfuscator = obfuscator; + this.sourceMapCorrector = sourceMapCorrector; this.customNodesStorage = customNodesStorage; this.options = options; } @@ -1652,13 +1653,13 @@ var JavaScriptObfuscatorInternal_1 = function () { }, { key: "getObfuscationResult", value: function getObfuscationResult(generatorOutput) { - return new SourceMapCorrector_1.SourceMapCorrector(new ObfuscationResult_1.ObfuscationResult(generatorOutput.code, generatorOutput.map), this.options.sourceMapBaseUrl + this.options.sourceMapFileName, this.options.sourceMapMode).correct(); + return this.sourceMapCorrector.correct(generatorOutput.code, generatorOutput.map); } }, { key: "obfuscate", value: function obfuscate(sourceCode) { if (this.options.seed !== 0) { - Utils_1.Utils.setRandomGenerator(new chance_1.Chance(this.options.seed)); + Utils_1.Utils.setRandomGeneratorSeed(this.options.seed); } var astTree = esprima.parse(sourceCode, JavaScriptObfuscatorInternal_1.esprimaParams); var obfuscatedAstTree = this.obfuscator.obfuscateAstTree(astTree, this.customNodesStorage); @@ -1677,11 +1678,52 @@ JavaScriptObfuscatorInternal.escodegenParams = { JavaScriptObfuscatorInternal.esprimaParams = { loc: true }; -JavaScriptObfuscatorInternal = JavaScriptObfuscatorInternal_1 = __decorate([inversify_1.injectable(), __param(0, inversify_1.inject(ServiceIdentifiers_1.ServiceIdentifiers.IObfuscator)), __param(1, inversify_1.inject(ServiceIdentifiers_1.ServiceIdentifiers['IStorage'])), __param(2, inversify_1.inject(ServiceIdentifiers_1.ServiceIdentifiers.IOptions)), __metadata('design:paramtypes', [Object, Object, Object])], JavaScriptObfuscatorInternal); +JavaScriptObfuscatorInternal = JavaScriptObfuscatorInternal_1 = __decorate([inversify_1.injectable(), __param(0, inversify_1.inject(ServiceIdentifiers_1.ServiceIdentifiers.IObfuscator)), __param(1, inversify_1.inject(ServiceIdentifiers_1.ServiceIdentifiers.ISourceMapCorrector)), __param(2, inversify_1.inject(ServiceIdentifiers_1.ServiceIdentifiers['IStorage'])), __param(3, inversify_1.inject(ServiceIdentifiers_1.ServiceIdentifiers.IOptions)), __metadata('design:paramtypes', [Object, Object, Object, Object])], JavaScriptObfuscatorInternal); exports.JavaScriptObfuscatorInternal = JavaScriptObfuscatorInternal; /***/ }, -/* 32 */ +/* 33 */ +/***/ function(module, exports) { + +"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 ObfuscationResult = function () { + function ObfuscationResult(obfuscatedCode, sourceMap) { + _classCallCheck(this, ObfuscationResult); + + this.obfuscatedCode = obfuscatedCode; + this.sourceMap = sourceMap; + } + + _createClass(ObfuscationResult, [{ + key: "getObfuscatedCode", + value: function getObfuscatedCode() { + return this.obfuscatedCode; + } + }, { + key: "getSourceMap", + value: function getSourceMap() { + return this.sourceMap; + } + }, { + key: "toString", + value: function toString() { + return this.obfuscatedCode; + } + }]); + + return ObfuscationResult; +}(); + +exports.ObfuscationResult = ObfuscationResult; + +/***/ }, +/* 34 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -1714,10 +1756,10 @@ var __param = undefined && undefined.__param || function (paramIndex, decorator) var inversify_1 = __webpack_require__(1); var ServiceIdentifiers_1 = __webpack_require__(2); var estraverse = __webpack_require__(6); -var NodeTransformers_1 = __webpack_require__(23); +var NodeTransformers_1 = __webpack_require__(24); var NodeType_1 = __webpack_require__(9); var ObfuscationEvents_1 = __webpack_require__(3); -var VisitorDirection_1 = __webpack_require__(57); +var VisitorDirection_1 = __webpack_require__(60); var Node_1 = __webpack_require__(4); var NodeUtils_1 = __webpack_require__(10); var Obfuscator_1 = function () { @@ -1772,7 +1814,7 @@ Obfuscator = Obfuscator_1 = __decorate([inversify_1.injectable(), __param(0, inv exports.Obfuscator = Obfuscator; /***/ }, -/* 33 */ +/* 35 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -1780,57 +1822,74 @@ exports.Obfuscator = Obfuscator; 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; }; })(); +var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; + function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +var __decorate = undefined && undefined.__decorate || function (decorators, target, key, desc) { + var c = arguments.length, + r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, + d; + if ((typeof Reflect === "undefined" ? "undefined" : _typeof(Reflect)) === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) { + if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + }return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __metadata = undefined && undefined.__metadata || function (k, v) { + if ((typeof Reflect === "undefined" ? "undefined" : _typeof(Reflect)) === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); +}; +var __param = undefined && undefined.__param || function (paramIndex, decorator) { + return function (target, key) { + decorator(target, key, paramIndex); + }; +}; +var inversify_1 = __webpack_require__(1); +var ServiceIdentifiers_1 = __webpack_require__(2); var SourceMapMode_1 = __webpack_require__(16); -var ObfuscationResult_1 = __webpack_require__(21); var Utils_1 = __webpack_require__(0); - var SourceMapCorrector = function () { - function SourceMapCorrector(obfuscationResult, sourceMapUrl, sourceMapMode) { + function SourceMapCorrector(obfuscationResultFactory, options) { _classCallCheck(this, SourceMapCorrector); - this.obfuscatedCode = obfuscationResult.getObfuscatedCode(); - this.sourceMap = obfuscationResult.getSourceMap(); - this.sourceMapUrl = sourceMapUrl; - this.sourceMapMode = sourceMapMode; + this.obfuscationResultFactory = obfuscationResultFactory; + this.options = options; } _createClass(SourceMapCorrector, [{ - key: 'correct', - value: function correct() { - return new ObfuscationResult_1.ObfuscationResult(this.correctObfuscatedCode(), this.sourceMap); + key: "correct", + value: function correct(obfuscatedCode, sourceMap) { + return this.obfuscationResultFactory(this.correctObfuscatedCode(obfuscatedCode, sourceMap), sourceMap); } }, { - key: 'correctObfuscatedCode', - value: function correctObfuscatedCode() { - if (!this.sourceMap) { - return this.obfuscatedCode; + key: "correctObfuscatedCode", + value: function correctObfuscatedCode(obfuscatedCode, sourceMap) { + if (!sourceMap) { + return obfuscatedCode; } + var sourceMapUrl = this.options.sourceMapBaseUrl + this.options.sourceMapFileName; var sourceMappingUrl = '//# sourceMappingURL='; - switch (this.sourceMapMode) { + switch (this.options.sourceMapMode) { case SourceMapMode_1.SourceMapMode.Inline: - sourceMappingUrl += 'data:application/json;base64,' + Utils_1.Utils.btoa(this.sourceMap); + sourceMappingUrl += "data:application/json;base64," + Utils_1.Utils.btoa(sourceMap); break; case SourceMapMode_1.SourceMapMode.Separate: default: - if (!this.sourceMapUrl) { - return this.obfuscatedCode; + if (!sourceMapUrl) { + return obfuscatedCode; } - sourceMappingUrl += this.sourceMapUrl; + sourceMappingUrl += sourceMapUrl; break; } - return this.obfuscatedCode + '\n' + sourceMappingUrl; + return obfuscatedCode + "\n" + sourceMappingUrl; } }]); return SourceMapCorrector; }(); - +SourceMapCorrector = __decorate([inversify_1.injectable(), __param(0, inversify_1.inject(ServiceIdentifiers_1.ServiceIdentifiers['Factory'])), __param(1, inversify_1.inject(ServiceIdentifiers_1.ServiceIdentifiers.IOptions)), __metadata('design:paramtypes', [Function, Object])], SourceMapCorrector); exports.SourceMapCorrector = SourceMapCorrector; /***/ }, -/* 34 */ +/* 36 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -1840,9 +1899,9 @@ var _createClass = (function () { function defineProperties(target, props) { for function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } -var fs = __webpack_require__(108); -var mkdirp = __webpack_require__(110); -var path = __webpack_require__(30); +var fs = __webpack_require__(111); +var mkdirp = __webpack_require__(113); +var path = __webpack_require__(31); var Utils_1 = __webpack_require__(0); var CLIUtils = function () { @@ -1922,7 +1981,7 @@ CLIUtils.encoding = 'utf8'; exports.CLIUtils = CLIUtils; /***/ }, -/* 35 */ +/* 37 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -1932,12 +1991,12 @@ var _createClass = (function () { function defineProperties(target, props) { for function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } -var commander = __webpack_require__(106); -var path = __webpack_require__(30); +var commander = __webpack_require__(109); +var path = __webpack_require__(31); var SourceMapMode_1 = __webpack_require__(16); var StringArrayEncoding_1 = __webpack_require__(20); -var DefaultPreset_1 = __webpack_require__(26); -var CLIUtils_1 = __webpack_require__(34); +var DefaultPreset_1 = __webpack_require__(27); +var CLIUtils_1 = __webpack_require__(36); var JavaScriptObfuscator_1 = __webpack_require__(13); var Utils_1 = __webpack_require__(0); @@ -2070,7 +2129,7 @@ var JavaScriptObfuscatorCLI = function () { exports.JavaScriptObfuscatorCLI = JavaScriptObfuscatorCLI; /***/ }, -/* 36 */ +/* 38 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -2082,26 +2141,34 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons var inversify_1 = __webpack_require__(1); var ServiceIdentifiers_1 = __webpack_require__(2); -var NodeControlFlowTransformersModule_1 = __webpack_require__(37); -var NodeObfuscatorsModule_1 = __webpack_require__(38); -var NodeTransformersModule_1 = __webpack_require__(39); -var StackTraceAnalyzerModule_1 = __webpack_require__(114); -var CustomNodesStorage_1 = __webpack_require__(83); -var JavaScriptObfuscatorInternal_1 = __webpack_require__(31); -var ObfuscationEventEmitter_1 = __webpack_require__(59); -var Obfuscator_1 = __webpack_require__(32); -var Options_1 = __webpack_require__(74); +var NodeControlFlowTransformersModule_1 = __webpack_require__(39); +var NodeObfuscatorsModule_1 = __webpack_require__(40); +var NodeTransformersModule_1 = __webpack_require__(41); +var StackTraceAnalyzerModule_1 = __webpack_require__(42); +var CustomNodesStorage_1 = __webpack_require__(86); +var JavaScriptObfuscatorInternal_1 = __webpack_require__(32); +var ObfuscationEventEmitter_1 = __webpack_require__(62); +var ObfuscationResult_1 = __webpack_require__(33); +var Obfuscator_1 = __webpack_require__(34); +var Options_1 = __webpack_require__(77); +var SourceMapCorrector_1 = __webpack_require__(35); var InversifyContainerFacade = function () { function InversifyContainerFacade(options) { _classCallCheck(this, InversifyContainerFacade); this.container = new inversify_1.Container(); - this.container.bind(ServiceIdentifiers_1.ServiceIdentifiers.IJavaScriptObfuscator).to(JavaScriptObfuscatorInternal_1.JavaScriptObfuscatorInternal).inSingletonScope(); this.container.bind(ServiceIdentifiers_1.ServiceIdentifiers.IOptions).toDynamicValue(function () { return new Options_1.Options(options); }).inSingletonScope(); + this.container.bind(ServiceIdentifiers_1.ServiceIdentifiers.IJavaScriptObfuscator).to(JavaScriptObfuscatorInternal_1.JavaScriptObfuscatorInternal).inSingletonScope(); this.container.bind(ServiceIdentifiers_1.ServiceIdentifiers.IObfuscator).to(Obfuscator_1.Obfuscator).inSingletonScope(); + this.container.bind(ServiceIdentifiers_1.ServiceIdentifiers['Factory']).toFactory(function () { + return function (obfuscatedCode, sourceMap) { + return new ObfuscationResult_1.ObfuscationResult(obfuscatedCode, sourceMap); + }; + }); + this.container.bind(ServiceIdentifiers_1.ServiceIdentifiers.ISourceMapCorrector).to(SourceMapCorrector_1.SourceMapCorrector).inSingletonScope(); this.container.bind(ServiceIdentifiers_1.ServiceIdentifiers.IObfuscationEventEmitter).to(ObfuscationEventEmitter_1.ObfuscationEventEmitter).inSingletonScope(); this.container.bind(ServiceIdentifiers_1.ServiceIdentifiers['IStorage']).to(CustomNodesStorage_1.CustomNodesStorage).inSingletonScope(); this.container.load(StackTraceAnalyzerModule_1.stackTraceAnalyzerModule); @@ -2115,11 +2182,6 @@ var InversifyContainerFacade = function () { value: function get(serviceIdentifier) { return this.container.get(serviceIdentifier); } - }, { - key: 'getTagged', - value: function getTagged(serviceIdentifier, key, value) { - return this.container.getTagged(serviceIdentifier, key, value); - } }]); return InversifyContainerFacade; @@ -2128,7 +2190,7 @@ var InversifyContainerFacade = function () { exports.InversifyContainerFacade = InversifyContainerFacade; /***/ }, -/* 37 */ +/* 39 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -2136,8 +2198,8 @@ exports.InversifyContainerFacade = InversifyContainerFacade; var inversify_1 = __webpack_require__(1); var ServiceIdentifiers_1 = __webpack_require__(2); -var NodeControlFlowTransformersReplacers_1 = __webpack_require__(58); -var BinaryExpressionControlFlowReplacer_1 = __webpack_require__(24); +var NodeControlFlowTransformersReplacers_1 = __webpack_require__(61); +var BinaryExpressionControlFlowReplacer_1 = __webpack_require__(25); exports.nodeControlFlowTransformersModule = new inversify_1.ContainerModule(function (bind) { var nodeControlFlowTransformersReplacersTag = 'nodeControlFlowTransformersReplacers'; bind(ServiceIdentifiers_1.ServiceIdentifiers.IControlFlowReplacer).to(BinaryExpressionControlFlowReplacer_1.BinaryExpressionControlFlowReplacer).whenTargetTagged(nodeControlFlowTransformersReplacersTag, NodeControlFlowTransformersReplacers_1.NodeControlFlowTransformersReplacers.BinaryExpressionControlFlowReplacer); @@ -2155,7 +2217,7 @@ exports.nodeControlFlowTransformersModule = new inversify_1.ContainerModule(func }); /***/ }, -/* 38 */ +/* 40 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -2164,10 +2226,10 @@ exports.nodeControlFlowTransformersModule = new inversify_1.ContainerModule(func var inversify_1 = __webpack_require__(1); var ServiceIdentifiers_1 = __webpack_require__(2); var NodeObfuscatorsReplacers_1 = __webpack_require__(12); -var BooleanLiteralReplacer_1 = __webpack_require__(71); -var IdentifierReplacer_1 = __webpack_require__(72); -var NumberLiteralReplacer_1 = __webpack_require__(25); -var StringLiteralReplacer_1 = __webpack_require__(73); +var BooleanLiteralReplacer_1 = __webpack_require__(74); +var IdentifierReplacer_1 = __webpack_require__(75); +var NumberLiteralReplacer_1 = __webpack_require__(26); +var StringLiteralReplacer_1 = __webpack_require__(76); exports.nodeObfuscatorsModule = new inversify_1.ContainerModule(function (bind) { var nodeObfuscatorsReplacersTag = 'nodeObfuscatorsReplacers'; bind(ServiceIdentifiers_1.ServiceIdentifiers.IReplacer).to(BooleanLiteralReplacer_1.BooleanLiteralReplacer).whenTargetTagged(nodeObfuscatorsReplacersTag, NodeObfuscatorsReplacers_1.NodeObfuscatorsReplacers.BooleanReplacer); @@ -2188,7 +2250,7 @@ exports.nodeObfuscatorsModule = new inversify_1.ContainerModule(function (bind) }); /***/ }, -/* 39 */ +/* 41 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -2196,17 +2258,17 @@ exports.nodeObfuscatorsModule = new inversify_1.ContainerModule(function (bind) var inversify_1 = __webpack_require__(1); var ServiceIdentifiers_1 = __webpack_require__(2); -var NodeTransformers_1 = __webpack_require__(23); -var FunctionControlFlowTransformer_1 = __webpack_require__(60); -var CatchClauseObfuscator_1 = __webpack_require__(62); -var FunctionDeclarationObfuscator_1 = __webpack_require__(63); -var FunctionObfuscator_1 = __webpack_require__(64); -var LabeledStatementObfuscator_1 = __webpack_require__(65); -var LiteralObfuscator_1 = __webpack_require__(66); -var MemberExpressionObfuscator_1 = __webpack_require__(67); -var MethodDefinitionObfuscator_1 = __webpack_require__(68); -var ObjectExpressionObfuscator_1 = __webpack_require__(69); -var VariableDeclarationObfuscator_1 = __webpack_require__(70); +var NodeTransformers_1 = __webpack_require__(24); +var FunctionControlFlowTransformer_1 = __webpack_require__(63); +var CatchClauseObfuscator_1 = __webpack_require__(65); +var FunctionDeclarationObfuscator_1 = __webpack_require__(66); +var FunctionObfuscator_1 = __webpack_require__(67); +var LabeledStatementObfuscator_1 = __webpack_require__(68); +var LiteralObfuscator_1 = __webpack_require__(69); +var MemberExpressionObfuscator_1 = __webpack_require__(70); +var MethodDefinitionObfuscator_1 = __webpack_require__(71); +var ObjectExpressionObfuscator_1 = __webpack_require__(72); +var VariableDeclarationObfuscator_1 = __webpack_require__(73); exports.nodeTransformersModule = new inversify_1.ContainerModule(function (bind) { var nodeTransformersTag = 'nodeTransformers'; bind(ServiceIdentifiers_1.ServiceIdentifiers.INodeTransformer).to(FunctionControlFlowTransformer_1.FunctionControlFlowTransformer).whenTargetTagged(nodeTransformersTag, NodeTransformers_1.NodeTransformers.FunctionControlFlowTransformer); @@ -2242,7 +2304,40 @@ exports.nodeTransformersModule = new inversify_1.ContainerModule(function (bind) }); /***/ }, -/* 40 */ +/* 42 */ +/***/ function(module, exports, __webpack_require__) { + +"use strict"; +"use strict"; + +var inversify_1 = __webpack_require__(1); +var ServiceIdentifiers_1 = __webpack_require__(2); +var FunctionDeclarationCalleeDataExtractor_1 = __webpack_require__(81); +var FunctionExpressionCalleeDataExtractor_1 = __webpack_require__(82); +var ObjectExpressionCalleeDataExtractor_1 = __webpack_require__(83); +var StackTraceAnalyzer_1 = __webpack_require__(80); +var CalleeDataExtractors_1 = __webpack_require__(23); +exports.stackTraceAnalyzerModule = new inversify_1.ContainerModule(function (bind) { + var calleeDataExtractorsTag = 'calleeDataExtractors'; + bind(ServiceIdentifiers_1.ServiceIdentifiers.IStackTraceAnalyzer).to(StackTraceAnalyzer_1.StackTraceAnalyzer).inSingletonScope(); + bind(ServiceIdentifiers_1.ServiceIdentifiers.ICalleeDataExtractor).to(FunctionDeclarationCalleeDataExtractor_1.FunctionDeclarationCalleeDataExtractor).whenTargetTagged(calleeDataExtractorsTag, CalleeDataExtractors_1.CalleeDataExtractors.FunctionDeclarationCalleeDataExtractor); + bind(ServiceIdentifiers_1.ServiceIdentifiers.ICalleeDataExtractor).to(FunctionExpressionCalleeDataExtractor_1.FunctionExpressionCalleeDataExtractor).whenTargetTagged(calleeDataExtractorsTag, CalleeDataExtractors_1.CalleeDataExtractors.FunctionExpressionCalleeDataExtractor); + bind(ServiceIdentifiers_1.ServiceIdentifiers.ICalleeDataExtractor).to(ObjectExpressionCalleeDataExtractor_1.ObjectExpressionCalleeDataExtractor).whenTargetTagged(calleeDataExtractorsTag, CalleeDataExtractors_1.CalleeDataExtractors.ObjectExpressionCalleeDataExtractor); + bind(ServiceIdentifiers_1.ServiceIdentifiers['Factory']).toFactory(function (context) { + var cache = new Map(); + return function (calleeDataExtractorName) { + if (cache.has(calleeDataExtractorName)) { + return cache.get(calleeDataExtractorName); + } + var calleeDataExtractor = context.container.getTagged(ServiceIdentifiers_1.ServiceIdentifiers.ICalleeDataExtractor, calleeDataExtractorsTag, calleeDataExtractorName); + cache.set(calleeDataExtractorName, calleeDataExtractor); + return calleeDataExtractor; + }; + }); +}); + +/***/ }, +/* 43 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -2258,7 +2353,7 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function" var format = __webpack_require__(8); var ObfuscationEvents_1 = __webpack_require__(3); -var ConsoleOutputDisableExpressionTemplate_1 = __webpack_require__(88); +var ConsoleOutputDisableExpressionTemplate_1 = __webpack_require__(91); var AbstractCustomNode_1 = __webpack_require__(7); var NodeAppender_1 = __webpack_require__(5); var Utils_1 = __webpack_require__(0); @@ -2299,7 +2394,7 @@ var ConsoleOutputDisableExpressionNode = function (_AbstractCustomNode_) { exports.ConsoleOutputDisableExpressionNode = ConsoleOutputDisableExpressionNode; /***/ }, -/* 41 */ +/* 44 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -2313,7 +2408,7 @@ 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__(40); +var ConsoleOutputDisableExpressionNode_1 = __webpack_require__(43); var NodeCallsControllerFunctionNode_1 = __webpack_require__(19); var AbstractCustomNodesFactory_1 = __webpack_require__(15); var NodeAppender_1 = __webpack_require__(5); @@ -2346,7 +2441,7 @@ var ConsoleOutputCustomNodesFactory = function (_AbstractCustomNodesF) { exports.ConsoleOutputCustomNodesFactory = ConsoleOutputCustomNodesFactory; /***/ }, -/* 42 */ +/* 45 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -2362,7 +2457,7 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function" var format = __webpack_require__(8); var ObfuscationEvents_1 = __webpack_require__(3); -var BinaryExpressionFunctionTemplate_1 = __webpack_require__(89); +var BinaryExpressionFunctionTemplate_1 = __webpack_require__(92); var AbstractCustomNode_1 = __webpack_require__(7); var Utils_1 = __webpack_require__(0); @@ -2398,7 +2493,7 @@ var BinaryExpressionFunctionNode = function (_AbstractCustomNode_) { exports.BinaryExpressionFunctionNode = BinaryExpressionFunctionNode; /***/ }, -/* 43 */ +/* 46 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -2414,7 +2509,7 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function" var format = __webpack_require__(8); var ObfuscationEvents_1 = __webpack_require__(3); -var ControlFlowStorageCallTemplate_1 = __webpack_require__(90); +var ControlFlowStorageCallTemplate_1 = __webpack_require__(93); var AbstractCustomNode_1 = __webpack_require__(7); var NodeAppender_1 = __webpack_require__(5); @@ -2457,7 +2552,7 @@ var ControlFlowStorageCallNode = function (_AbstractCustomNode_) { exports.ControlFlowStorageCallNode = ControlFlowStorageCallNode; /***/ }, -/* 44 */ +/* 47 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -2473,7 +2568,7 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function" var format = __webpack_require__(8); var ObfuscationEvents_1 = __webpack_require__(3); -var ControlFlowStorageTemplate_1 = __webpack_require__(91); +var ControlFlowStorageTemplate_1 = __webpack_require__(94); var AbstractCustomNode_1 = __webpack_require__(7); var NodeAppender_1 = __webpack_require__(5); @@ -2512,7 +2607,7 @@ var ControlFlowStorageNode = function (_AbstractCustomNode_) { exports.ControlFlowStorageNode = ControlFlowStorageNode; /***/ }, -/* 45 */ +/* 48 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -2528,7 +2623,7 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function" var format = __webpack_require__(8); var ObfuscationEvents_1 = __webpack_require__(3); -var DebufProtectionFunctionCallTemplate_1 = __webpack_require__(92); +var DebufProtectionFunctionCallTemplate_1 = __webpack_require__(95); var AbstractCustomNode_1 = __webpack_require__(7); var NodeAppender_1 = __webpack_require__(5); @@ -2565,7 +2660,7 @@ var DebugProtectionFunctionCallNode = function (_AbstractCustomNode_) { exports.DebugProtectionFunctionCallNode = DebugProtectionFunctionCallNode; /***/ }, -/* 46 */ +/* 49 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -2581,7 +2676,7 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function" var format = __webpack_require__(8); var ObfuscationEvents_1 = __webpack_require__(3); -var DebugProtectionFunctionIntervalTemplate_1 = __webpack_require__(93); +var DebugProtectionFunctionIntervalTemplate_1 = __webpack_require__(96); var AbstractCustomNode_1 = __webpack_require__(7); var NodeAppender_1 = __webpack_require__(5); @@ -2618,7 +2713,7 @@ var DebugProtectionFunctionIntervalNode = function (_AbstractCustomNode_) { exports.DebugProtectionFunctionIntervalNode = DebugProtectionFunctionIntervalNode; /***/ }, -/* 47 */ +/* 50 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -2634,7 +2729,7 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function" var format = __webpack_require__(8); var ObfuscationEvents_1 = __webpack_require__(3); -var DebugProtectionFunctionTemplate_1 = __webpack_require__(94); +var DebugProtectionFunctionTemplate_1 = __webpack_require__(97); var AbstractCustomNode_1 = __webpack_require__(7); var NodeAppender_1 = __webpack_require__(5); var Utils_1 = __webpack_require__(0); @@ -2674,7 +2769,7 @@ var DebugProtectionFunctionNode = function (_AbstractCustomNode_) { exports.DebugProtectionFunctionNode = DebugProtectionFunctionNode; /***/ }, -/* 48 */ +/* 51 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -2688,9 +2783,9 @@ 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 DebugProtectionFunctionCallNode_1 = __webpack_require__(45); -var DebugProtectionFunctionIntervalNode_1 = __webpack_require__(46); -var DebugProtectionFunctionNode_1 = __webpack_require__(47); +var DebugProtectionFunctionCallNode_1 = __webpack_require__(48); +var DebugProtectionFunctionIntervalNode_1 = __webpack_require__(49); +var DebugProtectionFunctionNode_1 = __webpack_require__(50); var AbstractCustomNodesFactory_1 = __webpack_require__(15); var Utils_1 = __webpack_require__(0); @@ -2724,7 +2819,7 @@ var DebugProtectionCustomNodesFactory = function (_AbstractCustomNodesF) { exports.DebugProtectionCustomNodesFactory = DebugProtectionCustomNodesFactory; /***/ }, -/* 49 */ +/* 52 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -2742,7 +2837,7 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function" var format = __webpack_require__(8); var ObfuscationEvents_1 = __webpack_require__(3); -var DomainLockNodeTemplate_1 = __webpack_require__(95); +var DomainLockNodeTemplate_1 = __webpack_require__(98); var AbstractCustomNode_1 = __webpack_require__(7); var NodeAppender_1 = __webpack_require__(5); var Utils_1 = __webpack_require__(0); @@ -2790,7 +2885,7 @@ var DomainLockNode = function (_AbstractCustomNode_) { exports.DomainLockNode = DomainLockNode; /***/ }, -/* 50 */ +/* 53 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -2804,7 +2899,7 @@ 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 DomainLockNode_1 = __webpack_require__(49); +var DomainLockNode_1 = __webpack_require__(52); var NodeCallsControllerFunctionNode_1 = __webpack_require__(19); var AbstractCustomNodesFactory_1 = __webpack_require__(15); var NodeAppender_1 = __webpack_require__(5); @@ -2837,7 +2932,7 @@ var DomainLockCustomNodesFactory = function (_AbstractCustomNodesF) { exports.DomainLockCustomNodesFactory = DomainLockCustomNodesFactory; /***/ }, -/* 51 */ +/* 54 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -2854,7 +2949,7 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function" var format = __webpack_require__(8); var ObfuscationEvents_1 = __webpack_require__(3); var NoCustomNodesPreset_1 = __webpack_require__(18); -var SelfDefendingTemplate_1 = __webpack_require__(96); +var SelfDefendingTemplate_1 = __webpack_require__(99); var AbstractCustomNode_1 = __webpack_require__(7); var NodeAppender_1 = __webpack_require__(5); var JavaScriptObfuscator_1 = __webpack_require__(13); @@ -2898,7 +2993,7 @@ var SelfDefendingUnicodeNode = function (_AbstractCustomNode_) { exports.SelfDefendingUnicodeNode = SelfDefendingUnicodeNode; /***/ }, -/* 52 */ +/* 55 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -2914,7 +3009,7 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function" var ObfuscationEvents_1 = __webpack_require__(3); var NodeCallsControllerFunctionNode_1 = __webpack_require__(19); -var SelfDefendingUnicodeNode_1 = __webpack_require__(51); +var SelfDefendingUnicodeNode_1 = __webpack_require__(54); var AbstractCustomNodesFactory_1 = __webpack_require__(15); var NodeAppender_1 = __webpack_require__(5); var Utils_1 = __webpack_require__(0); @@ -2949,7 +3044,7 @@ var SelfDefendingCustomNodesFactory = function (_AbstractCustomNodesF) { exports.SelfDefendingCustomNodesFactory = SelfDefendingCustomNodesFactory; /***/ }, -/* 53 */ +/* 56 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -2969,12 +3064,12 @@ var format = __webpack_require__(8); var ObfuscationEvents_1 = __webpack_require__(3); var StringArrayEncoding_1 = __webpack_require__(20); var NoCustomNodesPreset_1 = __webpack_require__(18); -var AtobTemplate_1 = __webpack_require__(85); -var Rc4Template_1 = __webpack_require__(86); -var SelfDefendingTemplate_1 = __webpack_require__(97); -var StringArrayBase64DecodeNodeTemplate_1 = __webpack_require__(98); -var StringArrayCallsWrapperTemplate_1 = __webpack_require__(99); -var StringArrayRC4DecodeNodeTemplate_1 = __webpack_require__(100); +var AtobTemplate_1 = __webpack_require__(88); +var Rc4Template_1 = __webpack_require__(89); +var SelfDefendingTemplate_1 = __webpack_require__(100); +var StringArrayBase64DecodeNodeTemplate_1 = __webpack_require__(101); +var StringArrayCallsWrapperTemplate_1 = __webpack_require__(102); +var StringArrayRC4DecodeNodeTemplate_1 = __webpack_require__(103); var AbstractCustomNode_1 = __webpack_require__(7); var JavaScriptObfuscator_1 = __webpack_require__(13); var NodeAppender_1 = __webpack_require__(5); @@ -3062,7 +3157,7 @@ var StringArrayCallsWrapper = function (_AbstractCustomNode_) { exports.StringArrayCallsWrapper = StringArrayCallsWrapper; /***/ }, -/* 54 */ +/* 57 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -3080,7 +3175,7 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function" var format = __webpack_require__(8); var ObfuscationEvents_1 = __webpack_require__(3); -var StringArrayTemplate_1 = __webpack_require__(101); +var StringArrayTemplate_1 = __webpack_require__(104); var AbstractCustomNode_1 = __webpack_require__(7); var NodeAppender_1 = __webpack_require__(5); @@ -3138,7 +3233,7 @@ StringArrayNode.ARRAY_RANDOM_LENGTH = 4; exports.StringArrayNode = StringArrayNode; /***/ }, -/* 55 */ +/* 58 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -3155,8 +3250,8 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function" var format = __webpack_require__(8); var ObfuscationEvents_1 = __webpack_require__(3); var NoCustomNodesPreset_1 = __webpack_require__(18); -var SelfDefendingTemplate_1 = __webpack_require__(102); -var StringArrayRotateFunctionTemplate_1 = __webpack_require__(103); +var SelfDefendingTemplate_1 = __webpack_require__(105); +var StringArrayRotateFunctionTemplate_1 = __webpack_require__(106); var AbstractCustomNode_1 = __webpack_require__(7); var JavaScriptObfuscator_1 = __webpack_require__(13); var NodeAppender_1 = __webpack_require__(5); @@ -3217,7 +3312,7 @@ var StringArrayRotateFunctionNode = function (_AbstractCustomNode_) { exports.StringArrayRotateFunctionNode = StringArrayRotateFunctionNode; /***/ }, -/* 56 */ +/* 59 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -3232,11 +3327,11 @@ 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 ObfuscationEvents_1 = __webpack_require__(3); -var StringArrayCallsWrapper_1 = __webpack_require__(53); -var StringArrayNode_1 = __webpack_require__(54); -var StringArrayRotateFunctionNode_1 = __webpack_require__(55); +var StringArrayCallsWrapper_1 = __webpack_require__(56); +var StringArrayNode_1 = __webpack_require__(57); +var StringArrayRotateFunctionNode_1 = __webpack_require__(58); var AbstractCustomNodesFactory_1 = __webpack_require__(15); -var StringArrayStorage_1 = __webpack_require__(84); +var StringArrayStorage_1 = __webpack_require__(87); var Utils_1 = __webpack_require__(0); var StringArrayCustomNodesFactory = function (_AbstractCustomNodesF) { @@ -3280,7 +3375,7 @@ var StringArrayCustomNodesFactory = function (_AbstractCustomNodesF) { exports.StringArrayCustomNodesFactory = StringArrayCustomNodesFactory; /***/ }, -/* 57 */ +/* 60 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -3293,7 +3388,7 @@ exports.VisitorDirection = Utils_1.Utils.strEnumify({ }); /***/ }, -/* 58 */ +/* 61 */ /***/ function(module, exports) { "use strict"; @@ -3305,7 +3400,7 @@ exports.VisitorDirection = Utils_1.Utils.strEnumify({ var NodeControlFlowTransformersReplacers = exports.NodeControlFlowTransformersReplacers; /***/ }, -/* 59 */ +/* 62 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -3331,7 +3426,7 @@ var __metadata = undefined && undefined.__metadata || function (k, v) { if ((typeof Reflect === "undefined" ? "undefined" : _typeof(Reflect)) === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var inversify_1 = __webpack_require__(1); -var events_1 = __webpack_require__(107); +var events_1 = __webpack_require__(110); inversify_1.decorate(inversify_1.injectable(), events_1.EventEmitter); var ObfuscationEventEmitter = function (_events_1$EventEmitte) { _inherits(ObfuscationEventEmitter, _events_1$EventEmitte); @@ -3348,7 +3443,7 @@ ObfuscationEventEmitter = __decorate([inversify_1.injectable(), __metadata('desi exports.ObfuscationEventEmitter = ObfuscationEventEmitter; /***/ }, -/* 60 */ +/* 63 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -3385,9 +3480,9 @@ var ServiceIdentifiers_1 = __webpack_require__(2); var estraverse = __webpack_require__(6); var NodeType_1 = __webpack_require__(9); var AbstractNodeTransformer_1 = __webpack_require__(11); -var BinaryExpressionControlFlowReplacer_1 = __webpack_require__(24); -var ControlFlowStorage_1 = __webpack_require__(82); -var ControlFlowStorageNode_1 = __webpack_require__(44); +var BinaryExpressionControlFlowReplacer_1 = __webpack_require__(25); +var ControlFlowStorage_1 = __webpack_require__(85); +var ControlFlowStorageNode_1 = __webpack_require__(47); var Node_1 = __webpack_require__(4); var NodeAppender_1 = __webpack_require__(5); var Utils_1 = __webpack_require__(0); @@ -3448,7 +3543,7 @@ FunctionControlFlowTransformer = FunctionControlFlowTransformer_1 = __decorate([ exports.FunctionControlFlowTransformer = FunctionControlFlowTransformer; /***/ }, -/* 61 */ +/* 64 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -3503,7 +3598,7 @@ AbstractControlFlowReplacer = __decorate([inversify_1.injectable(), __param(0, i exports.AbstractControlFlowReplacer = AbstractControlFlowReplacer; /***/ }, -/* 62 */ +/* 65 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -3598,7 +3693,7 @@ CatchClauseObfuscator = __decorate([inversify_1.injectable(), __param(0, inversi exports.CatchClauseObfuscator = CatchClauseObfuscator; /***/ }, -/* 63 */ +/* 66 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -3697,7 +3792,7 @@ FunctionDeclarationObfuscator = __decorate([inversify_1.injectable(), __param(0, exports.FunctionDeclarationObfuscator = FunctionDeclarationObfuscator; /***/ }, -/* 64 */ +/* 67 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -3802,7 +3897,7 @@ FunctionObfuscator = __decorate([inversify_1.injectable(), __param(0, inversify_ exports.FunctionObfuscator = FunctionObfuscator; /***/ }, -/* 65 */ +/* 68 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -3897,7 +3992,7 @@ LabeledStatementObfuscator = __decorate([inversify_1.injectable(), __param(0, in exports.LabeledStatementObfuscator = LabeledStatementObfuscator; /***/ }, -/* 66 */ +/* 69 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -3980,7 +4075,7 @@ LiteralObfuscator = __decorate([inversify_1.injectable(), __param(0, inversify_1 exports.LiteralObfuscator = LiteralObfuscator; /***/ }, -/* 67 */ +/* 70 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -4087,7 +4182,7 @@ MemberExpressionObfuscator = __decorate([inversify_1.injectable(), __param(0, in exports.MemberExpressionObfuscator = MemberExpressionObfuscator; /***/ }, -/* 68 */ +/* 71 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -4169,7 +4264,7 @@ MethodDefinitionObfuscator = MethodDefinitionObfuscator_1 = __decorate([inversif exports.MethodDefinitionObfuscator = MethodDefinitionObfuscator; /***/ }, -/* 69 */ +/* 72 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -4274,7 +4369,7 @@ ObjectExpressionObfuscator = __decorate([inversify_1.injectable(), __param(0, in exports.ObjectExpressionObfuscator = ObjectExpressionObfuscator; /***/ }, -/* 70 */ +/* 73 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -4376,7 +4471,7 @@ VariableDeclarationObfuscator = __decorate([inversify_1.injectable(), __param(0, exports.VariableDeclarationObfuscator = VariableDeclarationObfuscator; /***/ }, -/* 71 */ +/* 74 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -4434,7 +4529,7 @@ BooleanLiteralReplacer = __decorate([inversify_1.injectable(), __param(0, invers exports.BooleanLiteralReplacer = BooleanLiteralReplacer; /***/ }, -/* 72 */ +/* 75 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -4521,7 +4616,7 @@ IdentifierReplacer = __decorate([inversify_1.injectable(), __param(0, inversify_ exports.IdentifierReplacer = IdentifierReplacer; /***/ }, -/* 73 */ +/* 76 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -4557,7 +4652,6 @@ var inversify_1 = __webpack_require__(1); var ServiceIdentifiers_1 = __webpack_require__(2); var StringArrayEncoding_1 = __webpack_require__(20); var AbstractReplacer_1 = __webpack_require__(17); -var NumberLiteralReplacer_1 = __webpack_require__(25); var Utils_1 = __webpack_require__(0); var StringLiteralReplacer_1 = function (_AbstractReplacer_1$A) { _inherits(StringLiteralReplacer, _AbstractReplacer_1$A); @@ -4604,7 +4698,7 @@ var StringLiteralReplacer_1 = function (_AbstractReplacer_1$A) { stringArray.set(null, value); } var stringArrayCallsWrapper = this.customNodesStorage.get('stringArrayCallsWrapper'); - var hexadecimalIndex = new NumberLiteralReplacer_1.NumberLiteralReplacer(this.customNodesStorage, this.options).replace(indexOfValue); + var hexadecimalIndex = "" + Utils_1.Utils.hexadecimalPrefix + Utils_1.Utils.decToHex(indexOfValue); if (this.options.stringArrayEncoding === StringArrayEncoding_1.StringArrayEncoding.rc4) { return stringArrayCallsWrapper.getNodeIdentifier() + "('" + hexadecimalIndex + "', '" + Utils_1.Utils.stringToUnicodeEscapeSequence(rc4Key) + "')"; } @@ -4623,7 +4717,7 @@ StringLiteralReplacer = StringLiteralReplacer_1 = __decorate([inversify_1.inject exports.StringLiteralReplacer = StringLiteralReplacer; /***/ }, -/* 74 */ +/* 77 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -4645,10 +4739,10 @@ var __metadata = undefined && undefined.__metadata || function (k, v) { if ((typeof Reflect === "undefined" ? "undefined" : _typeof(Reflect)) === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var inversify_1 = __webpack_require__(1); -var class_validator_1 = __webpack_require__(105); -var DefaultPreset_1 = __webpack_require__(26); -var OptionsNormalizer_1 = __webpack_require__(75); -var ValidationErrorsFormatter_1 = __webpack_require__(76); +var class_validator_1 = __webpack_require__(108); +var DefaultPreset_1 = __webpack_require__(27); +var OptionsNormalizer_1 = __webpack_require__(78); +var ValidationErrorsFormatter_1 = __webpack_require__(79); var Options_1 = function Options(inputOptions) { _classCallCheck(this, Options); @@ -4696,7 +4790,7 @@ Options = Options_1 = __decorate([inversify_1.injectable(), __metadata('design:p exports.Options = Options; /***/ }, -/* 75 */ +/* 78 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -4863,7 +4957,7 @@ OptionsNormalizer.normalizerRules = [OptionsNormalizer.domainLockRule, OptionsNo exports.OptionsNormalizer = OptionsNormalizer; /***/ }, -/* 76 */ +/* 79 */ /***/ function(module, exports) { "use strict"; @@ -4930,7 +5024,7 @@ var ValidationErrorsFormatter = function () { exports.ValidationErrorsFormatter = ValidationErrorsFormatter; /***/ }, -/* 77 */ +/* 80 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -4961,7 +5055,7 @@ var __param = undefined && undefined.__param || function (paramIndex, decorator) var inversify_1 = __webpack_require__(1); var ServiceIdentifiers_1 = __webpack_require__(2); var estraverse = __webpack_require__(6); -var CalleeDataExtractors_1 = __webpack_require__(115); +var CalleeDataExtractors_1 = __webpack_require__(23); var Node_1 = __webpack_require__(4); var NodeUtils_1 = __webpack_require__(10); var StackTraceAnalyzer_1 = function () { @@ -4983,37 +5077,45 @@ var StackTraceAnalyzer_1 = function () { var limitIndex = StackTraceAnalyzer_1.getLimitIndex(blockScopeBody.length); var stackTraceData = []; + var blockScopeBodyLength = blockScopeBody.length; - var _loop = function _loop(index, blockScopeBodyLength) { - var rootNode = blockScopeBody[index]; + var _loop = function _loop(index) { if (index > limitIndex) { return "break"; } - estraverse.traverse(rootNode, { + var blockScopeBodyNode = blockScopeBody[index]; + estraverse.traverse(blockScopeBodyNode, { enter: function enter(node) { - if (!Node_1.Node.isCallExpressionNode(node) || rootNode.parentNode !== NodeUtils_1.NodeUtils.getBlockScopeOfNode(node)) { + if (!Node_1.Node.isCallExpressionNode(node) || blockScopeBodyNode.parentNode !== NodeUtils_1.NodeUtils.getBlockScopeOfNode(node)) { return; } - StackTraceAnalyzer_1.calleeDataExtractorsList.forEach(function (calleeDataExtractorName) { - var calleeData = _this.calleeDataExtractorsFactory(calleeDataExtractorName).extract(blockScopeBody, node.callee); - if (!calleeData) { - return; - } - stackTraceData.push(Object.assign({}, calleeData, { - stackTrace: _this.analyzeRecursive(calleeData.callee.body) - })); - }); + _this.analyzeCallExpressionNode(stackTraceData, blockScopeBody, node); } }); }; - for (var index = 0, blockScopeBodyLength = blockScopeBody.length; index < blockScopeBodyLength; index++) { - var _ret = _loop(index, blockScopeBodyLength); + for (var index = 0; index < blockScopeBodyLength; index++) { + var _ret = _loop(index); if (_ret === "break") break; } return stackTraceData; } + }, { + key: "analyzeCallExpressionNode", + value: function analyzeCallExpressionNode(stackTraceData, blockScopeBody, callExpressionNode) { + var _this2 = this; + + StackTraceAnalyzer_1.calleeDataExtractorsList.forEach(function (calleeDataExtractorName) { + var calleeData = _this2.calleeDataExtractorsFactory(calleeDataExtractorName).extract(blockScopeBody, callExpressionNode.callee); + if (!calleeData) { + return; + } + stackTraceData.push(Object.assign({}, calleeData, { + stackTrace: _this2.analyzeRecursive(calleeData.callee.body) + })); + }); + } }], [{ key: "getLimitIndex", value: function getLimitIndex(blockScopeBodyLength) { @@ -5040,7 +5142,7 @@ StackTraceAnalyzer = StackTraceAnalyzer_1 = __decorate([inversify_1.injectable() exports.StackTraceAnalyzer = StackTraceAnalyzer; /***/ }, -/* 78 */ +/* 81 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -5069,7 +5171,7 @@ var __metadata = undefined && undefined.__metadata || function (k, v) { }; var inversify_1 = __webpack_require__(1); var estraverse = __webpack_require__(6); -var AbstractCalleeDataExtractor_1 = __webpack_require__(116); +var AbstractCalleeDataExtractor_1 = __webpack_require__(21); var Node_1 = __webpack_require__(4); var NodeUtils_1 = __webpack_require__(10); var FunctionDeclarationCalleeDataExtractor = function (_AbstractCalleeDataEx) { @@ -5118,7 +5220,7 @@ FunctionDeclarationCalleeDataExtractor = __decorate([inversify_1.injectable(), _ exports.FunctionDeclarationCalleeDataExtractor = FunctionDeclarationCalleeDataExtractor; /***/ }, -/* 79 */ +/* 82 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -5147,7 +5249,7 @@ var __metadata = undefined && undefined.__metadata || function (k, v) { }; var inversify_1 = __webpack_require__(1); var estraverse = __webpack_require__(6); -var AbstractCalleeDataExtractor_1 = __webpack_require__(116); +var AbstractCalleeDataExtractor_1 = __webpack_require__(21); var Node_1 = __webpack_require__(4); var NodeUtils_1 = __webpack_require__(10); var FunctionExpressionCalleeDataExtractor = function (_AbstractCalleeDataEx) { @@ -5199,7 +5301,7 @@ FunctionExpressionCalleeDataExtractor = __decorate([inversify_1.injectable(), __ exports.FunctionExpressionCalleeDataExtractor = FunctionExpressionCalleeDataExtractor; /***/ }, -/* 80 */ +/* 83 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -5230,7 +5332,7 @@ var inversify_1 = __webpack_require__(1); var estraverse = __webpack_require__(6); var Node_1 = __webpack_require__(4); var NodeUtils_1 = __webpack_require__(10); -var AbstractCalleeDataExtractor_1 = __webpack_require__(116); +var AbstractCalleeDataExtractor_1 = __webpack_require__(21); var ObjectExpressionCalleeDataExtractor = function (_AbstractCalleeDataEx) { _inherits(ObjectExpressionCalleeDataExtractor, _AbstractCalleeDataEx); @@ -5350,7 +5452,7 @@ ObjectExpressionCalleeDataExtractor = __decorate([inversify_1.injectable(), __me exports.ObjectExpressionCalleeDataExtractor = ObjectExpressionCalleeDataExtractor; /***/ }, -/* 81 */ +/* 84 */ /***/ function(module, exports) { "use strict"; @@ -5407,7 +5509,7 @@ var ArrayStorage = function () { exports.ArrayStorage = ArrayStorage; /***/ }, -/* 82 */ +/* 85 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -5423,7 +5525,7 @@ 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 MapStorage_1 = __webpack_require__(27); +var MapStorage_1 = __webpack_require__(28); var ControlFlowStorage = function (_MapStorage_1$MapStor) { _inherits(ControlFlowStorage, _MapStorage_1$MapStor); @@ -5454,7 +5556,7 @@ var ControlFlowStorage = function (_MapStorage_1$MapStor) { exports.ControlFlowStorage = ControlFlowStorage; /***/ }, -/* 83 */ +/* 86 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -5490,12 +5592,12 @@ var __param = undefined && undefined.__param || function (paramIndex, decorator) }; var inversify_1 = __webpack_require__(1); var ServiceIdentifiers_1 = __webpack_require__(2); -var ConsoleOutputCustomNodesFactory_1 = __webpack_require__(41); -var DebugProtectionCustomNodesFactory_1 = __webpack_require__(48); -var DomainLockCustomNodesFactory_1 = __webpack_require__(50); -var MapStorage_1 = __webpack_require__(27); -var SelfDefendingCustomNodesFactory_1 = __webpack_require__(52); -var StringArrayCustomNodesFactory_1 = __webpack_require__(56); +var ConsoleOutputCustomNodesFactory_1 = __webpack_require__(44); +var DebugProtectionCustomNodesFactory_1 = __webpack_require__(51); +var DomainLockCustomNodesFactory_1 = __webpack_require__(53); +var MapStorage_1 = __webpack_require__(28); +var SelfDefendingCustomNodesFactory_1 = __webpack_require__(55); +var StringArrayCustomNodesFactory_1 = __webpack_require__(59); var CustomNodesStorage_1 = function (_MapStorage_1$MapStor) { _inherits(CustomNodesStorage, _MapStorage_1$MapStor); @@ -5533,7 +5635,7 @@ CustomNodesStorage = CustomNodesStorage_1 = __decorate([inversify_1.injectable() exports.CustomNodesStorage = CustomNodesStorage; /***/ }, -/* 84 */ +/* 87 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -5547,7 +5649,7 @@ 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 ArrayStorage_1 = __webpack_require__(81); +var ArrayStorage_1 = __webpack_require__(84); var Utils_1 = __webpack_require__(0); var StringArrayStorage = function (_ArrayStorage_1$Array) { @@ -5579,7 +5681,7 @@ var StringArrayStorage = function (_ArrayStorage_1$Array) { exports.StringArrayStorage = StringArrayStorage; /***/ }, -/* 85 */ +/* 88 */ /***/ function(module, exports) { "use strict"; @@ -5591,7 +5693,7 @@ function AtobTemplate() { exports.AtobTemplate = AtobTemplate; /***/ }, -/* 86 */ +/* 89 */ /***/ function(module, exports) { "use strict"; @@ -5603,7 +5705,7 @@ function Rc4Template() { exports.Rc4Template = Rc4Template; /***/ }, -/* 87 */ +/* 90 */ /***/ function(module, exports) { "use strict"; @@ -5615,7 +5717,7 @@ function SingleNodeCallControllerTemplate() { exports.SingleNodeCallControllerTemplate = SingleNodeCallControllerTemplate; /***/ }, -/* 88 */ +/* 91 */ /***/ function(module, exports) { "use strict"; @@ -5627,7 +5729,7 @@ function ConsoleOutputDisableExpressionTemplate() { exports.ConsoleOutputDisableExpressionTemplate = ConsoleOutputDisableExpressionTemplate; /***/ }, -/* 89 */ +/* 92 */ /***/ function(module, exports) { "use strict"; @@ -5639,7 +5741,7 @@ function BinaryExpressionFunctionTemplate() { exports.BinaryExpressionFunctionTemplate = BinaryExpressionFunctionTemplate; /***/ }, -/* 90 */ +/* 93 */ /***/ function(module, exports) { "use strict"; @@ -5651,7 +5753,7 @@ function ControlFlowStorageCallTemplate() { exports.ControlFlowStorageCallTemplate = ControlFlowStorageCallTemplate; /***/ }, -/* 91 */ +/* 94 */ /***/ function(module, exports) { "use strict"; @@ -5663,7 +5765,7 @@ function ControlFlowStorageTemplate() { exports.ControlFlowStorageTemplate = ControlFlowStorageTemplate; /***/ }, -/* 92 */ +/* 95 */ /***/ function(module, exports) { "use strict"; @@ -5675,7 +5777,7 @@ function DebugProtectionFunctionCallTemplate() { exports.DebugProtectionFunctionCallTemplate = DebugProtectionFunctionCallTemplate; /***/ }, -/* 93 */ +/* 96 */ /***/ function(module, exports) { "use strict"; @@ -5687,7 +5789,7 @@ function DebugProtectionFunctionIntervalTemplate() { exports.DebugProtectionFunctionIntervalTemplate = DebugProtectionFunctionIntervalTemplate; /***/ }, -/* 94 */ +/* 97 */ /***/ function(module, exports) { "use strict"; @@ -5699,7 +5801,7 @@ function DebugProtectionFunctionTemplate() { exports.DebugProtectionFunctionTemplate = DebugProtectionFunctionTemplate; /***/ }, -/* 95 */ +/* 98 */ /***/ function(module, exports) { "use strict"; @@ -5711,7 +5813,7 @@ function DomainLockNodeTemplate() { exports.DomainLockNodeTemplate = DomainLockNodeTemplate; /***/ }, -/* 96 */ +/* 99 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -5724,7 +5826,7 @@ function SelfDefendingTemplate() { exports.SelfDefendingTemplate = SelfDefendingTemplate; /***/ }, -/* 97 */ +/* 100 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -5737,7 +5839,7 @@ function SelfDefendingTemplate() { exports.SelfDefendingTemplate = SelfDefendingTemplate; /***/ }, -/* 98 */ +/* 101 */ /***/ function(module, exports) { "use strict"; @@ -5749,7 +5851,7 @@ function StringArrayBase64DecodeNodeTemplate() { exports.StringArrayBase64DecodeNodeTemplate = StringArrayBase64DecodeNodeTemplate; /***/ }, -/* 99 */ +/* 102 */ /***/ function(module, exports) { "use strict"; @@ -5761,7 +5863,7 @@ function StringArrayCallsWrapperTemplate() { exports.StringArrayCallsWrapperTemplate = StringArrayCallsWrapperTemplate; /***/ }, -/* 100 */ +/* 103 */ /***/ function(module, exports) { "use strict"; @@ -5773,7 +5875,7 @@ function StringArrayRc4DecodeNodeTemplate() { exports.StringArrayRc4DecodeNodeTemplate = StringArrayRc4DecodeNodeTemplate; /***/ }, -/* 101 */ +/* 104 */ /***/ function(module, exports) { "use strict"; @@ -5785,7 +5887,7 @@ function StringArrayTemplate() { exports.StringArrayTemplate = StringArrayTemplate; /***/ }, -/* 102 */ +/* 105 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -5798,7 +5900,7 @@ function SelfDefendingTemplate() { exports.SelfDefendingTemplate = SelfDefendingTemplate; /***/ }, -/* 103 */ +/* 106 */ /***/ function(module, exports) { "use strict"; @@ -5810,56 +5912,56 @@ function StringArrayRotateFunctionTemplate() { exports.StringArrayRotateFunctionTemplate = StringArrayRotateFunctionTemplate; /***/ }, -/* 104 */ +/* 107 */ /***/ function(module, exports) { module.exports = require("babel-polyfill"); /***/ }, -/* 105 */ +/* 108 */ /***/ function(module, exports) { module.exports = require("class-validator"); /***/ }, -/* 106 */ +/* 109 */ /***/ function(module, exports) { module.exports = require("commander"); /***/ }, -/* 107 */ +/* 110 */ /***/ function(module, exports) { module.exports = require("events"); /***/ }, -/* 108 */ +/* 111 */ /***/ function(module, exports) { module.exports = require("fs"); /***/ }, -/* 109 */ +/* 112 */ /***/ function(module, exports) { module.exports = require("is-equal"); /***/ }, -/* 110 */ +/* 113 */ /***/ function(module, exports) { module.exports = require("mkdirp"); /***/ }, -/* 111 */ +/* 114 */ /***/ function(module, exports) { module.exports = require("reflect-metadata"); /***/ }, -/* 112 */, -/* 113 */ +/* 115 */, +/* 116 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -5868,82 +5970,6 @@ module.exports = require("reflect-metadata"); var JavaScriptObfuscator_1 = __webpack_require__(13); module.exports = JavaScriptObfuscator_1.JavaScriptObfuscator; -/***/ }, -/* 114 */ -/***/ function(module, exports, __webpack_require__) { - -"use strict"; -"use strict"; - -var inversify_1 = __webpack_require__(1); -var ServiceIdentifiers_1 = __webpack_require__(2); -var FunctionDeclarationCalleeDataExtractor_1 = __webpack_require__(78); -var FunctionExpressionCalleeDataExtractor_1 = __webpack_require__(79); -var ObjectExpressionCalleeDataExtractor_1 = __webpack_require__(80); -var StackTraceAnalyzer_1 = __webpack_require__(77); -var CalleeDataExtractors_1 = __webpack_require__(115); -exports.stackTraceAnalyzerModule = new inversify_1.ContainerModule(function (bind) { - var calleeDataExtractorsTag = 'calleeDataExtractors'; - bind(ServiceIdentifiers_1.ServiceIdentifiers.IStackTraceAnalyzer).to(StackTraceAnalyzer_1.StackTraceAnalyzer).inSingletonScope(); - bind(ServiceIdentifiers_1.ServiceIdentifiers.ICalleeDataExtractor).to(FunctionDeclarationCalleeDataExtractor_1.FunctionDeclarationCalleeDataExtractor).whenTargetTagged(calleeDataExtractorsTag, CalleeDataExtractors_1.CalleeDataExtractors.FunctionDeclarationCalleeDataExtractor); - bind(ServiceIdentifiers_1.ServiceIdentifiers.ICalleeDataExtractor).to(FunctionExpressionCalleeDataExtractor_1.FunctionExpressionCalleeDataExtractor).whenTargetTagged(calleeDataExtractorsTag, CalleeDataExtractors_1.CalleeDataExtractors.FunctionExpressionCalleeDataExtractor); - bind(ServiceIdentifiers_1.ServiceIdentifiers.ICalleeDataExtractor).to(ObjectExpressionCalleeDataExtractor_1.ObjectExpressionCalleeDataExtractor).whenTargetTagged(calleeDataExtractorsTag, CalleeDataExtractors_1.CalleeDataExtractors.ObjectExpressionCalleeDataExtractor); - bind(ServiceIdentifiers_1.ServiceIdentifiers['Factory']).toFactory(function (context) { - var cache = new Map(); - return function (calleeDataExtractorName) { - if (cache.has(calleeDataExtractorName)) { - return cache.get(calleeDataExtractorName); - } - var calleeDataExtractor = context.container.getTagged(ServiceIdentifiers_1.ServiceIdentifiers.ICalleeDataExtractor, calleeDataExtractorsTag, calleeDataExtractorName); - cache.set(calleeDataExtractorName, calleeDataExtractor); - return calleeDataExtractor; - }; - }); -}); - -/***/ }, -/* 115 */ -/***/ function(module, exports) { - -"use strict"; -"use strict"; - -(function (CalleeDataExtractors) { - CalleeDataExtractors[CalleeDataExtractors["FunctionDeclarationCalleeDataExtractor"] = 0] = "FunctionDeclarationCalleeDataExtractor"; - CalleeDataExtractors[CalleeDataExtractors["FunctionExpressionCalleeDataExtractor"] = 1] = "FunctionExpressionCalleeDataExtractor"; - CalleeDataExtractors[CalleeDataExtractors["ObjectExpressionCalleeDataExtractor"] = 2] = "ObjectExpressionCalleeDataExtractor"; -})(exports.CalleeDataExtractors || (exports.CalleeDataExtractors = {})); -var CalleeDataExtractors = exports.CalleeDataExtractors; - -/***/ }, -/* 116 */ -/***/ function(module, exports, __webpack_require__) { - -"use strict"; -"use strict"; - -var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -var __decorate = undefined && undefined.__decorate || function (decorators, target, key, desc) { - var c = arguments.length, - r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, - d; - if ((typeof Reflect === "undefined" ? "undefined" : _typeof(Reflect)) === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) { - if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; - }return c > 3 && r && Object.defineProperty(target, key, r), r; -}; -var __metadata = undefined && undefined.__metadata || function (k, v) { - if ((typeof Reflect === "undefined" ? "undefined" : _typeof(Reflect)) === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); -}; -var inversify_1 = __webpack_require__(1); -var AbstractCalleeDataExtractor = function AbstractCalleeDataExtractor() { - _classCallCheck(this, AbstractCalleeDataExtractor); -}; -AbstractCalleeDataExtractor = __decorate([inversify_1.injectable(), __metadata('design:paramtypes', [])], AbstractCalleeDataExtractor); -exports.AbstractCalleeDataExtractor = AbstractCalleeDataExtractor; - /***/ } /******/ ]); //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/src/JavaScriptObfuscator.ts b/src/JavaScriptObfuscator.ts index 4c199830..c5c64be0 100644 --- a/src/JavaScriptObfuscator.ts +++ b/src/JavaScriptObfuscator.ts @@ -4,7 +4,7 @@ if (!(global)._babelPolyfill) { require('babel-polyfill'); } -import { IInputOptions } from './interfaces/IInputOptions'; +import { IInputOptions } from './interfaces/options/IInputOptions'; import { IInversifyContainerFacade } from './interfaces/container/IInversifyContainerFacade'; import { IJavaScriptObfuscator } from './interfaces/IJavaScriptObfsucator'; import { IObfuscationResult } from './interfaces/IObfuscationResult'; diff --git a/src/JavaScriptObfuscatorInternal.ts b/src/JavaScriptObfuscatorInternal.ts index c500c26f..19a28d6b 100644 --- a/src/JavaScriptObfuscatorInternal.ts +++ b/src/JavaScriptObfuscatorInternal.ts @@ -5,18 +5,15 @@ import * as esprima from 'esprima'; import * as escodegen from 'escodegen'; import * as ESTree from 'estree'; -import { Chance } from 'chance'; - import { ICustomNode } from './interfaces/custom-nodes/ICustomNode'; import { IJavaScriptObfuscator } from './interfaces/IJavaScriptObfsucator'; import { IObfuscationResult } from './interfaces/IObfuscationResult'; import { IObfuscator } from './interfaces/IObfuscator'; import { IGeneratorOutput } from './interfaces/IGeneratorOutput'; -import { IOptions } from './interfaces/IOptions'; -import { IStorage } from './interfaces/IStorage'; +import { IOptions } from './interfaces/options/IOptions'; +import { ISourceMapCorrector } from './interfaces/ISourceMapCorrector'; +import { IStorage } from './interfaces/storages/IStorage'; -import { ObfuscationResult } from './ObfuscationResult'; -import { SourceMapCorrector } from './SourceMapCorrector'; import { Utils } from './Utils'; @injectable() @@ -51,17 +48,25 @@ export class JavaScriptObfuscatorInternal implements IJavaScriptObfuscator { */ private readonly options: IOptions; + /** + * @type {ISourceMapCorrector} + */ + private readonly sourceMapCorrector: ISourceMapCorrector; + /** * @param obfuscator + * @param sourceMapCorrector * @param customNodesStorage * @param options */ constructor ( @inject(ServiceIdentifiers.IObfuscator) obfuscator: IObfuscator, + @inject(ServiceIdentifiers.ISourceMapCorrector) sourceMapCorrector: ISourceMapCorrector, @inject(ServiceIdentifiers['IStorage']) customNodesStorage: IStorage, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { this.obfuscator = obfuscator; + this.sourceMapCorrector = sourceMapCorrector; this.customNodesStorage = customNodesStorage; this.options = options; } @@ -97,14 +102,10 @@ export class JavaScriptObfuscatorInternal implements IJavaScriptObfuscator { * @returns {IObfuscationResult} */ private getObfuscationResult (generatorOutput: IGeneratorOutput): IObfuscationResult { - return new SourceMapCorrector( - new ObfuscationResult( - generatorOutput.code, - generatorOutput.map - ), - this.options.sourceMapBaseUrl + this.options.sourceMapFileName, - this.options.sourceMapMode - ).correct(); + return this.sourceMapCorrector.correct( + generatorOutput.code, + generatorOutput.map + ); } /** @@ -113,7 +114,7 @@ export class JavaScriptObfuscatorInternal implements IJavaScriptObfuscator { */ public obfuscate (sourceCode: string): IObfuscationResult { if (this.options.seed !== 0) { - Utils.setRandomGenerator(new Chance(this.options.seed)); + Utils.setRandomGeneratorSeed(this.options.seed); } // parse AST tree diff --git a/src/Obfuscator.ts b/src/Obfuscator.ts index f6e3761e..b5f92540 100644 --- a/src/Obfuscator.ts +++ b/src/Obfuscator.ts @@ -4,16 +4,16 @@ import { ServiceIdentifiers } from './container/ServiceIdentifiers'; import * as estraverse from 'estraverse'; import * as ESTree from 'estree'; -import { TNodeTransformersFactory } from './types/TNodeTransformersFactory'; +import { TNodeTransformersFactory } from './types/container/TNodeTransformersFactory'; import { TVisitorDirection } from './types/TVisitorDirection'; import { ICustomNode } from './interfaces/custom-nodes/ICustomNode'; -import { IObfuscationEventEmitter } from './interfaces/IObfuscationEventEmitter'; +import { IObfuscationEventEmitter } from './interfaces/event-emitters/IObfuscationEventEmitter'; import { IObfuscator } from './interfaces/IObfuscator'; -import { IOptions } from './interfaces/IOptions'; -import { INodeTransformer } from './interfaces/INodeTransformer'; +import { IOptions } from './interfaces/options/IOptions'; +import { INodeTransformer } from './interfaces/node-transformers/INodeTransformer'; import { IStackTraceAnalyzer } from './interfaces/stack-trace-analyzer/IStackTraceAnalyzer'; -import { IStorage } from './interfaces/IStorage'; +import { IStorage } from './interfaces/storages/IStorage'; import { NodeTransformers } from './enums/container/NodeTransformers'; import { NodeType } from './enums/NodeType'; diff --git a/src/SourceMapCorrector.ts b/src/SourceMapCorrector.ts index 8c60cd4c..92c407ee 100644 --- a/src/SourceMapCorrector.ts +++ b/src/SourceMapCorrector.ts @@ -1,88 +1,83 @@ -import { IObfuscationResult } from './interfaces/IObfuscationResult'; -import { ISourceMapCorrector } from './interfaces/ISourceMapCorrector'; +import { injectable, inject } from 'inversify'; +import { ServiceIdentifiers } from './container/ServiceIdentifiers'; -import { TSourceMapMode } from './types/TSourceMapMode'; +import { TObfuscationResultFactory } from './types/container/TObfuscationResultFactory'; + +import { IObfuscationResult } from './interfaces/IObfuscationResult'; +import { IOptions } from './interfaces/options/IOptions'; +import { ISourceMapCorrector } from './interfaces/ISourceMapCorrector'; import { SourceMapMode } from './enums/SourceMapMode'; -import { ObfuscationResult } from './ObfuscationResult'; import { Utils } from './Utils'; +@injectable() export class SourceMapCorrector implements ISourceMapCorrector { /** - * @type {string} + * @type {TObfuscationResultFactory} */ - private readonly obfuscatedCode: string; + private readonly obfuscationResultFactory: TObfuscationResultFactory; /** - * @type {string} + * @type {IOptions} */ - private readonly sourceMap: string; + private readonly options: IOptions; /** - * @type {TSourceMapMode} - */ - private readonly sourceMapMode: TSourceMapMode; - - /** - * @type {string} - */ - private readonly sourceMapUrl: string; - - /** - * @param obfuscationResult - * @param sourceMapUrl - * @param sourceMapMode + * @param obfuscationResultFactory + * @param options */ constructor ( - obfuscationResult: IObfuscationResult, - sourceMapUrl: string, - sourceMapMode: TSourceMapMode + @inject(ServiceIdentifiers['Factory']) obfuscationResultFactory: TObfuscationResultFactory, + @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - this.obfuscatedCode = obfuscationResult.getObfuscatedCode(); - this.sourceMap = obfuscationResult.getSourceMap(); - - this.sourceMapUrl = sourceMapUrl; - this.sourceMapMode = sourceMapMode; + this.obfuscationResultFactory = obfuscationResultFactory; + this.options = options; } /** * @returns {ObfuscationResult} + * @param obfuscatedCode + * @param sourceMap */ - public correct (): IObfuscationResult { - return new ObfuscationResult( - this.correctObfuscatedCode(), - this.sourceMap + public correct (obfuscatedCode: string, sourceMap: string): IObfuscationResult { + return this.obfuscationResultFactory( + this.correctObfuscatedCode(obfuscatedCode, sourceMap), + sourceMap ); } /** + * @param obfuscatedCode + * @param sourceMap * @returns {string} */ - private correctObfuscatedCode (): string { - if (!this.sourceMap) { - return this.obfuscatedCode; + private correctObfuscatedCode (obfuscatedCode: string, sourceMap: string): string { + if (!sourceMap) { + return obfuscatedCode; } + const sourceMapUrl: string = this.options.sourceMapBaseUrl + this.options.sourceMapFileName; + let sourceMappingUrl: string = '//# sourceMappingURL='; - switch (this.sourceMapMode) { + switch (this.options.sourceMapMode) { case SourceMapMode.Inline: - sourceMappingUrl += `data:application/json;base64,${Utils.btoa(this.sourceMap)}`; + sourceMappingUrl += `data:application/json;base64,${Utils.btoa(sourceMap)}`; break; case SourceMapMode.Separate: default: - if (!this.sourceMapUrl) { - return this.obfuscatedCode; + if (!sourceMapUrl) { + return obfuscatedCode; } - sourceMappingUrl += this.sourceMapUrl; + sourceMappingUrl += sourceMapUrl; break; } - return `${this.obfuscatedCode}\n${sourceMappingUrl}`; + return `${obfuscatedCode}\n${sourceMappingUrl}`; }; } diff --git a/src/Utils.ts b/src/Utils.ts index 57988d7c..8e56f6d2 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -5,6 +5,11 @@ import { JSFuck } from './enums/JSFuck'; const isEqual = require('is-equal'); export class Utils { + /** + * @type {string} + */ + public static readonly hexadecimalPrefix: string = '0x'; + /** * @type {string} */ @@ -58,7 +63,7 @@ export class Utils { let output: string = ''; string = encodeURIComponent(string).replace(/%([0-9A-F]{2})/g, (match, p1) => { - return String.fromCharCode(parseInt('0x' + p1)); + return String.fromCharCode(parseInt(`${Utils.hexadecimalPrefix}${p1}`)); }); for ( @@ -112,7 +117,7 @@ export class Utils { * @returns {number} */ public static getRandomFloat (min: number, max: number): number { - return Utils.getRandomGenerator().floating({ + return Utils.randomGenerator.floating({ min: min, max: max, fixed: 7 @@ -138,7 +143,7 @@ export class Utils { * @returns {number} */ public static getRandomInteger (min: number, max: number): number { - return Utils.getRandomGenerator().integer({ + return Utils.randomGenerator.integer({ min: min, max: max }); @@ -150,10 +155,9 @@ export class Utils { */ public static getRandomVariableName (length: number = 6): string { const rangeMinInteger: number = 10000, - rangeMaxInteger: number = 99999999, - prefix: string = '_0x'; + rangeMaxInteger: number = 99999999; - return `${prefix}${( + return `_${Utils.hexadecimalPrefix}${( Utils.decToHex( Utils.getRandomInteger(rangeMinInteger, rangeMaxInteger) ) @@ -267,10 +271,10 @@ export class Utils { } /** - * @param randomGenerator + * @param randomGeneratorSeed */ - public static setRandomGenerator (randomGenerator: Chance.Chance | Chance.SeededChance): void { - Utils.randomGenerator = randomGenerator; + public static setRandomGeneratorSeed (randomGeneratorSeed: number): void { + Utils.randomGenerator = new Chance(randomGeneratorSeed); } /** diff --git a/src/cli/JavaScriptObfuscatorCLI.ts b/src/cli/JavaScriptObfuscatorCLI.ts index 126185be..e049c2c7 100644 --- a/src/cli/JavaScriptObfuscatorCLI.ts +++ b/src/cli/JavaScriptObfuscatorCLI.ts @@ -1,9 +1,9 @@ import * as commander from 'commander'; import * as path from 'path'; -import { TStringArrayEncoding } from '../types/TStringArrayEncoding'; +import { TStringArrayEncoding } from '../types/options/TStringArrayEncoding'; -import { IInputOptions } from '../interfaces/IInputOptions'; +import { IInputOptions } from '../interfaces/options/IInputOptions'; import { IObfuscationResult } from '../interfaces/IObfuscationResult'; import { SourceMapMode } from '../enums/SourceMapMode'; diff --git a/src/container/InversifyContainerFacade.ts b/src/container/InversifyContainerFacade.ts index e5a8519b..d81263d7 100644 --- a/src/container/InversifyContainerFacade.ts +++ b/src/container/InversifyContainerFacade.ts @@ -7,19 +7,23 @@ import { nodeTransformersModule } from './modules/node-transformers/NodeTransfor import { stackTraceAnalyzerModule } from './modules/stack-trace-analyzer/StackTraceAnalyzerModule'; import { ICustomNode } from '../interfaces/custom-nodes/ICustomNode'; -import { IInputOptions } from '../interfaces/IInputOptions'; +import { IInputOptions } from '../interfaces/options/IInputOptions'; import { IInversifyContainerFacade } from '../interfaces/container/IInversifyContainerFacade'; import { IJavaScriptObfuscator } from '../interfaces/IJavaScriptObfsucator'; -import { IObfuscationEventEmitter } from '../interfaces/IObfuscationEventEmitter'; +import { IObfuscationEventEmitter } from '../interfaces/event-emitters/IObfuscationEventEmitter'; +import { IObfuscationResult } from '../interfaces/IObfuscationResult'; import { IObfuscator } from '../interfaces/IObfuscator'; -import { IOptions } from '../interfaces/IOptions'; -import { IStorage } from '../interfaces/IStorage'; +import { IOptions } from '../interfaces/options/IOptions'; +import { ISourceMapCorrector } from '../interfaces/ISourceMapCorrector'; +import { IStorage } from '../interfaces/storages/IStorage'; import { CustomNodesStorage } from '../storages/custom-nodes/CustomNodesStorage'; import { JavaScriptObfuscatorInternal } from '../JavaScriptObfuscatorInternal'; import { ObfuscationEventEmitter } from '../event-emitters/ObfuscationEventEmitter'; +import { ObfuscationResult } from '../ObfuscationResult'; import { Obfuscator } from '../Obfuscator'; import { Options } from "../options/Options"; +import { SourceMapCorrector } from '../SourceMapCorrector'; export class InversifyContainerFacade implements IInversifyContainerFacade { /** @@ -33,11 +37,6 @@ export class InversifyContainerFacade implements IInversifyContainerFacade { constructor (options: IInputOptions) { this.container = new Container(); - this.container - .bind(ServiceIdentifiers.IJavaScriptObfuscator) - .to(JavaScriptObfuscatorInternal) - .inSingletonScope(); - this.container .bind(ServiceIdentifiers.IOptions) .toDynamicValue(() => { @@ -45,11 +44,29 @@ export class InversifyContainerFacade implements IInversifyContainerFacade { }) .inSingletonScope(); + this.container + .bind(ServiceIdentifiers.IJavaScriptObfuscator) + .to(JavaScriptObfuscatorInternal) + .inSingletonScope(); + this.container .bind(ServiceIdentifiers.IObfuscator) .to(Obfuscator) .inSingletonScope(); + this.container + .bind(ServiceIdentifiers['Factory']) + .toFactory(() => { + return (obfuscatedCode: string, sourceMap: string) => { + return new ObfuscationResult(obfuscatedCode, sourceMap); + }; + }); + + this.container + .bind(ServiceIdentifiers.ISourceMapCorrector) + .to(SourceMapCorrector) + .inSingletonScope(); + this.container .bind(ServiceIdentifiers.IObfuscationEventEmitter) .to(ObfuscationEventEmitter) @@ -74,14 +91,4 @@ export class InversifyContainerFacade implements IInversifyContainerFacade { public get (serviceIdentifier: interfaces.ServiceIdentifier): T { return this.container.get(serviceIdentifier); } - - /** - * @param serviceIdentifier - * @param key - * @param value - * @returns {T} - */ - public getTagged (serviceIdentifier: interfaces.ServiceIdentifier, key: string, value: any): T { - return this.container.getTagged(serviceIdentifier, key, value); - } } diff --git a/src/container/ServiceIdentifiers.ts b/src/container/ServiceIdentifiers.ts index 47788e72..fc4b0711 100644 --- a/src/container/ServiceIdentifiers.ts +++ b/src/container/ServiceIdentifiers.ts @@ -4,6 +4,7 @@ export const ServiceIdentifiers: IContainerServiceIdentifiers = { 'Factory': Symbol('Factory'), 'Factory': Symbol('Factory'), 'Factory': Symbol('Factory'), + 'Factory': Symbol('Factory'), 'Factory': Symbol('Factory'), ICalleeDataExtractor: Symbol('ICalleeDataExtractor'), IControlFlowReplacer: Symbol('IControlFlowReplacer'), @@ -13,6 +14,7 @@ export const ServiceIdentifiers: IContainerServiceIdentifiers = { IObfuscator: Symbol('IObfuscator'), IOptions: Symbol('IOptions'), IReplacer: Symbol('IReplacer'), + ISourceMapCorrector: Symbol('ISourceMapCorrector'), IStackTraceAnalyzer: Symbol('IStackTraceAnalyzer'), 'IStorage': Symbol('IStorage') }; diff --git a/src/container/modules/node-transformers/NodeControlFlowTransformersModule.ts b/src/container/modules/node-transformers/NodeControlFlowTransformersModule.ts index c6e8de45..64e31ad3 100644 --- a/src/container/modules/node-transformers/NodeControlFlowTransformersModule.ts +++ b/src/container/modules/node-transformers/NodeControlFlowTransformersModule.ts @@ -1,7 +1,7 @@ import { ContainerModule, interfaces } from 'inversify'; import { ServiceIdentifiers } from '../../ServiceIdentifiers'; -import { IControlFlowReplacer } from '../../../interfaces/IControlFlowReplacer'; +import { IControlFlowReplacer } from '../../../interfaces/node-transformers/IControlFlowReplacer'; import { NodeControlFlowTransformersReplacers } from '../../../enums/container/NodeControlFlowTransformersReplacers'; diff --git a/src/container/modules/node-transformers/NodeObfuscatorsModule.ts b/src/container/modules/node-transformers/NodeObfuscatorsModule.ts index 627b21f7..b172af39 100644 --- a/src/container/modules/node-transformers/NodeObfuscatorsModule.ts +++ b/src/container/modules/node-transformers/NodeObfuscatorsModule.ts @@ -1,7 +1,7 @@ import { ContainerModule, interfaces } from 'inversify'; import { ServiceIdentifiers } from '../../ServiceIdentifiers'; -import { IReplacer } from '../../../interfaces/IReplacer'; +import { IReplacer } from '../../../interfaces/node-transformers/IReplacer'; import { NodeObfuscatorsReplacers } from '../../../enums/container/NodeObfuscatorsReplacers'; diff --git a/src/container/modules/node-transformers/NodeTransformersModule.ts b/src/container/modules/node-transformers/NodeTransformersModule.ts index 9a8603c9..508ac492 100644 --- a/src/container/modules/node-transformers/NodeTransformersModule.ts +++ b/src/container/modules/node-transformers/NodeTransformersModule.ts @@ -1,7 +1,7 @@ import { ContainerModule, interfaces } from 'inversify'; import { ServiceIdentifiers } from '../../ServiceIdentifiers'; -import { INodeTransformer } from '../../../interfaces/INodeTransformer'; +import { INodeTransformer } from '../../../interfaces/node-transformers/INodeTransformer'; import { NodeTransformers } from '../../../enums/container/NodeTransformers'; diff --git a/src/custom-nodes/AbstractCustomNode.ts b/src/custom-nodes/AbstractCustomNode.ts index 8c410b04..d1729a31 100644 --- a/src/custom-nodes/AbstractCustomNode.ts +++ b/src/custom-nodes/AbstractCustomNode.ts @@ -1,10 +1,10 @@ import * as ESTree from 'estree'; -import { TObfuscationEvent } from '../types/TObfuscationEvent'; +import { TObfuscationEvent } from '../types/event-emitters/TObfuscationEvent'; import { ICustomNode } from '../interfaces/custom-nodes/ICustomNode'; -import { IOptions } from '../interfaces/IOptions'; -import { TStatement } from '../types/TStatement'; +import { IOptions } from '../interfaces/options/IOptions'; +import { TStatement } from '../types/node/TStatement'; import { NodeUtils } from '../node/NodeUtils'; diff --git a/src/custom-nodes/AbstractCustomNodesFactory.ts b/src/custom-nodes/AbstractCustomNodesFactory.ts index b67735c7..acf83e4b 100644 --- a/src/custom-nodes/AbstractCustomNodesFactory.ts +++ b/src/custom-nodes/AbstractCustomNodesFactory.ts @@ -1,8 +1,8 @@ -import { TObfuscationEvent } from '../types/TObfuscationEvent'; +import { TObfuscationEvent } from '../types/event-emitters/TObfuscationEvent'; import { ICustomNode } from '../interfaces/custom-nodes/ICustomNode'; import { ICustomNodesFactory } from '../interfaces/custom-nodes/ICustomNodesFactory'; -import { IOptions } from '../interfaces/IOptions'; +import { IOptions } from '../interfaces/options/IOptions'; import { IStackTraceData } from '../interfaces/stack-trace-analyzer/IStackTraceData'; import { ObfuscationEvents } from '../enums/ObfuscationEvents'; diff --git a/src/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.ts b/src/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.ts index ebd573ef..9d7081a6 100644 --- a/src/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.ts +++ b/src/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.ts @@ -1,9 +1,9 @@ import * as format from 'string-template'; -import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement'; -import { TObfuscationEvent } from '../../types/TObfuscationEvent'; +import { TNodeWithBlockStatement } from '../../types/node/TNodeWithBlockStatement'; +import { TObfuscationEvent } from '../../types/event-emitters/TObfuscationEvent'; -import { IOptions } from '../../interfaces/IOptions'; +import { IOptions } from '../../interfaces/options/IOptions'; import { IStackTraceData } from '../../interfaces/stack-trace-analyzer/IStackTraceData'; import { ObfuscationEvents } from '../../enums/ObfuscationEvents'; diff --git a/src/custom-nodes/control-flow-replacers-nodes/binary-expression-control-flow-replacer-nodes/BinaryExpressionFunctionNode.ts b/src/custom-nodes/control-flow-replacers-nodes/binary-expression-control-flow-replacer-nodes/BinaryExpressionFunctionNode.ts index be09da71..db08caf4 100644 --- a/src/custom-nodes/control-flow-replacers-nodes/binary-expression-control-flow-replacer-nodes/BinaryExpressionFunctionNode.ts +++ b/src/custom-nodes/control-flow-replacers-nodes/binary-expression-control-flow-replacer-nodes/BinaryExpressionFunctionNode.ts @@ -1,9 +1,9 @@ import * as format from 'string-template'; -import { TNodeWithBlockStatement } from '../../../types/TNodeWithBlockStatement'; -import { TObfuscationEvent } from '../../../types/TObfuscationEvent'; +import { TNodeWithBlockStatement } from '../../../types/node/TNodeWithBlockStatement'; +import { TObfuscationEvent } from '../../../types/event-emitters/TObfuscationEvent'; -import { IOptions } from '../../../interfaces/IOptions'; +import { IOptions } from '../../../interfaces/options/IOptions'; import { ObfuscationEvents } from '../../../enums/ObfuscationEvents'; diff --git a/src/custom-nodes/control-flow-replacers-nodes/binary-expression-control-flow-replacer-nodes/ControlFlowStorageCallNode.ts b/src/custom-nodes/control-flow-replacers-nodes/binary-expression-control-flow-replacer-nodes/ControlFlowStorageCallNode.ts index 7cc94467..6df09596 100644 --- a/src/custom-nodes/control-flow-replacers-nodes/binary-expression-control-flow-replacer-nodes/ControlFlowStorageCallNode.ts +++ b/src/custom-nodes/control-flow-replacers-nodes/binary-expression-control-flow-replacer-nodes/ControlFlowStorageCallNode.ts @@ -1,9 +1,9 @@ import * as format from 'string-template'; -import { TNodeWithBlockStatement } from '../../../types/TNodeWithBlockStatement'; -import { TObfuscationEvent } from '../../../types/TObfuscationEvent'; +import { TNodeWithBlockStatement } from '../../../types/node/TNodeWithBlockStatement'; +import { TObfuscationEvent } from '../../../types/event-emitters/TObfuscationEvent'; -import { IOptions } from '../../../interfaces/IOptions'; +import { IOptions } from '../../../interfaces/options/IOptions'; import { ObfuscationEvents } from '../../../enums/ObfuscationEvents'; diff --git a/src/custom-nodes/control-flow-storage-nodes/ControlFlowStorageNode.ts b/src/custom-nodes/control-flow-storage-nodes/ControlFlowStorageNode.ts index 63bc0014..27d4d42b 100644 --- a/src/custom-nodes/control-flow-storage-nodes/ControlFlowStorageNode.ts +++ b/src/custom-nodes/control-flow-storage-nodes/ControlFlowStorageNode.ts @@ -1,11 +1,11 @@ import * as format from 'string-template'; -import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement'; -import { TObfuscationEvent } from '../../types/TObfuscationEvent'; +import { TNodeWithBlockStatement } from '../../types/node/TNodeWithBlockStatement'; +import { TObfuscationEvent } from '../../types/event-emitters/TObfuscationEvent'; import { ICustomNode } from '../../interfaces/custom-nodes/ICustomNode'; -import { IOptions } from '../../interfaces/IOptions'; -import { IStorage } from '../../interfaces/IStorage'; +import { IOptions } from '../../interfaces/options/IOptions'; +import { IStorage } from '../../interfaces/storages/IStorage'; import { ObfuscationEvents } from '../../enums/ObfuscationEvents'; diff --git a/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionCallNode.ts b/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionCallNode.ts index b01e342e..c1e5b0a6 100644 --- a/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionCallNode.ts +++ b/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionCallNode.ts @@ -1,9 +1,9 @@ import * as format from 'string-template'; -import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement'; -import { TObfuscationEvent } from '../../types/TObfuscationEvent'; +import { TNodeWithBlockStatement } from '../../types/node/TNodeWithBlockStatement'; +import { TObfuscationEvent } from '../../types/event-emitters/TObfuscationEvent'; -import { IOptions } from '../../interfaces/IOptions'; +import { IOptions } from '../../interfaces/options/IOptions'; import { ObfuscationEvents } from '../../enums/ObfuscationEvents'; diff --git a/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionIntervalNode.ts b/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionIntervalNode.ts index 9dcee71d..b510dcf4 100644 --- a/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionIntervalNode.ts +++ b/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionIntervalNode.ts @@ -1,9 +1,9 @@ import * as format from 'string-template'; -import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement'; -import { TObfuscationEvent } from '../../types/TObfuscationEvent'; +import { TNodeWithBlockStatement } from '../../types/node/TNodeWithBlockStatement'; +import { TObfuscationEvent } from '../../types/event-emitters/TObfuscationEvent'; -import { IOptions } from '../../interfaces/IOptions'; +import { IOptions } from '../../interfaces/options/IOptions'; import { ObfuscationEvents } from '../../enums/ObfuscationEvents'; diff --git a/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionNode.ts b/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionNode.ts index 13c0b97a..29e7c738 100644 --- a/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionNode.ts +++ b/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionNode.ts @@ -1,9 +1,9 @@ import * as format from 'string-template'; -import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement'; -import { TObfuscationEvent } from '../../types/TObfuscationEvent'; +import { TNodeWithBlockStatement } from '../../types/node/TNodeWithBlockStatement'; +import { TObfuscationEvent } from '../../types/event-emitters/TObfuscationEvent'; -import { IOptions } from '../../interfaces/IOptions'; +import { IOptions } from '../../interfaces/options/IOptions'; import { ObfuscationEvents } from '../../enums/ObfuscationEvents'; diff --git a/src/custom-nodes/domain-lock-nodes/DomainLockNode.ts b/src/custom-nodes/domain-lock-nodes/DomainLockNode.ts index 7b7533c5..f6ffadfb 100644 --- a/src/custom-nodes/domain-lock-nodes/DomainLockNode.ts +++ b/src/custom-nodes/domain-lock-nodes/DomainLockNode.ts @@ -1,9 +1,9 @@ import * as format from 'string-template'; -import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement'; -import { TObfuscationEvent } from '../../types/TObfuscationEvent'; +import { TNodeWithBlockStatement } from '../../types/node/TNodeWithBlockStatement'; +import { TObfuscationEvent } from '../../types/event-emitters/TObfuscationEvent'; -import { IOptions } from '../../interfaces/IOptions'; +import { IOptions } from '../../interfaces/options/IOptions'; import { IStackTraceData } from '../../interfaces/stack-trace-analyzer/IStackTraceData'; import { ObfuscationEvents } from '../../enums/ObfuscationEvents'; diff --git a/src/custom-nodes/node-calls-controller-nodes/NodeCallsControllerFunctionNode.ts b/src/custom-nodes/node-calls-controller-nodes/NodeCallsControllerFunctionNode.ts index 5e7d6bde..98626e7a 100644 --- a/src/custom-nodes/node-calls-controller-nodes/NodeCallsControllerFunctionNode.ts +++ b/src/custom-nodes/node-calls-controller-nodes/NodeCallsControllerFunctionNode.ts @@ -1,9 +1,9 @@ import * as format from 'string-template'; -import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement'; -import { TObfuscationEvent } from '../../types/TObfuscationEvent'; +import { TNodeWithBlockStatement } from '../../types/node/TNodeWithBlockStatement'; +import { TObfuscationEvent } from '../../types/event-emitters/TObfuscationEvent'; -import { IOptions } from '../../interfaces/IOptions'; +import { IOptions } from '../../interfaces/options/IOptions'; import { IStackTraceData } from '../../interfaces/stack-trace-analyzer/IStackTraceData'; import { ObfuscationEvents } from '../../enums/ObfuscationEvents'; diff --git a/src/custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode.ts b/src/custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode.ts index 15d282c5..1f04a6f1 100644 --- a/src/custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode.ts +++ b/src/custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode.ts @@ -1,9 +1,9 @@ import * as format from 'string-template'; -import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement'; -import { TObfuscationEvent } from '../../types/TObfuscationEvent'; +import { TNodeWithBlockStatement } from '../../types/node/TNodeWithBlockStatement'; +import { TObfuscationEvent } from '../../types/event-emitters/TObfuscationEvent'; -import { IOptions } from '../../interfaces/IOptions'; +import { IOptions } from '../../interfaces/options/IOptions'; import { IStackTraceData } from '../../interfaces/stack-trace-analyzer/IStackTraceData'; import { ObfuscationEvents } from '../../enums/ObfuscationEvents'; diff --git a/src/custom-nodes/self-defending-nodes/factory/SelfDefendingCustomNodesFactory.ts b/src/custom-nodes/self-defending-nodes/factory/SelfDefendingCustomNodesFactory.ts index 7d20a5c0..f19b9bc4 100644 --- a/src/custom-nodes/self-defending-nodes/factory/SelfDefendingCustomNodesFactory.ts +++ b/src/custom-nodes/self-defending-nodes/factory/SelfDefendingCustomNodesFactory.ts @@ -1,4 +1,4 @@ -import { TObfuscationEvent } from '../../../types/TObfuscationEvent'; +import { TObfuscationEvent } from '../../../types/event-emitters/TObfuscationEvent'; import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode'; import { IStackTraceData } from '../../../interfaces/stack-trace-analyzer/IStackTraceData'; diff --git a/src/custom-nodes/string-array-nodes/StringArrayCallsWrapper.ts b/src/custom-nodes/string-array-nodes/StringArrayCallsWrapper.ts index 67af17af..4c42f3be 100644 --- a/src/custom-nodes/string-array-nodes/StringArrayCallsWrapper.ts +++ b/src/custom-nodes/string-array-nodes/StringArrayCallsWrapper.ts @@ -1,12 +1,12 @@ import * as format from 'string-template'; -import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement'; -import { TObfuscationEvent } from '../../types/TObfuscationEvent'; -import { TStatement } from '../../types/TStatement'; +import { TNodeWithBlockStatement } from '../../types/node/TNodeWithBlockStatement'; +import { TObfuscationEvent } from '../../types/event-emitters/TObfuscationEvent'; +import { TStatement } from '../../types/node/TStatement'; import { ICustomNodeWithIdentifier } from '../../interfaces/custom-nodes/ICustomNodeWithIdentifier'; -import { IOptions } from '../../interfaces/IOptions'; -import { IStorage } from '../../interfaces/IStorage'; +import { IOptions } from '../../interfaces/options/IOptions'; +import { IStorage } from '../../interfaces/storages/IStorage'; import { ObfuscationEvents } from '../../enums/ObfuscationEvents'; import { StringArrayEncoding } from '../../enums/StringArrayEncoding'; diff --git a/src/custom-nodes/string-array-nodes/StringArrayNode.ts b/src/custom-nodes/string-array-nodes/StringArrayNode.ts index 05975387..f99a74e7 100644 --- a/src/custom-nodes/string-array-nodes/StringArrayNode.ts +++ b/src/custom-nodes/string-array-nodes/StringArrayNode.ts @@ -1,12 +1,12 @@ import * as format from 'string-template'; -import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement'; -import { TObfuscationEvent } from '../../types/TObfuscationEvent'; -import { TStatement } from '../../types/TStatement'; +import { TNodeWithBlockStatement } from '../../types/node/TNodeWithBlockStatement'; +import { TObfuscationEvent } from '../../types/event-emitters/TObfuscationEvent'; +import { TStatement } from '../../types/node/TStatement'; import { ICustomNodeWithData } from '../../interfaces/custom-nodes/ICustomNodeWithData'; -import { IOptions } from '../../interfaces/IOptions'; -import { IStorage } from '../../interfaces/IStorage'; +import { IOptions } from '../../interfaces/options/IOptions'; +import { IStorage } from '../../interfaces/storages/IStorage'; import { ObfuscationEvents } from '../../enums/ObfuscationEvents'; diff --git a/src/custom-nodes/string-array-nodes/StringArrayRotateFunctionNode.ts b/src/custom-nodes/string-array-nodes/StringArrayRotateFunctionNode.ts index 260f4f73..10f8a6c5 100644 --- a/src/custom-nodes/string-array-nodes/StringArrayRotateFunctionNode.ts +++ b/src/custom-nodes/string-array-nodes/StringArrayRotateFunctionNode.ts @@ -1,10 +1,10 @@ import * as format from 'string-template'; -import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement'; -import { TObfuscationEvent } from '../../types/TObfuscationEvent'; +import { TNodeWithBlockStatement } from '../../types/node/TNodeWithBlockStatement'; +import { TObfuscationEvent } from '../../types/event-emitters/TObfuscationEvent'; -import { IOptions } from '../../interfaces/IOptions'; -import { IStorage } from '../../interfaces/IStorage'; +import { IOptions } from '../../interfaces/options/IOptions'; +import { IStorage } from '../../interfaces/storages/IStorage'; import { ObfuscationEvents } from '../../enums/ObfuscationEvents'; diff --git a/src/custom-nodes/string-array-nodes/factory/StringArrayCustomNodesFactory.ts b/src/custom-nodes/string-array-nodes/factory/StringArrayCustomNodesFactory.ts index b11512d9..76d7bf5f 100644 --- a/src/custom-nodes/string-array-nodes/factory/StringArrayCustomNodesFactory.ts +++ b/src/custom-nodes/string-array-nodes/factory/StringArrayCustomNodesFactory.ts @@ -1,4 +1,4 @@ -import { TObfuscationEvent } from '../../../types/TObfuscationEvent'; +import { TObfuscationEvent } from '../../../types/event-emitters/TObfuscationEvent'; import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode'; import { IStackTraceData } from '../../../interfaces/stack-trace-analyzer/IStackTraceData'; @@ -12,7 +12,7 @@ import { StringArrayRotateFunctionNode } from '../StringArrayRotateFunctionNode' import { AbstractCustomNodesFactory } from '../../AbstractCustomNodesFactory'; import { StringArrayStorage } from '../../../storages/string-array/StringArrayStorage'; import { Utils } from '../../../Utils'; -import { IStorage } from '../../../interfaces/IStorage'; +import { IStorage } from '../../../interfaces/storages/IStorage'; export class StringArrayCustomNodesFactory extends AbstractCustomNodesFactory { /** diff --git a/src/enums/ObfuscationEvents.ts b/src/enums/ObfuscationEvents.ts index b98fffa6..36211c1d 100644 --- a/src/enums/ObfuscationEvents.ts +++ b/src/enums/ObfuscationEvents.ts @@ -1,4 +1,4 @@ -import { TObfuscationEvent } from '../types/TObfuscationEvent'; +import { TObfuscationEvent } from '../types/event-emitters/TObfuscationEvent'; import { Utils } from '../Utils'; diff --git a/src/event-emitters/ObfuscationEventEmitter.ts b/src/event-emitters/ObfuscationEventEmitter.ts index 84306412..f22763a6 100644 --- a/src/event-emitters/ObfuscationEventEmitter.ts +++ b/src/event-emitters/ObfuscationEventEmitter.ts @@ -1,6 +1,6 @@ import { decorate, injectable } from 'inversify'; -import { IObfuscationEventEmitter } from '../interfaces/IObfuscationEventEmitter'; +import { IObfuscationEventEmitter } from '../interfaces/event-emitters/IObfuscationEventEmitter'; import { EventEmitter } from 'events'; diff --git a/src/interfaces/IObfuscator.d.ts b/src/interfaces/IObfuscator.d.ts index bd9fef1d..f11a624e 100644 --- a/src/interfaces/IObfuscator.d.ts +++ b/src/interfaces/IObfuscator.d.ts @@ -1,7 +1,7 @@ import * as ESTree from 'estree'; import { ICustomNode } from './custom-nodes/ICustomNode'; -import { IStorage } from './IStorage'; +import { IStorage } from './storages/IStorage'; export interface IObfuscator { obfuscateAstTree (astTree: ESTree.Program, customNodesStorage: IStorage): ESTree.Program; diff --git a/src/interfaces/ISourceMapCorrector.d.ts b/src/interfaces/ISourceMapCorrector.d.ts index 56aae140..ff24ebe7 100644 --- a/src/interfaces/ISourceMapCorrector.d.ts +++ b/src/interfaces/ISourceMapCorrector.d.ts @@ -1,5 +1,5 @@ import { IObfuscationResult } from './IObfuscationResult'; export interface ISourceMapCorrector { - correct (): IObfuscationResult; + correct (obfuscatedCode: string, sourceMap: string): IObfuscationResult; } diff --git a/src/interfaces/container/IContainerServiceIdentifiers.d.ts b/src/interfaces/container/IContainerServiceIdentifiers.d.ts index e138b4f5..8f4dedc8 100644 --- a/src/interfaces/container/IContainerServiceIdentifiers.d.ts +++ b/src/interfaces/container/IContainerServiceIdentifiers.d.ts @@ -4,6 +4,7 @@ export interface IContainerServiceIdentifiers { 'Factory': interfaces.ServiceIdentifier; 'Factory': interfaces.ServiceIdentifier; 'Factory': interfaces.ServiceIdentifier; + 'Factory': interfaces.ServiceIdentifier; 'Factory': interfaces.ServiceIdentifier; ICalleeDataExtractor: interfaces.ServiceIdentifier; IControlFlowReplacer: interfaces.ServiceIdentifier; @@ -13,6 +14,7 @@ export interface IContainerServiceIdentifiers { IObfuscator: interfaces.ServiceIdentifier; IOptions: interfaces.ServiceIdentifier; IReplacer: interfaces.ServiceIdentifier; + ISourceMapCorrector: interfaces.ServiceIdentifier; IStackTraceAnalyzer: interfaces.ServiceIdentifier; 'IStorage': interfaces.ServiceIdentifier; [key: string]: interfaces.ServiceIdentifier; diff --git a/src/interfaces/container/IInversifyContainerFacade.d.ts b/src/interfaces/container/IInversifyContainerFacade.d.ts index d6238bee..48e99bb1 100644 --- a/src/interfaces/container/IInversifyContainerFacade.d.ts +++ b/src/interfaces/container/IInversifyContainerFacade.d.ts @@ -2,5 +2,4 @@ import { interfaces } from 'inversify'; export interface IInversifyContainerFacade { get (serviceIdentifier: interfaces.ServiceIdentifier): T; - getTagged (serviceIdentifier: interfaces.ServiceIdentifier, key: string, value: any): T; } diff --git a/src/interfaces/custom-nodes/ICustomNode.d.ts b/src/interfaces/custom-nodes/ICustomNode.d.ts index 4b94ef85..ecb96396 100644 --- a/src/interfaces/custom-nodes/ICustomNode.d.ts +++ b/src/interfaces/custom-nodes/ICustomNode.d.ts @@ -1,7 +1,7 @@ import * as ESTree from 'estree'; -import { TObfuscationEvent } from '../../types/TObfuscationEvent'; -import { TStatement } from '../../types/TStatement'; +import { TObfuscationEvent } from '../../types/event-emitters/TObfuscationEvent'; +import { TStatement } from '../../types/node/TStatement'; export interface ICustomNode { /** diff --git a/src/interfaces/IObfuscationEventEmitter.d.ts b/src/interfaces/event-emitters/IObfuscationEventEmitter.d.ts similarity index 72% rename from src/interfaces/IObfuscationEventEmitter.d.ts rename to src/interfaces/event-emitters/IObfuscationEventEmitter.d.ts index bae9f7e7..df5714e4 100644 --- a/src/interfaces/IObfuscationEventEmitter.d.ts +++ b/src/interfaces/event-emitters/IObfuscationEventEmitter.d.ts @@ -1,6 +1,6 @@ import Events = NodeJS.Events; -import { TObfuscationEvent } from '../types/TObfuscationEvent'; +import { TObfuscationEvent } from '../../types/event-emitters/TObfuscationEvent'; export interface IObfuscationEventEmitter extends Events { on(event: TObfuscationEvent, listener: Function): this; diff --git a/src/interfaces/IControlFlowReplacer.d.ts b/src/interfaces/node-transformers/IControlFlowReplacer.d.ts similarity index 72% rename from src/interfaces/IControlFlowReplacer.d.ts rename to src/interfaces/node-transformers/IControlFlowReplacer.d.ts index 7a8912b8..cd30a0c8 100644 --- a/src/interfaces/IControlFlowReplacer.d.ts +++ b/src/interfaces/node-transformers/IControlFlowReplacer.d.ts @@ -1,7 +1,7 @@ import * as ESTree from 'estree'; -import { ICustomNode } from './custom-nodes/ICustomNode'; -import { IStorage } from './IStorage'; +import { ICustomNode } from '../custom-nodes/ICustomNode'; +import { IStorage } from '../storages/IStorage'; export interface IControlFlowReplacer { replace ( diff --git a/src/interfaces/INodeTransformer.d.ts b/src/interfaces/node-transformers/INodeTransformer.d.ts similarity index 100% rename from src/interfaces/INodeTransformer.d.ts rename to src/interfaces/node-transformers/INodeTransformer.d.ts diff --git a/src/interfaces/IReplacer.d.ts b/src/interfaces/node-transformers/IReplacer.d.ts similarity index 100% rename from src/interfaces/IReplacer.d.ts rename to src/interfaces/node-transformers/IReplacer.d.ts diff --git a/src/interfaces/IInputOptions.d.ts b/src/interfaces/options/IInputOptions.d.ts similarity index 81% rename from src/interfaces/IInputOptions.d.ts rename to src/interfaces/options/IInputOptions.d.ts index 733ccf0b..91363998 100644 --- a/src/interfaces/IInputOptions.d.ts +++ b/src/interfaces/options/IInputOptions.d.ts @@ -1,5 +1,5 @@ -import { TSourceMapMode } from '../types/TSourceMapMode'; -import { TStringArrayEncoding } from '../types/TStringArrayEncoding'; +import { TSourceMapMode } from '../../types/TSourceMapMode'; +import { TStringArrayEncoding } from '../../types/options/TStringArrayEncoding'; export interface IInputOptions { compact?: boolean; diff --git a/src/interfaces/IOptions.d.ts b/src/interfaces/options/IOptions.d.ts similarity index 84% rename from src/interfaces/IOptions.d.ts rename to src/interfaces/options/IOptions.d.ts index a9e187ad..093f2d3d 100644 --- a/src/interfaces/IOptions.d.ts +++ b/src/interfaces/options/IOptions.d.ts @@ -1,5 +1,5 @@ -import { TSourceMapMode } from '../types/TSourceMapMode'; -import { TStringArrayEncoding } from '../types/TStringArrayEncoding'; +import { TSourceMapMode } from '../../types/TSourceMapMode'; +import { TStringArrayEncoding } from '../../types/options/TStringArrayEncoding'; export interface IOptions { readonly compact: boolean; diff --git a/src/interfaces/IStorage.d.ts b/src/interfaces/storages/IStorage.d.ts similarity index 100% rename from src/interfaces/IStorage.d.ts rename to src/interfaces/storages/IStorage.d.ts diff --git a/src/node-transformers/AbstractNodeTransformer.ts b/src/node-transformers/AbstractNodeTransformer.ts index dd8b8007..a78ccfd3 100644 --- a/src/node-transformers/AbstractNodeTransformer.ts +++ b/src/node-transformers/AbstractNodeTransformer.ts @@ -3,9 +3,9 @@ import { injectable, inject } from 'inversify'; import * as ESTree from 'estree'; import { ICustomNode } from '../interfaces/custom-nodes/ICustomNode'; -import { INodeTransformer } from '../interfaces/INodeTransformer'; -import { IOptions } from '../interfaces/IOptions'; -import { IStorage } from '../interfaces/IStorage'; +import { INodeTransformer } from '../interfaces/node-transformers/INodeTransformer'; +import { IOptions } from '../interfaces/options/IOptions'; +import { IStorage } from '../interfaces/storages/IStorage'; import { ServiceIdentifiers } from '../container/ServiceIdentifiers'; @injectable() diff --git a/src/node-transformers/node-control-flow-transformers/FunctionControlFlowTransformer.ts b/src/node-transformers/node-control-flow-transformers/FunctionControlFlowTransformer.ts index d7d969d3..30f2be8e 100644 --- a/src/node-transformers/node-control-flow-transformers/FunctionControlFlowTransformer.ts +++ b/src/node-transformers/node-control-flow-transformers/FunctionControlFlowTransformer.ts @@ -4,12 +4,12 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as estraverse from 'estraverse'; import * as ESTree from 'estree'; -import { TControlFlowReplacer } from '../../types/TControlFlowReplacer'; -import { TStatement } from '../../types/TStatement'; +import { TControlFlowReplacer } from '../../types/node-transformers/TControlFlowReplacer'; +import { TStatement } from '../../types/node/TStatement'; import { ICustomNode } from '../../interfaces/custom-nodes/ICustomNode'; -import { IOptions } from '../../interfaces/IOptions'; -import { IStorage } from '../../interfaces/IStorage'; +import { IOptions } from '../../interfaces/options/IOptions'; +import { IStorage } from '../../interfaces/storages/IStorage'; import { NodeType } from '../../enums/NodeType'; diff --git a/src/node-transformers/node-control-flow-transformers/control-flow-replacers/AbstractControlFlowReplacer.ts b/src/node-transformers/node-control-flow-transformers/control-flow-replacers/AbstractControlFlowReplacer.ts index 26ada910..3bc5d6ac 100644 --- a/src/node-transformers/node-control-flow-transformers/control-flow-replacers/AbstractControlFlowReplacer.ts +++ b/src/node-transformers/node-control-flow-transformers/control-flow-replacers/AbstractControlFlowReplacer.ts @@ -3,10 +3,10 @@ import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers'; import * as ESTree from 'estree'; -import { IControlFlowReplacer } from '../../../interfaces/IControlFlowReplacer'; +import { IControlFlowReplacer } from '../../../interfaces/node-transformers/IControlFlowReplacer'; import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode'; -import { IOptions } from '../../../interfaces/IOptions'; -import { IStorage } from '../../../interfaces/IStorage'; +import { IOptions } from '../../../interfaces/options/IOptions'; +import { IStorage } from '../../../interfaces/storages/IStorage'; import { Utils } from '../../../Utils'; diff --git a/src/node-transformers/node-control-flow-transformers/control-flow-replacers/BinaryExpressionControlFlowReplacer.ts b/src/node-transformers/node-control-flow-transformers/control-flow-replacers/BinaryExpressionControlFlowReplacer.ts index 3c8068e5..2dbdef45 100644 --- a/src/node-transformers/node-control-flow-transformers/control-flow-replacers/BinaryExpressionControlFlowReplacer.ts +++ b/src/node-transformers/node-control-flow-transformers/control-flow-replacers/BinaryExpressionControlFlowReplacer.ts @@ -5,8 +5,8 @@ import * as escodegen from 'escodegen'; import * as ESTree from 'estree'; import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode'; -import { IOptions } from '../../../interfaces/IOptions'; -import { IStorage } from '../../../interfaces/IStorage'; +import { IOptions } from '../../../interfaces/options/IOptions'; +import { IStorage } from '../../../interfaces/storages/IStorage'; import { AbstractControlFlowReplacer } from './AbstractControlFlowReplacer'; import { BinaryExpressionFunctionNode } from '../../../custom-nodes/control-flow-replacers-nodes/binary-expression-control-flow-replacer-nodes/BinaryExpressionFunctionNode'; @@ -40,14 +40,14 @@ export class BinaryExpressionControlFlowReplacer extends AbstractControlFlowRepl * @param parentNode * @param controlFlowStorage * @param controlFlowStorageCustomNodeName - * @returns {ICustomNode | undefined} + * @returns {ICustomNode} */ public replace ( binaryExpressionNode: ESTree.BinaryExpression, parentNode: ESTree.Node, controlFlowStorage: IStorage , controlFlowStorageCustomNodeName: string - ): ICustomNode | undefined { + ): ICustomNode { const key: string = AbstractControlFlowReplacer.getStorageKey(); controlFlowStorage.set(key, new BinaryExpressionFunctionNode(binaryExpressionNode.operator, this.options)); diff --git a/src/node-transformers/node-obfuscators/CatchClauseObfuscator.ts b/src/node-transformers/node-obfuscators/CatchClauseObfuscator.ts index d3bdf1a4..003eef3f 100644 --- a/src/node-transformers/node-obfuscators/CatchClauseObfuscator.ts +++ b/src/node-transformers/node-obfuscators/CatchClauseObfuscator.ts @@ -5,9 +5,9 @@ import * as estraverse from 'estraverse'; import * as ESTree from 'estree'; import { ICustomNode } from '../../interfaces/custom-nodes/ICustomNode'; -import { IOptions } from '../../interfaces/IOptions'; -import { IReplacer } from '../../interfaces/IReplacer'; -import { IStorage } from '../../interfaces/IStorage'; +import { IOptions } from '../../interfaces/options/IOptions'; +import { IReplacer } from '../../interfaces/node-transformers/IReplacer'; +import { IStorage } from '../../interfaces/storages/IStorage'; import { NodeObfuscatorsReplacers } from '../../enums/container/NodeObfuscatorsReplacers'; import { NodeType } from '../../enums/NodeType'; diff --git a/src/node-transformers/node-obfuscators/FunctionDeclarationObfuscator.ts b/src/node-transformers/node-obfuscators/FunctionDeclarationObfuscator.ts index 3771ca9e..f67ff275 100644 --- a/src/node-transformers/node-obfuscators/FunctionDeclarationObfuscator.ts +++ b/src/node-transformers/node-obfuscators/FunctionDeclarationObfuscator.ts @@ -4,12 +4,12 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as estraverse from 'estraverse'; import * as ESTree from 'estree'; -import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement'; +import { TNodeWithBlockStatement } from '../../types/node/TNodeWithBlockStatement'; import { ICustomNode } from '../../interfaces/custom-nodes/ICustomNode'; -import { IOptions } from '../../interfaces/IOptions'; -import { IReplacer } from '../../interfaces/IReplacer'; -import { IStorage } from '../../interfaces/IStorage'; +import { IOptions } from '../../interfaces/options/IOptions'; +import { IReplacer } from '../../interfaces/node-transformers/IReplacer'; +import { IStorage } from '../../interfaces/storages/IStorage'; import { NodeObfuscatorsReplacers } from '../../enums/container/NodeObfuscatorsReplacers'; import { NodeType } from '../../enums/NodeType'; diff --git a/src/node-transformers/node-obfuscators/FunctionObfuscator.ts b/src/node-transformers/node-obfuscators/FunctionObfuscator.ts index f543733b..6a0234f7 100644 --- a/src/node-transformers/node-obfuscators/FunctionObfuscator.ts +++ b/src/node-transformers/node-obfuscators/FunctionObfuscator.ts @@ -5,9 +5,9 @@ import * as estraverse from 'estraverse'; import * as ESTree from 'estree'; import { ICustomNode } from '../../interfaces/custom-nodes/ICustomNode'; -import { IOptions } from '../../interfaces/IOptions'; -import { IReplacer } from '../../interfaces/IReplacer'; -import { IStorage } from '../../interfaces/IStorage'; +import { IOptions } from '../../interfaces/options/IOptions'; +import { IReplacer } from '../../interfaces/node-transformers/IReplacer'; +import { IStorage } from '../../interfaces/storages/IStorage'; import { NodeObfuscatorsReplacers } from '../../enums/container/NodeObfuscatorsReplacers'; import { NodeType } from '../../enums/NodeType'; diff --git a/src/node-transformers/node-obfuscators/LabeledStatementObfuscator.ts b/src/node-transformers/node-obfuscators/LabeledStatementObfuscator.ts index 3640ab76..a12f9e0f 100644 --- a/src/node-transformers/node-obfuscators/LabeledStatementObfuscator.ts +++ b/src/node-transformers/node-obfuscators/LabeledStatementObfuscator.ts @@ -5,9 +5,9 @@ import * as estraverse from 'estraverse'; import * as ESTree from 'estree'; import { ICustomNode } from '../../interfaces/custom-nodes/ICustomNode'; -import { IOptions } from '../../interfaces/IOptions'; -import { IReplacer } from '../../interfaces/IReplacer'; -import { IStorage } from '../../interfaces/IStorage'; +import { IOptions } from '../../interfaces/options/IOptions'; +import { IReplacer } from '../../interfaces/node-transformers/IReplacer'; +import { IStorage } from '../../interfaces/storages/IStorage'; import { NodeObfuscatorsReplacers } from '../../enums/container/NodeObfuscatorsReplacers'; import { NodeType } from '../../enums/NodeType'; diff --git a/src/node-transformers/node-obfuscators/LiteralObfuscator.ts b/src/node-transformers/node-obfuscators/LiteralObfuscator.ts index 71059291..67121ce9 100644 --- a/src/node-transformers/node-obfuscators/LiteralObfuscator.ts +++ b/src/node-transformers/node-obfuscators/LiteralObfuscator.ts @@ -5,9 +5,9 @@ import * as escodegen from 'escodegen'; import * as ESTree from 'estree'; import { ICustomNode } from '../../interfaces/custom-nodes/ICustomNode'; -import { IOptions } from '../../interfaces/IOptions'; -import { IReplacer } from '../../interfaces/IReplacer'; -import { IStorage } from '../../interfaces/IStorage'; +import { IOptions } from '../../interfaces/options/IOptions'; +import { IReplacer } from '../../interfaces/node-transformers/IReplacer'; +import { IStorage } from '../../interfaces/storages/IStorage'; import { NodeObfuscatorsReplacers } from '../../enums/container/NodeObfuscatorsReplacers'; diff --git a/src/node-transformers/node-obfuscators/MemberExpressionObfuscator.ts b/src/node-transformers/node-obfuscators/MemberExpressionObfuscator.ts index b58a0a27..a79249b6 100644 --- a/src/node-transformers/node-obfuscators/MemberExpressionObfuscator.ts +++ b/src/node-transformers/node-obfuscators/MemberExpressionObfuscator.ts @@ -6,9 +6,9 @@ import * as estraverse from 'estraverse'; import * as ESTree from 'estree'; import { ICustomNode } from '../../interfaces/custom-nodes/ICustomNode'; -import { IOptions } from '../../interfaces/IOptions'; -import { IReplacer } from '../../interfaces/IReplacer'; -import { IStorage } from '../../interfaces/IStorage'; +import { IOptions } from '../../interfaces/options/IOptions'; +import { IReplacer } from '../../interfaces/node-transformers/IReplacer'; +import { IStorage } from '../../interfaces/storages/IStorage'; import { NodeObfuscatorsReplacers } from '../../enums/container/NodeObfuscatorsReplacers'; import { NodeType } from '../../enums/NodeType'; diff --git a/src/node-transformers/node-obfuscators/MethodDefinitionObfuscator.ts b/src/node-transformers/node-obfuscators/MethodDefinitionObfuscator.ts index a695eed1..6cc4a774 100644 --- a/src/node-transformers/node-obfuscators/MethodDefinitionObfuscator.ts +++ b/src/node-transformers/node-obfuscators/MethodDefinitionObfuscator.ts @@ -5,9 +5,9 @@ import * as estraverse from 'estraverse'; import * as ESTree from 'estree'; import { ICustomNode } from '../../interfaces/custom-nodes/ICustomNode'; -import { IOptions } from '../../interfaces/IOptions'; -import { IReplacer } from '../../interfaces/IReplacer'; -import { IStorage } from '../../interfaces/IStorage'; +import { IOptions } from '../../interfaces/options/IOptions'; +import { IReplacer } from '../../interfaces/node-transformers/IReplacer'; +import { IStorage } from '../../interfaces/storages/IStorage'; import { NodeObfuscatorsReplacers } from '../../enums/container/NodeObfuscatorsReplacers'; diff --git a/src/node-transformers/node-obfuscators/ObjectExpressionObfuscator.ts b/src/node-transformers/node-obfuscators/ObjectExpressionObfuscator.ts index 9e332410..23911520 100644 --- a/src/node-transformers/node-obfuscators/ObjectExpressionObfuscator.ts +++ b/src/node-transformers/node-obfuscators/ObjectExpressionObfuscator.ts @@ -6,8 +6,8 @@ import * as estraverse from 'estraverse'; import * as ESTree from 'estree'; import { ICustomNode } from '../../interfaces/custom-nodes/ICustomNode'; -import { IOptions } from '../../interfaces/IOptions'; -import { IStorage } from '../../interfaces/IStorage'; +import { IOptions } from '../../interfaces/options/IOptions'; +import { IStorage } from '../../interfaces/storages/IStorage'; import { NodeType } from '../../enums/NodeType'; diff --git a/src/node-transformers/node-obfuscators/VariableDeclarationObfuscator.ts b/src/node-transformers/node-obfuscators/VariableDeclarationObfuscator.ts index 0bec2b52..a7721afc 100644 --- a/src/node-transformers/node-obfuscators/VariableDeclarationObfuscator.ts +++ b/src/node-transformers/node-obfuscators/VariableDeclarationObfuscator.ts @@ -4,12 +4,12 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import * as estraverse from 'estraverse'; import * as ESTree from 'estree'; -import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement'; +import { TNodeWithBlockStatement } from '../../types/node/TNodeWithBlockStatement'; import { ICustomNode } from '../../interfaces/custom-nodes/ICustomNode'; -import { IOptions } from '../../interfaces/IOptions'; -import { IReplacer } from '../../interfaces/IReplacer'; -import { IStorage } from '../../interfaces/IStorage'; +import { IOptions } from '../../interfaces/options/IOptions'; +import { IReplacer } from '../../interfaces/node-transformers/IReplacer'; +import { IStorage } from '../../interfaces/storages/IStorage'; import { NodeObfuscatorsReplacers } from '../../enums/container/NodeObfuscatorsReplacers'; import { NodeType } from '../../enums/NodeType'; diff --git a/src/node-transformers/node-obfuscators/replacers/AbstractReplacer.ts b/src/node-transformers/node-obfuscators/replacers/AbstractReplacer.ts index c0dcc783..037c2ef5 100644 --- a/src/node-transformers/node-obfuscators/replacers/AbstractReplacer.ts +++ b/src/node-transformers/node-obfuscators/replacers/AbstractReplacer.ts @@ -2,9 +2,9 @@ import { injectable, inject } from 'inversify'; import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers'; import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode'; -import { IOptions } from '../../../interfaces/IOptions'; -import { IReplacer } from '../../../interfaces/IReplacer'; -import { IStorage } from '../../../interfaces/IStorage'; +import { IOptions } from '../../../interfaces/options/IOptions'; +import { IReplacer } from '../../../interfaces/node-transformers/IReplacer'; +import { IStorage } from '../../../interfaces/storages/IStorage'; @injectable() export abstract class AbstractReplacer implements IReplacer { diff --git a/src/node-transformers/node-obfuscators/replacers/BooleanLiteralReplacer.ts b/src/node-transformers/node-obfuscators/replacers/BooleanLiteralReplacer.ts index 23bb96e0..0918ff75 100644 --- a/src/node-transformers/node-obfuscators/replacers/BooleanLiteralReplacer.ts +++ b/src/node-transformers/node-obfuscators/replacers/BooleanLiteralReplacer.ts @@ -2,8 +2,8 @@ import { injectable, inject } from 'inversify'; import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers'; import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode'; -import { IOptions } from '../../../interfaces/IOptions'; -import { IStorage } from '../../../interfaces/IStorage'; +import { IOptions } from '../../../interfaces/options/IOptions'; +import { IStorage } from '../../../interfaces/storages/IStorage'; import { JSFuck } from '../../../enums/JSFuck'; diff --git a/src/node-transformers/node-obfuscators/replacers/IdentifierReplacer.ts b/src/node-transformers/node-obfuscators/replacers/IdentifierReplacer.ts index f11e6297..32b49346 100644 --- a/src/node-transformers/node-obfuscators/replacers/IdentifierReplacer.ts +++ b/src/node-transformers/node-obfuscators/replacers/IdentifierReplacer.ts @@ -2,8 +2,8 @@ import { injectable, inject } from 'inversify'; import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers'; import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode'; -import { IOptions } from '../../../interfaces/IOptions'; -import { IStorage } from '../../../interfaces/IStorage'; +import { IOptions } from '../../../interfaces/options/IOptions'; +import { IStorage } from '../../../interfaces/storages/IStorage'; import { AbstractReplacer } from './AbstractReplacer'; import { Utils } from '../../../Utils'; diff --git a/src/node-transformers/node-obfuscators/replacers/NumberLiteralReplacer.ts b/src/node-transformers/node-obfuscators/replacers/NumberLiteralReplacer.ts index b4b1bb75..b978ae45 100644 --- a/src/node-transformers/node-obfuscators/replacers/NumberLiteralReplacer.ts +++ b/src/node-transformers/node-obfuscators/replacers/NumberLiteralReplacer.ts @@ -2,8 +2,8 @@ import { injectable, inject } from 'inversify'; import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers'; import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode'; -import { IOptions } from '../../../interfaces/IOptions'; -import { IStorage } from '../../../interfaces/IStorage'; +import { IOptions } from '../../../interfaces/options/IOptions'; +import { IStorage } from '../../../interfaces/storages/IStorage'; import { AbstractReplacer } from './AbstractReplacer'; import { Utils } from '../../../Utils'; @@ -26,12 +26,10 @@ export class NumberLiteralReplacer extends AbstractReplacer { * @returns {string} */ public replace (nodeValue: number): string { - const prefix: string = '0x'; - if (!Utils.isInteger(nodeValue)) { return String(nodeValue); } - return `${prefix}${Utils.decToHex(nodeValue)}`; + return `${Utils.hexadecimalPrefix}${Utils.decToHex(nodeValue)}`; } } diff --git a/src/node-transformers/node-obfuscators/replacers/StringLiteralReplacer.ts b/src/node-transformers/node-obfuscators/replacers/StringLiteralReplacer.ts index 3be273c2..a2b9ef01 100644 --- a/src/node-transformers/node-obfuscators/replacers/StringLiteralReplacer.ts +++ b/src/node-transformers/node-obfuscators/replacers/StringLiteralReplacer.ts @@ -4,13 +4,12 @@ import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers'; import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode'; import { ICustomNodeWithData } from '../../../interfaces/custom-nodes/ICustomNodeWithData'; import { ICustomNodeWithIdentifier } from '../../../interfaces/custom-nodes/ICustomNodeWithIdentifier'; -import { IOptions } from '../../../interfaces/IOptions'; -import { IStorage } from '../../../interfaces/IStorage'; +import { IOptions } from '../../../interfaces/options/IOptions'; +import { IStorage } from '../../../interfaces/storages/IStorage'; import { StringArrayEncoding } from '../../../enums/StringArrayEncoding'; import { AbstractReplacer } from './AbstractReplacer'; -import { NumberLiteralReplacer } from './NumberLiteralReplacer'; import { Utils } from '../../../Utils'; @injectable() @@ -93,7 +92,7 @@ export class StringLiteralReplacer extends AbstractReplacer { } const stringArrayCallsWrapper: ICustomNodeWithIdentifier = this.customNodesStorage.get('stringArrayCallsWrapper'); - const hexadecimalIndex: string = new NumberLiteralReplacer(this.customNodesStorage, this.options).replace(indexOfValue); + const hexadecimalIndex: string = `${Utils.hexadecimalPrefix}${Utils.decToHex(indexOfValue)}`; if (this.options.stringArrayEncoding === StringArrayEncoding.rc4) { return `${stringArrayCallsWrapper.getNodeIdentifier()}('${hexadecimalIndex}', '${Utils.stringToUnicodeEscapeSequence(rc4Key)}')`; diff --git a/src/node/Node.ts b/src/node/Node.ts index ec963822..13bcdd66 100644 --- a/src/node/Node.ts +++ b/src/node/Node.ts @@ -1,7 +1,7 @@ import * as ESTree from 'estree'; -import { TNodeWithBlockStatement } from '../types/TNodeWithBlockStatement'; -import { TStatement } from '../types/TStatement'; +import { TNodeWithBlockStatement } from '../types/node/TNodeWithBlockStatement'; +import { TStatement } from '../types/node/TStatement'; import { NodeType } from '../enums/NodeType'; diff --git a/src/node/NodeAppender.ts b/src/node/NodeAppender.ts index af01e760..6b671185 100644 --- a/src/node/NodeAppender.ts +++ b/src/node/NodeAppender.ts @@ -1,7 +1,7 @@ import * as ESTree from 'estree'; -import { TNodeWithBlockStatement } from '../types/TNodeWithBlockStatement'; -import { TStatement } from '../types/TStatement'; +import { TNodeWithBlockStatement } from '../types/node/TNodeWithBlockStatement'; +import { TStatement } from '../types/node/TStatement'; import { IStackTraceData } from '../interfaces/stack-trace-analyzer/IStackTraceData'; diff --git a/src/node/NodeUtils.ts b/src/node/NodeUtils.ts index 743faf7a..7a3bc9af 100644 --- a/src/node/NodeUtils.ts +++ b/src/node/NodeUtils.ts @@ -3,8 +3,8 @@ import * as esprima from 'esprima'; import * as estraverse from 'estraverse'; import * as ESTree from 'estree'; -import { TNodeWithBlockStatement } from '../types/TNodeWithBlockStatement'; -import { TStatement } from '../types/TStatement'; +import { TNodeWithBlockStatement } from '../types/node/TNodeWithBlockStatement'; +import { TStatement } from '../types/node/TStatement'; import { NodeType } from '../enums/NodeType'; @@ -116,7 +116,7 @@ export class NodeUtils { return depth; } - if (Node.isBlockStatementNode(node)) { + if (Node.isBlockStatementNode(node) && Utils.arrayContains(NodeUtils.nodesWithBlockScope, parentNode.type)) { return NodeUtils.getNodeBlockScopeDepth(parentNode, ++depth); } diff --git a/src/options/Options.ts b/src/options/Options.ts index c44eabb8..1484bd6e 100644 --- a/src/options/Options.ts +++ b/src/options/Options.ts @@ -16,11 +16,11 @@ ValidationError, ValidatorOptions } from 'class-validator'; -import { IInputOptions } from '../interfaces/IInputOptions'; -import { IOptions } from '../interfaces/IOptions'; +import { IInputOptions } from '../interfaces/options/IInputOptions'; +import { IOptions } from '../interfaces/options/IOptions'; import { TSourceMapMode } from '../types/TSourceMapMode'; -import { TStringArrayEncoding } from '../types/TStringArrayEncoding'; +import { TStringArrayEncoding } from '../types/options/TStringArrayEncoding'; import { DEFAULT_PRESET } from '../preset-options/DefaultPreset'; diff --git a/src/options/OptionsNormalizer.ts b/src/options/OptionsNormalizer.ts index ed972fa7..2d5daf01 100644 --- a/src/options/OptionsNormalizer.ts +++ b/src/options/OptionsNormalizer.ts @@ -1,7 +1,7 @@ -import { IInputOptions } from '../interfaces/IInputOptions'; -import { IOptions } from '../interfaces/IOptions'; +import { IInputOptions } from '../interfaces/options/IInputOptions'; +import { IOptions } from '../interfaces/options/IOptions'; -import { TOptionsNormalizerRule } from '../types/TOptionsNormalizerRule'; +import { TOptionsNormalizerRule } from '../types/options/TOptionsNormalizerRule'; import { Utils } from '../Utils'; diff --git a/src/preset-options/DefaultPreset.ts b/src/preset-options/DefaultPreset.ts index f765c99c..ed828ca4 100644 --- a/src/preset-options/DefaultPreset.ts +++ b/src/preset-options/DefaultPreset.ts @@ -1,4 +1,4 @@ -import { IInputOptions } from '../interfaces/IInputOptions'; +import { IInputOptions } from '../interfaces/options/IInputOptions'; import { SourceMapMode } from '../enums/SourceMapMode'; diff --git a/src/preset-options/NoCustomNodesPreset.ts b/src/preset-options/NoCustomNodesPreset.ts index 2a62063d..98d187ac 100644 --- a/src/preset-options/NoCustomNodesPreset.ts +++ b/src/preset-options/NoCustomNodesPreset.ts @@ -1,4 +1,4 @@ -import { IInputOptions } from '../interfaces/IInputOptions'; +import { IInputOptions } from '../interfaces/options/IInputOptions'; import { SourceMapMode } from '../enums/SourceMapMode'; diff --git a/src/stack-trace-analyzer/StackTraceAnalyzer.ts b/src/stack-trace-analyzer/StackTraceAnalyzer.ts index 5fa9585b..83c51794 100644 --- a/src/stack-trace-analyzer/StackTraceAnalyzer.ts +++ b/src/stack-trace-analyzer/StackTraceAnalyzer.ts @@ -4,7 +4,7 @@ import { ServiceIdentifiers } from '../container/ServiceIdentifiers'; import * as estraverse from 'estraverse'; import * as ESTree from 'estree'; -import { TCalleeDataExtractorsFactory } from '../types/TCalleeDataExtractorsFactory'; +import { TCalleeDataExtractorsFactory } from '../types/container/TCalleeDataExtractorsFactory'; import { ICalleeData } from '../interfaces/stack-trace-analyzer/ICalleeData'; import { ICalleeDataExtractor } from '../interfaces/stack-trace-analyzer/ICalleeDataExtractor'; @@ -117,42 +117,56 @@ export class StackTraceAnalyzer implements IStackTraceAnalyzer { private analyzeRecursive (blockScopeBody: ESTree.Node[]): IStackTraceData[] { const limitIndex: number = StackTraceAnalyzer.getLimitIndex(blockScopeBody.length); const stackTraceData: IStackTraceData[] = []; + const blockScopeBodyLength: number = blockScopeBody.length; - for ( - let index: number = 0, blockScopeBodyLength: number = blockScopeBody.length; - index < blockScopeBodyLength; - index++ - ) { - const rootNode: ESTree.Node = blockScopeBody[index]; - + for (let index: number = 0; index < blockScopeBodyLength; index++) { if (index > limitIndex) { break; } - estraverse.traverse(rootNode, { - enter: (node: ESTree.Node): any => { - if (!Node.isCallExpressionNode(node) || rootNode.parentNode !== NodeUtils.getBlockScopeOfNode(node)) { + const blockScopeBodyNode: ESTree.Node = blockScopeBody[index]; + + estraverse.traverse(blockScopeBodyNode, { + enter: (node: ESTree.Node): void => { + if ( + !Node.isCallExpressionNode(node) || + blockScopeBodyNode.parentNode !== NodeUtils.getBlockScopeOfNode(node) + ) { return; } - StackTraceAnalyzer.calleeDataExtractorsList.forEach((calleeDataExtractorName: CalleeDataExtractors) => { - const calleeData: ICalleeData | null = this.calleeDataExtractorsFactory(calleeDataExtractorName) - .extract(blockScopeBody, node.callee); - - if (!calleeData) { - return; - } - - stackTraceData.push( - Object.assign({}, calleeData, { - stackTrace: this.analyzeRecursive(calleeData.callee.body) - }) - ); - }); + this.analyzeCallExpressionNode(stackTraceData, blockScopeBody, node); } }); } return stackTraceData; } + + /** + * @param stackTraceData + * @param blockScopeBody + * @param callExpressionNode + * @returns {IStackTraceData[]} + */ + private analyzeCallExpressionNode ( + stackTraceData: IStackTraceData[], + blockScopeBody: ESTree.Node[], + callExpressionNode: ESTree.CallExpression + ): void { + StackTraceAnalyzer.calleeDataExtractorsList.forEach((calleeDataExtractorName: CalleeDataExtractors) => { + const calleeData: ICalleeData | null = this.calleeDataExtractorsFactory(calleeDataExtractorName) + .extract(blockScopeBody, callExpressionNode.callee); + + if (!calleeData) { + return; + } + + stackTraceData.push( + Object.assign({}, calleeData, { + stackTrace: this.analyzeRecursive(calleeData.callee.body) + }) + ); + }); + } } diff --git a/src/stack-trace-analyzer/callee-data-extractors/ObjectExpressionCalleeDataExtractor.ts b/src/stack-trace-analyzer/callee-data-extractors/ObjectExpressionCalleeDataExtractor.ts index c4ba48b6..8dc69290 100644 --- a/src/stack-trace-analyzer/callee-data-extractors/ObjectExpressionCalleeDataExtractor.ts +++ b/src/stack-trace-analyzer/callee-data-extractors/ObjectExpressionCalleeDataExtractor.ts @@ -3,7 +3,7 @@ import { injectable } from 'inversify'; import * as estraverse from 'estraverse'; import * as ESTree from 'estree'; -import { TObjectMembersCallsChain } from '../../types/TObjectMembersCallsChain'; +import { TObjectMembersCallsChain } from '../../types/stack-trace-analyzer/TObjectMembersCallsChain'; import { ICalleeData } from '../../interfaces/stack-trace-analyzer/ICalleeData'; diff --git a/src/storages/ArrayStorage.ts b/src/storages/ArrayStorage.ts index 6f902dce..8dee95c8 100644 --- a/src/storages/ArrayStorage.ts +++ b/src/storages/ArrayStorage.ts @@ -1,4 +1,4 @@ -import { IStorage } from '../interfaces/IStorage'; +import { IStorage } from '../interfaces/storages/IStorage'; export abstract class ArrayStorage implements IStorage { /** diff --git a/src/storages/MapStorage.ts b/src/storages/MapStorage.ts index 3a806c63..3f0da4da 100644 --- a/src/storages/MapStorage.ts +++ b/src/storages/MapStorage.ts @@ -1,6 +1,6 @@ import { injectable } from 'inversify'; -import { IStorage } from '../interfaces/IStorage'; +import { IStorage } from '../interfaces/storages/IStorage'; import { Utils } from '../Utils'; diff --git a/src/storages/custom-nodes/CustomNodesStorage.ts b/src/storages/custom-nodes/CustomNodesStorage.ts index 3135a255..cb17eb42 100644 --- a/src/storages/custom-nodes/CustomNodesStorage.ts +++ b/src/storages/custom-nodes/CustomNodesStorage.ts @@ -1,10 +1,10 @@ import { injectable, inject } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; -import { TCustomNodesFactory } from '../../types/TCustomNodesFactory'; +import { TCustomNodesFactory } from '../../types/container/TCustomNodesFactory'; import { ICustomNode } from '../../interfaces/custom-nodes/ICustomNode'; -import { IOptions } from '../../interfaces/IOptions'; +import { IOptions } from '../../interfaces/options/IOptions'; import { IStackTraceData } from '../../interfaces/stack-trace-analyzer/IStackTraceData'; import { ConsoleOutputCustomNodesFactory } from '../../custom-nodes/console-output-nodes/factory/ConsoleOutputCustomNodesFactory'; diff --git a/src/types/TCalleeDataExtractorsFactory.d.ts b/src/types/TCalleeDataExtractorsFactory.d.ts deleted file mode 100644 index b242ba0c..00000000 --- a/src/types/TCalleeDataExtractorsFactory.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { ICalleeDataExtractor } from '../interfaces/stack-trace-analyzer/ICalleeDataExtractor'; - -import { CalleeDataExtractors } from '../enums/container/CalleeDataExtractors'; - -export type TCalleeDataExtractorsFactory = (calleeDataExtractorName: CalleeDataExtractors) => ICalleeDataExtractor; diff --git a/src/types/TControlFlowReplacer.d.ts b/src/types/TControlFlowReplacer.d.ts deleted file mode 100644 index ef54b014..00000000 --- a/src/types/TControlFlowReplacer.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { IControlFlowReplacer } from '../interfaces/IControlFlowReplacer'; -import { ICustomNode } from '../interfaces/custom-nodes/ICustomNode'; -import { IOptions } from '../interfaces/IOptions'; -import { IStorage } from '../interfaces/IStorage'; - -export type TControlFlowReplacer = (new (customNodesStorage: IStorage, options: IOptions) => IControlFlowReplacer); diff --git a/src/types/TCustomNodesFactory.d.ts b/src/types/TCustomNodesFactory.d.ts deleted file mode 100644 index a4b54e1b..00000000 --- a/src/types/TCustomNodesFactory.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { ICustomNodesFactory } from '../interfaces/custom-nodes/ICustomNodesFactory'; -import { IOptions } from '../interfaces/IOptions'; - -export type TCustomNodesFactory = new (options: IOptions) => ICustomNodesFactory; diff --git a/src/types/TNodeTransformer.d.ts b/src/types/TNodeTransformer.d.ts deleted file mode 100644 index e7c1a05f..00000000 --- a/src/types/TNodeTransformer.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { ICustomNode } from '../interfaces/custom-nodes/ICustomNode'; -import { INodeTransformer } from '../interfaces/INodeTransformer'; -import { IOptions } from '../interfaces/IOptions'; -import { IStorage } from '../interfaces/IStorage'; - -export type TNodeTransformer = (new (customNodesStorage: IStorage, options: IOptions) => INodeTransformer); diff --git a/src/types/TNodeTransformersFactory.d.ts b/src/types/TNodeTransformersFactory.d.ts deleted file mode 100644 index ac5cc2ec..00000000 --- a/src/types/TNodeTransformersFactory.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { INodeTransformer } from '../interfaces/INodeTransformer'; - -import { NodeTransformers } from '../enums/container/NodeTransformers'; - -export type TNodeTransformersFactory = (nodeTransformersMap: Map) => (nodeType: string) => INodeTransformer[]; diff --git a/src/types/container/TCalleeDataExtractorsFactory.d.ts b/src/types/container/TCalleeDataExtractorsFactory.d.ts new file mode 100644 index 00000000..362a383e --- /dev/null +++ b/src/types/container/TCalleeDataExtractorsFactory.d.ts @@ -0,0 +1,5 @@ +import { ICalleeDataExtractor } from '../../interfaces/stack-trace-analyzer/ICalleeDataExtractor'; + +import { CalleeDataExtractors } from '../../enums/container/CalleeDataExtractors'; + +export type TCalleeDataExtractorsFactory = (calleeDataExtractorName: CalleeDataExtractors) => ICalleeDataExtractor; diff --git a/src/types/container/TCustomNodesFactory.d.ts b/src/types/container/TCustomNodesFactory.d.ts new file mode 100644 index 00000000..9e3f9805 --- /dev/null +++ b/src/types/container/TCustomNodesFactory.d.ts @@ -0,0 +1,4 @@ +import { ICustomNodesFactory } from '../../interfaces/custom-nodes/ICustomNodesFactory'; +import { IOptions } from '../../interfaces/options/IOptions'; + +export type TCustomNodesFactory = new (options: IOptions) => ICustomNodesFactory; diff --git a/src/types/container/TNodeTransformersFactory.d.ts b/src/types/container/TNodeTransformersFactory.d.ts new file mode 100644 index 00000000..b74bf7f9 --- /dev/null +++ b/src/types/container/TNodeTransformersFactory.d.ts @@ -0,0 +1,5 @@ +import { INodeTransformer } from '../../interfaces/node-transformers/INodeTransformer'; + +import { NodeTransformers } from '../../enums/container/NodeTransformers'; + +export type TNodeTransformersFactory = (nodeTransformersMap: Map) => (nodeType: string) => INodeTransformer[]; diff --git a/src/types/container/TObfuscationResultFactory.d.ts b/src/types/container/TObfuscationResultFactory.d.ts new file mode 100644 index 00000000..4acf9d5f --- /dev/null +++ b/src/types/container/TObfuscationResultFactory.d.ts @@ -0,0 +1,3 @@ +import { IObfuscationResult } from '../../interfaces/IObfuscationResult'; + +export type TObfuscationResultFactory = (obfuscatedCode: string, sourceMap: string) => IObfuscationResult; diff --git a/src/types/TObfuscationEvent.d.ts b/src/types/event-emitters/TObfuscationEvent.d.ts similarity index 100% rename from src/types/TObfuscationEvent.d.ts rename to src/types/event-emitters/TObfuscationEvent.d.ts diff --git a/src/types/node-transformers/TControlFlowReplacer.d.ts b/src/types/node-transformers/TControlFlowReplacer.d.ts new file mode 100644 index 00000000..cc5fd582 --- /dev/null +++ b/src/types/node-transformers/TControlFlowReplacer.d.ts @@ -0,0 +1,6 @@ +import { IControlFlowReplacer } from '../../interfaces/node-transformers/IControlFlowReplacer'; +import { ICustomNode } from '../../interfaces/custom-nodes/ICustomNode'; +import { IOptions } from '../../interfaces/options/IOptions'; +import { IStorage } from '../../interfaces/storages/IStorage'; + +export type TControlFlowReplacer = (new (customNodesStorage: IStorage, options: IOptions) => IControlFlowReplacer); diff --git a/src/types/node-transformers/TNodeTransformer.d.ts b/src/types/node-transformers/TNodeTransformer.d.ts new file mode 100644 index 00000000..fe82ea15 --- /dev/null +++ b/src/types/node-transformers/TNodeTransformer.d.ts @@ -0,0 +1,6 @@ +import { ICustomNode } from '../../interfaces/custom-nodes/ICustomNode'; +import { INodeTransformer } from '../../interfaces/node-transformers/INodeTransformer'; +import { IOptions } from '../../interfaces/options/IOptions'; +import { IStorage } from '../../interfaces/storages/IStorage'; + +export type TNodeTransformer = (new (customNodesStorage: IStorage, options: IOptions) => INodeTransformer); diff --git a/src/types/TNodeWithBlockStatement.d.ts b/src/types/node/TNodeWithBlockStatement.d.ts similarity index 100% rename from src/types/TNodeWithBlockStatement.d.ts rename to src/types/node/TNodeWithBlockStatement.d.ts diff --git a/src/types/TStatement.d.ts b/src/types/node/TStatement.d.ts similarity index 100% rename from src/types/TStatement.d.ts rename to src/types/node/TStatement.d.ts diff --git a/src/types/TOptionsNormalizerRule.d.ts b/src/types/options/TOptionsNormalizerRule.d.ts similarity index 53% rename from src/types/TOptionsNormalizerRule.d.ts rename to src/types/options/TOptionsNormalizerRule.d.ts index 7b5ff938..11fa0bc6 100644 --- a/src/types/TOptionsNormalizerRule.d.ts +++ b/src/types/options/TOptionsNormalizerRule.d.ts @@ -1,3 +1,3 @@ -import { IOptions } from '../interfaces/IOptions'; +import { IOptions } from '../../interfaces/options/IOptions'; export type TOptionsNormalizerRule = (options: IOptions) => IOptions; diff --git a/src/types/TStringArrayEncoding.d.ts b/src/types/options/TStringArrayEncoding.d.ts similarity index 100% rename from src/types/TStringArrayEncoding.d.ts rename to src/types/options/TStringArrayEncoding.d.ts diff --git a/src/types/TObjectMembersCallsChain.d.ts b/src/types/stack-trace-analyzer/TObjectMembersCallsChain.d.ts similarity index 100% rename from src/types/TObjectMembersCallsChain.d.ts rename to src/types/stack-trace-analyzer/TObjectMembersCallsChain.d.ts diff --git a/test/functional-tests/stack-trace-analyzer/StackTraceAnalyzer.spec.ts b/test/functional-tests/stack-trace-analyzer/StackTraceAnalyzer.spec.ts index ca705c30..bc6c5f4a 100644 --- a/test/functional-tests/stack-trace-analyzer/StackTraceAnalyzer.spec.ts +++ b/test/functional-tests/stack-trace-analyzer/StackTraceAnalyzer.spec.ts @@ -4,7 +4,7 @@ import * as chai from 'chai'; import * as estraverse from 'estraverse'; import * as ESTree from 'estree'; -import { TNodeWithBlockStatement } from '../../../src/types/TNodeWithBlockStatement'; +import { TNodeWithBlockStatement } from '../../../src/types/node/TNodeWithBlockStatement'; import { IInversifyContainerFacade } from '../../../src/interfaces/container/IInversifyContainerFacade'; import { IStackTraceAnalyzer } from '../../../src/interfaces/stack-trace-analyzer/IStackTraceAnalyzer'; diff --git a/test/mocks/NodeMocks.ts b/test/mocks/NodeMocks.ts index 5802e8a4..7cdf34ca 100644 --- a/test/mocks/NodeMocks.ts +++ b/test/mocks/NodeMocks.ts @@ -1,7 +1,7 @@ import * as escodegen from 'escodegen'; import * as ESTree from 'estree'; -import { TStatement } from '../../src/types/TStatement'; +import { TStatement } from '../../src/types/node/TStatement'; import { NodeType } from '../../src/enums/NodeType'; diff --git a/test/unit-tests/OptionsNormalizer.spec.ts b/test/unit-tests/OptionsNormalizer.spec.ts index 8cffac69..3a81cf62 100644 --- a/test/unit-tests/OptionsNormalizer.spec.ts +++ b/test/unit-tests/OptionsNormalizer.spec.ts @@ -1,5 +1,5 @@ -import { IInputOptions } from '../../src/interfaces/IInputOptions'; -import { IOptions } from '../../src/interfaces/IOptions'; +import { IInputOptions } from '../../src/interfaces/options/IInputOptions'; +import { IOptions } from '../../src/interfaces/options/IOptions'; import { DEFAULT_PRESET } from '../../src/preset-options/DefaultPreset'; diff --git a/test/unit-tests/SourceMapCorrector.spec.ts b/test/unit-tests/SourceMapCorrector.spec.ts index 230b1d65..c82bfa66 100644 --- a/test/unit-tests/SourceMapCorrector.spec.ts +++ b/test/unit-tests/SourceMapCorrector.spec.ts @@ -1,35 +1,41 @@ -import { IObfuscationResult } from '../../src/interfaces/IObfuscationResult'; -import { ISourceMapCorrector } from '../../src/interfaces/ISourceMapCorrector'; +import { ServiceIdentifiers } from '../../src/container/ServiceIdentifiers'; import { TSourceMapMode } from '../../src/types/TSourceMapMode'; +import { IInversifyContainerFacade } from '../../src/interfaces/container/IInversifyContainerFacade'; +import { IObfuscationResult } from '../../src/interfaces/IObfuscationResult'; +import { ISourceMapCorrector } from '../../src/interfaces/ISourceMapCorrector'; + import { SourceMapMode } from '../../src/enums/SourceMapMode'; -import { ObfuscationResult } from '../../src/ObfuscationResult'; -import { SourceMapCorrector } from '../../src/SourceMapCorrector'; +import { InversifyContainerFacade } from '../../src/container/InversifyContainerFacade'; const assert: Chai.AssertStatic = require('chai').assert; /** * @param obfuscatedCode * @param sourceMap - * @param sourceMapUrl + * @param sourceMapBaseUrl + * @param sourceMapFileName * @param sourceMapMode */ function getCorrectedObfuscationResult ( obfuscatedCode: string, sourceMap: string, - sourceMapUrl: string, + sourceMapBaseUrl: string, + sourceMapFileName: string, sourceMapMode: TSourceMapMode ): IObfuscationResult { - let obfuscationResult: IObfuscationResult = new ObfuscationResult(obfuscatedCode, sourceMap), - sourceMapCorrector: ISourceMapCorrector = new SourceMapCorrector( - obfuscationResult, - sourceMapUrl, - sourceMapMode - ); + const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade({ + sourceMap: true, + sourceMapBaseUrl: sourceMapBaseUrl, + sourceMapFileName: sourceMapFileName, + sourceMapMode: sourceMapMode + }); + const sourceMapCorrector: ISourceMapCorrector = inversifyContainerFacade + .get(ServiceIdentifiers.ISourceMapCorrector); - return sourceMapCorrector.correct(); + return sourceMapCorrector.correct(obfuscatedCode, sourceMap); } describe('SourceMapCorrector', () => { @@ -39,7 +45,13 @@ describe('SourceMapCorrector', () => { sourceMap: string = 'test'; it('should return untouched obfuscated code if source map does not exist', () => { - expectedObfuscationResult = getCorrectedObfuscationResult(obfuscatedCode, '', '', SourceMapMode.Separate); + expectedObfuscationResult = getCorrectedObfuscationResult( + obfuscatedCode, + '', + '', + '', + SourceMapMode.Separate) + ; assert.equal(expectedObfuscationResult.getObfuscatedCode(), obfuscatedCode); }); @@ -50,6 +62,7 @@ describe('SourceMapCorrector', () => { obfuscatedCode, sourceMap, '', + '', SourceMapMode.Inline ); }); @@ -63,11 +76,12 @@ describe('SourceMapCorrector', () => { expectedObfuscationResult = getCorrectedObfuscationResult( obfuscatedCode, sourceMap, + 'http://example.com', 'output.js.map', SourceMapMode.Separate ); - assert.match(expectedObfuscationResult.getObfuscatedCode(), /sourceMappingURL=output\.js\.map/); + assert.match(expectedObfuscationResult.getObfuscatedCode(), /sourceMappingURL=http:\/\/example\.com\/output\.js\.map/); }); it('should not touch obfuscated code if source map mode is `separate` and `sourceMapUrl` is not set', () => { @@ -75,6 +89,7 @@ describe('SourceMapCorrector', () => { obfuscatedCode, sourceMap, '', + '', SourceMapMode.Separate ); diff --git a/test/unit-tests/node/NodeAppender.spec.ts b/test/unit-tests/node/NodeAppender.spec.ts index f609a710..f2eeb94b 100644 --- a/test/unit-tests/node/NodeAppender.spec.ts +++ b/test/unit-tests/node/NodeAppender.spec.ts @@ -3,7 +3,7 @@ import { ServiceIdentifiers } from '../../../src/container/ServiceIdentifiers'; import * as chai from 'chai'; import * as ESTree from 'estree'; -import { TStatement } from '../../../src/types/TStatement'; +import { TStatement } from '../../../src/types/node/TStatement'; import { IInversifyContainerFacade } from '../../../src/interfaces/container/IInversifyContainerFacade'; import { IStackTraceAnalyzer } from '../../../src/interfaces/stack-trace-analyzer/IStackTraceAnalyzer'; diff --git a/test/unit-tests/node/NodeUtils.spec.ts b/test/unit-tests/node/NodeUtils.spec.ts index 126c4838..dbf85edb 100644 --- a/test/unit-tests/node/NodeUtils.spec.ts +++ b/test/unit-tests/node/NodeUtils.spec.ts @@ -159,6 +159,88 @@ describe('NodeUtils', () => { }); }); + + describe('getNodeBlockScopeDepth (node: ESTree.Node, depth: number = 0): number', () => { + let functionDeclarationBlockStatementNode1: ESTree.BlockStatement, + functionDeclarationBlockStatementNode2: ESTree.BlockStatement, + ifStatementBlockStatementNode1: ESTree.BlockStatement, + ifStatementBlockStatementNode2: ESTree.BlockStatement, + ifStatementNode1: ESTree.IfStatement, + ifStatementNode2: ESTree.IfStatement, + expressionStatementNode1: ESTree.ExpressionStatement, + expressionStatementNode2: ESTree.ExpressionStatement, + expressionStatementNode3: ESTree.ExpressionStatement, + functionDeclarationNode1: ESTree.FunctionDeclaration, + functionDeclarationNode2: ESTree.FunctionDeclaration, + programNode: ESTree.Program; + + beforeEach(() => { + expressionStatementNode1 = NodeMocks.getExpressionStatementNode(); + expressionStatementNode2 = NodeMocks.getExpressionStatementNode(); + expressionStatementNode3 = NodeMocks.getExpressionStatementNode(); + + ifStatementBlockStatementNode2 = NodeMocks.getBlockStatementNode([ + expressionStatementNode3 + ]); + + ifStatementNode2 = NodeMocks.getIfStatementNode(ifStatementBlockStatementNode2); + + functionDeclarationBlockStatementNode2 = NodeMocks.getBlockStatementNode([ + ifStatementNode2, + expressionStatementNode2 + ]); + + functionDeclarationNode2 = NodeMocks.getFunctionDeclarationNode('test', functionDeclarationBlockStatementNode2); + + ifStatementBlockStatementNode1 = NodeMocks.getBlockStatementNode([ + functionDeclarationNode2 + ]); + + ifStatementNode1 = NodeMocks.getIfStatementNode(ifStatementBlockStatementNode1); + + functionDeclarationBlockStatementNode1 = NodeMocks.getBlockStatementNode([ + expressionStatementNode1, + ifStatementNode1 + ]); + + functionDeclarationNode1 = NodeMocks.getFunctionDeclarationNode('test', functionDeclarationBlockStatementNode1); + + programNode = NodeMocks.getProgramNode([ + functionDeclarationNode1 + ]); + + programNode['parentNode'] = programNode; + functionDeclarationNode1['parentNode'] = programNode; + functionDeclarationBlockStatementNode1['parentNode'] = functionDeclarationNode1; + expressionStatementNode1['parentNode'] = functionDeclarationBlockStatementNode1; + ifStatementNode1['parentNode'] = functionDeclarationBlockStatementNode1; + ifStatementBlockStatementNode1['parentNode'] = ifStatementNode1; + functionDeclarationNode2['parentNode'] = ifStatementBlockStatementNode1; + functionDeclarationBlockStatementNode2['parentNode'] = functionDeclarationNode2; + expressionStatementNode2['parentNode'] = functionDeclarationBlockStatementNode2; + ifStatementNode2['parentNode'] = functionDeclarationBlockStatementNode2; + ifStatementBlockStatementNode2['parentNode'] = ifStatementNode2; + }); + + it('should return block-scope depth for given node', () => { + assert.deepEqual(NodeUtils.getNodeBlockScopeDepth(programNode), 0); + assert.deepEqual(NodeUtils.getNodeBlockScopeDepth(functionDeclarationNode1), 0); + assert.deepEqual(NodeUtils.getNodeBlockScopeDepth(functionDeclarationBlockStatementNode1), 1); + assert.deepEqual(NodeUtils.getNodeBlockScopeDepth(expressionStatementNode1), 1); + assert.deepEqual(NodeUtils.getNodeBlockScopeDepth(ifStatementNode1), 1); + assert.deepEqual(NodeUtils.getNodeBlockScopeDepth(ifStatementBlockStatementNode1), 1); + assert.deepEqual(NodeUtils.getNodeBlockScopeDepth(functionDeclarationNode2), 1); + assert.deepEqual(NodeUtils.getNodeBlockScopeDepth(functionDeclarationBlockStatementNode2), 2); + assert.deepEqual(NodeUtils.getNodeBlockScopeDepth(expressionStatementNode2), 2); + assert.deepEqual(NodeUtils.getNodeBlockScopeDepth(ifStatementNode2), 2); + assert.deepEqual(NodeUtils.getNodeBlockScopeDepth(ifStatementBlockStatementNode2), 2); + }); + + it('should throw a `ReferenceError` if node has no `parentNode` property', () => { + assert.throws(() => NodeUtils.getNodeBlockScopeDepth(expressionStatementNode3), ReferenceError); + }); + }); + describe('parentize (node: ESTree.Node): void', () => { let ifStatementNode: ESTree.IfStatement, ifStatementBlockStatementNode: ESTree.BlockStatement,