From add062feeee17e7eb73364171c8de1c3fda78f15 Mon Sep 17 00:00:00 2001 From: sanex3339 Date: Sat, 29 Oct 2016 21:58:59 +0300 Subject: [PATCH] rc4 preparation --- README.md | 15 +- dist/index.js | 178 ++++++------------ src/cli/JavaScriptObfuscatorCLI.ts | 3 +- .../UnicodeArrayCallsWrapper.ts | 47 ++++- .../UnicodeArrayDecodeNode.ts | 101 ---------- src/interfaces/IObfuscatorOptions.d.ts | 1 - src/interfaces/IOptions.d.ts | 1 - src/node-groups/UnicodeArrayNodesGroup.ts | 34 +--- .../replacers/StringLiteralReplacer.ts | 12 +- src/options/Options.ts | 6 - .../SelfDefendingTemplate.ts | 0 .../UnicodeArrayAtobDecodeNodeTemplate.ts | 12 ++ .../UnicodeArrayCallsWrapperTemplate.ts | 8 +- .../UnicodeArrayRC4DecodeNodeTemplate.ts} | 0 .../JavaScriptObfuscator.spec.ts | 23 ++- .../UnicodeArrayCallsWrapper.spec.ts | 16 +- .../UnicodeArrayDecodeNode.spec.ts | 29 --- .../MemberExpressionObfuscator.spec.ts | 4 +- .../MethodDefinitionObfuscator.spec.ts | 2 +- .../UnicodeArrayDecodeNodeTemplate.spec.ts | 6 +- test/index.spec.ts | 1 - 21 files changed, 150 insertions(+), 349 deletions(-) delete mode 100644 src/custom-nodes/unicode-array-nodes/UnicodeArrayDecodeNode.ts rename src/templates/custom-nodes/unicode-array-nodes/{unicode-array-decode-node => unicode-array-calls-wrapper}/SelfDefendingTemplate.ts (100%) create mode 100644 src/templates/custom-nodes/unicode-array-nodes/unicode-array-calls-wrapper/UnicodeArrayAtobDecodeNodeTemplate.ts rename src/templates/custom-nodes/unicode-array-nodes/{unicode-array-decode-node/UnicodeArrayDecodeNodeTemplate.ts => unicode-array-calls-wrapper/UnicodeArrayRC4DecodeNodeTemplate.ts} (100%) delete mode 100644 test/functional-tests/custom-nodes/unicode-array-nodes/UnicodeArrayDecodeNode.spec.ts diff --git a/README.md b/README.md index 557a910f..588942bc 100644 --- a/README.md +++ b/README.md @@ -126,8 +126,7 @@ Following options available for the JS Obfuscator: sourceMapFileName: '', sourceMapMode: 'separate', unicodeArray: true, - unicodeArrayThreshold: 0.8, - wrapUnicodeArrayCalls: true + unicodeArrayThreshold: 0.8 } ``` @@ -153,7 +152,6 @@ Following options available for the JS Obfuscator: --sourceMapMode [inline, separate] --unicodeArray --unicodeArrayThreshold - --wrapUnicodeArrayCalls ``` ### `compact` @@ -292,17 +290,6 @@ This setting is useful with large code size because repeatdely calls to the `Uni `unicodeArrayThreshold: 0` equals to `unicodeArray: false`. -### `wrapUnicodeArrayCalls` -Type: `boolean` Default: `true` - -##### :warning: `unicodeArray` option must be enabled - -Replaces the direct array indexing `var m = _0x12c456[0x1];` with a call to a special function `var m = _0x23c123('0x1');`. Some JavaScript beautifiers (such as the Google Closure Compiler) can replace direct array indexing with the indexed string, and this option mitigates that. - -```javascript -var t = _0x12a634('0x0') -``` - ## License Copyright (C) 2016 [Timofey Kachalov](http://github.com/sanex3339). diff --git a/dist/index.js b/dist/index.js index 671e0db7..865331bc 100644 --- a/dist/index.js +++ b/dist/index.js @@ -938,14 +938,11 @@ var StringLiteralReplacer = function (_AbstractReplacer_1$A) { unicodeArrayNode.updateNodeData(value); } hexadecimalIndex = new NumberLiteralReplacer_1.NumberLiteralReplacer(this.nodes, this.options).replace(indexOfValue); - if (this.options.wrapUnicodeArrayCalls) { - var unicodeArrayCallsWrapper = this.nodes.get('unicodeArrayCallsWrapper'); - if (!unicodeArrayCallsWrapper) { - throw new ReferenceError('`unicodeArrayCallsWrapper` node is not found in Map with custom nodes.'); - } - return unicodeArrayCallsWrapper.getNodeIdentifier() + '(\'' + hexadecimalIndex + '\')'; + var unicodeArrayCallsWrapper = this.nodes.get('unicodeArrayCallsWrapper'); + if (!unicodeArrayCallsWrapper) { + throw new ReferenceError('`unicodeArrayCallsWrapper` node is not found in Map with custom nodes.'); } - return unicodeArrayNode.getNodeIdentifier() + '[' + hexadecimalIndex + ']'; + return unicodeArrayCallsWrapper.getNodeIdentifier() + '(\'' + hexadecimalIndex + '\')'; } }]); @@ -1614,11 +1611,11 @@ var JavaScriptObfuscatorCLI = function () { }, { key: 'configureCommands', value: function configureCommands() { - this.commands = new commander.Command().version(JavaScriptObfuscatorCLI.getBuildVersion(), '-v, --version').usage(' [options]').option('-o, --output ', 'Output path for obfuscated code').option('--compact ', 'Disable one line output code compacting', JavaScriptObfuscatorCLI.parseBoolean).option('--debugProtection ', 'Disable browser Debug panel (can cause DevTools enabled browser freeze)', JavaScriptObfuscatorCLI.parseBoolean).option('--debugProtectionInterval ', 'Disable browser Debug panel even after page was loaded (can cause DevTools enabled browser freeze)', JavaScriptObfuscatorCLI.parseBoolean).option('--disableConsoleOutput ', 'Allow console.log, console.info, console.error and console.warn messages output into browser console', JavaScriptObfuscatorCLI.parseBoolean).option('--encodeUnicodeLiterals ', 'All literals in Unicode array become encoded in Base64 (this option can slightly slow down your code speed)', JavaScriptObfuscatorCLI.parseBoolean).option('--reservedNames ', 'Disable obfuscation of variable names, function names and names of function parameters that match the passed RegExp patterns (comma separated)', function (val) { + this.commands = new commander.Command().version(JavaScriptObfuscatorCLI.getBuildVersion(), '-v, --version').usage(' [options]').option('-o, --output ', 'Output path for obfuscated code').option('--compact ', 'Disable one line output code compacting', JavaScriptObfuscatorCLI.parseBoolean).option('--debugProtection ', 'Disable browser Debug panel (can cause DevTools enabled browser freeze)', JavaScriptObfuscatorCLI.parseBoolean).option('--debugProtectionInterval ', 'Disable browser Debug panel even after page was loaded (can cause DevTools enabled browser freeze)', JavaScriptObfuscatorCLI.parseBoolean).option('--disableConsoleOutput ', 'Allow console.log, console.info, console.error and console.warn messages output into browser console', JavaScriptObfuscatorCLI.parseBoolean).option('--domainLock ', 'Blocks the execution of the code in domains that do not match the passed RegExp patterns (comma separated)', function (val) { return val.split(','); - }).option('--rotateUnicodeArray ', 'Disable rotation of unicode array values during obfuscation', JavaScriptObfuscatorCLI.parseBoolean).option('--selfDefending ', 'Disables self-defending for obfuscated code', JavaScriptObfuscatorCLI.parseBoolean).option('--sourceMap ', 'Enables source map generation', JavaScriptObfuscatorCLI.parseBoolean).option('--sourceMapBaseUrl ', 'Sets base url to the source map import url when `--sourceMapMode=separate`').option('--sourceMapFileName ', 'Sets file name for output source map when `--sourceMapMode=separate`').option('--sourceMapMode [inline, separate]', 'Specify source map output mode', JavaScriptObfuscatorCLI.parseSourceMapMode).option('--unicodeArray ', 'Disables gathering of all literal strings into an array and replacing every literal string with an array call', JavaScriptObfuscatorCLI.parseBoolean).option('--unicodeArrayThreshold ', 'The probability that the literal string will be inserted into unicodeArray (Default: 0.8, Min: 0, Max: 1)', parseFloat).option('--wrapUnicodeArrayCalls ', 'Disables usage of special access function instead of direct array call', JavaScriptObfuscatorCLI.parseBoolean).option('--domainLock ', 'Blocks the execution of the code in domains that do not match the passed RegExp patterns (comma separated)', function (val) { + }).option('--encodeUnicodeLiterals ', 'All literals in Unicode array become encoded in Base64 (this option can slightly slow down your code speed)', JavaScriptObfuscatorCLI.parseBoolean).option('--reservedNames ', 'Disable obfuscation of variable names, function names and names of function parameters that match the passed RegExp patterns (comma separated)', function (val) { return val.split(','); - }).parse(this.rawArguments); + }).option('--rotateUnicodeArray ', 'Disable rotation of unicode array values during obfuscation', JavaScriptObfuscatorCLI.parseBoolean).option('--selfDefending ', 'Disables self-defending for obfuscated code', JavaScriptObfuscatorCLI.parseBoolean).option('--sourceMap ', 'Enables source map generation', JavaScriptObfuscatorCLI.parseBoolean).option('--sourceMapBaseUrl ', 'Sets base url to the source map import url when `--sourceMapMode=separate`').option('--sourceMapFileName ', 'Sets file name for output source map when `--sourceMapMode=separate`').option('--sourceMapMode [inline, separate]', 'Specify source map output mode', JavaScriptObfuscatorCLI.parseSourceMapMode).option('--unicodeArray ', 'Disables gathering of all literal strings into an array and replacing every literal string with an array call', JavaScriptObfuscatorCLI.parseBoolean).option('--unicodeArrayThreshold ', 'The probability that the literal string will be inserted into unicodeArray (Default: 0.8, Min: 0, Max: 1)', parseFloat).parse(this.rawArguments); this.commands.on('--help', function () { console.log(' Examples:\n'); console.log(' %> javascript-obfuscator in.js --compact true --selfDefending false'); @@ -2043,10 +2040,14 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function" __webpack_require__(8); var AppendState_1 = __webpack_require__(4); +var NoCustomNodesPreset_1 = __webpack_require__(17); +var AtobTemplate_1 = __webpack_require__(62); +var SelfDefendingTemplate_1 = __webpack_require__(83); var UnicodeArrayCallsWrapperTemplate_1 = __webpack_require__(69); var AbstractCustomNode_1 = __webpack_require__(5); +var JavaScriptObfuscator_1 = __webpack_require__(9); var NodeUtils_1 = __webpack_require__(1); -var Utils_1 = __webpack_require__(0); +var UnicodeArrayAtobDecodeNodeTemplate_1 = __webpack_require__(84); var UnicodeArrayCallsWrapper = function (_AbstractCustomNode_) { _inherits(UnicodeArrayCallsWrapper, _AbstractCustomNode_); @@ -2082,79 +2083,8 @@ var UnicodeArrayCallsWrapper = function (_AbstractCustomNode_) { return _get(UnicodeArrayCallsWrapper.prototype.__proto__ || Object.getPrototypeOf(UnicodeArrayCallsWrapper.prototype), 'getNode', this).call(this); } }, { - key: 'getNodeStructure', - value: function getNodeStructure() { - var keyName = Utils_1.Utils.getRandomVariableName(); - return NodeUtils_1.NodeUtils.convertCodeToStructure(UnicodeArrayCallsWrapperTemplate_1.UnicodeArrayCallsWrapperTemplate().formatUnicorn({ - keyName: keyName, - unicodeArrayCallsWrapperName: this.unicodeArrayCallsWrapperName, - unicodeArrayName: this.unicodeArrayName - })); - } - }]); - - return UnicodeArrayCallsWrapper; -}(AbstractCustomNode_1.AbstractCustomNode); - -exports.UnicodeArrayCallsWrapper = UnicodeArrayCallsWrapper; - -/***/ }, -/* 38 */ -/***/ function(module, exports, __webpack_require__) { - -"use strict"; -"use strict"; - -var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - -var _get = (function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }); - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - -__webpack_require__(8); -var AppendState_1 = __webpack_require__(4); -var NoCustomNodesPreset_1 = __webpack_require__(17); -var AtobTemplate_1 = __webpack_require__(62); -var SelfDefendingTemplate_1 = __webpack_require__(70); -var UnicodeArrayDecodeNodeTemplate_1 = __webpack_require__(71); -var AbstractCustomNode_1 = __webpack_require__(5); -var JavaScriptObfuscator_1 = __webpack_require__(9); -var NodeUtils_1 = __webpack_require__(1); - -var UnicodeArrayDecodeNode = function (_AbstractCustomNode_) { - _inherits(UnicodeArrayDecodeNode, _AbstractCustomNode_); - - function UnicodeArrayDecodeNode(unicodeArrayName, unicodeArray, options) { - _classCallCheck(this, UnicodeArrayDecodeNode); - - var _this = _possibleConstructorReturn(this, (UnicodeArrayDecodeNode.__proto__ || Object.getPrototypeOf(UnicodeArrayDecodeNode)).call(this, options)); - - _this.appendState = AppendState_1.AppendState.AfterObfuscation; - _this.unicodeArrayName = unicodeArrayName; - _this.unicodeArray = unicodeArray; - return _this; - } - - _createClass(UnicodeArrayDecodeNode, [{ - key: 'appendNode', - value: function appendNode(blockScopeNode) { - if (!this.unicodeArray.getLength()) { - return; - } - NodeUtils_1.NodeUtils.insertNodeAtIndex(blockScopeNode.body, this.getNode(), 1); - } - }, { - key: 'getNode', - value: function getNode() { - return _get(UnicodeArrayDecodeNode.prototype.__proto__ || Object.getPrototypeOf(UnicodeArrayDecodeNode.prototype), 'getNode', this).call(this); - } - }, { - key: 'getNodeStructure', - value: function getNodeStructure() { + key: 'getDecodeUnicodeArrayTemplate', + value: function getDecodeUnicodeArrayTemplate() { var forLoopFunctionName = 'forLoopFunc'; var code = void 0; if (this.options.selfDefending) { @@ -2165,21 +2095,32 @@ var UnicodeArrayDecodeNode = function (_AbstractCustomNode_) { } else { code = forLoopFunctionName + '();'; } - return NodeUtils_1.NodeUtils.convertCodeToStructure(JavaScriptObfuscator_1.JavaScriptObfuscator.obfuscate(UnicodeArrayDecodeNodeTemplate_1.UnicodeArrayDecodeNodeTemplate().formatUnicorn({ + return UnicodeArrayAtobDecodeNodeTemplate_1.UnicodeArrayAtobDecodeNodeTemplate().formatUnicorn({ atobPolyfill: AtobTemplate_1.AtobTemplate(), code: code, forLoopFunctionName: forLoopFunctionName, unicodeArrayName: this.unicodeArrayName + }); + } + }, { + key: 'getNodeStructure', + value: function getNodeStructure() { + var decodeNodeTemplate = this.options.encodeUnicodeLiterals ? this.getDecodeUnicodeArrayTemplate() : ''; + return NodeUtils_1.NodeUtils.convertCodeToStructure(JavaScriptObfuscator_1.JavaScriptObfuscator.obfuscate(UnicodeArrayCallsWrapperTemplate_1.UnicodeArrayCallsWrapperTemplate().formatUnicorn({ + decodeNodeTemplate: decodeNodeTemplate, + unicodeArrayCallsWrapperName: this.unicodeArrayCallsWrapperName, + unicodeArrayName: this.unicodeArrayName }), NoCustomNodesPreset_1.NO_CUSTOM_NODES_PRESET).getObfuscatedCode()); } }]); - return UnicodeArrayDecodeNode; + return UnicodeArrayCallsWrapper; }(AbstractCustomNode_1.AbstractCustomNode); -exports.UnicodeArrayDecodeNode = UnicodeArrayDecodeNode; +exports.UnicodeArrayCallsWrapper = UnicodeArrayCallsWrapper; /***/ }, +/* 38 */, /* 39 */ /***/ function(module, exports, __webpack_require__) { @@ -2517,7 +2458,6 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function" var AbstractNodesGroup_1 = __webpack_require__(10); var UnicodeArray_1 = __webpack_require__(28); var UnicodeArrayCallsWrapper_1 = __webpack_require__(37); -var UnicodeArrayDecodeNode_1 = __webpack_require__(38); var UnicodeArrayNode_1 = __webpack_require__(39); var UnicodeArrayRotateFunctionNode_1 = __webpack_require__(40); var Utils_1 = __webpack_require__(0); @@ -2546,12 +2486,7 @@ var UnicodeArrayNodesGroup = function (_AbstractNodesGroup_) { var unicodeArray = new UnicodeArray_1.UnicodeArray(), unicodeArrayNode = new UnicodeArrayNode_1.UnicodeArrayNode(unicodeArray, _this.unicodeArrayName, _this.unicodeArrayRotateValue, _this.options); _this.nodes.set('unicodeArrayNode', unicodeArrayNode); - if (_this.options.wrapUnicodeArrayCalls) { - _this.nodes.set('unicodeArrayCallsWrapper', new UnicodeArrayCallsWrapper_1.UnicodeArrayCallsWrapper(_this.unicodeArrayTranslatorName, _this.unicodeArrayName, unicodeArray, _this.options)); - } - if (_this.options.encodeUnicodeLiterals) { - _this.nodes.set('unicodeArrayDecodeNode', new UnicodeArrayDecodeNode_1.UnicodeArrayDecodeNode(_this.unicodeArrayName, unicodeArray, _this.options)); - } + _this.nodes.set('unicodeArrayCallsWrapper', new UnicodeArrayCallsWrapper_1.UnicodeArrayCallsWrapper(_this.unicodeArrayTranslatorName, _this.unicodeArrayName, unicodeArray, _this.options)); if (_this.options.rotateUnicodeArray) { _this.nodes.set('unicodeArrayRotateFunctionNode', new UnicodeArrayRotateFunctionNode_1.UnicodeArrayRotateFunctionNode(_this.unicodeArrayName, unicodeArray, _this.unicodeArrayRotateValue, _this.options)); } @@ -3271,7 +3206,6 @@ __decorate([class_validator_1.IsString(), __metadata('design:type', String)], Op __decorate([class_validator_1.IsIn(['inline', 'separate']), __metadata('design:type', typeof (_a = typeof TSourceMapMode_1.TSourceMapMode !== 'undefined' && TSourceMapMode_1.TSourceMapMode) === 'function' && _a || Object)], Options.prototype, "sourceMapMode", void 0); __decorate([class_validator_1.IsBoolean(), __metadata('design:type', Boolean)], Options.prototype, "unicodeArray", void 0); __decorate([class_validator_1.IsNumber(), class_validator_1.Min(0), class_validator_1.Max(1), __metadata('design:type', Number)], Options.prototype, "unicodeArrayThreshold", void 0); -__decorate([class_validator_1.IsBoolean(), __metadata('design:type', Boolean)], Options.prototype, "wrapUnicodeArrayCalls", void 0); exports.Options = Options; var _a; @@ -3949,36 +3883,13 @@ exports.SelfDefendingTemplate = SelfDefendingTemplate; "use strict"; function UnicodeArrayCallsWrapperTemplate() { - return "\n var {unicodeArrayCallsWrapperName} = function ({keyName}) {\n return {unicodeArrayName}[parseInt({keyName}, 0x010)];\n };\n "; + return "\n var {unicodeArrayCallsWrapperName} = function (index, key) {\n var value = {unicodeArrayName}[parseInt(index, 0x010)]\n \n {decodeNodeTemplate}\n \n return value;\n };\n "; } exports.UnicodeArrayCallsWrapperTemplate = UnicodeArrayCallsWrapperTemplate; /***/ }, -/* 70 */ -/***/ function(module, exports, __webpack_require__) { - -"use strict"; -"use strict"; - -var Utils_1 = __webpack_require__(0); -function SelfDefendingTemplate() { - return '\n var func = function(){return \'dev\';};\n \n Function(' + Utils_1.Utils.stringToUnicode('return/\\w+ *\\(\\) *{\\w+ *[\'|"].+[\'|"];? *}/') + ')()[\'test\'](func[\'toString\']()) !== true && !{unicodeArrayName}++ ? [][\'filter\'][\'constructor\'](' + Utils_1.Utils.stringToJSFuck('while') + ' + \'(true){}\')() : Function(\'a\', atob(' + Utils_1.Utils.stringToUnicode(Utils_1.Utils.btoa('a.call()')) + '))({forLoopFunctionName}) ? [][\'filter\'][\'constructor\'](' + Utils_1.Utils.stringToJSFuck('while') + ' + \'(false){}\')() : [][\'filter\'][\'constructor\'](' + Utils_1.Utils.stringToJSFuck('while') + ' + \'(false){}\')();\n '; -} -exports.SelfDefendingTemplate = SelfDefendingTemplate; - -/***/ }, -/* 71 */ -/***/ function(module, exports) { - -"use strict"; -"use strict"; - -function UnicodeArrayDecodeNodeTemplate() { - return "\n (function () {\n {atobPolyfill}\n \n var {forLoopFunctionName} = function () {\n var array = [];\n \n for (var i in {unicodeArrayName}) {\n array['push'](decodeURI(atob({unicodeArrayName}[i])));\n }\n \n {unicodeArrayName} = array;\n };\n \n {code}\n })();\n "; -} -exports.UnicodeArrayDecodeNodeTemplate = UnicodeArrayDecodeNodeTemplate; - -/***/ }, +/* 70 */, +/* 71 */, /* 72 */ /***/ function(module, exports) { @@ -4066,6 +3977,31 @@ if (!global._babelPolyfill) { } module.exports = JavaScriptObfuscator_1.JavaScriptObfuscator; +/***/ }, +/* 83 */ +/***/ function(module, exports, __webpack_require__) { + +"use strict"; +"use strict"; + +var Utils_1 = __webpack_require__(0); +function SelfDefendingTemplate() { + return '\n var func = function(){return \'dev\';};\n \n Function(' + Utils_1.Utils.stringToUnicode('return/\\w+ *\\(\\) *{\\w+ *[\'|"].+[\'|"];? *}/') + ')()[\'test\'](func[\'toString\']()) !== true && !{unicodeArrayName}++ ? [][\'filter\'][\'constructor\'](' + Utils_1.Utils.stringToJSFuck('while') + ' + \'(true){}\')() : Function(\'a\', atob(' + Utils_1.Utils.stringToUnicode(Utils_1.Utils.btoa('a.call()')) + '))({forLoopFunctionName}) ? [][\'filter\'][\'constructor\'](' + Utils_1.Utils.stringToJSFuck('while') + ' + \'(false){}\')() : [][\'filter\'][\'constructor\'](' + Utils_1.Utils.stringToJSFuck('while') + ' + \'(false){}\')();\n '; +} +exports.SelfDefendingTemplate = SelfDefendingTemplate; + +/***/ }, +/* 84 */ +/***/ function(module, exports) { + +"use strict"; +"use strict"; + +function UnicodeArrayAtobDecodeNodeTemplate() { + return "\n var decodedIndices = [];\n \n if (decodedIndices.indexOf(index) === -1) {\n value = atob(value);\n }\n "; +} +exports.UnicodeArrayAtobDecodeNodeTemplate = UnicodeArrayAtobDecodeNodeTemplate; + /***/ } /******/ ]); //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/src/cli/JavaScriptObfuscatorCLI.ts b/src/cli/JavaScriptObfuscatorCLI.ts index 824bdb13..cd4ef4ac 100644 --- a/src/cli/JavaScriptObfuscatorCLI.ts +++ b/src/cli/JavaScriptObfuscatorCLI.ts @@ -126,6 +126,7 @@ export class JavaScriptObfuscatorCLI { .option('--debugProtection ', 'Disable browser Debug panel (can cause DevTools enabled browser freeze)', JavaScriptObfuscatorCLI.parseBoolean) .option('--debugProtectionInterval ', 'Disable browser Debug panel even after page was loaded (can cause DevTools enabled browser freeze)', JavaScriptObfuscatorCLI.parseBoolean) .option('--disableConsoleOutput ', 'Allow console.log, console.info, console.error and console.warn messages output into browser console', JavaScriptObfuscatorCLI.parseBoolean) + .option('--domainLock ', 'Blocks the execution of the code in domains that do not match the passed RegExp patterns (comma separated)', (val: string) => val.split(',')) .option('--encodeUnicodeLiterals ', 'All literals in Unicode array become encoded in Base64 (this option can slightly slow down your code speed)', JavaScriptObfuscatorCLI.parseBoolean) .option('--reservedNames ', 'Disable obfuscation of variable names, function names and names of function parameters that match the passed RegExp patterns (comma separated)', (val: string) => val.split(',')) .option('--rotateUnicodeArray ', 'Disable rotation of unicode array values during obfuscation', JavaScriptObfuscatorCLI.parseBoolean) @@ -140,8 +141,6 @@ export class JavaScriptObfuscatorCLI { ) .option('--unicodeArray ', 'Disables gathering of all literal strings into an array and replacing every literal string with an array call', JavaScriptObfuscatorCLI.parseBoolean) .option('--unicodeArrayThreshold ', 'The probability that the literal string will be inserted into unicodeArray (Default: 0.8, Min: 0, Max: 1)', parseFloat) - .option('--wrapUnicodeArrayCalls ', 'Disables usage of special access function instead of direct array call', JavaScriptObfuscatorCLI.parseBoolean) - .option('--domainLock ', 'Blocks the execution of the code in domains that do not match the passed RegExp patterns (comma separated)', (val: string) => val.split(',')) .parse(this.rawArguments); this.commands.on('--help', () => { diff --git a/src/custom-nodes/unicode-array-nodes/UnicodeArrayCallsWrapper.ts b/src/custom-nodes/unicode-array-nodes/UnicodeArrayCallsWrapper.ts index dc893eda..e288deb3 100644 --- a/src/custom-nodes/unicode-array-nodes/UnicodeArrayCallsWrapper.ts +++ b/src/custom-nodes/unicode-array-nodes/UnicodeArrayCallsWrapper.ts @@ -8,12 +8,17 @@ import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement'; import { AppendState } from '../../enums/AppendState'; +import { NO_CUSTOM_NODES_PRESET } from '../../preset-options/NoCustomNodesPreset'; + +import { AtobTemplate } from '../../templates/custom-nodes/AtobTemplate'; +import { SelfDefendingTemplate } from '../../templates/custom-nodes/unicode-array-nodes/unicode-array-calls-wrapper/SelfDefendingTemplate'; import { UnicodeArrayCallsWrapperTemplate } from '../../templates/custom-nodes/unicode-array-nodes/unicode-array-calls-wrapper/UnicodeArrayCallsWrapperTemplate'; import { AbstractCustomNode } from '../AbstractCustomNode'; +import { JavaScriptObfuscator } from '../../JavaScriptObfuscator'; import { NodeUtils } from '../../NodeUtils'; import { UnicodeArray } from '../../UnicodeArray'; -import { Utils } from '../../Utils'; +import { UnicodeArrayAtobDecodeNodeTemplate } from '../../templates/custom-nodes/unicode-array-nodes/unicode-array-calls-wrapper/UnicodeArrayAtobDecodeNodeTemplate'; export class UnicodeArrayCallsWrapper extends AbstractCustomNode { /** @@ -80,18 +85,46 @@ export class UnicodeArrayCallsWrapper extends AbstractCustomNode { return super.getNode(); } + /** + * @returns {any} + */ + protected getDecodeUnicodeArrayTemplate (): string { + const forLoopFunctionName: string = 'forLoopFunc'; + + let code: string; + + if (this.options.selfDefending) { + code = SelfDefendingTemplate().formatUnicorn({ + forLoopFunctionName, + unicodeArrayName: this.unicodeArrayName + }); + } else { + code = `${forLoopFunctionName}();`; + } + + return UnicodeArrayAtobDecodeNodeTemplate().formatUnicorn({ + atobPolyfill: AtobTemplate(), + code, + forLoopFunctionName, + unicodeArrayName: this.unicodeArrayName + }) + } + /** * @returns {ESTree.Node} */ protected getNodeStructure (): ESTree.Node { - let keyName: string = Utils.getRandomVariableName(); + let decodeNodeTemplate: string = this.options.encodeUnicodeLiterals ? this.getDecodeUnicodeArrayTemplate() : ''; return NodeUtils.convertCodeToStructure( - UnicodeArrayCallsWrapperTemplate().formatUnicorn({ - keyName: keyName, - unicodeArrayCallsWrapperName: this.unicodeArrayCallsWrapperName, - unicodeArrayName: this.unicodeArrayName - }) + JavaScriptObfuscator.obfuscate( + UnicodeArrayCallsWrapperTemplate().formatUnicorn({ + decodeNodeTemplate: decodeNodeTemplate, + unicodeArrayCallsWrapperName: this.unicodeArrayCallsWrapperName, + unicodeArrayName: this.unicodeArrayName + }), + NO_CUSTOM_NODES_PRESET + ).getObfuscatedCode() ); } } diff --git a/src/custom-nodes/unicode-array-nodes/UnicodeArrayDecodeNode.ts b/src/custom-nodes/unicode-array-nodes/UnicodeArrayDecodeNode.ts deleted file mode 100644 index 07938a48..00000000 --- a/src/custom-nodes/unicode-array-nodes/UnicodeArrayDecodeNode.ts +++ /dev/null @@ -1,101 +0,0 @@ -import * as ESTree from 'estree'; - -import 'format-unicorn'; - -import { IOptions } from '../../interfaces/IOptions'; - -import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement'; - -import { AppendState } from '../../enums/AppendState'; - -import { NO_CUSTOM_NODES_PRESET } from '../../preset-options/NoCustomNodesPreset'; - -import { AtobTemplate } from '../../templates/custom-nodes/AtobTemplate'; -import { SelfDefendingTemplate } from '../../templates/custom-nodes/unicode-array-nodes/unicode-array-decode-node/SelfDefendingTemplate'; -import { UnicodeArrayDecodeNodeTemplate } from '../../templates/custom-nodes/unicode-array-nodes/unicode-array-decode-node/UnicodeArrayDecodeNodeTemplate'; - -import { AbstractCustomNode } from '../AbstractCustomNode'; -import { JavaScriptObfuscator } from '../../JavaScriptObfuscator'; -import { NodeUtils } from '../../NodeUtils'; -import { UnicodeArray } from '../../UnicodeArray'; - -export class UnicodeArrayDecodeNode extends AbstractCustomNode { - /** - * @type {AppendState} - */ - protected appendState: AppendState = AppendState.AfterObfuscation; - - /** - * @type {UnicodeArray} - */ - private unicodeArray: UnicodeArray; - - /** - * @type {string} - */ - private unicodeArrayName: string; - - /** - * @param unicodeArrayName - * @param unicodeArray - * @param options - */ - constructor ( - unicodeArrayName: string, - unicodeArray: UnicodeArray, - options: IOptions - ) { - super(options); - - this.unicodeArrayName = unicodeArrayName; - this.unicodeArray = unicodeArray; - } - - /** - * @param blockScopeNode - */ - public appendNode (blockScopeNode: TNodeWithBlockStatement): void { - if (!this.unicodeArray.getLength()) { - return; - } - - NodeUtils.insertNodeAtIndex(blockScopeNode.body, this.getNode(), 1); - } - - /** - * @returns {ESTree.Node} - */ - public getNode (): ESTree.Node { - return super.getNode(); - } - - /** - * @returns {ESTree.Node} - */ - protected getNodeStructure (): ESTree.Node { - const forLoopFunctionName: string = 'forLoopFunc'; - - let code: string; - - if (this.options.selfDefending) { - code = SelfDefendingTemplate().formatUnicorn({ - forLoopFunctionName, - unicodeArrayName: this.unicodeArrayName - }); - } else { - code = `${forLoopFunctionName}();`; - } - - return NodeUtils.convertCodeToStructure( - JavaScriptObfuscator.obfuscate( - UnicodeArrayDecodeNodeTemplate().formatUnicorn({ - atobPolyfill: AtobTemplate(), - code, - forLoopFunctionName, - unicodeArrayName: this.unicodeArrayName - }), - NO_CUSTOM_NODES_PRESET - ).getObfuscatedCode() - ); - } -} diff --git a/src/interfaces/IObfuscatorOptions.d.ts b/src/interfaces/IObfuscatorOptions.d.ts index 9039b4d0..efe3c53a 100644 --- a/src/interfaces/IObfuscatorOptions.d.ts +++ b/src/interfaces/IObfuscatorOptions.d.ts @@ -16,6 +16,5 @@ export interface IObfuscatorOptions { sourceMapMode?: TSourceMapMode; unicodeArray?: boolean; unicodeArrayThreshold?: number; - wrapUnicodeArrayCalls?: boolean; [key: string]: any; } diff --git a/src/interfaces/IOptions.d.ts b/src/interfaces/IOptions.d.ts index a156a6f7..1113310e 100644 --- a/src/interfaces/IOptions.d.ts +++ b/src/interfaces/IOptions.d.ts @@ -16,5 +16,4 @@ export interface IOptions { readonly sourceMapMode: TSourceMapMode; readonly unicodeArray: boolean; readonly unicodeArrayThreshold: number; - readonly wrapUnicodeArrayCalls: boolean; } diff --git a/src/node-groups/UnicodeArrayNodesGroup.ts b/src/node-groups/UnicodeArrayNodesGroup.ts index 9d887e0d..72f97a39 100644 --- a/src/node-groups/UnicodeArrayNodesGroup.ts +++ b/src/node-groups/UnicodeArrayNodesGroup.ts @@ -3,7 +3,6 @@ import { IOptions } from '../interfaces/IOptions'; import { AbstractNodesGroup } from './AbstractNodesGroup'; import { UnicodeArray } from '../UnicodeArray'; import { UnicodeArrayCallsWrapper } from '../custom-nodes/unicode-array-nodes/UnicodeArrayCallsWrapper'; -import { UnicodeArrayDecodeNode } from '../custom-nodes/unicode-array-nodes/UnicodeArrayDecodeNode'; import { UnicodeArrayNode } from '../custom-nodes/unicode-array-nodes/UnicodeArrayNode'; import { UnicodeArrayRotateFunctionNode } from '../custom-nodes/unicode-array-nodes/UnicodeArrayRotateFunctionNode'; import { Utils } from '../Utils'; @@ -51,34 +50,17 @@ export class UnicodeArrayNodesGroup extends AbstractNodesGroup { this.options ); + this.nodes.set('unicodeArrayNode', unicodeArrayNode); this.nodes.set( - 'unicodeArrayNode', - unicodeArrayNode + 'unicodeArrayCallsWrapper', + new UnicodeArrayCallsWrapper( + this.unicodeArrayTranslatorName, + this.unicodeArrayName, + unicodeArray, + this.options + ) ); - if (this.options.wrapUnicodeArrayCalls) { - this.nodes.set( - 'unicodeArrayCallsWrapper', - new UnicodeArrayCallsWrapper( - this.unicodeArrayTranslatorName, - this.unicodeArrayName, - unicodeArray, - this.options - ) - ); - } - - if (this.options.encodeUnicodeLiterals) { - this.nodes.set( - 'unicodeArrayDecodeNode', - new UnicodeArrayDecodeNode ( - this.unicodeArrayName, - unicodeArray, - this.options - ) - ); - } - if (this.options.rotateUnicodeArray) { this.nodes.set( 'unicodeArrayRotateFunctionNode', diff --git a/src/node-obfuscators/replacers/StringLiteralReplacer.ts b/src/node-obfuscators/replacers/StringLiteralReplacer.ts index 8031e333..0564042e 100644 --- a/src/node-obfuscators/replacers/StringLiteralReplacer.ts +++ b/src/node-obfuscators/replacers/StringLiteralReplacer.ts @@ -53,16 +53,12 @@ export class StringLiteralReplacer extends AbstractReplacer { hexadecimalIndex = new NumberLiteralReplacer(this.nodes, this.options) .replace(indexOfValue); - if (this.options.wrapUnicodeArrayCalls) { - const unicodeArrayCallsWrapper: TUnicodeArrayCallsWrapper = this.nodes.get('unicodeArrayCallsWrapper'); + const unicodeArrayCallsWrapper: TUnicodeArrayCallsWrapper = this.nodes.get('unicodeArrayCallsWrapper'); - if (!unicodeArrayCallsWrapper) { - throw new ReferenceError('`unicodeArrayCallsWrapper` node is not found in Map with custom nodes.'); - } - - return `${unicodeArrayCallsWrapper.getNodeIdentifier()}('${hexadecimalIndex}')`; + if (!unicodeArrayCallsWrapper) { + throw new ReferenceError('`unicodeArrayCallsWrapper` node is not found in Map with custom nodes.'); } - return `${unicodeArrayNode.getNodeIdentifier()}[${hexadecimalIndex}]`; + return `${unicodeArrayCallsWrapper.getNodeIdentifier()}('${hexadecimalIndex}')`; } } diff --git a/src/options/Options.ts b/src/options/Options.ts index 4ba0bb3f..94af7e64 100644 --- a/src/options/Options.ts +++ b/src/options/Options.ts @@ -139,12 +139,6 @@ export class Options implements IOptions { @Max(1) public readonly unicodeArrayThreshold: number; - /** - * @type {boolean} - */ - @IsBoolean() - public readonly wrapUnicodeArrayCalls: boolean; - /** * @param obfuscatorOptions */ diff --git a/src/templates/custom-nodes/unicode-array-nodes/unicode-array-decode-node/SelfDefendingTemplate.ts b/src/templates/custom-nodes/unicode-array-nodes/unicode-array-calls-wrapper/SelfDefendingTemplate.ts similarity index 100% rename from src/templates/custom-nodes/unicode-array-nodes/unicode-array-decode-node/SelfDefendingTemplate.ts rename to src/templates/custom-nodes/unicode-array-nodes/unicode-array-calls-wrapper/SelfDefendingTemplate.ts diff --git a/src/templates/custom-nodes/unicode-array-nodes/unicode-array-calls-wrapper/UnicodeArrayAtobDecodeNodeTemplate.ts b/src/templates/custom-nodes/unicode-array-nodes/unicode-array-calls-wrapper/UnicodeArrayAtobDecodeNodeTemplate.ts new file mode 100644 index 00000000..2e14184c --- /dev/null +++ b/src/templates/custom-nodes/unicode-array-nodes/unicode-array-calls-wrapper/UnicodeArrayAtobDecodeNodeTemplate.ts @@ -0,0 +1,12 @@ +/** + * @returns {string} + */ +export function UnicodeArrayAtobDecodeNodeTemplate (): string { + return ` + var decodedIndices = []; + + if (decodedIndices.indexOf(index) === -1) { + value = atob(value); + } + `; +} diff --git a/src/templates/custom-nodes/unicode-array-nodes/unicode-array-calls-wrapper/UnicodeArrayCallsWrapperTemplate.ts b/src/templates/custom-nodes/unicode-array-nodes/unicode-array-calls-wrapper/UnicodeArrayCallsWrapperTemplate.ts index 6fdb66fd..e93a7129 100644 --- a/src/templates/custom-nodes/unicode-array-nodes/unicode-array-calls-wrapper/UnicodeArrayCallsWrapperTemplate.ts +++ b/src/templates/custom-nodes/unicode-array-nodes/unicode-array-calls-wrapper/UnicodeArrayCallsWrapperTemplate.ts @@ -3,8 +3,12 @@ */ export function UnicodeArrayCallsWrapperTemplate (): string { return ` - var {unicodeArrayCallsWrapperName} = function ({keyName}) { - return {unicodeArrayName}[parseInt({keyName}, 0x010)]; + var {unicodeArrayCallsWrapperName} = function (index, key) { + var value = {unicodeArrayName}[parseInt(index, 0x010)] + + {decodeNodeTemplate} + + return value; }; `; } diff --git a/src/templates/custom-nodes/unicode-array-nodes/unicode-array-decode-node/UnicodeArrayDecodeNodeTemplate.ts b/src/templates/custom-nodes/unicode-array-nodes/unicode-array-calls-wrapper/UnicodeArrayRC4DecodeNodeTemplate.ts similarity index 100% rename from src/templates/custom-nodes/unicode-array-nodes/unicode-array-decode-node/UnicodeArrayDecodeNodeTemplate.ts rename to src/templates/custom-nodes/unicode-array-nodes/unicode-array-calls-wrapper/UnicodeArrayRC4DecodeNodeTemplate.ts diff --git a/test/functional-tests/JavaScriptObfuscator.spec.ts b/test/functional-tests/JavaScriptObfuscator.spec.ts index f4c6aabd..e1a43d04 100644 --- a/test/functional-tests/JavaScriptObfuscator.spec.ts +++ b/test/functional-tests/JavaScriptObfuscator.spec.ts @@ -102,29 +102,28 @@ describe('JavaScriptObfuscator', () => { }); it('should obfuscate simple code with literal variable value', () => { - let pattern: RegExp = /^var _0x(\w){4} *= *\['(\\[x|u]\d+)+'\]; *var *test *= *_0x(\w){4}\[0x0\];$/; - - assert.match( - JavaScriptObfuscator.obfuscate( + let pattern1: RegExp = /^var _0x(\w){4} *= *\['(\\[x|u]\d+)+'\];/, + pattern2: RegExp = /var *test *= *_0x(\w){4}\('0x0'\);$/, + obfuscatedCode1: string = JavaScriptObfuscator.obfuscate( `var test = 'abc';`, Object.assign({}, NO_CUSTOM_NODES_PRESET, { unicodeArray: true, unicodeArrayThreshold: 1 }) ).getObfuscatedCode(), - pattern - ); - - assert.match( - JavaScriptObfuscator.obfuscate( + obfuscatedCode2: string = JavaScriptObfuscator.obfuscate( `var test = 'абц';`, Object.assign({}, NO_CUSTOM_NODES_PRESET, { unicodeArray: true, unicodeArrayThreshold: 1 }) - ).getObfuscatedCode(), - pattern - ); + ).getObfuscatedCode(); + + assert.match(obfuscatedCode1, pattern1); + assert.match(obfuscatedCode1, pattern2); + + assert.match(obfuscatedCode2, pattern1); + assert.match(obfuscatedCode2, pattern2); }); }); }); diff --git a/test/functional-tests/custom-nodes/unicode-array-nodes/UnicodeArrayCallsWrapper.spec.ts b/test/functional-tests/custom-nodes/unicode-array-nodes/UnicodeArrayCallsWrapper.spec.ts index f4067139..a4e82037 100644 --- a/test/functional-tests/custom-nodes/unicode-array-nodes/UnicodeArrayCallsWrapper.spec.ts +++ b/test/functional-tests/custom-nodes/unicode-array-nodes/UnicodeArrayCallsWrapper.spec.ts @@ -5,7 +5,7 @@ import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscator'; const assert: Chai.AssertStatic = require('chai').assert; describe('UnicodeArrayCallsWrapper', () => { - it('should correctly appendNode `UnicodeArrayCallsWrapper` custom node into the obfuscated code if `wrapUnicodeArrayCalls` option is set', () => { + it('should correctly appendNode `UnicodeArrayCallsWrapper` custom node into the obfuscated code', () => { let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( `var test = 'test';`, { @@ -13,17 +13,9 @@ describe('UnicodeArrayCallsWrapper', () => { } ); - assert.match(obfuscationResult.getObfuscatedCode(), /return _0x([a-z0-9]){4}\[parseInt\(_0x([a-z0-9]){4,6}, *0x010\)\];/); - }); - - it('should\'t appendNode `UnicodeArrayDecodeNode` custom node into the obfuscated code if `wrapUnicodeArrayCalls` option is not set', () => { - let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - `var test = 'test';`, - { - wrapUnicodeArrayCalls: false - } + assert.match( + obfuscationResult.getObfuscatedCode(), + /var *_0x([a-z0-9]){4,6} *= *_0x([a-z0-9]){4}\[parseInt\(_0x([a-z0-9]){4,6}, *0x10\)\];/ ); - - assert.notMatch(obfuscationResult.getObfuscatedCode(), /return _0x([a-z0-9]){4}\[parseInt\(_0x([a-z0-9]){4,6}, *0x010\)\];/); }); }); diff --git a/test/functional-tests/custom-nodes/unicode-array-nodes/UnicodeArrayDecodeNode.spec.ts b/test/functional-tests/custom-nodes/unicode-array-nodes/UnicodeArrayDecodeNode.spec.ts deleted file mode 100644 index e3fc6058..00000000 --- a/test/functional-tests/custom-nodes/unicode-array-nodes/UnicodeArrayDecodeNode.spec.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { IObfuscationResult } from '../../../../src/interfaces/IObfuscationResult'; - -import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscator'; - -const assert: Chai.AssertStatic = require('chai').assert; - -describe('UnicodeArrayDecodeNode', () => { - it('should correctly appendNode `UnicodeArrayDecodeNode` custom node into the obfuscated code if `encodeUnicodeLiterals` option is set', () => { - let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - `var test = 'test';`, - { - encodeUnicodeLiterals: true - } - ); - - assert.match(obfuscationResult.getObfuscatedCode(), /decodeURI\(atob\(_0x([a-z0-9]){4}\[_0x([a-z0-9]){4,6}\]\)\)/); - }); - - it('should\'t appendNode `UnicodeArrayDecodeNode` custom node into the obfuscated code if `encodeUnicodeLiterals` option is not set', () => { - let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( - `var test = 'test';`, - { - encodeUnicodeLiterals: false - } - ); - - assert.notMatch(obfuscationResult.getObfuscatedCode(), /decodeURI\(atob\(_0x([a-z0-9]){4}\[_0x([a-z0-9]){4,6}\]\)\)/); - }); -}); diff --git a/test/functional-tests/node-obfuscators/MemberExpressionObfuscator.spec.ts b/test/functional-tests/node-obfuscators/MemberExpressionObfuscator.spec.ts index 34c1d13f..a0c04159 100644 --- a/test/functional-tests/node-obfuscators/MemberExpressionObfuscator.spec.ts +++ b/test/functional-tests/node-obfuscators/MemberExpressionObfuscator.spec.ts @@ -27,7 +27,7 @@ describe('MemberExpressionObfuscator', () => { ); assert.match(obfuscationResult.getObfuscatedCode(), /var *_0x([a-z0-9]){4} *= *\['\\x6c\\x6f\\x67'\];/); - assert.match(obfuscationResult.getObfuscatedCode(), /var *test *= *console\[_0x([a-z0-9]){4}\[0x0\]\];/); + assert.match(obfuscationResult.getObfuscatedCode(), /var *test *= *console\[_0x([a-z0-9]){4}\('0x0'\)\];/); }); }); @@ -42,7 +42,7 @@ describe('MemberExpressionObfuscator', () => { ); assert.match(obfuscationResult.getObfuscatedCode(), /var *_0x([a-z0-9]){4} *= *\['\\x6c\\x6f\\x67'\];/); - assert.match(obfuscationResult.getObfuscatedCode(), /var *test *= *console\[_0x([a-z0-9]){4}\[0x0\]\];/); + assert.match(obfuscationResult.getObfuscatedCode(), /var *test *= *console\[_0x([a-z0-9]){4}\('0x0'\)\];/); }); it('should ignore square brackets call with identifier value', () => { diff --git a/test/functional-tests/node-obfuscators/MethodDefinitionObfuscator.spec.ts b/test/functional-tests/node-obfuscators/MethodDefinitionObfuscator.spec.ts index dd1e0fcd..b62404b7 100644 --- a/test/functional-tests/node-obfuscators/MethodDefinitionObfuscator.spec.ts +++ b/test/functional-tests/node-obfuscators/MethodDefinitionObfuscator.spec.ts @@ -33,7 +33,7 @@ describe('MethodDefinitionObfuscator', () => { ); assert.match(obfuscationResult.getObfuscatedCode(), /var *_0x([a-z0-9]){4} *= *\['\\x62\\x61\\x72'\];/); - assert.match(obfuscationResult.getObfuscatedCode(), /\[_0x([a-z0-9]){4}\[0x0\]\]\(\)\{\}/); + assert.match(obfuscationResult.getObfuscatedCode(), /\[_0x([a-z0-9]){4}\('0x0'\)\]\(\)\{\}/); }); it('should not obfuscate method definition node with `constructor` key', () => { diff --git a/test/functional-tests/templates/custom-nodes/unicode-array-nodes/UnicodeArrayDecodeNodeTemplate.spec.ts b/test/functional-tests/templates/custom-nodes/unicode-array-nodes/UnicodeArrayDecodeNodeTemplate.spec.ts index abc3a6eb..1ab92ee6 100644 --- a/test/functional-tests/templates/custom-nodes/unicode-array-nodes/UnicodeArrayDecodeNodeTemplate.spec.ts +++ b/test/functional-tests/templates/custom-nodes/unicode-array-nodes/UnicodeArrayDecodeNodeTemplate.spec.ts @@ -1,7 +1,7 @@ import 'format-unicorn'; import { AtobTemplate } from '../../../../../src/templates/custom-nodes/AtobTemplate'; -import { UnicodeArrayDecodeNodeTemplate } from '../../../../../src/templates/custom-nodes/unicode-array-nodes/unicode-array-decode-node/UnicodeArrayDecodeNodeTemplate'; +import { UnicodeArrayAtobDecodeNodeTemplate } from '../../../../../src/templates/custom-nodes/unicode-array-nodes/unicode-array-calls-wrapper/UnicodeArrayAtobDecodeNodeTemplate'; import { Utils } from '../../../../../src/Utils'; @@ -13,7 +13,7 @@ const assert: Chai.AssertStatic = require('chai').assert; * @returns {Function} */ function getFunctionFromTemplate (templateData: any, unicodeArrayName: string) { - let domainLockTemplate: string = UnicodeArrayDecodeNodeTemplate().formatUnicorn(templateData); + let domainLockTemplate: string = UnicodeArrayAtobDecodeNodeTemplate().formatUnicorn(templateData); return Function(` var ${unicodeArrayName} = ['${Utils.btoa('test1')}', '${Utils.btoa('test2')}']; @@ -24,7 +24,7 @@ function getFunctionFromTemplate (templateData: any, unicodeArrayName: string) { `)(); } -describe('UnicodeArrayDecodeNodeTemplate (): string', () => { +describe('UnicodeArrayAtobDecodeNodeTemplate (): string', () => { let forLoopFunctionName: string = 'forLoop', code: string = `${forLoopFunctionName}();`, unicodeArrayName: string = 'unicodeArray'; diff --git a/test/index.spec.ts b/test/index.spec.ts index df1564ab..5108a506 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -27,7 +27,6 @@ import './functional-tests/JavaScriptObfuscatorInternal.spec'; import './functional-tests/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.spec'; import './functional-tests/custom-nodes/domain-lock-nodes/DomainLockNode.spec'; import './functional-tests/custom-nodes/unicode-array-nodes/UnicodeArrayCallsWrapper.spec'; -import './functional-tests/custom-nodes/unicode-array-nodes/UnicodeArrayDecodeNode.spec'; import './functional-tests/custom-nodes/unicode-array-nodes/UnicodeArrayRotateFunctionNode.spec'; import './functional-tests/custom-nodes/unicode-array-nodes/UnicodeArrayNode.spec'; import './functional-tests/node-obfuscators/FunctionObfuscator.spec';