diff --git a/dist/index.js b/dist/index.js index 78ef97bf..dc97d70b 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 = 120); +/******/ return __webpack_require__(__webpack_require__.s = 121); /******/ }) /************************************************************************/ /******/ ([ @@ -141,9 +141,8 @@ 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__(111); var JSFuck_1 = __webpack_require__(28); -var isEqual = __webpack_require__(116); +var isEqual = __webpack_require__(117); var Utils = function () { function Utils() { @@ -172,23 +171,6 @@ var Utils = function () { } return newArray; } - }, { - key: 'btoa', - value: function btoa(string) { - var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; - var output = ''; - string = encodeURIComponent(string).replace(/%([0-9A-F]{2})/g, function (match, 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); - if (charCode > 0xFF) { - throw new Error("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range."); - } - block = block << 8 | charCode; - } - return output; - } }, { key: 'decToHex', value: function decToHex(dec) { @@ -207,70 +189,6 @@ var Utils = function () { domain = domain.split(':')[0]; return domain; } - }, { - key: 'getRandomFloat', - value: function getRandomFloat(min, max) { - return Utils.randomGenerator.floating({ - min: min, - max: max, - fixed: 7 - }); - } - }, { - key: 'getRandomGenerator', - value: function getRandomGenerator() { - var randomGenerator = Utils.randomGenerator; - if (!randomGenerator) { - throw new Error('`randomGenerator` static property is undefined'); - } - return Utils.randomGenerator; - } - }, { - key: 'getRandomInteger', - value: function getRandomInteger(min, max) { - return Utils.randomGenerator.integer({ - min: min, - max: max - }); - } - }, { - key: 'getRandomVariableName', - value: function getRandomVariableName() { - var length = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 6; - - var rangeMinInteger = 10000, - rangeMaxInteger = 99999999; - return '_' + Utils.hexadecimalPrefix + Utils.decToHex(Utils.getRandomInteger(rangeMinInteger, rangeMaxInteger)).substr(0, length); - } - }, { - key: 'hideString', - value: function hideString(str, length) { - var escapeRegExp = function escapeRegExp(s) { - return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); - }; - var randomMerge = function randomMerge(s1, s2) { - var i1 = -1, - i2 = -1, - result = ''; - while (i1 < s1.length || i2 < s2.length) { - if (Utils.getRandomFloat(0, 1) < 0.5 && i2 < s2.length) { - result += s2.charAt(++i2); - } else { - result += s1.charAt(++i1); - } - } - return result; - }; - var randomString = Utils.randomGenerator.string({ - length: length, - pool: Utils.randomGeneratorPool - }); - var randomStringDiff = randomString.replace(new RegExp('[' + escapeRegExp(str) + ']', 'g'), ''); - var randomStringDiffArray = randomStringDiff.split(''); - Utils.randomGenerator.shuffle(randomStringDiffArray); - randomStringDiff = randomStringDiffArray.join(''); - return [randomMerge(str, randomStringDiff), randomStringDiff]; - } }, { key: 'isInteger', value: function isInteger(number) { @@ -310,39 +228,6 @@ var Utils = function () { return null; } - }, { - key: 'rc4', - value: function rc4(string, key) { - var s = [], - j = 0, - x = void 0, - result = ''; - for (var i = 0; i < 256; i++) { - s[i] = i; - } - for (i = 0; i < 256; i++) { - j = (j + s[i] + key.charCodeAt(i % key.length)) % 256; - x = s[i]; - s[i] = s[j]; - s[j] = x; - } - i = 0; - j = 0; - for (var y = 0; y < string.length; y++) { - i = (i + 1) % 256; - j = (j + s[i]) % 256; - x = s[i]; - s[i] = s[j]; - s[j] = x; - result += String.fromCharCode(string.charCodeAt(y) ^ s[(s[i] + s[j]) % 256]); - } - return result; - } - }, { - key: 'setRandomGeneratorSeed', - value: function setRandomGeneratorSeed(randomGeneratorSeed) { - Utils.randomGenerator = new chance_1.Chance(randomGeneratorSeed); - } }, { key: 'strEnumify', value: function strEnumify(obj) { @@ -379,9 +264,6 @@ var Utils = function () { }(); Utils.hexadecimalPrefix = '0x'; -Utils.randomGeneratorPool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; -Utils.randomGeneratorPoolWithNumbers = Utils.randomGeneratorPool + '0123456789'; -Utils.randomGenerator = new chance_1.Chance(); exports.Utils = Utils; /***/ }, @@ -441,7 +323,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 NodeType_1 = __webpack_require__(9); +var NodeType_1 = __webpack_require__(8); var Node = function () { function Node() { @@ -575,25 +457,12 @@ exports.Node = Node; /***/ }, /* 5 */ -/***/ function(module, exports, __webpack_require__) { - -"use strict"; -"use strict"; - -var Utils_1 = __webpack_require__(2); -exports.ObfuscationEvents = Utils_1.Utils.strEnumify({ - AfterObfuscation: 'afterObfuscation', - BeforeObfuscation: 'beforeObfuscation' -}); - -/***/ }, -/* 6 */ /***/ function(module, exports) { module.exports = require("estraverse"); /***/ }, -/* 7 */ +/* 6 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -623,7 +492,7 @@ var __param = undefined && undefined.__param || function (paramIndex, decorator) }; var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); -var NodeUtils_1 = __webpack_require__(10); +var NodeUtils_1 = __webpack_require__(9); var AbstractCustomNode = function () { function AbstractCustomNode(options) { _classCallCheck(this, AbstractCustomNode); @@ -649,13 +518,13 @@ AbstractCustomNode = __decorate([inversify_1.injectable(), __param(0, inversify_ exports.AbstractCustomNode = AbstractCustomNode; /***/ }, -/* 8 */ +/* 7 */ /***/ function(module, exports) { module.exports = require("string-template"); /***/ }, -/* 9 */ +/* 8 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -696,7 +565,7 @@ exports.NodeType = Utils_1.Utils.strEnumify({ }); /***/ }, -/* 10 */ +/* 9 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -708,8 +577,8 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons var escodegen = __webpack_require__(16); var esprima = __webpack_require__(34); -var estraverse = __webpack_require__(6); -var NodeType_1 = __webpack_require__(9); +var estraverse = __webpack_require__(5); +var NodeType_1 = __webpack_require__(8); var Node_1 = __webpack_require__(4); var Utils_1 = __webpack_require__(2); @@ -848,7 +717,7 @@ NodeUtils.nodesWithBlockScope = [NodeType_1.NodeType.ArrowFunctionExpression, No exports.NodeUtils = NodeUtils; /***/ }, -/* 11 */ +/* 10 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -885,7 +754,7 @@ AbstractNodeTransformer = __decorate([inversify_1.injectable(), __param(0, inver exports.AbstractNodeTransformer = AbstractNodeTransformer; /***/ }, -/* 12 */ +/* 11 */ /***/ function(module, exports) { "use strict"; @@ -899,6 +768,19 @@ exports.AbstractNodeTransformer = AbstractNodeTransformer; })(exports.NodeObfuscatorsReplacers || (exports.NodeObfuscatorsReplacers = {})); var NodeObfuscatorsReplacers = exports.NodeObfuscatorsReplacers; +/***/ }, +/* 12 */ +/***/ function(module, exports, __webpack_require__) { + +"use strict"; +"use strict"; + +var Utils_1 = __webpack_require__(2); +exports.ObfuscationEvents = Utils_1.Utils.strEnumify({ + AfterObfuscation: 'afterObfuscation', + BeforeObfuscation: 'beforeObfuscation' +}); + /***/ }, /* 13 */ /***/ function(module, exports) { @@ -934,9 +816,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"); } } -__webpack_require__(118); +__webpack_require__(119); if (!global._babelPolyfill) { - __webpack_require__(110); + __webpack_require__(111); } var InversifyContainerFacade_1 = __webpack_require__(42); var JavaScriptObfuscatorCLI_1 = __webpack_require__(41); @@ -981,7 +863,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } -var Utils_1 = __webpack_require__(2); +var RandomGeneratorUtils_1 = __webpack_require__(110); var NodeAppender = function () { function NodeAppender() { @@ -1028,7 +910,7 @@ var NodeAppender = function () { }, { key: 'getRandomStackTraceIndex', value: function getRandomStackTraceIndex(stackTraceRootLength) { - return Utils_1.Utils.getRandomInteger(0, Math.max(0, Math.round(stackTraceRootLength - 1))); + return RandomGeneratorUtils_1.RandomGeneratorUtils.getRandomInteger(0, Math.max(0, Math.round(stackTraceRootLength - 1))); } }, { key: 'insertNodeAtIndex', @@ -1332,11 +1214,11 @@ var __param = undefined && undefined.__param || function (paramIndex, decorator) }; var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); -var format = __webpack_require__(8); +var format = __webpack_require__(7); var Initializable_1 = __webpack_require__(3); var BinaryExpressionFunctionTemplate_1 = __webpack_require__(95); -var AbstractCustomNode_1 = __webpack_require__(7); -var Utils_1 = __webpack_require__(2); +var AbstractCustomNode_1 = __webpack_require__(6); +var RandomGeneratorUtils_1 = __webpack_require__(110); var BinaryExpressionFunctionNode = function (_AbstractCustomNode_) { _inherits(BinaryExpressionFunctionNode, _AbstractCustomNode_); @@ -1355,7 +1237,7 @@ var BinaryExpressionFunctionNode = function (_AbstractCustomNode_) { key: "getCode", value: function getCode() { return format(BinaryExpressionFunctionTemplate_1.BinaryExpressionFunctionTemplate(), { - functionName: Utils_1.Utils.getRandomVariableName(1), + functionName: RandomGeneratorUtils_1.RandomGeneratorUtils.getRandomVariableName(1), operator: this.operator }); } @@ -1402,10 +1284,10 @@ var __param = undefined && undefined.__param || function (paramIndex, decorator) }; var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); -var format = __webpack_require__(8); +var format = __webpack_require__(7); var Initializable_1 = __webpack_require__(3); var ControlFlowStorageCallTemplate_1 = __webpack_require__(96); -var AbstractCustomNode_1 = __webpack_require__(7); +var AbstractCustomNode_1 = __webpack_require__(6); var ControlFlowStorageCallNode = function (_AbstractCustomNode_) { _inherits(ControlFlowStorageCallNode, _AbstractCustomNode_); @@ -1479,10 +1361,10 @@ var __param = undefined && undefined.__param || function (paramIndex, decorator) }; var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); -var format = __webpack_require__(8); +var format = __webpack_require__(7); var Initializable_1 = __webpack_require__(3); var ControlFlowStorageTemplate_1 = __webpack_require__(97); -var AbstractCustomNode_1 = __webpack_require__(7); +var AbstractCustomNode_1 = __webpack_require__(6); var ControlFlowStorageNode = function (_AbstractCustomNode_) { _inherits(ControlFlowStorageNode, _AbstractCustomNode_); @@ -1552,10 +1434,10 @@ var __param = undefined && undefined.__param || function (paramIndex, decorator) }; var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); -var format = __webpack_require__(8); +var format = __webpack_require__(7); var Initializable_1 = __webpack_require__(3); var StringArrayTemplate_1 = __webpack_require__(107); -var AbstractCustomNode_1 = __webpack_require__(7); +var AbstractCustomNode_1 = __webpack_require__(6); var StringArrayNode = function (_AbstractCustomNode_) { _inherits(StringArrayNode, _AbstractCustomNode_); @@ -1923,7 +1805,7 @@ var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); var esprima = __webpack_require__(34); var escodegen = __webpack_require__(16); -var Utils_1 = __webpack_require__(2); +var RandomGeneratorUtils_1 = __webpack_require__(110); var JavaScriptObfuscatorInternal_1 = function () { function JavaScriptObfuscatorInternal(obfuscator, sourceMapCorrector, options) { _classCallCheck(this, JavaScriptObfuscatorInternal); @@ -1957,7 +1839,7 @@ var JavaScriptObfuscatorInternal_1 = function () { key: "obfuscate", value: function obfuscate(sourceCode) { if (this.options.seed !== 0) { - Utils_1.Utils.setRandomGeneratorSeed(this.options.seed); + RandomGeneratorUtils_1.RandomGeneratorUtils.setRandomGeneratorSeed(this.options.seed); } var astTree = esprima.parse(sourceCode, JavaScriptObfuscatorInternal_1.esprimaParams); var obfuscatedAstTree = this.obfuscator.obfuscateAstTree(astTree); @@ -2073,13 +1955,13 @@ var __param = undefined && undefined.__param || function (paramIndex, decorator) }; var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); -var estraverse = __webpack_require__(6); +var estraverse = __webpack_require__(5); var NodeTransformers_1 = __webpack_require__(30); -var NodeType_1 = __webpack_require__(9); -var ObfuscationEvents_1 = __webpack_require__(5); +var NodeType_1 = __webpack_require__(8); +var ObfuscationEvents_1 = __webpack_require__(12); var VisitorDirection_1 = __webpack_require__(62); var Node_1 = __webpack_require__(4); -var NodeUtils_1 = __webpack_require__(10); +var NodeUtils_1 = __webpack_require__(9); var Obfuscator_1 = function () { function Obfuscator(stackTraceAnalyzer, obfuscationEventEmitter, customNodeGroupStorage, nodeTransformersFactory, options) { _classCallCheck(this, Obfuscator); @@ -2165,7 +2047,7 @@ var __param = undefined && undefined.__param || function (paramIndex, decorator) var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); var SourceMapMode_1 = __webpack_require__(18); -var Utils_1 = __webpack_require__(2); +var CryptUtils_1 = __webpack_require__(122); var SourceMapCorrector = function () { function SourceMapCorrector(obfuscationResultFactory, options) { _classCallCheck(this, SourceMapCorrector); @@ -2189,7 +2071,7 @@ var SourceMapCorrector = function () { var sourceMappingUrl = '//# sourceMappingURL='; switch (this.options.sourceMapMode) { case SourceMapMode_1.SourceMapMode.Inline: - sourceMappingUrl += "data:application/json;base64," + Utils_1.Utils.btoa(sourceMap); + sourceMappingUrl += "data:application/json;base64," + CryptUtils_1.CryptUtils.btoa(sourceMap); break; case SourceMapMode_1.SourceMapMode.Separate: default: @@ -2219,8 +2101,8 @@ 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__(115); -var mkdirp = __webpack_require__(117); +var fs = __webpack_require__(116); +var mkdirp = __webpack_require__(118); var path = __webpack_require__(35); var Utils_1 = __webpack_require__(2); @@ -2311,7 +2193,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 commander = __webpack_require__(113); +var commander = __webpack_require__(114); var path = __webpack_require__(35); var SourceMapMode_1 = __webpack_require__(18); var StringArrayEncoding_1 = __webpack_require__(21); @@ -2614,7 +2496,7 @@ exports.nodeControlFlowTransformersModule = new inversify_1.ContainerModule(func var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); -var NodeObfuscatorsReplacers_1 = __webpack_require__(12); +var NodeObfuscatorsReplacers_1 = __webpack_require__(11); var BooleanLiteralReplacer_1 = __webpack_require__(76); var IdentifierReplacer_1 = __webpack_require__(77); var NumberLiteralReplacer_1 = __webpack_require__(78); @@ -2757,11 +2639,11 @@ var __param = undefined && undefined.__param || function (paramIndex, decorator) }; var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); -var format = __webpack_require__(8); +var format = __webpack_require__(7); var ConsoleOutputDisableExpressionTemplate_1 = __webpack_require__(94); var Initializable_1 = __webpack_require__(3); -var AbstractCustomNode_1 = __webpack_require__(7); -var Utils_1 = __webpack_require__(2); +var AbstractCustomNode_1 = __webpack_require__(6); +var RandomGeneratorUtils_1 = __webpack_require__(110); var ConsoleOutputDisableExpressionNode = function (_AbstractCustomNode_) { _inherits(ConsoleOutputDisableExpressionNode, _AbstractCustomNode_); @@ -2780,7 +2662,7 @@ var ConsoleOutputDisableExpressionNode = function (_AbstractCustomNode_) { key: "getCode", value: function getCode() { return format(ConsoleOutputDisableExpressionTemplate_1.ConsoleOutputDisableExpressionTemplate(), { - consoleLogDisableFunctionName: Utils_1.Utils.getRandomVariableName(), + consoleLogDisableFunctionName: RandomGeneratorUtils_1.RandomGeneratorUtils.getRandomVariableName(), singleNodeCallControllerFunctionName: this.callsControllerFunctionName }); } @@ -2829,10 +2711,10 @@ var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); var Initializable_1 = __webpack_require__(3); var CustomNodes_1 = __webpack_require__(13); -var ObfuscationEvents_1 = __webpack_require__(5); +var ObfuscationEvents_1 = __webpack_require__(12); var AbstractCustomNodeGroup_1 = __webpack_require__(17); var NodeAppender_1 = __webpack_require__(15); -var Utils_1 = __webpack_require__(2); +var RandomGeneratorUtils_1 = __webpack_require__(110); var ConsoleOutputCustomNodeGroup = function (_AbstractCustomNodeGr) { _inherits(ConsoleOutputCustomNodeGroup, _AbstractCustomNodeGr); @@ -2871,7 +2753,7 @@ var ConsoleOutputCustomNodeGroup = function (_AbstractCustomNodeGr) { if (!this.options.disableConsoleOutput) { return; } - var callsControllerFunctionName = Utils_1.Utils.getRandomVariableName(); + var callsControllerFunctionName = RandomGeneratorUtils_1.RandomGeneratorUtils.getRandomVariableName(); var consoleOutputDisableExpressionNode = this.customNodeFactory(CustomNodes_1.CustomNodes.ConsoleOutputDisableExpressionNode); var nodeCallsControllerFunctionNode = this.customNodeFactory(CustomNodes_1.CustomNodes.NodeCallsControllerFunctionNode); consoleOutputDisableExpressionNode.initialize(callsControllerFunctionName); @@ -2922,10 +2804,10 @@ var __param = undefined && undefined.__param || function (paramIndex, decorator) }; var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); -var format = __webpack_require__(8); +var format = __webpack_require__(7); var Initializable_1 = __webpack_require__(3); var DebufProtectionFunctionCallTemplate_1 = __webpack_require__(98); -var AbstractCustomNode_1 = __webpack_require__(7); +var AbstractCustomNode_1 = __webpack_require__(6); var DebugProtectionFunctionCallNode = function (_AbstractCustomNode_) { _inherits(DebugProtectionFunctionCallNode, _AbstractCustomNode_); @@ -2990,10 +2872,10 @@ var __param = undefined && undefined.__param || function (paramIndex, decorator) }; var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); -var format = __webpack_require__(8); +var format = __webpack_require__(7); var Initializable_1 = __webpack_require__(3); var DebugProtectionFunctionIntervalTemplate_1 = __webpack_require__(99); -var AbstractCustomNode_1 = __webpack_require__(7); +var AbstractCustomNode_1 = __webpack_require__(6); var DebugProtectionFunctionIntervalNode = function (_AbstractCustomNode_) { _inherits(DebugProtectionFunctionIntervalNode, _AbstractCustomNode_); @@ -3058,10 +2940,10 @@ var __param = undefined && undefined.__param || function (paramIndex, decorator) }; var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); -var format = __webpack_require__(8); +var format = __webpack_require__(7); var Initializable_1 = __webpack_require__(3); var DebugProtectionFunctionTemplate_1 = __webpack_require__(100); -var AbstractCustomNode_1 = __webpack_require__(7); +var AbstractCustomNode_1 = __webpack_require__(6); var DebugProtectionFunctionNode = function (_AbstractCustomNode_) { _inherits(DebugProtectionFunctionNode, _AbstractCustomNode_); @@ -3128,10 +3010,10 @@ var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); var Initializable_1 = __webpack_require__(3); var CustomNodes_1 = __webpack_require__(13); -var ObfuscationEvents_1 = __webpack_require__(5); +var ObfuscationEvents_1 = __webpack_require__(12); var AbstractCustomNodeGroup_1 = __webpack_require__(17); var NodeAppender_1 = __webpack_require__(15); -var Utils_1 = __webpack_require__(2); +var RandomGeneratorUtils_1 = __webpack_require__(110); var DebugProtectionCustomNodeGroup = function (_AbstractCustomNodeGr) { _inherits(DebugProtectionCustomNodeGroup, _AbstractCustomNodeGr); @@ -3157,7 +3039,7 @@ var DebugProtectionCustomNodeGroup = function (_AbstractCustomNodeGr) { }); this.appendCustomNodeIfExist(CustomNodes_1.CustomNodes.DebugProtectionFunctionIntervalNode, function (customNode) { var programBodyLength = blockScopeNode.body.length; - var randomIndex = Utils_1.Utils.getRandomInteger(0, programBodyLength); + var randomIndex = RandomGeneratorUtils_1.RandomGeneratorUtils.getRandomInteger(0, programBodyLength); NodeAppender_1.NodeAppender.insertNodeAtIndex(blockScopeNode, customNode.getNode(), randomIndex); }); } @@ -3168,7 +3050,7 @@ var DebugProtectionCustomNodeGroup = function (_AbstractCustomNodeGr) { if (!this.options.debugProtection) { return; } - var debugProtectionFunctionName = Utils_1.Utils.getRandomVariableName(); + var debugProtectionFunctionName = RandomGeneratorUtils_1.RandomGeneratorUtils.getRandomVariableName(); var debugProtectionFunctionNode = this.customNodeFactory(CustomNodes_1.CustomNodes.DebugProtectionFunctionNode); var debugProtectionFunctionCallNode = this.customNodeFactory(CustomNodes_1.CustomNodes.DebugProtectionFunctionCallNode); var debugProtectionFunctionIntervalNode = this.customNodeFactory(CustomNodes_1.CustomNodes.DebugProtectionFunctionIntervalNode); @@ -3226,11 +3108,12 @@ var __param = undefined && undefined.__param || function (paramIndex, decorator) }; var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); -var format = __webpack_require__(8); +var format = __webpack_require__(7); var Initializable_1 = __webpack_require__(3); var DomainLockNodeTemplate_1 = __webpack_require__(101); -var AbstractCustomNode_1 = __webpack_require__(7); -var Utils_1 = __webpack_require__(2); +var AbstractCustomNode_1 = __webpack_require__(6); +var CryptUtils_1 = __webpack_require__(122); +var RandomGeneratorUtils_1 = __webpack_require__(110); var DomainLockNode = function (_AbstractCustomNode_) { _inherits(DomainLockNode, _AbstractCustomNode_); @@ -3249,12 +3132,12 @@ var DomainLockNode = function (_AbstractCustomNode_) { key: "getCode", value: function getCode() { var domainsString = this.options.domainLock.join(';'), - _Utils_1$Utils$hideSt = Utils_1.Utils.hideString(domainsString, domainsString.length * 3), - _Utils_1$Utils$hideSt2 = _slicedToArray(_Utils_1$Utils$hideSt, 2), - hiddenDomainsString = _Utils_1$Utils$hideSt2[0], - diff = _Utils_1$Utils$hideSt2[1]; + _CryptUtils_1$CryptUt = CryptUtils_1.CryptUtils.hideString(domainsString, domainsString.length * 3), + _CryptUtils_1$CryptUt2 = _slicedToArray(_CryptUtils_1$CryptUt, 2), + hiddenDomainsString = _CryptUtils_1$CryptUt2[0], + diff = _CryptUtils_1$CryptUt2[1]; return format(DomainLockNodeTemplate_1.DomainLockNodeTemplate(), { - domainLockFunctionName: Utils_1.Utils.getRandomVariableName(), + domainLockFunctionName: RandomGeneratorUtils_1.RandomGeneratorUtils.getRandomVariableName(), diff: diff, domains: hiddenDomainsString, singleNodeCallControllerFunctionName: this.callsControllerFunctionName @@ -3305,10 +3188,10 @@ var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); var Initializable_1 = __webpack_require__(3); var CustomNodes_1 = __webpack_require__(13); -var ObfuscationEvents_1 = __webpack_require__(5); +var ObfuscationEvents_1 = __webpack_require__(12); var AbstractCustomNodeGroup_1 = __webpack_require__(17); var NodeAppender_1 = __webpack_require__(15); -var Utils_1 = __webpack_require__(2); +var RandomGeneratorUtils_1 = __webpack_require__(110); var DomainLockCustomNodeGroup = function (_AbstractCustomNodeGr) { _inherits(DomainLockCustomNodeGroup, _AbstractCustomNodeGr); @@ -3347,7 +3230,7 @@ var DomainLockCustomNodeGroup = function (_AbstractCustomNodeGr) { if (!this.options.domainLock.length) { return; } - var callsControllerFunctionName = Utils_1.Utils.getRandomVariableName(); + var callsControllerFunctionName = RandomGeneratorUtils_1.RandomGeneratorUtils.getRandomVariableName(); var domainLockNode = this.customNodeFactory(CustomNodes_1.CustomNodes.DomainLockNode); var nodeCallsControllerFunctionNode = this.customNodeFactory(CustomNodes_1.CustomNodes.NodeCallsControllerFunctionNode); domainLockNode.initialize(callsControllerFunctionName); @@ -3398,12 +3281,12 @@ var __param = undefined && undefined.__param || function (paramIndex, decorator) }; var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); -var format = __webpack_require__(8); -var ObfuscationEvents_1 = __webpack_require__(5); +var format = __webpack_require__(7); +var ObfuscationEvents_1 = __webpack_require__(12); var Initializable_1 = __webpack_require__(3); var SingleNodeCallControllerTemplate_1 = __webpack_require__(93); var NoCustomNodesPreset_1 = __webpack_require__(20); -var AbstractCustomNode_1 = __webpack_require__(7); +var AbstractCustomNode_1 = __webpack_require__(6); var JavaScriptObfuscator_1 = __webpack_require__(14); var NodeCallsControllerFunctionNode = function (_AbstractCustomNode_) { _inherits(NodeCallsControllerFunctionNode, _AbstractCustomNode_); @@ -3478,13 +3361,13 @@ var __param = undefined && undefined.__param || function (paramIndex, decorator) }; var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); -var format = __webpack_require__(8); +var format = __webpack_require__(7); var Initializable_1 = __webpack_require__(3); var NoCustomNodesPreset_1 = __webpack_require__(20); var SelfDefendingTemplate_1 = __webpack_require__(102); -var AbstractCustomNode_1 = __webpack_require__(7); +var AbstractCustomNode_1 = __webpack_require__(6); var JavaScriptObfuscator_1 = __webpack_require__(14); -var Utils_1 = __webpack_require__(2); +var RandomGeneratorUtils_1 = __webpack_require__(110); var SelfDefendingUnicodeNode = function (_AbstractCustomNode_) { _inherits(SelfDefendingUnicodeNode, _AbstractCustomNode_); @@ -3503,7 +3386,7 @@ var SelfDefendingUnicodeNode = function (_AbstractCustomNode_) { key: "getCode", value: function getCode() { return JavaScriptObfuscator_1.JavaScriptObfuscator.obfuscate(format(SelfDefendingTemplate_1.SelfDefendingTemplate(), { - selfDefendingFunctionName: Utils_1.Utils.getRandomVariableName(), + selfDefendingFunctionName: RandomGeneratorUtils_1.RandomGeneratorUtils.getRandomVariableName(), singleNodeCallControllerFunctionName: this.callsControllerFunctionName }), Object.assign({}, NoCustomNodesPreset_1.NO_CUSTOM_NODES_PRESET, { seed: this.options.seed @@ -3554,10 +3437,10 @@ var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); var Initializable_1 = __webpack_require__(3); var CustomNodes_1 = __webpack_require__(13); -var ObfuscationEvents_1 = __webpack_require__(5); +var ObfuscationEvents_1 = __webpack_require__(12); var AbstractCustomNodeGroup_1 = __webpack_require__(17); var NodeAppender_1 = __webpack_require__(15); -var Utils_1 = __webpack_require__(2); +var RandomGeneratorUtils_1 = __webpack_require__(110); var SelfDefendingCustomNodeGroup = function (_AbstractCustomNodeGr) { _inherits(SelfDefendingCustomNodeGroup, _AbstractCustomNodeGr); @@ -3596,7 +3479,7 @@ var SelfDefendingCustomNodeGroup = function (_AbstractCustomNodeGr) { if (!this.options.selfDefending) { return; } - var callsControllerFunctionName = Utils_1.Utils.getRandomVariableName(); + var callsControllerFunctionName = RandomGeneratorUtils_1.RandomGeneratorUtils.getRandomVariableName(); var selfDefendingUnicodeNode = this.customNodeFactory(CustomNodes_1.CustomNodes.SelfDefendingUnicodeNode); var nodeCallsControllerFunctionNode = this.customNodeFactory(CustomNodes_1.CustomNodes.NodeCallsControllerFunctionNode); selfDefendingUnicodeNode.initialize(callsControllerFunctionName); @@ -3647,7 +3530,7 @@ var __param = undefined && undefined.__param || function (paramIndex, decorator) }; var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); -var format = __webpack_require__(8); +var format = __webpack_require__(7); var StringArrayEncoding_1 = __webpack_require__(21); var Initializable_1 = __webpack_require__(3); var NoCustomNodesPreset_1 = __webpack_require__(20); @@ -3657,7 +3540,7 @@ var SelfDefendingTemplate_1 = __webpack_require__(103); var StringArrayBase64DecodeNodeTemplate_1 = __webpack_require__(104); var StringArrayCallsWrapperTemplate_1 = __webpack_require__(105); var StringArrayRC4DecodeNodeTemplate_1 = __webpack_require__(106); -var AbstractCustomNode_1 = __webpack_require__(7); +var AbstractCustomNode_1 = __webpack_require__(6); var JavaScriptObfuscator_1 = __webpack_require__(14); var StringArrayCallsWrapper = function (_AbstractCustomNode_) { _inherits(StringArrayCallsWrapper, _AbstractCustomNode_); @@ -3767,13 +3650,14 @@ var __param = undefined && undefined.__param || function (paramIndex, decorator) }; var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); -var format = __webpack_require__(8); +var format = __webpack_require__(7); var Initializable_1 = __webpack_require__(3); var NoCustomNodesPreset_1 = __webpack_require__(20); var SelfDefendingTemplate_1 = __webpack_require__(108); var StringArrayRotateFunctionTemplate_1 = __webpack_require__(109); -var AbstractCustomNode_1 = __webpack_require__(7); +var AbstractCustomNode_1 = __webpack_require__(6); var JavaScriptObfuscator_1 = __webpack_require__(14); +var RandomGeneratorUtils_1 = __webpack_require__(110); var Utils_1 = __webpack_require__(2); var StringArrayRotateFunctionNode = function (_AbstractCustomNode_) { _inherits(StringArrayRotateFunctionNode, _AbstractCustomNode_); @@ -3795,8 +3679,8 @@ var StringArrayRotateFunctionNode = function (_AbstractCustomNode_) { key: "getCode", value: function getCode() { var code = '', - timesName = Utils_1.Utils.getRandomVariableName(), - whileFunctionName = Utils_1.Utils.getRandomVariableName(); + timesName = RandomGeneratorUtils_1.RandomGeneratorUtils.getRandomVariableName(), + whileFunctionName = RandomGeneratorUtils_1.RandomGeneratorUtils.getRandomVariableName(); if (this.options.selfDefending) { code = format(SelfDefendingTemplate_1.SelfDefendingTemplate(), { timesName: timesName, @@ -3862,12 +3746,12 @@ var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); var Initializable_1 = __webpack_require__(3); var CustomNodes_1 = __webpack_require__(13); -var ObfuscationEvents_1 = __webpack_require__(5); +var ObfuscationEvents_1 = __webpack_require__(12); var StringArrayNode_1 = __webpack_require__(27); var AbstractCustomNodeGroup_1 = __webpack_require__(17); var NodeAppender_1 = __webpack_require__(15); +var RandomGeneratorUtils_1 = __webpack_require__(110); var StringArrayStorage_1 = __webpack_require__(90); -var Utils_1 = __webpack_require__(2); var StringArrayCustomNodeGroup = function (_AbstractCustomNodeGr) { _inherits(StringArrayCustomNodeGroup, _AbstractCustomNodeGr); @@ -3909,11 +3793,11 @@ var StringArrayCustomNodeGroup = function (_AbstractCustomNodeGr) { var stringArrayNode = this.customNodeFactory(CustomNodes_1.CustomNodes.StringArrayNode); var stringArrayCallsWrapper = this.customNodeFactory(CustomNodes_1.CustomNodes.StringArrayCallsWrapper); var stringArrayRotateFunctionNode = this.customNodeFactory(CustomNodes_1.CustomNodes.StringArrayRotateFunctionNode); - var stringArrayName = Utils_1.Utils.getRandomVariableName(StringArrayNode_1.StringArrayNode.ARRAY_RANDOM_LENGTH); - var stringArrayCallsWrapperName = Utils_1.Utils.getRandomVariableName(StringArrayNode_1.StringArrayNode.ARRAY_RANDOM_LENGTH); + var stringArrayName = RandomGeneratorUtils_1.RandomGeneratorUtils.getRandomVariableName(StringArrayNode_1.StringArrayNode.ARRAY_RANDOM_LENGTH); + var stringArrayCallsWrapperName = RandomGeneratorUtils_1.RandomGeneratorUtils.getRandomVariableName(StringArrayNode_1.StringArrayNode.ARRAY_RANDOM_LENGTH); var stringArrayRotateValue = void 0; if (this.options.rotateStringArray) { - stringArrayRotateValue = Utils_1.Utils.getRandomInteger(100, 500); + stringArrayRotateValue = RandomGeneratorUtils_1.RandomGeneratorUtils.getRandomInteger(100, 500); } else { stringArrayRotateValue = 0; } @@ -3987,7 +3871,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__(0); -var events_1 = __webpack_require__(114); +var events_1 = __webpack_require__(115); inversify_1.decorate(inversify_1.injectable(), events_1.EventEmitter); var ObfuscationEventEmitter = function (_events_1$EventEmitte) { _inherits(ObfuscationEventEmitter, _events_1$EventEmitte); @@ -4038,15 +3922,15 @@ var __param = undefined && undefined.__param || function (paramIndex, decorator) }; var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); -var estraverse = __webpack_require__(6); -var NodeType_1 = __webpack_require__(9); -var AbstractNodeTransformer_1 = __webpack_require__(11); +var estraverse = __webpack_require__(5); +var NodeType_1 = __webpack_require__(8); +var AbstractNodeTransformer_1 = __webpack_require__(10); var BinaryExpressionControlFlowReplacer_1 = __webpack_require__(31); var ControlFlowStorage_1 = __webpack_require__(88); var ControlFlowStorageNode_1 = __webpack_require__(26); var Node_1 = __webpack_require__(4); var NodeAppender_1 = __webpack_require__(15); -var Utils_1 = __webpack_require__(2); +var RandomGeneratorUtils_1 = __webpack_require__(110); var FunctionControlFlowTransformer_1 = function (_AbstractNodeTransfor) { _inherits(FunctionControlFlowTransformer, _AbstractNodeTransfor); @@ -4070,7 +3954,7 @@ var FunctionControlFlowTransformer_1 = function (_AbstractNodeTransfor) { return; } var controlFlowStorage = new ControlFlowStorage_1.ControlFlowStorage(); - var controlFlowStorageCustomNodeName = Utils_1.Utils.getRandomVariableName(6); + var controlFlowStorageCustomNodeName = RandomGeneratorUtils_1.RandomGeneratorUtils.getRandomVariableName(6); estraverse.replace(functionNode.body, { enter: function enter(node, parentNode) { var controlFlowReplacer = FunctionControlFlowTransformer_1.controlFlowReplacers.get(node.type); @@ -4135,7 +4019,7 @@ var __param = undefined && undefined.__param || function (paramIndex, decorator) }; var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); -var Utils_1 = __webpack_require__(2); +var RandomGeneratorUtils_1 = __webpack_require__(110); var AbstractControlFlowReplacer = function () { function AbstractControlFlowReplacer(options) { _classCallCheck(this, AbstractControlFlowReplacer); @@ -4146,9 +4030,9 @@ var AbstractControlFlowReplacer = function () { _createClass(AbstractControlFlowReplacer, null, [{ key: "getStorageKey", value: function getStorageKey() { - return Utils_1.Utils.getRandomGenerator().string({ + return RandomGeneratorUtils_1.RandomGeneratorUtils.getRandomGenerator().string({ length: 3, - pool: Utils_1.Utils.randomGeneratorPool + pool: RandomGeneratorUtils_1.RandomGeneratorUtils.randomGeneratorPool }); } }]); @@ -4193,13 +4077,13 @@ var __param = undefined && undefined.__param || function (paramIndex, decorator) }; var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); -var estraverse = __webpack_require__(6); -var NodeObfuscatorsReplacers_1 = __webpack_require__(12); -var NodeType_1 = __webpack_require__(9); -var AbstractNodeTransformer_1 = __webpack_require__(11); +var estraverse = __webpack_require__(5); +var NodeObfuscatorsReplacers_1 = __webpack_require__(11); +var NodeType_1 = __webpack_require__(8); +var AbstractNodeTransformer_1 = __webpack_require__(10); var Node_1 = __webpack_require__(4); -var NodeUtils_1 = __webpack_require__(10); -var Utils_1 = __webpack_require__(2); +var NodeUtils_1 = __webpack_require__(9); +var RandomGeneratorUtils_1 = __webpack_require__(110); var CatchClauseObfuscator = function (_AbstractNodeTransfor) { _inherits(CatchClauseObfuscator, _AbstractNodeTransfor); @@ -4215,9 +4099,9 @@ var CatchClauseObfuscator = function (_AbstractNodeTransfor) { _createClass(CatchClauseObfuscator, [{ key: "transformNode", value: function transformNode(catchClauseNode) { - this.identifierReplacer.setPrefix(Utils_1.Utils.getRandomGenerator().string({ + this.identifierReplacer.setPrefix(RandomGeneratorUtils_1.RandomGeneratorUtils.getRandomGenerator().string({ length: 5, - pool: Utils_1.Utils.randomGeneratorPool + pool: RandomGeneratorUtils_1.RandomGeneratorUtils.randomGeneratorPool })); this.storeCatchClauseParam(catchClauseNode); this.replaceCatchClauseParam(catchClauseNode); @@ -4288,13 +4172,13 @@ var __param = undefined && undefined.__param || function (paramIndex, decorator) }; var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); -var estraverse = __webpack_require__(6); -var NodeObfuscatorsReplacers_1 = __webpack_require__(12); -var NodeType_1 = __webpack_require__(9); -var AbstractNodeTransformer_1 = __webpack_require__(11); +var estraverse = __webpack_require__(5); +var NodeObfuscatorsReplacers_1 = __webpack_require__(11); +var NodeType_1 = __webpack_require__(8); +var AbstractNodeTransformer_1 = __webpack_require__(10); var Node_1 = __webpack_require__(4); -var NodeUtils_1 = __webpack_require__(10); -var Utils_1 = __webpack_require__(2); +var NodeUtils_1 = __webpack_require__(9); +var RandomGeneratorUtils_1 = __webpack_require__(110); var FunctionDeclarationObfuscator = function (_AbstractNodeTransfor) { _inherits(FunctionDeclarationObfuscator, _AbstractNodeTransfor); @@ -4310,9 +4194,9 @@ var FunctionDeclarationObfuscator = function (_AbstractNodeTransfor) { _createClass(FunctionDeclarationObfuscator, [{ key: "transformNode", value: function transformNode(functionDeclarationNode, parentNode) { - this.identifierReplacer.setPrefix(Utils_1.Utils.getRandomGenerator().string({ + this.identifierReplacer.setPrefix(RandomGeneratorUtils_1.RandomGeneratorUtils.getRandomGenerator().string({ length: 5, - pool: Utils_1.Utils.randomGeneratorPool + pool: RandomGeneratorUtils_1.RandomGeneratorUtils.randomGeneratorPool })); var blockScopeOfFunctionDeclarationNode = NodeUtils_1.NodeUtils.getBlockScopeOfNode(functionDeclarationNode); if (blockScopeOfFunctionDeclarationNode.type === NodeType_1.NodeType.Program) { @@ -4387,13 +4271,13 @@ var __param = undefined && undefined.__param || function (paramIndex, decorator) }; var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); -var estraverse = __webpack_require__(6); -var NodeObfuscatorsReplacers_1 = __webpack_require__(12); -var NodeType_1 = __webpack_require__(9); -var AbstractNodeTransformer_1 = __webpack_require__(11); +var estraverse = __webpack_require__(5); +var NodeObfuscatorsReplacers_1 = __webpack_require__(11); +var NodeType_1 = __webpack_require__(8); +var AbstractNodeTransformer_1 = __webpack_require__(10); var Node_1 = __webpack_require__(4); -var NodeUtils_1 = __webpack_require__(10); -var Utils_1 = __webpack_require__(2); +var NodeUtils_1 = __webpack_require__(9); +var RandomGeneratorUtils_1 = __webpack_require__(110); var FunctionObfuscator = function (_AbstractNodeTransfor) { _inherits(FunctionObfuscator, _AbstractNodeTransfor); @@ -4409,9 +4293,9 @@ var FunctionObfuscator = function (_AbstractNodeTransfor) { _createClass(FunctionObfuscator, [{ key: "transformNode", value: function transformNode(functionNode) { - this.identifierReplacer.setPrefix(Utils_1.Utils.getRandomGenerator().string({ + this.identifierReplacer.setPrefix(RandomGeneratorUtils_1.RandomGeneratorUtils.getRandomGenerator().string({ length: 5, - pool: Utils_1.Utils.randomGeneratorPool + pool: RandomGeneratorUtils_1.RandomGeneratorUtils.randomGeneratorPool })); this.storeFunctionParams(functionNode); this.replaceFunctionParams(functionNode); @@ -4492,13 +4376,13 @@ var __param = undefined && undefined.__param || function (paramIndex, decorator) }; var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); -var estraverse = __webpack_require__(6); -var NodeObfuscatorsReplacers_1 = __webpack_require__(12); -var NodeType_1 = __webpack_require__(9); -var AbstractNodeTransformer_1 = __webpack_require__(11); +var estraverse = __webpack_require__(5); +var NodeObfuscatorsReplacers_1 = __webpack_require__(11); +var NodeType_1 = __webpack_require__(8); +var AbstractNodeTransformer_1 = __webpack_require__(10); var Node_1 = __webpack_require__(4); -var NodeUtils_1 = __webpack_require__(10); -var Utils_1 = __webpack_require__(2); +var NodeUtils_1 = __webpack_require__(9); +var RandomGeneratorUtils_1 = __webpack_require__(110); var LabeledStatementObfuscator = function (_AbstractNodeTransfor) { _inherits(LabeledStatementObfuscator, _AbstractNodeTransfor); @@ -4514,9 +4398,9 @@ var LabeledStatementObfuscator = function (_AbstractNodeTransfor) { _createClass(LabeledStatementObfuscator, [{ key: "transformNode", value: function transformNode(labeledStatementNode) { - this.identifierReplacer.setPrefix(Utils_1.Utils.getRandomGenerator().string({ + this.identifierReplacer.setPrefix(RandomGeneratorUtils_1.RandomGeneratorUtils.getRandomGenerator().string({ length: 5, - pool: Utils_1.Utils.randomGeneratorPool + pool: RandomGeneratorUtils_1.RandomGeneratorUtils.randomGeneratorPool })); this.storeLabeledStatementName(labeledStatementNode); this.replaceLabeledStatementName(labeledStatementNode); @@ -4588,8 +4472,8 @@ var __param = undefined && undefined.__param || function (paramIndex, decorator) var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); var escodegen = __webpack_require__(16); -var NodeObfuscatorsReplacers_1 = __webpack_require__(12); -var AbstractNodeTransformer_1 = __webpack_require__(11); +var NodeObfuscatorsReplacers_1 = __webpack_require__(11); +var AbstractNodeTransformer_1 = __webpack_require__(10); var Node_1 = __webpack_require__(4); var LiteralObfuscator = function (_AbstractNodeTransfor) { _inherits(LiteralObfuscator, _AbstractNodeTransfor); @@ -4671,10 +4555,10 @@ var __param = undefined && undefined.__param || function (paramIndex, decorator) var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); var escodegen = __webpack_require__(16); -var estraverse = __webpack_require__(6); -var NodeObfuscatorsReplacers_1 = __webpack_require__(12); -var NodeType_1 = __webpack_require__(9); -var AbstractNodeTransformer_1 = __webpack_require__(11); +var estraverse = __webpack_require__(5); +var NodeObfuscatorsReplacers_1 = __webpack_require__(11); +var NodeType_1 = __webpack_require__(8); +var AbstractNodeTransformer_1 = __webpack_require__(10); var Node_1 = __webpack_require__(4); var MemberExpressionObfuscator = function (_AbstractNodeTransfor) { _inherits(MemberExpressionObfuscator, _AbstractNodeTransfor); @@ -4777,9 +4661,9 @@ var __param = undefined && undefined.__param || function (paramIndex, decorator) }; var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); -var estraverse = __webpack_require__(6); -var NodeObfuscatorsReplacers_1 = __webpack_require__(12); -var AbstractNodeTransformer_1 = __webpack_require__(11); +var estraverse = __webpack_require__(5); +var NodeObfuscatorsReplacers_1 = __webpack_require__(11); +var AbstractNodeTransformer_1 = __webpack_require__(10); var Node_1 = __webpack_require__(4); var Utils_1 = __webpack_require__(2); var MethodDefinitionObfuscator_1 = function (_AbstractNodeTransfor) { @@ -4860,9 +4744,9 @@ var __param = undefined && undefined.__param || function (paramIndex, decorator) var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); var escodegen = __webpack_require__(16); -var estraverse = __webpack_require__(6); -var NodeType_1 = __webpack_require__(9); -var AbstractNodeTransformer_1 = __webpack_require__(11); +var estraverse = __webpack_require__(5); +var NodeType_1 = __webpack_require__(8); +var AbstractNodeTransformer_1 = __webpack_require__(10); var Node_1 = __webpack_require__(4); var Utils_1 = __webpack_require__(2); var ObjectExpressionObfuscator = function (_AbstractNodeTransfor) { @@ -4964,13 +4848,13 @@ var __param = undefined && undefined.__param || function (paramIndex, decorator) }; var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); -var estraverse = __webpack_require__(6); -var NodeObfuscatorsReplacers_1 = __webpack_require__(12); -var NodeType_1 = __webpack_require__(9); -var AbstractNodeTransformer_1 = __webpack_require__(11); +var estraverse = __webpack_require__(5); +var NodeObfuscatorsReplacers_1 = __webpack_require__(11); +var NodeType_1 = __webpack_require__(8); +var AbstractNodeTransformer_1 = __webpack_require__(10); var Node_1 = __webpack_require__(4); -var NodeUtils_1 = __webpack_require__(10); -var Utils_1 = __webpack_require__(2); +var NodeUtils_1 = __webpack_require__(9); +var RandomGeneratorUtils_1 = __webpack_require__(110); var VariableDeclarationObfuscator = function (_AbstractNodeTransfor) { _inherits(VariableDeclarationObfuscator, _AbstractNodeTransfor); @@ -4986,9 +4870,9 @@ var VariableDeclarationObfuscator = function (_AbstractNodeTransfor) { _createClass(VariableDeclarationObfuscator, [{ key: "transformNode", value: function transformNode(variableDeclarationNode, parentNode) { - this.identifierReplacer.setPrefix(Utils_1.Utils.getRandomGenerator().string({ + this.identifierReplacer.setPrefix(RandomGeneratorUtils_1.RandomGeneratorUtils.getRandomGenerator().string({ length: 5, - pool: Utils_1.Utils.randomGeneratorPool + pool: RandomGeneratorUtils_1.RandomGeneratorUtils.randomGeneratorPool })); var blockScopeOfVariableDeclarationNode = NodeUtils_1.NodeUtils.getBlockScopeOfNode(variableDeclarationNode); if (blockScopeOfVariableDeclarationNode.type === NodeType_1.NodeType.Program) { @@ -5125,7 +5009,7 @@ var __param = undefined && undefined.__param || function (paramIndex, decorator) var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); var AbstractReplacer_1 = __webpack_require__(19); -var Utils_1 = __webpack_require__(2); +var RandomGeneratorUtils_1 = __webpack_require__(110); var IdentifierReplacer = function (_AbstractReplacer_1$A) { _inherits(IdentifierReplacer, _AbstractReplacer_1$A); @@ -5159,7 +5043,7 @@ var IdentifierReplacer = function (_AbstractReplacer_1$A) { throw new Error('`uniquePrefix` is `undefined`. Set it before `storeNames`'); } if (!this.isReservedName(nodeName)) { - this.namesMap.set(nodeName + "-" + this.uniquePrefix, Utils_1.Utils.getRandomVariableName()); + this.namesMap.set(nodeName + "-" + this.uniquePrefix, RandomGeneratorUtils_1.RandomGeneratorUtils.getRandomVariableName()); } } }, { @@ -5274,9 +5158,11 @@ var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); var StringArrayEncoding_1 = __webpack_require__(21); var AbstractReplacer_1 = __webpack_require__(19); -var CustomNodeGroups_1 = __webpack_require__(22); -var Utils_1 = __webpack_require__(2); +var CryptUtils_1 = __webpack_require__(122); var CustomNodes_1 = __webpack_require__(13); +var CustomNodeGroups_1 = __webpack_require__(22); +var RandomGeneratorUtils_1 = __webpack_require__(110); +var Utils_1 = __webpack_require__(2); var StringLiteralReplacer_1 = function (_AbstractReplacer_1$A) { _inherits(StringLiteralReplacer, _AbstractReplacer_1$A); @@ -5292,7 +5178,7 @@ var StringLiteralReplacer_1 = function (_AbstractReplacer_1$A) { _createClass(StringLiteralReplacer, [{ key: "replace", value: function replace(nodeValue) { - var replaceWithStringArrayFlag = nodeValue.length >= StringLiteralReplacer_1.minimumLengthForStringArray && Utils_1.Utils.getRandomFloat(0, 1) <= this.options.stringArrayThreshold; + var replaceWithStringArrayFlag = nodeValue.length >= StringLiteralReplacer_1.minimumLengthForStringArray && RandomGeneratorUtils_1.RandomGeneratorUtils.getRandomFloat(0, 1) <= this.options.stringArrayThreshold; if (this.options.stringArray && replaceWithStringArrayFlag) { return this.replaceStringLiteralWithStringArrayCall(nodeValue); } @@ -5306,11 +5192,11 @@ var StringLiteralReplacer_1 = function (_AbstractReplacer_1$A) { var rc4Key = ''; switch (this.options.stringArrayEncoding) { case StringArrayEncoding_1.StringArrayEncoding.base64: - value = Utils_1.Utils.btoa(value); + value = CryptUtils_1.CryptUtils.btoa(value); break; case StringArrayEncoding_1.StringArrayEncoding.rc4: - rc4Key = Utils_1.Utils.getRandomGenerator().pickone(StringLiteralReplacer_1.rc4Keys); - value = Utils_1.Utils.btoa(Utils_1.Utils.rc4(value, rc4Key)); + rc4Key = RandomGeneratorUtils_1.RandomGeneratorUtils.getRandomGenerator().pickone(StringLiteralReplacer_1.rc4Keys); + value = CryptUtils_1.CryptUtils.btoa(CryptUtils_1.CryptUtils.rc4(value, rc4Key)); break; } if (this.options.unicodeEscapeSequence) { @@ -5338,8 +5224,8 @@ var StringLiteralReplacer_1 = function (_AbstractReplacer_1$A) { }(AbstractReplacer_1.AbstractReplacer); var StringLiteralReplacer = StringLiteralReplacer_1; StringLiteralReplacer.minimumLengthForStringArray = 3; -StringLiteralReplacer.rc4Keys = Utils_1.Utils.getRandomGenerator().n(function () { - return Utils_1.Utils.getRandomGenerator().string({ length: 4 }); +StringLiteralReplacer.rc4Keys = RandomGeneratorUtils_1.RandomGeneratorUtils.getRandomGenerator().n(function () { + return RandomGeneratorUtils_1.RandomGeneratorUtils.getRandomGenerator().string({ length: 4 }); }, 50); StringLiteralReplacer = StringLiteralReplacer_1 = __decorate([inversify_1.injectable(), __param(0, inversify_1.inject(ServiceIdentifiers_1.ServiceIdentifiers['IStorage'])), __param(1, inversify_1.inject(ServiceIdentifiers_1.ServiceIdentifiers.IOptions)), __metadata('design:paramtypes', [Object, Object])], StringLiteralReplacer); exports.StringLiteralReplacer = StringLiteralReplacer; @@ -5367,7 +5253,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__(0); -var class_validator_1 = __webpack_require__(112); +var class_validator_1 = __webpack_require__(113); var DefaultPreset_1 = __webpack_require__(32); var OptionsNormalizer_1 = __webpack_require__(81); var ValidationErrorsFormatter_1 = __webpack_require__(82); @@ -5682,10 +5568,10 @@ var __param = undefined && undefined.__param || function (paramIndex, decorator) }; var inversify_1 = __webpack_require__(0); var ServiceIdentifiers_1 = __webpack_require__(1); -var estraverse = __webpack_require__(6); +var estraverse = __webpack_require__(5); var CalleeDataExtractors_1 = __webpack_require__(29); var Node_1 = __webpack_require__(4); -var NodeUtils_1 = __webpack_require__(10); +var NodeUtils_1 = __webpack_require__(9); var StackTraceAnalyzer_1 = function () { function StackTraceAnalyzer(calleeDataExtractorsFactory) { _classCallCheck(this, StackTraceAnalyzer); @@ -5798,10 +5684,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__(0); -var estraverse = __webpack_require__(6); +var estraverse = __webpack_require__(5); var AbstractCalleeDataExtractor_1 = __webpack_require__(23); var Node_1 = __webpack_require__(4); -var NodeUtils_1 = __webpack_require__(10); +var NodeUtils_1 = __webpack_require__(9); var FunctionDeclarationCalleeDataExtractor = function (_AbstractCalleeDataEx) { _inherits(FunctionDeclarationCalleeDataExtractor, _AbstractCalleeDataEx); @@ -5876,10 +5762,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__(0); -var estraverse = __webpack_require__(6); +var estraverse = __webpack_require__(5); var AbstractCalleeDataExtractor_1 = __webpack_require__(23); var Node_1 = __webpack_require__(4); -var NodeUtils_1 = __webpack_require__(10); +var NodeUtils_1 = __webpack_require__(9); var FunctionExpressionCalleeDataExtractor = function (_AbstractCalleeDataEx) { _inherits(FunctionExpressionCalleeDataExtractor, _AbstractCalleeDataEx); @@ -5957,9 +5843,9 @@ 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__(0); -var estraverse = __webpack_require__(6); +var estraverse = __webpack_require__(5); var Node_1 = __webpack_require__(4); -var NodeUtils_1 = __webpack_require__(10); +var NodeUtils_1 = __webpack_require__(9); var AbstractCalleeDataExtractor_1 = __webpack_require__(23); var ObjectExpressionCalleeDataExtractor = function (_AbstractCalleeDataEx) { _inherits(ObjectExpressionCalleeDataExtractor, _AbstractCalleeDataEx); @@ -6558,61 +6444,130 @@ exports.StringArrayRotateFunctionTemplate = StringArrayRotateFunctionTemplate; /***/ }, /* 110 */ -/***/ function(module, exports) { +/***/ function(module, exports, __webpack_require__) { -module.exports = require("babel-polyfill"); +"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 chance_1 = __webpack_require__(112); +var Utils_1 = __webpack_require__(2); + +var RandomGeneratorUtils = function () { + function RandomGeneratorUtils() { + _classCallCheck(this, RandomGeneratorUtils); + } + + _createClass(RandomGeneratorUtils, null, [{ + key: 'getRandomFloat', + value: function getRandomFloat(min, max) { + return RandomGeneratorUtils.randomGenerator.floating({ + min: min, + max: max, + fixed: 7 + }); + } + }, { + key: 'getRandomGenerator', + value: function getRandomGenerator() { + var randomGenerator = RandomGeneratorUtils.randomGenerator; + if (!randomGenerator) { + throw new Error('`randomGenerator` static property is undefined'); + } + return RandomGeneratorUtils.randomGenerator; + } + }, { + key: 'getRandomInteger', + value: function getRandomInteger(min, max) { + return RandomGeneratorUtils.randomGenerator.integer({ + min: min, + max: max + }); + } + }, { + key: 'getRandomVariableName', + value: function getRandomVariableName() { + var length = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 6; + + var rangeMinInteger = 10000, + rangeMaxInteger = 99999999; + return '_' + Utils_1.Utils.hexadecimalPrefix + Utils_1.Utils.decToHex(RandomGeneratorUtils.getRandomInteger(rangeMinInteger, rangeMaxInteger)).substr(0, length); + } + }, { + key: 'setRandomGeneratorSeed', + value: function setRandomGeneratorSeed(randomGeneratorSeed) { + RandomGeneratorUtils.randomGenerator = new chance_1.Chance(randomGeneratorSeed); + } + }]); + + return RandomGeneratorUtils; +}(); + +RandomGeneratorUtils.randomGeneratorPool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; +RandomGeneratorUtils.randomGeneratorPoolWithNumbers = RandomGeneratorUtils.randomGeneratorPool + '0123456789'; +RandomGeneratorUtils.randomGenerator = new chance_1.Chance(); +exports.RandomGeneratorUtils = RandomGeneratorUtils; /***/ }, /* 111 */ /***/ function(module, exports) { -module.exports = require("chance"); +module.exports = require("babel-polyfill"); /***/ }, /* 112 */ /***/ function(module, exports) { -module.exports = require("class-validator"); +module.exports = require("chance"); /***/ }, /* 113 */ /***/ function(module, exports) { -module.exports = require("commander"); +module.exports = require("class-validator"); /***/ }, /* 114 */ /***/ function(module, exports) { -module.exports = require("events"); +module.exports = require("commander"); /***/ }, /* 115 */ /***/ function(module, exports) { -module.exports = require("fs"); +module.exports = require("events"); /***/ }, /* 116 */ /***/ function(module, exports) { -module.exports = require("is-equal"); +module.exports = require("fs"); /***/ }, /* 117 */ /***/ function(module, exports) { -module.exports = require("mkdirp"); +module.exports = require("is-equal"); /***/ }, /* 118 */ /***/ function(module, exports) { +module.exports = require("mkdirp"); + +/***/ }, +/* 119 */ +/***/ function(module, exports) { + module.exports = require("reflect-metadata"); /***/ }, -/* 119 */, -/* 120 */ +/* 120 */, +/* 121 */ /***/ function(module, exports, __webpack_require__) { "use strict"; @@ -6621,6 +6576,106 @@ module.exports = require("reflect-metadata"); var JavaScriptObfuscator_1 = __webpack_require__(14); module.exports = JavaScriptObfuscator_1.JavaScriptObfuscator; +/***/ }, +/* 122 */ +/***/ function(module, exports, __webpack_require__) { + +"use strict"; +"use strict"; + +var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var RandomGeneratorUtils_1 = __webpack_require__(110); +var Utils_1 = __webpack_require__(2); + +var CryptUtils = function () { + function CryptUtils() { + _classCallCheck(this, CryptUtils); + } + + _createClass(CryptUtils, null, [{ + key: 'btoa', + value: function btoa(string) { + var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + var output = ''; + string = encodeURIComponent(string).replace(/%([0-9A-F]{2})/g, function (match, p1) { + return String.fromCharCode(parseInt('' + Utils_1.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); + if (charCode > 0xFF) { + throw new Error("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range."); + } + block = block << 8 | charCode; + } + return output; + } + }, { + key: 'hideString', + value: function hideString(str, length) { + var escapeRegExp = function escapeRegExp(s) { + return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); + }; + var randomMerge = function randomMerge(s1, s2) { + var i1 = -1, + i2 = -1, + result = ''; + while (i1 < s1.length || i2 < s2.length) { + if (RandomGeneratorUtils_1.RandomGeneratorUtils.getRandomFloat(0, 1) < 0.5 && i2 < s2.length) { + result += s2.charAt(++i2); + } else { + result += s1.charAt(++i1); + } + } + return result; + }; + var randomString = RandomGeneratorUtils_1.RandomGeneratorUtils.randomGenerator.string({ + length: length, + pool: RandomGeneratorUtils_1.RandomGeneratorUtils.randomGeneratorPool + }); + var randomStringDiff = randomString.replace(new RegExp('[' + escapeRegExp(str) + ']', 'g'), ''); + var randomStringDiffArray = randomStringDiff.split(''); + RandomGeneratorUtils_1.RandomGeneratorUtils.randomGenerator.shuffle(randomStringDiffArray); + randomStringDiff = randomStringDiffArray.join(''); + return [randomMerge(str, randomStringDiff), randomStringDiff]; + } + }, { + key: 'rc4', + value: function rc4(string, key) { + var s = [], + j = 0, + x = void 0, + result = ''; + for (var i = 0; i < 256; i++) { + s[i] = i; + } + for (i = 0; i < 256; i++) { + j = (j + s[i] + key.charCodeAt(i % key.length)) % 256; + x = s[i]; + s[i] = s[j]; + s[j] = x; + } + i = 0; + j = 0; + for (var y = 0; y < string.length; y++) { + i = (i + 1) % 256; + j = (j + s[i]) % 256; + x = s[i]; + s[i] = s[j]; + s[j] = x; + result += String.fromCharCode(string.charCodeAt(y) ^ s[(s[i] + s[j]) % 256]); + } + return result; + } + }]); + + return CryptUtils; +}(); + +exports.CryptUtils = CryptUtils; + /***/ } /******/ ]); //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/src/JavaScriptObfuscatorInternal.ts b/src/JavaScriptObfuscatorInternal.ts index ce59a42a..9c0a9f28 100644 --- a/src/JavaScriptObfuscatorInternal.ts +++ b/src/JavaScriptObfuscatorInternal.ts @@ -12,7 +12,7 @@ import { IGeneratorOutput } from './interfaces/IGeneratorOutput'; import { IOptions } from './interfaces/options/IOptions'; import { ISourceMapCorrector } from './interfaces/ISourceMapCorrector'; -import { Utils } from './Utils'; +import { RandomGeneratorUtils } from './utils/RandomGeneratorUtils'; @injectable() export class JavaScriptObfuscatorInternal implements IJavaScriptObfuscator { @@ -104,7 +104,7 @@ export class JavaScriptObfuscatorInternal implements IJavaScriptObfuscator { */ public obfuscate (sourceCode: string): IObfuscationResult { if (this.options.seed !== 0) { - Utils.setRandomGeneratorSeed(this.options.seed); + RandomGeneratorUtils.setRandomGeneratorSeed(this.options.seed); } // parse AST tree diff --git a/src/SourceMapCorrector.ts b/src/SourceMapCorrector.ts index 92c407ee..ce52010d 100644 --- a/src/SourceMapCorrector.ts +++ b/src/SourceMapCorrector.ts @@ -9,7 +9,7 @@ import { ISourceMapCorrector } from './interfaces/ISourceMapCorrector'; import { SourceMapMode } from './enums/SourceMapMode'; -import { Utils } from './Utils'; +import { CryptUtils } from './utils/CryptUtils'; @injectable() export class SourceMapCorrector implements ISourceMapCorrector { @@ -63,7 +63,7 @@ export class SourceMapCorrector implements ISourceMapCorrector { switch (this.options.sourceMapMode) { case SourceMapMode.Inline: - sourceMappingUrl += `data:application/json;base64,${Utils.btoa(sourceMap)}`; + sourceMappingUrl += `data:application/json;base64,${CryptUtils.btoa(sourceMap)}`; break; diff --git a/src/Utils.ts b/src/Utils.ts deleted file mode 100644 index 8ce2f828..00000000 --- a/src/Utils.ts +++ /dev/null @@ -1,329 +0,0 @@ -import { Chance } from 'chance'; - -import { JSFuck } from './enums/JSFuck'; - -const isEqual = require('is-equal'); - -export class Utils { - /** - * @type {string} - */ - public static readonly hexadecimalPrefix: string = '0x'; - - /** - * @type {string} - */ - public static readonly randomGeneratorPool: string = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - - /** - * @type {string} - */ - public static readonly randomGeneratorPoolWithNumbers: string = `${Utils.randomGeneratorPool}0123456789`; - - /** - * @type {Chance.Chance | Chance.SeededChance} - */ - private static randomGenerator: Chance.Chance | Chance.SeededChance = new Chance(); - - /** - * @param array - * @param searchElement - * @returns {boolean} - */ - public static arrayContains (array: any[], searchElement: any): boolean { - return array.indexOf(searchElement) >= 0; - } - - /** - * @param array - * @param times - * @returns {T[]} - */ - public static arrayRotate (array: T[], times: number): T[] { - if (!array.length) { - throw new ReferenceError(`Cannot rotate empty array.`); - } - - if (times <= 0) { - return array; - } - - let newArray: T[] = array, - temp: T | undefined; - - while (times--) { - temp = newArray.pop()!; - newArray.unshift(temp); - } - - return newArray; - } - - /** - * @param string - */ - public static btoa (string: string): string { - const chars: string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; - - let output: string = ''; - - string = encodeURIComponent(string).replace(/%([0-9A-F]{2})/g, (match, p1) => { - return String.fromCharCode(parseInt(`${Utils.hexadecimalPrefix}${p1}`)); - }); - - for ( - let block: number|undefined, charCode: number, idx: number = 0, map: string = chars; - string.charAt(idx | 0) || (map = '=', idx % 1); - output += map.charAt(63 & block >> 8 - idx % 1 * 8) - ) { - charCode = string.charCodeAt(idx += 3/4); - - if (charCode > 0xFF) { - throw new Error("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range."); - } - - block = block << 8 | charCode; - } - - return output; - } - - /** - * @param dec - * @returns {string} - */ - public static decToHex (dec: number): string { - const radix: number = 16; - - return Number(dec).toString(radix); - } - - /** - * @param url - * @returns {string} - */ - public static extractDomainFromUrl (url: string): string { - let domain: string; - - if (url.indexOf('://') > -1 || url.indexOf('//') === 0) { - domain = url.split('/')[2]; - } else { - domain = url.split('/')[0]; - } - - domain = domain.split(':')[0]; - - return domain; - } - - /** - * @param min - * @param max - * @returns {number} - */ - public static getRandomFloat (min: number, max: number): number { - return Utils.randomGenerator.floating({ - min: min, - max: max, - fixed: 7 - }); - } - - /** - * @returns {Chance.Chance} - */ - public static getRandomGenerator (): Chance.Chance { - const randomGenerator: Chance.Chance = Utils.randomGenerator; - - if (!randomGenerator) { - throw new Error(`\`randomGenerator\` static property is undefined`); - } - - return Utils.randomGenerator; - } - - /** - * @param min - * @param max - * @returns {number} - */ - public static getRandomInteger (min: number, max: number): number { - return Utils.randomGenerator.integer({ - min: min, - max: max - }); - } - - /** - * @param length - * @returns {string} - */ - public static getRandomVariableName (length: number = 6): string { - const rangeMinInteger: number = 10000, - rangeMaxInteger: number = 99999999; - - return `_${Utils.hexadecimalPrefix}${( - Utils.decToHex( - Utils.getRandomInteger(rangeMinInteger, rangeMaxInteger) - ) - ).substr(0, length)}`; - } - - /** - * @param str - * @param length - * @returns {string[]} - */ - public static hideString(str: string, length: number): [string, string] { - const escapeRegExp: (s: string) => string = (s: string) => - s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); - - const randomMerge: (s1: string, s2: string) => string = function (s1: string, s2: string): string { - let i1: number = -1, - i2: number = -1, - result: string = ''; - - while (i1 < s1.length || i2 < s2.length) { - if (Utils.getRandomFloat(0, 1) < 0.5 && i2 < s2.length) { - result += s2.charAt(++i2); - } else { - result += s1.charAt(++i1); - } - } - - return result; - }; - - const randomString: string = Utils.randomGenerator.string({ - length: length, - pool: Utils.randomGeneratorPool - }); - - let randomStringDiff: string = randomString.replace( - new RegExp('[' + escapeRegExp(str) + ']', 'g'), - ''); - - const randomStringDiffArray: string[] = randomStringDiff.split(''); - - Utils.randomGenerator.shuffle(randomStringDiffArray); - randomStringDiff = randomStringDiffArray.join(''); - - return [randomMerge(str, randomStringDiff), randomStringDiff]; - - } - - /** - * @param number - * @returns {boolean} - */ - public static isInteger (number: number): boolean { - return number % 1 === 0; - } - - /** - * @param map - * @param value - * @returns {any} - */ - public static mapGetFirstKeyOf(map: Map , value: any): any { - for (var [key, storageValue] of map) { - if (isEqual(value, storageValue)) { - return key; - } - } - - return null; - } - - /** - * RC4 symmetric cipher encryption/decryption - * https://gist.github.com/farhadi/2185197 - * - * @param key - * @param string - * @returns {string} - */ - public static rc4 (string: string, key: string) { - let s: number[] = [], - j: number = 0, - x: number, - result: string = ''; - - for (var i = 0; i < 256; i++) { - s[i] = i; - } - - for (i = 0; i < 256; i++) { - j = (j + s[i] + key.charCodeAt(i % key.length)) % 256; - x = s[i]; - s[i] = s[j]; - s[j] = x; - } - - i = 0; - j = 0; - - for (let y = 0; y < string.length; y++) { - i = (i + 1) % 256; - j = (j + s[i]) % 256; - x = s[i]; - s[i] = s[j]; - s[j] = x; - result += String.fromCharCode(string.charCodeAt(y) ^ s[(s[i] + s[j]) % 256]); - } - - return result; - } - - /** - * @param randomGeneratorSeed - */ - public static setRandomGeneratorSeed (randomGeneratorSeed: number): void { - Utils.randomGenerator = new Chance(randomGeneratorSeed); - } - - /** - * @param obj - * @returns {T} - */ - public static strEnumify (obj: T): T { - return obj; - } - - /** - * @param string - * @returns {string} - */ - public static stringToJSFuck (string: string): string { - return Array - .from(string) - .map((character: string): string => { - return JSFuck[character] || character; - }) - .join(' + '); - } - - /** - * @param string - * @returns {string} - */ - public static stringToUnicodeEscapeSequence (string: string): string { - const radix: number = 16; - - let prefix: string, - regexp: RegExp = new RegExp('[\x00-\x7F]'), - template: string; - - return `${string.replace(/[\s\S]/g, (escape: string): string => { - if (regexp.test(escape)) { - prefix = '\\x'; - template = '0'.repeat(2); - } else { - prefix = '\\u'; - template = '0'.repeat(4); - } - - return `${prefix}${(template + escape.charCodeAt(0).toString(radix)).slice(-template.length)}`; - })}`; - } -} diff --git a/src/cli/CLIUtils.ts b/src/cli/CLIUtils.ts index 0f8f5a23..149f1098 100644 --- a/src/cli/CLIUtils.ts +++ b/src/cli/CLIUtils.ts @@ -4,7 +4,7 @@ import * as path from 'path'; import { IPackageConfig } from '../interfaces/IPackageConfig'; -import { Utils } from '../Utils'; +import { Utils } from '../utils/Utils'; export class CLIUtils { /** diff --git a/src/cli/JavaScriptObfuscatorCLI.ts b/src/cli/JavaScriptObfuscatorCLI.ts index e049c2c7..e504edb4 100644 --- a/src/cli/JavaScriptObfuscatorCLI.ts +++ b/src/cli/JavaScriptObfuscatorCLI.ts @@ -13,7 +13,7 @@ import { DEFAULT_PRESET } from '../preset-options/DefaultPreset'; import { CLIUtils } from './CLIUtils'; import { JavaScriptObfuscator } from '../JavaScriptObfuscator'; -import { Utils } from '../Utils'; +import { Utils } from '../utils/Utils'; export class JavaScriptObfuscatorCLI { /** diff --git a/src/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.ts b/src/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.ts index 5c1fa8a9..396012a7 100644 --- a/src/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.ts +++ b/src/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.ts @@ -10,7 +10,7 @@ import { ConsoleOutputDisableExpressionTemplate } from '../../templates/custom-n import { initializable } from '../../decorators/Initializable'; import { AbstractCustomNode } from '../AbstractCustomNode'; -import { Utils } from '../../Utils'; +import { RandomGeneratorUtils } from '../../utils/RandomGeneratorUtils'; @injectable() export class ConsoleOutputDisableExpressionNode extends AbstractCustomNode { @@ -41,7 +41,7 @@ export class ConsoleOutputDisableExpressionNode extends AbstractCustomNode { */ public getCode (): string { return format(ConsoleOutputDisableExpressionTemplate(), { - consoleLogDisableFunctionName: Utils.getRandomVariableName(), + consoleLogDisableFunctionName: RandomGeneratorUtils.getRandomVariableName(), singleNodeCallControllerFunctionName: this.callsControllerFunctionName }); } diff --git a/src/custom-nodes/console-output-nodes/group/ConsoleOutputCustomNodeGroup.ts b/src/custom-nodes/console-output-nodes/group/ConsoleOutputCustomNodeGroup.ts index 4e44f423..0df48851 100644 --- a/src/custom-nodes/console-output-nodes/group/ConsoleOutputCustomNodeGroup.ts +++ b/src/custom-nodes/console-output-nodes/group/ConsoleOutputCustomNodeGroup.ts @@ -17,7 +17,7 @@ import { ObfuscationEvents } from '../../../enums/ObfuscationEvents'; import { AbstractCustomNodeGroup } from '../../AbstractCustomNodeGroup'; import { NodeAppender } from '../../../node/NodeAppender'; -import { Utils } from '../../../Utils'; +import { RandomGeneratorUtils } from '../../../utils/RandomGeneratorUtils'; @injectable() export class ConsoleOutputCustomNodeGroup extends AbstractCustomNodeGroup { @@ -96,7 +96,7 @@ export class ConsoleOutputCustomNodeGroup extends AbstractCustomNodeGroup { return; } - const callsControllerFunctionName: string = Utils.getRandomVariableName(); + const callsControllerFunctionName: string = RandomGeneratorUtils.getRandomVariableName(); const consoleOutputDisableExpressionNode: ICustomNode = this.customNodeFactory(CustomNodes.ConsoleOutputDisableExpressionNode); const nodeCallsControllerFunctionNode: ICustomNode = this.customNodeFactory(CustomNodes.NodeCallsControllerFunctionNode); 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 1ced900e..c10e7a0a 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 @@ -10,7 +10,7 @@ import { initializable } from '../../../decorators/Initializable'; import { BinaryExpressionFunctionTemplate } from '../../../templates/custom-nodes/control-flow-replacers-nodes/binary-expression-control-flow-replacer-nodes/BinaryExpressionFunctionTemplate'; import { AbstractCustomNode } from '../../AbstractCustomNode'; -import { Utils } from '../../../Utils'; +import { RandomGeneratorUtils } from '../../../utils/RandomGeneratorUtils'; @injectable() export class BinaryExpressionFunctionNode extends AbstractCustomNode { @@ -41,7 +41,7 @@ export class BinaryExpressionFunctionNode extends AbstractCustomNode { */ public getCode (): string { return format(BinaryExpressionFunctionTemplate(), { - functionName: Utils.getRandomVariableName(1), + functionName: RandomGeneratorUtils.getRandomVariableName(1), operator: this.operator }); } diff --git a/src/custom-nodes/debug-protection-nodes/group/DebugProtectionCustomNodeGroup.ts b/src/custom-nodes/debug-protection-nodes/group/DebugProtectionCustomNodeGroup.ts index df482279..dcd220c2 100644 --- a/src/custom-nodes/debug-protection-nodes/group/DebugProtectionCustomNodeGroup.ts +++ b/src/custom-nodes/debug-protection-nodes/group/DebugProtectionCustomNodeGroup.ts @@ -17,7 +17,7 @@ import { ObfuscationEvents } from '../../../enums/ObfuscationEvents'; import { AbstractCustomNodeGroup } from '../../AbstractCustomNodeGroup'; import { NodeAppender } from '../../../node/NodeAppender'; -import { Utils } from '../../../Utils'; +import { RandomGeneratorUtils } from '../../../utils/RandomGeneratorUtils'; @injectable() export class DebugProtectionCustomNodeGroup extends AbstractCustomNodeGroup { @@ -76,7 +76,7 @@ export class DebugProtectionCustomNodeGroup extends AbstractCustomNodeGroup { // debugProtectionFunctionIntervalNode append this.appendCustomNodeIfExist(CustomNodes.DebugProtectionFunctionIntervalNode, (customNode: ICustomNode) => { const programBodyLength: number = blockScopeNode.body.length; - const randomIndex: number = Utils.getRandomInteger(0, programBodyLength); + const randomIndex: number = RandomGeneratorUtils.getRandomInteger(0, programBodyLength); NodeAppender.insertNodeAtIndex(blockScopeNode, customNode.getNode(), randomIndex); }); @@ -89,7 +89,7 @@ export class DebugProtectionCustomNodeGroup extends AbstractCustomNodeGroup { return; } - const debugProtectionFunctionName: string = Utils.getRandomVariableName(); + const debugProtectionFunctionName: string = RandomGeneratorUtils.getRandomVariableName(); const debugProtectionFunctionNode: ICustomNode = this.customNodeFactory(CustomNodes.DebugProtectionFunctionNode); const debugProtectionFunctionCallNode: ICustomNode = this.customNodeFactory(CustomNodes.DebugProtectionFunctionCallNode); diff --git a/src/custom-nodes/domain-lock-nodes/DomainLockNode.ts b/src/custom-nodes/domain-lock-nodes/DomainLockNode.ts index 169cdb0a..50d1133f 100644 --- a/src/custom-nodes/domain-lock-nodes/DomainLockNode.ts +++ b/src/custom-nodes/domain-lock-nodes/DomainLockNode.ts @@ -10,7 +10,8 @@ import { initializable } from '../../decorators/Initializable'; import { DomainLockNodeTemplate } from '../../templates/custom-nodes/domain-lock-nodes/domain-lock-node/DomainLockNodeTemplate'; import { AbstractCustomNode } from '../AbstractCustomNode'; -import { Utils } from '../../Utils'; +import { CryptUtils } from '../../utils/CryptUtils'; +import { RandomGeneratorUtils } from '../../utils/RandomGeneratorUtils'; @injectable() export class DomainLockNode extends AbstractCustomNode { @@ -41,10 +42,10 @@ export class DomainLockNode extends AbstractCustomNode { */ public getCode (): string { let domainsString: string = this.options.domainLock.join(';'), - [hiddenDomainsString, diff]: string[] = Utils.hideString(domainsString, domainsString.length * 3); + [hiddenDomainsString, diff]: string[] = CryptUtils.hideString(domainsString, domainsString.length * 3); return format(DomainLockNodeTemplate(), { - domainLockFunctionName: Utils.getRandomVariableName(), + domainLockFunctionName: RandomGeneratorUtils.getRandomVariableName(), diff: diff, domains: hiddenDomainsString, singleNodeCallControllerFunctionName: this.callsControllerFunctionName diff --git a/src/custom-nodes/domain-lock-nodes/group/DomainLockCustomNodeGroup.ts b/src/custom-nodes/domain-lock-nodes/group/DomainLockCustomNodeGroup.ts index c4a89860..a7b79d7a 100644 --- a/src/custom-nodes/domain-lock-nodes/group/DomainLockCustomNodeGroup.ts +++ b/src/custom-nodes/domain-lock-nodes/group/DomainLockCustomNodeGroup.ts @@ -17,7 +17,7 @@ import { ObfuscationEvents } from '../../../enums/ObfuscationEvents'; import { AbstractCustomNodeGroup } from '../../AbstractCustomNodeGroup'; import { NodeAppender } from '../../../node/NodeAppender'; -import { Utils } from '../../../Utils'; +import { RandomGeneratorUtils } from '../../../utils/RandomGeneratorUtils'; @injectable() export class DomainLockCustomNodeGroup extends AbstractCustomNodeGroup { @@ -96,7 +96,7 @@ export class DomainLockCustomNodeGroup extends AbstractCustomNodeGroup { return; } - const callsControllerFunctionName: string = Utils.getRandomVariableName(); + const callsControllerFunctionName: string = RandomGeneratorUtils.getRandomVariableName(); const domainLockNode: ICustomNode = this.customNodeFactory(CustomNodes.DomainLockNode); const nodeCallsControllerFunctionNode: ICustomNode = this.customNodeFactory(CustomNodes.NodeCallsControllerFunctionNode); diff --git a/src/custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode.ts b/src/custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode.ts index 97e9396b..dbf133af 100644 --- a/src/custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode.ts +++ b/src/custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode.ts @@ -13,7 +13,7 @@ import { SelfDefendingTemplate } from '../../templates/custom-nodes/self-defendi import { AbstractCustomNode } from '../AbstractCustomNode'; import { JavaScriptObfuscator } from '../../JavaScriptObfuscator'; -import { Utils } from '../../Utils'; +import { RandomGeneratorUtils } from '../../utils/RandomGeneratorUtils'; @injectable() export class SelfDefendingUnicodeNode extends AbstractCustomNode { @@ -45,7 +45,7 @@ export class SelfDefendingUnicodeNode extends AbstractCustomNode { public getCode (): string { return JavaScriptObfuscator.obfuscate( format(SelfDefendingTemplate(), { - selfDefendingFunctionName: Utils.getRandomVariableName(), + selfDefendingFunctionName: RandomGeneratorUtils.getRandomVariableName(), singleNodeCallControllerFunctionName: this.callsControllerFunctionName }), Object.assign({}, NO_CUSTOM_NODES_PRESET, { diff --git a/src/custom-nodes/self-defending-nodes/group/SelfDefendingCustomNodeGroup.ts b/src/custom-nodes/self-defending-nodes/group/SelfDefendingCustomNodeGroup.ts index e227dfb4..db2341f1 100644 --- a/src/custom-nodes/self-defending-nodes/group/SelfDefendingCustomNodeGroup.ts +++ b/src/custom-nodes/self-defending-nodes/group/SelfDefendingCustomNodeGroup.ts @@ -17,7 +17,7 @@ import { ObfuscationEvents } from '../../../enums/ObfuscationEvents'; import { AbstractCustomNodeGroup } from '../../AbstractCustomNodeGroup'; import { NodeAppender } from '../../../node/NodeAppender'; -import { Utils } from '../../../Utils'; +import { RandomGeneratorUtils } from '../../../utils/RandomGeneratorUtils'; @injectable() export class SelfDefendingCustomNodeGroup extends AbstractCustomNodeGroup { @@ -96,7 +96,7 @@ export class SelfDefendingCustomNodeGroup extends AbstractCustomNodeGroup { return; } - const callsControllerFunctionName: string = Utils.getRandomVariableName(); + const callsControllerFunctionName: string = RandomGeneratorUtils.getRandomVariableName(); const selfDefendingUnicodeNode: ICustomNode = this.customNodeFactory(CustomNodes.SelfDefendingUnicodeNode); const nodeCallsControllerFunctionNode: ICustomNode = this.customNodeFactory(CustomNodes.NodeCallsControllerFunctionNode); diff --git a/src/custom-nodes/string-array-nodes/StringArrayRotateFunctionNode.ts b/src/custom-nodes/string-array-nodes/StringArrayRotateFunctionNode.ts index 141c79e8..6f5b6a36 100644 --- a/src/custom-nodes/string-array-nodes/StringArrayRotateFunctionNode.ts +++ b/src/custom-nodes/string-array-nodes/StringArrayRotateFunctionNode.ts @@ -15,7 +15,8 @@ import { StringArrayRotateFunctionTemplate } from '../../templates/custom-nodes/ import { AbstractCustomNode } from '../AbstractCustomNode'; import { JavaScriptObfuscator } from '../../JavaScriptObfuscator'; -import { Utils } from '../../Utils'; +import { RandomGeneratorUtils } from '../../utils/RandomGeneratorUtils'; +import { Utils } from '../../utils/Utils'; @injectable() export class StringArrayRotateFunctionNode extends AbstractCustomNode { @@ -66,8 +67,8 @@ export class StringArrayRotateFunctionNode extends AbstractCustomNode { */ public getCode (): string { let code: string = '', - timesName: string = Utils.getRandomVariableName(), - whileFunctionName: string = Utils.getRandomVariableName(); + timesName: string = RandomGeneratorUtils.getRandomVariableName(), + whileFunctionName: string = RandomGeneratorUtils.getRandomVariableName(); if (this.options.selfDefending) { code = format(SelfDefendingTemplate(), { diff --git a/src/custom-nodes/string-array-nodes/group/StringArrayCustomNodeGroup.ts b/src/custom-nodes/string-array-nodes/group/StringArrayCustomNodeGroup.ts index 983c7060..adb65346 100644 --- a/src/custom-nodes/string-array-nodes/group/StringArrayCustomNodeGroup.ts +++ b/src/custom-nodes/string-array-nodes/group/StringArrayCustomNodeGroup.ts @@ -20,8 +20,8 @@ import { StringArrayNode } from '../StringArrayNode'; import { AbstractCustomNodeGroup } from '../../AbstractCustomNodeGroup'; import { NodeAppender } from '../../../node/NodeAppender'; +import { RandomGeneratorUtils } from '../../../utils/RandomGeneratorUtils'; import { StringArrayStorage } from '../../../storages/string-array/StringArrayStorage'; -import { Utils } from '../../../Utils'; @injectable() export class StringArrayCustomNodeGroup extends AbstractCustomNodeGroup { @@ -105,13 +105,13 @@ export class StringArrayCustomNodeGroup extends AbstractCustomNodeGroup { const stringArrayCallsWrapper: ICustomNode = this.customNodeFactory(CustomNodes.StringArrayCallsWrapper); const stringArrayRotateFunctionNode: ICustomNode = this.customNodeFactory(CustomNodes.StringArrayRotateFunctionNode); - const stringArrayName: string = Utils.getRandomVariableName(StringArrayNode.ARRAY_RANDOM_LENGTH); - const stringArrayCallsWrapperName: string = Utils.getRandomVariableName(StringArrayNode.ARRAY_RANDOM_LENGTH); + const stringArrayName: string = RandomGeneratorUtils.getRandomVariableName(StringArrayNode.ARRAY_RANDOM_LENGTH); + const stringArrayCallsWrapperName: string = RandomGeneratorUtils.getRandomVariableName(StringArrayNode.ARRAY_RANDOM_LENGTH); let stringArrayRotateValue: number; if (this.options.rotateStringArray) { - stringArrayRotateValue = Utils.getRandomInteger(100, 500); + stringArrayRotateValue = RandomGeneratorUtils.getRandomInteger(100, 500); } else { stringArrayRotateValue = 0; } diff --git a/src/enums/NodeType.ts b/src/enums/NodeType.ts index 19120f46..631ab1cb 100644 --- a/src/enums/NodeType.ts +++ b/src/enums/NodeType.ts @@ -1,4 +1,4 @@ -import { Utils } from '../Utils'; +import { Utils } from '../utils/Utils'; export const NodeType: any = Utils.strEnumify({ ArrayExpression: 'ArrayExpression', diff --git a/src/enums/ObfuscationEvents.ts b/src/enums/ObfuscationEvents.ts index 36211c1d..396eb7dd 100644 --- a/src/enums/ObfuscationEvents.ts +++ b/src/enums/ObfuscationEvents.ts @@ -1,6 +1,6 @@ import { TObfuscationEvent } from '../types/event-emitters/TObfuscationEvent'; -import { Utils } from '../Utils'; +import { Utils } from '../utils/Utils'; export const ObfuscationEvents: { AfterObfuscation: TObfuscationEvent, diff --git a/src/enums/VisitorDirection.ts b/src/enums/VisitorDirection.ts index b21f6532..38a1c124 100644 --- a/src/enums/VisitorDirection.ts +++ b/src/enums/VisitorDirection.ts @@ -1,4 +1,4 @@ -import { Utils } from '../Utils'; +import { Utils } from '../utils/Utils'; export const VisitorDirection: any = Utils.strEnumify({ enter: 'enter', diff --git a/src/node-transformers/node-control-flow-transformers/FunctionControlFlowTransformer.ts b/src/node-transformers/node-control-flow-transformers/FunctionControlFlowTransformer.ts index a8acb4c7..1da1fe92 100644 --- a/src/node-transformers/node-control-flow-transformers/FunctionControlFlowTransformer.ts +++ b/src/node-transformers/node-control-flow-transformers/FunctionControlFlowTransformer.ts @@ -19,7 +19,7 @@ import { ControlFlowStorage } from '../../storages/control-flow/ControlFlowStora import { ControlFlowStorageNode } from '../../custom-nodes/control-flow-storage-nodes/ControlFlowStorageNode'; import { Node } from '../../node/Node'; import { NodeAppender } from '../../node/NodeAppender'; -import { Utils } from '../../Utils'; +import { RandomGeneratorUtils } from '../../utils/RandomGeneratorUtils'; @injectable() export class FunctionControlFlowTransformer extends AbstractNodeTransformer { @@ -55,7 +55,7 @@ export class FunctionControlFlowTransformer extends AbstractNodeTransformer { } const controlFlowStorage: IStorage = new ControlFlowStorage(); - const controlFlowStorageCustomNodeName: string = Utils.getRandomVariableName(6); + const controlFlowStorageCustomNodeName: string = RandomGeneratorUtils.getRandomVariableName(6); estraverse.replace(functionNode.body, { enter: (node: ESTree.Node, parentNode: ESTree.Node): any => { 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 35f9323b..835b5f95 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 @@ -8,7 +8,7 @@ import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode'; import { IOptions } from '../../../interfaces/options/IOptions'; import { IStorage } from '../../../interfaces/storages/IStorage'; -import { Utils } from '../../../Utils'; +import { RandomGeneratorUtils } from '../../../utils/RandomGeneratorUtils'; @injectable() export abstract class AbstractControlFlowReplacer implements IControlFlowReplacer { @@ -30,9 +30,9 @@ export abstract class AbstractControlFlowReplacer implements IControlFlowReplace * @returns {string} */ protected static getStorageKey (): string { - return Utils.getRandomGenerator().string({ + return RandomGeneratorUtils.getRandomGenerator().string({ length: 3, - pool: Utils.randomGeneratorPool + pool: RandomGeneratorUtils.randomGeneratorPool }); } diff --git a/src/node-transformers/node-obfuscators/CatchClauseObfuscator.ts b/src/node-transformers/node-obfuscators/CatchClauseObfuscator.ts index 8e83148e..763ba232 100644 --- a/src/node-transformers/node-obfuscators/CatchClauseObfuscator.ts +++ b/src/node-transformers/node-obfuscators/CatchClauseObfuscator.ts @@ -14,7 +14,7 @@ import { AbstractNodeTransformer } from '../AbstractNodeTransformer'; import { IdentifierReplacer } from './replacers/IdentifierReplacer'; import { Node } from '../../node/Node'; import { NodeUtils } from '../../node/NodeUtils'; -import { Utils } from '../../Utils'; +import { RandomGeneratorUtils } from '../../utils/RandomGeneratorUtils'; /** * replaces: @@ -48,9 +48,9 @@ export class CatchClauseObfuscator extends AbstractNodeTransformer { * @param catchClauseNode */ public transformNode (catchClauseNode: ESTree.CatchClause): void { - this.identifierReplacer.setPrefix(Utils.getRandomGenerator().string({ + this.identifierReplacer.setPrefix(RandomGeneratorUtils.getRandomGenerator().string({ length: 5, - pool: Utils.randomGeneratorPool + pool: RandomGeneratorUtils.randomGeneratorPool })); this.storeCatchClauseParam(catchClauseNode); diff --git a/src/node-transformers/node-obfuscators/FunctionDeclarationObfuscator.ts b/src/node-transformers/node-obfuscators/FunctionDeclarationObfuscator.ts index 5d55453b..1b4e1f94 100644 --- a/src/node-transformers/node-obfuscators/FunctionDeclarationObfuscator.ts +++ b/src/node-transformers/node-obfuscators/FunctionDeclarationObfuscator.ts @@ -16,7 +16,7 @@ import { AbstractNodeTransformer } from '../AbstractNodeTransformer'; import { IdentifierReplacer } from './replacers/IdentifierReplacer'; import { Node } from '../../node/Node'; import { NodeUtils } from '../../node/NodeUtils'; -import { Utils } from '../../Utils'; +import { RandomGeneratorUtils } from '../../utils/RandomGeneratorUtils'; /** * replaces: @@ -52,9 +52,9 @@ export class FunctionDeclarationObfuscator extends AbstractNodeTransformer { * @param parentNode */ public transformNode (functionDeclarationNode: ESTree.FunctionDeclaration, parentNode: ESTree.Node): void { - this.identifierReplacer.setPrefix(Utils.getRandomGenerator().string({ + this.identifierReplacer.setPrefix(RandomGeneratorUtils.getRandomGenerator().string({ length: 5, - pool: Utils.randomGeneratorPool + pool: RandomGeneratorUtils.randomGeneratorPool })); const blockScopeOfFunctionDeclarationNode: TNodeWithBlockStatement = NodeUtils diff --git a/src/node-transformers/node-obfuscators/FunctionObfuscator.ts b/src/node-transformers/node-obfuscators/FunctionObfuscator.ts index d74a4727..d2d158bb 100644 --- a/src/node-transformers/node-obfuscators/FunctionObfuscator.ts +++ b/src/node-transformers/node-obfuscators/FunctionObfuscator.ts @@ -14,7 +14,7 @@ import { AbstractNodeTransformer } from '../AbstractNodeTransformer'; import { IdentifierReplacer } from './replacers/IdentifierReplacer'; import { Node } from '../../node/Node'; import { NodeUtils } from '../../node/NodeUtils'; -import { Utils } from '../../Utils'; +import { RandomGeneratorUtils } from '../../utils/RandomGeneratorUtils'; /** * replaces: @@ -48,9 +48,9 @@ export class FunctionObfuscator extends AbstractNodeTransformer { * @param functionNode */ public transformNode (functionNode: ESTree.Function): void { - this.identifierReplacer.setPrefix(Utils.getRandomGenerator().string({ + this.identifierReplacer.setPrefix(RandomGeneratorUtils.getRandomGenerator().string({ length: 5, - pool: Utils.randomGeneratorPool + pool: RandomGeneratorUtils.randomGeneratorPool })); this.storeFunctionParams(functionNode); diff --git a/src/node-transformers/node-obfuscators/LabeledStatementObfuscator.ts b/src/node-transformers/node-obfuscators/LabeledStatementObfuscator.ts index 7b48cff0..79f68de1 100644 --- a/src/node-transformers/node-obfuscators/LabeledStatementObfuscator.ts +++ b/src/node-transformers/node-obfuscators/LabeledStatementObfuscator.ts @@ -14,7 +14,7 @@ import { AbstractNodeTransformer } from '../AbstractNodeTransformer'; import { IdentifierReplacer } from './replacers/IdentifierReplacer'; import { Node } from '../../node/Node'; import { NodeUtils } from '../../node/NodeUtils'; -import { Utils } from '../../Utils'; +import { RandomGeneratorUtils } from '../../utils/RandomGeneratorUtils'; /** * replaces: @@ -56,9 +56,9 @@ export class LabeledStatementObfuscator extends AbstractNodeTransformer { * @param labeledStatementNode */ public transformNode (labeledStatementNode: ESTree.LabeledStatement): void { - this.identifierReplacer.setPrefix(Utils.getRandomGenerator().string({ + this.identifierReplacer.setPrefix(RandomGeneratorUtils.getRandomGenerator().string({ length: 5, - pool: Utils.randomGeneratorPool + pool: RandomGeneratorUtils.randomGeneratorPool })); this.storeLabeledStatementName(labeledStatementNode); diff --git a/src/node-transformers/node-obfuscators/MethodDefinitionObfuscator.ts b/src/node-transformers/node-obfuscators/MethodDefinitionObfuscator.ts index a08023b0..b6bef011 100644 --- a/src/node-transformers/node-obfuscators/MethodDefinitionObfuscator.ts +++ b/src/node-transformers/node-obfuscators/MethodDefinitionObfuscator.ts @@ -11,7 +11,7 @@ import { NodeObfuscatorsReplacers } from '../../enums/container/NodeObfuscatorsR import { AbstractNodeTransformer } from '../AbstractNodeTransformer'; import { Node } from '../../node/Node'; -import { Utils } from '../../Utils'; +import { Utils } from '../../utils/Utils'; /** * replaces: diff --git a/src/node-transformers/node-obfuscators/ObjectExpressionObfuscator.ts b/src/node-transformers/node-obfuscators/ObjectExpressionObfuscator.ts index b68086e7..d19d0fe2 100644 --- a/src/node-transformers/node-obfuscators/ObjectExpressionObfuscator.ts +++ b/src/node-transformers/node-obfuscators/ObjectExpressionObfuscator.ts @@ -11,7 +11,7 @@ import { NodeType } from '../../enums/NodeType'; import { AbstractNodeTransformer } from '../AbstractNodeTransformer'; import { Node } from '../../node/Node'; -import { Utils } from '../../Utils'; +import { Utils } from '../../utils/Utils'; /** * replaces: diff --git a/src/node-transformers/node-obfuscators/VariableDeclarationObfuscator.ts b/src/node-transformers/node-obfuscators/VariableDeclarationObfuscator.ts index 068a4612..f9dfd663 100644 --- a/src/node-transformers/node-obfuscators/VariableDeclarationObfuscator.ts +++ b/src/node-transformers/node-obfuscators/VariableDeclarationObfuscator.ts @@ -16,7 +16,7 @@ import { AbstractNodeTransformer } from '../AbstractNodeTransformer'; import { IdentifierReplacer } from './replacers/IdentifierReplacer'; import { Node } from '../../node/Node'; import { NodeUtils } from '../../node/NodeUtils'; -import { Utils } from '../../Utils'; +import { RandomGeneratorUtils } from '../../utils/RandomGeneratorUtils'; /** * replaces: @@ -53,9 +53,9 @@ export class VariableDeclarationObfuscator extends AbstractNodeTransformer { * @param parentNode */ public transformNode (variableDeclarationNode: ESTree.VariableDeclaration, parentNode: ESTree.Node): void { - this.identifierReplacer.setPrefix(Utils.getRandomGenerator().string({ + this.identifierReplacer.setPrefix(RandomGeneratorUtils.getRandomGenerator().string({ length: 5, - pool: Utils.randomGeneratorPool + pool: RandomGeneratorUtils.randomGeneratorPool })); const blockScopeOfVariableDeclarationNode: TNodeWithBlockStatement = NodeUtils diff --git a/src/node-transformers/node-obfuscators/replacers/IdentifierReplacer.ts b/src/node-transformers/node-obfuscators/replacers/IdentifierReplacer.ts index aee1acd3..af352995 100644 --- a/src/node-transformers/node-obfuscators/replacers/IdentifierReplacer.ts +++ b/src/node-transformers/node-obfuscators/replacers/IdentifierReplacer.ts @@ -4,7 +4,7 @@ import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers'; import { IOptions } from '../../../interfaces/options/IOptions'; import { AbstractReplacer } from './AbstractReplacer'; -import { Utils } from '../../../Utils'; +import { RandomGeneratorUtils } from '../../../utils/RandomGeneratorUtils'; @injectable() export class IdentifierReplacer extends AbstractReplacer { @@ -60,7 +60,7 @@ export class IdentifierReplacer extends AbstractReplacer { } if (!this.isReservedName(nodeName)) { - this.namesMap.set(`${nodeName}-${this.uniquePrefix}`, Utils.getRandomVariableName()); + this.namesMap.set(`${nodeName}-${this.uniquePrefix}`, RandomGeneratorUtils.getRandomVariableName()); } } diff --git a/src/node-transformers/node-obfuscators/replacers/NumberLiteralReplacer.ts b/src/node-transformers/node-obfuscators/replacers/NumberLiteralReplacer.ts index 289f1f3c..96ba8ed9 100644 --- a/src/node-transformers/node-obfuscators/replacers/NumberLiteralReplacer.ts +++ b/src/node-transformers/node-obfuscators/replacers/NumberLiteralReplacer.ts @@ -4,7 +4,7 @@ import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers'; import { IOptions } from '../../../interfaces/options/IOptions'; import { AbstractReplacer } from './AbstractReplacer'; -import { Utils } from '../../../Utils'; +import { Utils } from '../../../utils/Utils'; @injectable() export class NumberLiteralReplacer extends AbstractReplacer { diff --git a/src/node-transformers/node-obfuscators/replacers/StringLiteralReplacer.ts b/src/node-transformers/node-obfuscators/replacers/StringLiteralReplacer.ts index 3f1c5e19..2a678a80 100644 --- a/src/node-transformers/node-obfuscators/replacers/StringLiteralReplacer.ts +++ b/src/node-transformers/node-obfuscators/replacers/StringLiteralReplacer.ts @@ -11,9 +11,11 @@ import { IStorage } from '../../../interfaces/storages/IStorage'; import { StringArrayEncoding } from '../../../enums/StringArrayEncoding'; import { AbstractReplacer } from './AbstractReplacer'; -import { CustomNodeGroups } from '../../../enums/container/CustomNodeGroups'; -import { Utils } from '../../../Utils'; +import { CryptUtils } from '../../../utils/CryptUtils'; import { CustomNodes } from '../../../enums/container/CustomNodes'; +import { CustomNodeGroups } from '../../../enums/container/CustomNodeGroups'; +import { RandomGeneratorUtils } from '../../../utils/RandomGeneratorUtils'; +import { Utils } from '../../../utils/Utils'; @injectable() export class StringLiteralReplacer extends AbstractReplacer { @@ -25,8 +27,8 @@ export class StringLiteralReplacer extends AbstractReplacer { /** * @type {string[]} */ - private static readonly rc4Keys: string[] = Utils.getRandomGenerator() - .n(() => Utils.getRandomGenerator().string({length: 4}), 50); + private static readonly rc4Keys: string[] = RandomGeneratorUtils.getRandomGenerator() + .n(() => RandomGeneratorUtils.getRandomGenerator().string({length: 4}), 50); /** * @type {IStorage} @@ -53,7 +55,7 @@ export class StringLiteralReplacer extends AbstractReplacer { public replace (nodeValue: string): string { const replaceWithStringArrayFlag: boolean = ( nodeValue.length >= StringLiteralReplacer.minimumLengthForStringArray - && Utils.getRandomFloat(0, 1) <= this.options.stringArrayThreshold + && RandomGeneratorUtils.getRandomFloat(0, 1) <= this.options.stringArrayThreshold ); if (this.options.stringArray && replaceWithStringArrayFlag) { @@ -78,13 +80,13 @@ export class StringLiteralReplacer extends AbstractReplacer { switch (this.options.stringArrayEncoding) { case StringArrayEncoding.base64: - value = Utils.btoa(value); + value = CryptUtils.btoa(value); break; case StringArrayEncoding.rc4: - rc4Key = Utils.getRandomGenerator().pickone(StringLiteralReplacer.rc4Keys); - value = Utils.btoa(Utils.rc4(value, rc4Key)); + rc4Key = RandomGeneratorUtils.getRandomGenerator().pickone(StringLiteralReplacer.rc4Keys); + value = CryptUtils.btoa(CryptUtils.rc4(value, rc4Key)); break; } diff --git a/src/node/NodeAppender.ts b/src/node/NodeAppender.ts index 6b671185..9e6047b7 100644 --- a/src/node/NodeAppender.ts +++ b/src/node/NodeAppender.ts @@ -5,7 +5,7 @@ import { TStatement } from '../types/node/TStatement'; import { IStackTraceData } from '../interfaces/stack-trace-analyzer/IStackTraceData'; -import { Utils } from '../Utils'; +import { RandomGeneratorUtils } from '../utils/RandomGeneratorUtils'; /** * This class appends node into a first deepest BlockStatement in order of function calls @@ -101,7 +101,7 @@ export class NodeAppender { * @param stackTraceRootLength */ public static getRandomStackTraceIndex (stackTraceRootLength: number): number { - return Utils.getRandomInteger(0, Math.max(0, Math.round(stackTraceRootLength - 1))); + return RandomGeneratorUtils.getRandomInteger(0, Math.max(0, Math.round(stackTraceRootLength - 1))); } /** diff --git a/src/node/NodeUtils.ts b/src/node/NodeUtils.ts index 7a3bc9af..4509fed0 100644 --- a/src/node/NodeUtils.ts +++ b/src/node/NodeUtils.ts @@ -9,7 +9,7 @@ import { TStatement } from '../types/node/TStatement'; import { NodeType } from '../enums/NodeType'; import { Node } from './Node'; -import { Utils } from '../Utils'; +import { Utils } from '../utils/Utils'; export class NodeUtils { /** diff --git a/src/options/OptionsNormalizer.ts b/src/options/OptionsNormalizer.ts index 2d5daf01..689d4815 100644 --- a/src/options/OptionsNormalizer.ts +++ b/src/options/OptionsNormalizer.ts @@ -3,7 +3,7 @@ import { IOptions } from '../interfaces/options/IOptions'; import { TOptionsNormalizerRule } from '../types/options/TOptionsNormalizerRule'; -import { Utils } from '../Utils'; +import { Utils } from '../utils/Utils'; export class OptionsNormalizer { /** diff --git a/src/storages/MapStorage.ts b/src/storages/MapStorage.ts index b1321221..b8ba7ec7 100644 --- a/src/storages/MapStorage.ts +++ b/src/storages/MapStorage.ts @@ -4,7 +4,7 @@ import { IStorage } from '../interfaces/storages/IStorage'; import { initializable } from '../decorators/Initializable'; -import { Utils } from '../Utils'; +import { Utils } from '../utils/Utils'; @injectable() export abstract class MapStorage implements IStorage { diff --git a/src/storages/string-array/StringArrayStorage.ts b/src/storages/string-array/StringArrayStorage.ts index a6153a4f..33c68893 100644 --- a/src/storages/string-array/StringArrayStorage.ts +++ b/src/storages/string-array/StringArrayStorage.ts @@ -1,5 +1,5 @@ import { ArrayStorage } from '../ArrayStorage'; -import { Utils } from '../../Utils'; +import { Utils } from '../../utils/Utils'; export class StringArrayStorage extends ArrayStorage { constructor () { diff --git a/src/templates/custom-nodes/self-defending-nodes/self-defending-unicode-node/SelfDefendingTemplate.ts b/src/templates/custom-nodes/self-defending-nodes/self-defending-unicode-node/SelfDefendingTemplate.ts index 2c1579f7..84c3afe7 100644 --- a/src/templates/custom-nodes/self-defending-nodes/self-defending-unicode-node/SelfDefendingTemplate.ts +++ b/src/templates/custom-nodes/self-defending-nodes/self-defending-unicode-node/SelfDefendingTemplate.ts @@ -1,4 +1,4 @@ -import { Utils } from '../../../../Utils'; +import { Utils } from '../../../../utils/Utils'; /** * SelfDefendingTemplate. Enters code in infinity loop. diff --git a/src/templates/custom-nodes/string-array-nodes/string-array-calls-wrapper/SelfDefendingTemplate.ts b/src/templates/custom-nodes/string-array-nodes/string-array-calls-wrapper/SelfDefendingTemplate.ts index 1835890c..555ef4e0 100644 --- a/src/templates/custom-nodes/string-array-nodes/string-array-calls-wrapper/SelfDefendingTemplate.ts +++ b/src/templates/custom-nodes/string-array-nodes/string-array-calls-wrapper/SelfDefendingTemplate.ts @@ -1,4 +1,4 @@ -import { Utils } from '../../../../Utils'; +import { Utils } from '../../../../utils/Utils'; /** * @returns {string} diff --git a/src/templates/custom-nodes/string-array-nodes/string-array-rotate-function-node/SelfDefendingTemplate.ts b/src/templates/custom-nodes/string-array-nodes/string-array-rotate-function-node/SelfDefendingTemplate.ts index 1a15c0cb..13b5a0ce 100644 --- a/src/templates/custom-nodes/string-array-nodes/string-array-rotate-function-node/SelfDefendingTemplate.ts +++ b/src/templates/custom-nodes/string-array-nodes/string-array-rotate-function-node/SelfDefendingTemplate.ts @@ -1,4 +1,4 @@ -import { Utils } from '../../../../Utils'; +import { Utils } from '../../../../utils/Utils'; /** * SelfDefendingTemplate. Enter code in infinity loop. diff --git a/src/utils/CryptUtils.ts b/src/utils/CryptUtils.ts new file mode 100644 index 00000000..c6faa752 --- /dev/null +++ b/src/utils/CryptUtils.ts @@ -0,0 +1,116 @@ +import { RandomGeneratorUtils } from './RandomGeneratorUtils'; +import { Utils } from './Utils'; + +export class CryptUtils { + /** + * @param string + */ + public static btoa (string: string): string { + const chars: string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + let output: string = ''; + + string = encodeURIComponent(string).replace(/%([0-9A-F]{2})/g, (match, p1) => { + return String.fromCharCode(parseInt(`${Utils.hexadecimalPrefix}${p1}`)); + }); + + for ( + let block: number|undefined, charCode: number, idx: number = 0, map: string = chars; + string.charAt(idx | 0) || (map = '=', idx % 1); + output += map.charAt(63 & block >> 8 - idx % 1 * 8) + ) { + charCode = string.charCodeAt(idx += 3/4); + + if (charCode > 0xFF) { + throw new Error("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range."); + } + + block = block << 8 | charCode; + } + + return output; + } + + /** + * @param str + * @param length + * @returns {string[]} + */ + public static hideString(str: string, length: number): [string, string] { + const escapeRegExp: (s: string) => string = (s: string) => + s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); + + const randomMerge: (s1: string, s2: string) => string = function (s1: string, s2: string): string { + let i1: number = -1, + i2: number = -1, + result: string = ''; + + while (i1 < s1.length || i2 < s2.length) { + if (RandomGeneratorUtils.getRandomFloat(0, 1) < 0.5 && i2 < s2.length) { + result += s2.charAt(++i2); + } else { + result += s1.charAt(++i1); + } + } + + return result; + }; + + const randomString: string = RandomGeneratorUtils.randomGenerator.string({ + length: length, + pool: RandomGeneratorUtils.randomGeneratorPool + }); + + let randomStringDiff: string = randomString.replace( + new RegExp('[' + escapeRegExp(str) + ']', 'g'), + ''); + + const randomStringDiffArray: string[] = randomStringDiff.split(''); + + RandomGeneratorUtils.randomGenerator.shuffle(randomStringDiffArray); + randomStringDiff = randomStringDiffArray.join(''); + + return [randomMerge(str, randomStringDiff), randomStringDiff]; + + } + + /** + * RC4 symmetric cipher encryption/decryption + * https://gist.github.com/farhadi/2185197 + * + * @param key + * @param string + * @returns {string} + */ + public static rc4 (string: string, key: string): string { + let s: number[] = [], + j: number = 0, + x: number, + result: string = ''; + + for (var i = 0; i < 256; i++) { + s[i] = i; + } + + for (i = 0; i < 256; i++) { + j = (j + s[i] + key.charCodeAt(i % key.length)) % 256; + x = s[i]; + s[i] = s[j]; + s[j] = x; + } + + i = 0; + j = 0; + + for (let y = 0; y < string.length; y++) { + i = (i + 1) % 256; + j = (j + s[i]) % 256; + x = s[i]; + s[i] = s[j]; + s[j] = x; + result += String.fromCharCode(string.charCodeAt(y) ^ s[(s[i] + s[j]) % 256]); + } + + return result; + } +} diff --git a/src/utils/RandomGeneratorUtils.ts b/src/utils/RandomGeneratorUtils.ts new file mode 100644 index 00000000..55ca5751 --- /dev/null +++ b/src/utils/RandomGeneratorUtils.ts @@ -0,0 +1,80 @@ +import { Chance } from 'chance'; + +import { Utils } from './Utils'; + +export class RandomGeneratorUtils { + /** + * @type {string} + */ + public static readonly randomGeneratorPool: string = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + + /** + * @type {string} + */ + public static readonly randomGeneratorPoolWithNumbers: string = `${RandomGeneratorUtils.randomGeneratorPool}0123456789`; + + /** + * @type {Chance.Chance | Chance.SeededChance} + */ + public static randomGenerator: Chance.Chance | Chance.SeededChance = new Chance(); + + /** + * @param min + * @param max + * @returns {number} + */ + public static getRandomFloat (min: number, max: number): number { + return RandomGeneratorUtils.randomGenerator.floating({ + min: min, + max: max, + fixed: 7 + }); + } + + /** + * @returns {Chance.Chance} + */ + public static getRandomGenerator (): Chance.Chance { + const randomGenerator: Chance.Chance = RandomGeneratorUtils.randomGenerator; + + if (!randomGenerator) { + throw new Error(`\`randomGenerator\` static property is undefined`); + } + + return RandomGeneratorUtils.randomGenerator; + } + + /** + * @param min + * @param max + * @returns {number} + */ + public static getRandomInteger (min: number, max: number): number { + return RandomGeneratorUtils.randomGenerator.integer({ + min: min, + max: max + }); + } + + /** + * @param length + * @returns {string} + */ + public static getRandomVariableName (length: number = 6): string { + const rangeMinInteger: number = 10000, + rangeMaxInteger: number = 99999999; + + return `_${Utils.hexadecimalPrefix}${( + Utils.decToHex( + RandomGeneratorUtils.getRandomInteger(rangeMinInteger, rangeMaxInteger) + ) + ).substr(0, length)}`; + } + + /** + * @param randomGeneratorSeed + */ + public static setRandomGeneratorSeed (randomGeneratorSeed: number): void { + RandomGeneratorUtils.randomGenerator = new Chance(randomGeneratorSeed); + } +} diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts new file mode 100644 index 00000000..919c2e76 --- /dev/null +++ b/src/utils/Utils.ts @@ -0,0 +1,140 @@ +import { JSFuck } from '../enums/JSFuck'; + +const isEqual = require('is-equal'); + +export class Utils { + /** + * @type {string} + */ + public static readonly hexadecimalPrefix: string = '0x'; + + /** + * @param array + * @param searchElement + * @returns {boolean} + */ + public static arrayContains (array: any[], searchElement: any): boolean { + return array.indexOf(searchElement) >= 0; + } + + /** + * @param array + * @param times + * @returns {T[]} + */ + public static arrayRotate (array: T[], times: number): T[] { + if (!array.length) { + throw new ReferenceError(`Cannot rotate empty array.`); + } + + if (times <= 0) { + return array; + } + + let newArray: T[] = array, + temp: T | undefined; + + while (times--) { + temp = newArray.pop()!; + newArray.unshift(temp); + } + + return newArray; + } + + /** + * @param dec + * @returns {string} + */ + public static decToHex (dec: number): string { + const radix: number = 16; + + return Number(dec).toString(radix); + } + + /** + * @param url + * @returns {string} + */ + public static extractDomainFromUrl (url: string): string { + let domain: string; + + if (url.indexOf('://') > -1 || url.indexOf('//') === 0) { + domain = url.split('/')[2]; + } else { + domain = url.split('/')[0]; + } + + domain = domain.split(':')[0]; + + return domain; + } + + /** + * @param number + * @returns {boolean} + */ + public static isInteger (number: number): boolean { + return number % 1 === 0; + } + + /** + * @param map + * @param value + * @returns {any} + */ + public static mapGetFirstKeyOf(map: Map , value: any): any { + for (var [key, storageValue] of map) { + if (isEqual(value, storageValue)) { + return key; + } + } + + return null; + } + + /** + * @param obj + * @returns {T} + */ + public static strEnumify (obj: T): T { + return obj; + } + + /** + * @param string + * @returns {string} + */ + public static stringToJSFuck (string: string): string { + return Array + .from(string) + .map((character: string): string => { + return JSFuck[character] || character; + }) + .join(' + '); + } + + /** + * @param string + * @returns {string} + */ + public static stringToUnicodeEscapeSequence (string: string): string { + const radix: number = 16; + + let prefix: string, + regexp: RegExp = new RegExp('[\x00-\x7F]'), + template: string; + + return `${string.replace(/[\s\S]/g, (escape: string): string => { + if (regexp.test(escape)) { + prefix = '\\x'; + template = '0'.repeat(2); + } else { + prefix = '\\u'; + template = '0'.repeat(4); + } + + return `${prefix}${(template + escape.charCodeAt(0).toString(radix)).slice(-template.length)}`; + })}`; + } +} diff --git a/test/functional-tests/templates/custom-nodes/domain-lock-nodes/DomainLockNodeTemplate.spec.ts b/test/functional-tests/templates/custom-nodes/domain-lock-nodes/DomainLockNodeTemplate.spec.ts index 7a63ee44..dec80d69 100644 --- a/test/functional-tests/templates/custom-nodes/domain-lock-nodes/DomainLockNodeTemplate.spec.ts +++ b/test/functional-tests/templates/custom-nodes/domain-lock-nodes/DomainLockNodeTemplate.spec.ts @@ -2,7 +2,7 @@ import * as format from 'string-template'; import { DomainLockNodeTemplate } from '../../../../../src/templates/custom-nodes/domain-lock-nodes/domain-lock-node/DomainLockNodeTemplate'; -import { Utils } from '../../../../../src/Utils'; +import { CryptUtils } from '../../../../../src/utils/CryptUtils'; const assert: Chai.AssertStatic = require('chai').assert; @@ -46,7 +46,7 @@ describe('DomainLockNodeTemplate (): string', () => { [ hiddenDomainsString, diff - ] = Utils.hideString(domainsString, domainsString.length * 3); + ] = CryptUtils.hideString(domainsString, domainsString.length * 3); assert.doesNotThrow(() => getFunctionFromTemplate({ domainLockFunctionName: 'domainLockFunction', @@ -62,7 +62,7 @@ describe('DomainLockNodeTemplate (): string', () => { [ hiddenDomainsString, diff - ] = Utils.hideString(domainsString, domainsString.length * 3); + ] = CryptUtils.hideString(domainsString, domainsString.length * 3); assert.doesNotThrow(() => getFunctionFromTemplate({ domainLockFunctionName: 'domainLockFunction', @@ -78,7 +78,7 @@ describe('DomainLockNodeTemplate (): string', () => { [ hiddenDomainsString, diff - ] = Utils.hideString(domainsString, domainsString.length * 3); + ] = CryptUtils.hideString(domainsString, domainsString.length * 3); assert.throws(() => getFunctionFromTemplate({ domainLockFunctionName: 'domainLockFunction', diff --git a/test/functional-tests/templates/custom-nodes/string-array-nodes/StringArrayCallsWrapperNodeTemplate.spec.ts b/test/functional-tests/templates/custom-nodes/string-array-nodes/StringArrayCallsWrapperNodeTemplate.spec.ts index 773039b4..86f1ac27 100644 --- a/test/functional-tests/templates/custom-nodes/string-array-nodes/StringArrayCallsWrapperNodeTemplate.spec.ts +++ b/test/functional-tests/templates/custom-nodes/string-array-nodes/StringArrayCallsWrapperNodeTemplate.spec.ts @@ -6,7 +6,7 @@ import { StringArrayBase64DecodeNodeTemplate } from '../../../../../src/template import { StringArrayCallsWrapperTemplate } from '../../../../../src/templates/custom-nodes/string-array-nodes/string-array-calls-wrapper/StringArrayCallsWrapperTemplate'; import { StringArrayRc4DecodeNodeTemplate } from '../../../../../src/templates/custom-nodes/string-array-nodes/string-array-calls-wrapper/StringArrayRC4DecodeNodeTemplate'; -import { Utils } from '../../../../../src/Utils'; +import { CryptUtils } from '../../../../../src/utils/CryptUtils'; const assert: Chai.AssertStatic = require('chai').assert; @@ -26,7 +26,7 @@ function getFunctionFromTemplateBase64Encoding ( let stringArrayCallsWrapperTemplate: string = format(StringArrayCallsWrapperTemplate(), templateData); return Function(` - var ${stringArrayName} = ['${Utils.btoa('test1')}']; + var ${stringArrayName} = ['${CryptUtils.btoa('test1')}']; ${stringArrayCallsWrapperTemplate} @@ -52,7 +52,7 @@ function getFunctionFromTemplateRc4Encoding ( let stringArrayCallsWrapperTemplate: string = format(StringArrayCallsWrapperTemplate(), templateData); return Function(` - var ${stringArrayName} = ['${Utils.btoa(Utils.rc4('test1', key))}']; + var ${stringArrayName} = ['${CryptUtils.btoa(CryptUtils.rc4('test1', key))}']; ${stringArrayCallsWrapperTemplate} diff --git a/test/index.spec.ts b/test/index.spec.ts index 9dab2f68..7cf18b2f 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -7,16 +7,18 @@ BabelPolyfill.append(); /** * Unit tests */ +import './unit-tests/ObfuscationResult.spec'; +import './unit-tests/OptionsNormalizer.spec'; +import './unit-tests/SourceMapCorrector.spec'; import './unit-tests/cli/CLIUtils.spec'; import './unit-tests/decorators/Initializable.spec'; import './unit-tests/node/NodeAppender.spec'; import './unit-tests/node/NodeUtils.spec'; -import './unit-tests/ObfuscationResult.spec'; -import './unit-tests/OptionsNormalizer.spec'; -import './unit-tests/SourceMapCorrector.spec'; import './unit-tests/stack-trace-analyzer/StackTraceAnalyzer.spec'; import './unit-tests/storages/ControlFlowStorage.spec'; -import './unit-tests/Utils.spec'; +import './unit-tests/utils/CryptUtils.spec'; +import './unit-tests/utils/RandomGeneratorUtils.spec'; +import './unit-tests/utils/Utils.spec'; /** * Functional tests diff --git a/test/unit-tests/utils/CryptUtils.spec.ts b/test/unit-tests/utils/CryptUtils.spec.ts new file mode 100644 index 00000000..932eaacb --- /dev/null +++ b/test/unit-tests/utils/CryptUtils.spec.ts @@ -0,0 +1,38 @@ +import { CryptUtils } from '../../../src/utils/CryptUtils'; + +const assert: Chai.AssertStatic = require('chai').assert; + +describe('CryptUtils', () => { + describe('btoa (string: string): string', () => { + it('should create a base-64 encoded string from a given string', () => { + assert.equal(CryptUtils.btoa('string'), 'c3RyaW5n'); + }); + }); + + describe('hideString (str: string, length: number): [string, string]', () => { + let original1: string = 'example.com', + [str1, diff] = CryptUtils.hideString(original1, 30); + + it('should return a string with the original string within', () => { + assert.isTrue(str1.length > original1.length); + assert.equal(str1.replace(new RegExp('[' + diff + ']', 'g'), ''), original1); + }); + + }); + + describe('rc4 (string: string, key: string): string', () => { + it('should encode string using the rc4 algorithm', () => { + const string: string = 'test'; + const key: string = 'key'; + + assert.notEqual(CryptUtils.rc4(string, key), string); + }); + + it('should encode and successfully decode string using the rc4 algorithm', () => { + const string: string = 'test'; + const key: string = 'key'; + + assert.equal(CryptUtils.rc4(CryptUtils.rc4(string, key), key), string); + }); + }); +}); diff --git a/test/unit-tests/utils/RandomGeneratorUtils.spec.ts b/test/unit-tests/utils/RandomGeneratorUtils.spec.ts new file mode 100644 index 00000000..b55ce4b5 --- /dev/null +++ b/test/unit-tests/utils/RandomGeneratorUtils.spec.ts @@ -0,0 +1,12 @@ +import { RandomGeneratorUtils } from '../../../src/utils/RandomGeneratorUtils'; + +const assert: Chai.AssertStatic = require('chai').assert; + +describe('RandomGeneratorUtils', () => { + describe('getRandomVariableName (length: number = 6): string', () => { + it('should return a string of given length with random variable name', () => { + assert.match(RandomGeneratorUtils.getRandomVariableName(4), /^_0x(\w){4}$/); + assert.match(RandomGeneratorUtils.getRandomVariableName(6), /^_0x(\w){4,6}$/); + }); + }); +}); diff --git a/test/unit-tests/Utils.spec.ts b/test/unit-tests/utils/Utils.spec.ts similarity index 80% rename from test/unit-tests/Utils.spec.ts rename to test/unit-tests/utils/Utils.spec.ts index 8f9c6898..524f390a 100644 --- a/test/unit-tests/Utils.spec.ts +++ b/test/unit-tests/utils/Utils.spec.ts @@ -1,6 +1,6 @@ -import { Utils } from '../../src/Utils'; +import { Utils } from '../../../src/utils/Utils'; -import { JSFuck } from '../../src/enums/JSFuck'; +import { JSFuck } from '../../../src/enums/JSFuck'; const assert: Chai.AssertStatic = require('chai').assert; @@ -35,12 +35,6 @@ describe('Utils', () => { }); }); - describe('btoa (string: string): string', () => { - it('should creates a base-64 encoded string from a given string', () => { - assert.equal(Utils.btoa('string'), 'c3RyaW5n'); - }); - }); - describe('decToHex (dec: number): string', () => { it('should creates a string with hexadecimal value from a given decimal number', () => { assert.equal(Utils.decToHex(0), '0'); @@ -60,13 +54,6 @@ describe('Utils', () => { }); }); - describe('getRandomVariableName (length: number = 6): string', () => { - it('should return a string of given length with random variable name', () => { - assert.match(Utils.getRandomVariableName(4), /^_0x(\w){4}$/); - assert.match(Utils.getRandomVariableName(6), /^_0x(\w){4,6}$/); - }); - }); - describe('isInteger (number: number): boolean', () => { it('should return true if given number or string is integer', () => { assert.equal(Utils.isInteger(4), true); @@ -118,15 +105,4 @@ describe('Utils', () => { assert.equal(Utils.stringToUnicodeEscapeSequence('string'), expected); }); }); - - describe('hideString (str: string, length: number): [string, string]', () => { - let original1: string = 'example.com', - [str1, diff] = Utils.hideString(original1, 30); - - it('should return a string with the original string within', () => { - assert.isTrue(str1.length > original1.length); - assert.equal(str1.replace(new RegExp('[' + diff + ']', 'g'), ''), original1); - }); - - }); });