diff --git a/CHANGELOG.md b/CHANGELOG.md index c66bb7ad..a640d513 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ Change Log === v0.12.0 --- +* **New option:** `target` allows to set target environment for obfuscated code. * Added ability to disable and enable obfuscation for specific parts of the code by adding conditional comments. * Added obfuscation of `es2015` class names. * CLI: added directory obfuscation. diff --git a/README.md b/README.md index a5ca5269..e7c8d249 100644 --- a/README.md +++ b/README.md @@ -266,6 +266,7 @@ Following options are available for the JS Obfuscator: stringArray: true, stringArrayEncoding: false, stringArrayThreshold: 0.75, + target: 'browser', unicodeEscapeSequence: false } ``` @@ -301,6 +302,7 @@ Following options are available for the JS Obfuscator: --stringArray --stringArrayEncoding [true, false, base64, rc4] --stringArrayThreshold + --target [browser, extension, node] --unicodeEscapeSequence ``` @@ -664,6 +666,19 @@ This setting is especially useful for large code size because it repeatedly call `stringArrayThreshold: 0` equals to `stringArray: false`. +### `target` +Type: `string` Default: `browser` + +Allows to set target environment for obfuscated code. + +Available values: +* `browser`; +* `extension`; +* `node`. + +Currently output code for `browser` and `node` targets is identical. +Output code for `extension` target is not using `eval`. + ### `unicodeEscapeSequence` Type: `boolean` Default: `false` diff --git a/dist/index.js b/dist/index.js index 35573a83..4fba0926 100644 --- a/dist/index.js +++ b/dist/index.js @@ -21,5 +21,5 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -require("source-map-support").install(),module.exports=function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={};return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=42)}([function(e,t){e.exports=require("inversify")},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});!function(e){e.Factory__ICalleeDataExtractor="Factory",e.Factory__IControlFlowCustomNode="Factory",e.Factory__IControlFlowReplacer="Factory",e.Factory__ICustomNode="Factory",e.Factory__ICustomNodeGroup="Factory",e.Factory__IIdentifierObfuscatingReplacer="Factory",e.Factory__INodeGuard="Factory",e.Factory__INodeTransformer="Factory",e.Factory__IObfuscationResult="Factory",e.Factory__IObfuscatingReplacer="Factory",e.Factory__TControlFlowStorage="Factory",e.IArrayUtils="IArrayUtils",e.ICalleeDataExtractor="ICalleeDataExtractor",e.ICryptUtils="ICryptUtils",e.ICustomNode="ICustomNode",e.ICustomNodeGroup="ICustomNodeGroup",e.IControlFlowReplacer="IControlFlowReplacer",e.IDeadCodeInjectionReplacer="IDeadCodeInjectionReplacer",e.IEscapeSequenceEncoder="IEscapeSequenceEncoder",e.IIdentifierObfuscatingReplacer="IIdentifierObfuscatingReplacer",e.IJavaScriptObfuscator="IJavaScriptObfuscator",e.ILogger="ILogger",e.INodeGuard="INodeGuard",e.INodeTransformer="INodeTransformer",e.IObfuscationEventEmitter="IObfuscationEventEmitter",e.IObfuscationResult="IObfuscationResult",e.IOptions="IOptions",e.IObfuscatingReplacer="IObfuscatingReplacer",e.IRandomGenerator="IRandomGenerator",e.ISourceCode="ISourceCode",e.ISourceMapCorrector="ISourceMapCorrector",e.IStackTraceAnalyzer="IStackTraceAnalyzer",e.ITransformersRunner="ITransformersRunner",e.Newable__ICustomNode="Newable",e.Newable__TControlFlowStorage="Newable",e.TCustomNodeGroupStorage="TCustomNodeGroupStorage",e.TStringArrayStorage="TStringArrayStorage"}(t.ServiceIdentifiers||(t.ServiceIdentifiers={}))},function(e,t){e.exports=require("tslib")},function(e,t,r){"use strict";function n(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"initialize",t=Object.keys(this)[0];return function(r,n){var o={configurable:!0,enumerable:!0},a=r[e];if(!a||"function"!=typeof a)throw new Error("`"+e+"` method with initialization logic not found. `@"+t+"` decorator requires `"+e+"` method");var i="_"+n,c=Object.getOwnPropertyDescriptor(r,i)||o,s=Object.getOwnPropertyDescriptor(r,e)||o,u=s.value;return Object.defineProperty(r,n,Object.assign({},c,{get:function(){if(void 0===this[i])throw new Error("Property `"+n+"` is not initialized! Initialize it first!");return this[i]},set:function(e){this[i]=e}})),Object.defineProperty(r,e,Object.assign({},s,{value:function(){u.apply(this,arguments),this[n]}})),c}}Object.defineProperty(t,"__esModule",{value:!0}),t.initializable=n},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a=function(){function e(e,t){for(var r=0;r1&&void 0!==arguments[1]?arguments[1]:0;if(l.NodeGuards.isNodeHasBlockStatement(e)){if(void 0===e.body[t])throw new ReferenceError("Wrong index `"+t+"`. Block-statement body length is `"+e.body.length+"`");return e.body[t]}throw new TypeError("The specified node have no a block-statement")}},{key:"getBlockScopesOfNode",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],n=t.parentNode;if(!n)throw new ReferenceError("`parentNode` property of given node is `undefined`");if(l.NodeGuards.isBlockStatementNode(n)){if(!n.parentNode)throw new ReferenceError("`parentNode` property of `parentNode` of given node is `undefined`");-1!==e.nodesWithBlockScope.indexOf(n.parentNode.type)&&r.push(n)}return t!==n?e.getBlockScopesOfNode(n,r):(l.NodeGuards.isNodeHasBlockStatement(n)&&r.push(n),r)}},{key:"getNodeBlockScopeDepth",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=t.parentNode;if(!n)throw new ReferenceError("`parentNode` property of given node is `undefined`");return l.NodeGuards.isProgramNode(n)?r:l.NodeGuards.isBlockStatementNode(t)&&-1!==e.nodesWithBlockScope.indexOf(n.type)?e.getNodeBlockScopeDepth(n,++r):e.getNodeBlockScopeDepth(n,r)}},{key:"getUnaryExpressionArgumentNode",value:function(t){return l.NodeGuards.isUnaryExpressionNode(t.argument)?e.getUnaryExpressionArgumentNode(t.argument):t.argument}},{key:"parentize",value:function(t){return s.traverse(t,{enter:e.parentizeNode}),t}},{key:"parentizeNode",value:function(e,t){return e.parentNode=t||e,e.obfuscatedNode=!1,e}},{key:"typedReplace",value:function(t,r,n){e.typedTraverse(t,r,n,"replace")}},{key:"typedTraverse",value:function(e,t,r){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"traverse";s[n](e,{enter:function(e,n){if(e.type===t&&r.enter)return r.enter(e,n)},leave:function(e,n){if(e.type===t&&r.leave)return r.leave(e,n)}})}}]),e}();f.nodesWithBlockScope=[u.NodeType.ArrowFunctionExpression,u.NodeType.FunctionDeclaration,u.NodeType.FunctionExpression,u.NodeType.MethodDefinition,u.NodeType.Program],t.NodeUtils=f},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function e(e,t){for(var r=0;r0&&void 0!==arguments[0]?arguments[0]:[];return{type:i.NodeType.Program,body:e,sourceType:"script",obfuscatedNode:!1}}},{key:"getArrayExpressionNode",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return{type:i.NodeType.ArrayExpression,elements:e}}},{key:"getAssignmentExpressionNode",value:function(e,t,r){return{type:i.NodeType.AssignmentExpression,operator:e,left:t,right:r,obfuscatedNode:!1}}},{key:"getBinaryExpressionNode",value:function(e,t,r){return{type:i.NodeType.BinaryExpression,operator:e,left:t,right:r,obfuscatedNode:!1}}},{key:"getBlockStatementNode",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return{type:i.NodeType.BlockStatement,body:e,obfuscatedNode:!1}}},{key:"getBreakStatement",value:function(e){var t={type:i.NodeType.BreakStatement,obfuscatedNode:!1};return e&&(t.label=e),t}},{key:"getCatchClauseNode",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return{type:i.NodeType.CatchClause,param:e.getIdentifierNode("err"),body:e.getBlockStatementNode(t),obfuscatedNode:!1}}},{key:"getCallExpressionNode",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return{type:i.NodeType.CallExpression,callee:e,arguments:t,obfuscatedNode:!1}}},{key:"getContinueStatement",value:function(e){var t={type:i.NodeType.ContinueStatement,obfuscatedNode:!1};return e&&(t.label=e),t}},{key:"getExpressionStatementNode",value:function(e){return{type:i.NodeType.ExpressionStatement,expression:e,obfuscatedNode:!1}}},{key:"getFunctionDeclarationNode",value:function(t,r,n){return{type:i.NodeType.FunctionDeclaration,id:e.getIdentifierNode(t),params:r,body:n,generator:!1,obfuscatedNode:!1}}},{key:"getFunctionExpressionNode",value:function(e,t){return{type:i.NodeType.FunctionExpression,params:e,body:t,generator:!1,obfuscatedNode:!1}}},{key:"getIfStatementNode",value:function(e,t,r){return Object.assign({type:i.NodeType.IfStatement,test:e,consequent:t},r&&{alternate:r},{obfuscatedNode:!1})}},{key:"getIdentifierNode",value:function(e){return{type:i.NodeType.Identifier,name:e,obfuscatedNode:!1}}},{key:"getLabeledStatement",value:function(e,t){return{type:i.NodeType.LabeledStatement,label:e,body:t,obfuscatedNode:!1}}},{key:"getLiteralNode",value:function(e,t){return t=void 0!==t?t:"'"+e+"'",{type:i.NodeType.Literal,value:e,raw:t,"x-verbatim-property":{content:t,precedence:a.Precedence.Primary},obfuscatedNode:!1}}},{key:"getLogicalExpressionNode",value:function(e,t,r){return{type:i.NodeType.LogicalExpression,operator:e,left:t,right:r,obfuscatedNode:!1}}},{key:"getMemberExpressionNode",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return{type:i.NodeType.MemberExpression,computed:r,object:e,property:t,obfuscatedNode:!1}}},{key:"getObjectExpressionNode",value:function(e){return{type:i.NodeType.ObjectExpression,properties:e,obfuscatedNode:!1}}},{key:"getPropertyNode",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return{type:i.NodeType.Property,key:e,value:t,kind:"init",method:!1,shorthand:!1,computed:r,obfuscatedNode:!1}}},{key:"getUnaryExpressionNode",value:function(e,t){var r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return{type:i.NodeType.UnaryExpression,operator:e,argument:t,prefix:r,obfuscatedNode:!1}}},{key:"getReturnStatementNode",value:function(e){return{type:i.NodeType.ReturnStatement,argument:e,obfuscatedNode:!1}}},{key:"getSwitchStatementNode",value:function(e,t){return{type:i.NodeType.SwitchStatement,discriminant:e,cases:t,obfuscatedNode:!1}}},{key:"getSwitchCaseNode",value:function(e,t){return{type:i.NodeType.SwitchCase,test:e,consequent:t,obfuscatedNode:!1}}},{key:"getUpdateExpressionNode",value:function(e,t){return{type:i.NodeType.UpdateExpression,operator:e,argument:t,prefix:!1,obfuscatedNode:!1}}},{key:"getVariableDeclarationNode",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"var";return{type:i.NodeType.VariableDeclaration,declarations:e,kind:t,obfuscatedNode:!1}}},{key:"getVariableDeclaratorNode",value:function(e,t){return{type:i.NodeType.VariableDeclarator,id:e,init:t,obfuscatedNode:!1}}},{key:"getWhileStatementNode",value:function(e,t){return{type:i.NodeType.WhileStatement,test:e,body:t,obfuscatedNode:!1}}}]),e}();t.Nodes=c},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});!function(e){e.ArrayExpression="ArrayExpression",e.ArrowFunctionExpression="ArrowFunctionExpression",e.AssignmentExpression="AssignmentExpression",e.AssignmentPattern="AssignmentPattern",e.BinaryExpression="BinaryExpression",e.BlockStatement="BlockStatement",e.BreakStatement="BreakStatement",e.CallExpression="CallExpression",e.CatchClause="CatchClause",e.ClassDeclaration="ClassDeclaration",e.ContinueStatement="ContinueStatement",e.ExpressionStatement="ExpressionStatement",e.FunctionDeclaration="FunctionDeclaration",e.FunctionExpression="FunctionExpression",e.Identifier="Identifier",e.IfStatement="IfStatement",e.LabeledStatement="LabeledStatement",e.Literal="Literal",e.LogicalExpression="LogicalExpression",e.MemberExpression="MemberExpression",e.MethodDefinition="MethodDefinition",e.ObjectExpression="ObjectExpression",e.ObjectPattern="ObjectPattern",e.Program="Program",e.Property="Property",e.ReturnStatement="ReturnStatement",e.SwitchCase="SwitchCase",e.SwitchStatement="SwitchStatement",e.TemplateLiteral="TemplateLiteral",e.TryStatement="TryStatement",e.UnaryExpression="UnaryExpression",e.UpdateExpression="UpdateExpression",e.VariableDeclaration="VariableDeclaration",e.VariableDeclarator="VariableDeclarator",e.WhileStatement="WhileStatement"}(t.NodeType||(t.NodeType={}))},function(e,t){e.exports=require("string-template")},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});!function(e){e[e.BinaryExpressionFunctionNode=0]="BinaryExpressionFunctionNode",e[e.BlockStatementControlFlowFlatteningNode=1]="BlockStatementControlFlowFlatteningNode",e[e.CallExpressionControlFlowStorageCallNode=2]="CallExpressionControlFlowStorageCallNode",e[e.CallExpressionFunctionNode=3]="CallExpressionFunctionNode",e[e.ControlFlowStorageNode=4]="ControlFlowStorageNode",e[e.ExpressionWithOperatorControlFlowStorageCallNode=5]="ExpressionWithOperatorControlFlowStorageCallNode",e[e.LogicalExpressionFunctionNode=6]="LogicalExpressionFunctionNode",e[e.StringLiteralControlFlowStorageCallNode=7]="StringLiteralControlFlowStorageCallNode",e[e.StringLiteralNode=8]="StringLiteralNode"}(t.ControlFlowCustomNode||(t.ControlFlowCustomNode={}))},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function e(e,t){for(var r=0;r1?t-1:0),n=1;n-1||0===e.indexOf("//")?e.split("/")[2]:e.split("/")[0],t=t.split(":")[0]}},{key:"isCeilNumber",value:function(e){return e%1==0}},{key:"stringRotate",value:function(e,t){if(!e)throw new ReferenceError("Cannot rotate empty string.");for(var r=0;r1&&void 0!==arguments[1]?arguments[1]:{},r=new i.InversifyContainerFacade;r.load(e,t);var n=r.get(a.ServiceIdentifiers.IJavaScriptObfuscator),o=n.obfuscate(e);return r.unload(),o}},{key:"runCLI",value:function(e){var t=new c.JavaScriptObfuscatorCLI(e);t.initialize(),t.run()}}]),e}();t.JavaScriptObfuscator=s},function(e,t,r){"use strict";function n(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t3&&void 0!==arguments[3]?arguments[3]:0,a=void 0;a=t.length?e.getOptimalBlockScope(t,o):r,e.prependNode(a,n)}},{key:"getOptimalBlockScope",value:function(t,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1/0,o=t[r];if(n<=0)throw new Error("Invalid `deep` argument value. Value should be bigger then 0.");return n>1&&o.stackTrace.length?e.getOptimalBlockScope(o.stackTrace,0,--n):o.callee}},{key:"insertNodeAtIndex",value:function(t,r,o){e.validateBodyStatements(r)||(r=[]),r=e.parentizeBodyStatementsBeforeAppend(t,r),t.body=[].concat(n(t.body.slice(0,o)),n(r),n(t.body.slice(o)))}},{key:"prependNode",value:function(t,r){e.validateBodyStatements(r)||(r=[]),r=e.parentizeBodyStatementsBeforeAppend(t,r),t.body=[].concat(n(r),n(t.body))}},{key:"parentizeBodyStatementsBeforeAppend",value:function(e,t){return t.forEach(function(t){t.parentNode=e}),t}},{key:"validateBodyStatements",value:function(e){return e.every(function(e){return!!e&&e.hasOwnProperty("type")})}}]),e}();t.NodeAppender=i},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});!function(e){e[e.ConsoleOutputDisableExpressionNode=0]="ConsoleOutputDisableExpressionNode",e[e.DebugProtectionFunctionCallNode=1]="DebugProtectionFunctionCallNode",e[e.DebugProtectionFunctionIntervalNode=2]="DebugProtectionFunctionIntervalNode",e[e.DebugProtectionFunctionNode=3]="DebugProtectionFunctionNode",e[e.DomainLockNode=4]="DomainLockNode",e[e.NodeCallsControllerFunctionNode=5]="NodeCallsControllerFunctionNode",e[e.SelfDefendingUnicodeNode=6]="SelfDefendingUnicodeNode",e[e.StringArrayCallsWrapper=7]="StringArrayCallsWrapper",e[e.StringArrayNode=8]="StringArrayNode",e[e.StringArrayRotateFunctionNode=9]="StringArrayRotateFunctionNode"}(t.CustomNode||(t.CustomNode={}))},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});!function(e){e[e.BlockStatementControlFlowTransformer=0]="BlockStatementControlFlowTransformer",e[e.ClassDeclarationTransformer=1]="ClassDeclarationTransformer",e[e.DeadCodeInjectionTransformer=2]="DeadCodeInjectionTransformer",e[e.FunctionControlFlowTransformer=3]="FunctionControlFlowTransformer",e[e.CatchClauseTransformer=4]="CatchClauseTransformer",e[e.FunctionDeclarationTransformer=5]="FunctionDeclarationTransformer",e[e.FunctionTransformer=6]="FunctionTransformer",e[e.LabeledStatementTransformer=7]="LabeledStatementTransformer",e[e.LiteralTransformer=8]="LiteralTransformer",e[e.MemberExpressionTransformer=9]="MemberExpressionTransformer",e[e.MethodDefinitionTransformer=10]="MethodDefinitionTransformer",e[e.ObfuscatingGuardsTransformer=11]="ObfuscatingGuardsTransformer",e[e.ObjectExpressionTransformer=12]="ObjectExpressionTransformer",e[e.ParentificationTransformer=13]="ParentificationTransformer",e[e.TemplateLiteralTransformer=14]="TemplateLiteralTransformer",e[e.VariableDeclarationTransformer=15]="VariableDeclarationTransformer"}(t.NodeTransformer||(t.NodeTransformer={}))},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function e(e,t){for(var r=0;r1&&void 0!==arguments[1]?arguments[1]:p.randomGeneratorPool;return this.getRandomGenerator().string({length:e,pool:t})}},{key:"getRandomVariableName",value:function(e){var t="_"+f.Utils.hexadecimalPrefix,r=this.getRandomInteger(1e4,99999999),n=f.Utils.decToHex(r),o=""+t+n.substr(0,e);return this.randomVariableNameSet.has(o)?this.getRandomVariableName(e):(this.randomVariableNameSet.add(o),o)}},{key:"getSeed",value:function(){return this.seed}}]),e}();d.randomGeneratorPool="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",d.randomGeneratorPoolNumbers="0123456789",d.randomGeneratorPoolHexadecimal="abcdef"+p.randomGeneratorPoolNumbers,a.__decorate([l.initializable(),a.__metadata("design:type",Object)],d.prototype,"randomGenerator",void 0),a.__decorate([l.initializable(),a.__metadata("design:type",Number)],d.prototype,"seed",void 0),a.__decorate([i.postConstruct(),a.__metadata("design:type",Function),a.__metadata("design:paramtypes",[]),a.__metadata("design:returntype",void 0)],d.prototype,"initialize",null),d=p=a.__decorate([i.injectable(),a.__param(0,i.inject(c.ServiceIdentifiers.ISourceCode)),a.__param(1,i.inject(c.ServiceIdentifiers.IOptions)),a.__metadata("design:paramtypes",[Object,Object])],d),t.RandomGenerator=d;var p},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(23);t.DEFAULT_PRESET=Object.freeze({compact:!0,config:"",controlFlowFlattening:!1,controlFlowFlatteningThreshold:.75,deadCodeInjection:!1,deadCodeInjectionThreshold:.4,debugProtection:!1,debugProtectionInterval:!1,disableConsoleOutput:!1,domainLock:[],log:!1,mangle:!1,renameGlobals:!1,reservedNames:[],rotateStringArray:!0,seed:0,selfDefending:!1,sourceMap:!1,sourceMapBaseUrl:"",sourceMapFileName:"",sourceMapMode:n.SourceMapMode.Separate,stringArray:!0,stringArrayEncoding:!1,stringArrayThreshold:.75,unicodeEscapeSequence:!1})},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function e(e,t){for(var r=0;r [options]").version(y.CLIUtils.getPackageConfig().version,"-v, --version").option("-o, --output ","Output path for obfuscated code").option("--compact ","Disable one line output code compacting",f.BooleanSanitizer).option("--config ","Name of js / json config file").option("--controlFlowFlattening ","Enables control flow flattening",f.BooleanSanitizer).option("--controlFlowFlatteningThreshold ","The probability that the control flow flattening transformation will be applied to the node",parseFloat).option("--deadCodeInjection ","Enables dead code injection",f.BooleanSanitizer).option("--deadCodeInjectionThreshold ","The probability that the dead code injection transformation will be applied to the node",parseFloat).option("--debugProtection ","Disable browser Debug panel (can cause DevTools enabled browser freeze)",f.BooleanSanitizer).option("--debugProtectionInterval ","Disable browser Debug panel even after page was loaded (can cause DevTools enabled browser freeze)",f.BooleanSanitizer).option("--disableConsoleOutput ","Allow console.log, console.info, console.error and console.warn messages output into browser console",f.BooleanSanitizer).option("--domainLock '' (comma separated)","Blocks the execution of the code in domains that do not match the passed RegExp patterns (comma separated)",l.ArraySanitizer).option("--log ","Enables logging of the information to the console",f.BooleanSanitizer).option("--mangle ","Enables mangling of variable names",f.BooleanSanitizer).option("--reservedNames '' (comma separated)","Disable obfuscation of variable names, function names and names of function parameters that match the passed RegExp patterns (comma separated)",l.ArraySanitizer).option("--renameGlobals ","Allows to enable obfuscation of global variable and function names with declaration.",f.BooleanSanitizer).option("--rotateStringArray ","Disable rotation of unicode array values during obfuscation",f.BooleanSanitizer).option("--seed ","Sets seed for random generator. This is useful for creating repeatable results.",parseFloat).option("--selfDefending ","Disables self-defending for obfuscated code",f.BooleanSanitizer).option("--sourceMap ","Enables source map generation",f.BooleanSanitizer).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",d.SourceMapModeSanitizer).option("--stringArray ","Disables gathering of all literal strings into an array and replacing every literal string with an array call",f.BooleanSanitizer).option("--stringArrayEncoding [true, false, base64, rc4]","Encodes all strings in strings array using base64 or rc4 (this option can slow down your code speed",p.StringArrayEncodingSanitizer).option("--stringArrayThreshold ","The probability that the literal string will be inserted into stringArray (Default: 0.8, Min: 0, Max: 1)",parseFloat).option("--unicodeEscapeSequence ","Allows to enable/disable string conversion to unicode escape sequence",f.BooleanSanitizer).parse(this.rawArguments)}},{key:"configureHelp",value:function(){this.commands.on("--help",function(){console.log(" Examples:\n"),console.log(" %> javascript-obfuscator input_file_name.js --compact true --selfDefending false"),console.log(" %> javascript-obfuscator input_file_name.js --output output_file_name.js --compact true --selfDefending false"),console.log(" %> javascript-obfuscator input_directory_name --compact true --selfDefending false"),console.log("")})}},{key:"processSourceCodeData",value:function(e){var t=this;if(Array.isArray(e))e.forEach(function(e){var r=e.filePath,n=e.content,o=y.CLIUtils.getOutputCodePath(r);t.processSourceCode(n,o)});else{var r=this.inputCLIOptions.output||y.CLIUtils.getOutputCodePath(this.inputPath);this.processSourceCode(e,r)}}},{key:"processSourceCode",value:function(t,r){var n=this.buildOptions();n.sourceMap?e.processSourceCodeWithSourceMap(t,r,n):e.processSourceCodeWithoutSourceMap(t,r,n)}}],[{key:"filterOptions",value:function(e){var t={};for(var r in e)e.hasOwnProperty(r)&&void 0!==e[r]&&(t[r]=e[r]);return t}},{key:"processSourceCodeWithoutSourceMap",value:function(e,t,r){var n=m.JavaScriptObfuscator.obfuscate(e,r).getObfuscatedCode();y.CLIUtils.writeFile(t,n)}},{key:"processSourceCodeWithSourceMap",value:function(e,t,r){var n=y.CLIUtils.getOutputSourceMapPath(t,r.sourceMapFileName||"");r=Object.assign({},r,{sourceMapFileName:c.basename(n)});var o=m.JavaScriptObfuscator.obfuscate(e,r);y.CLIUtils.writeFile(t,o.getObfuscatedCode()),"separate"===r.sourceMapMode&&o.getSourceMap()&&y.CLIUtils.writeFile(n,o.getSourceMap())}}]),e}();g.availableInputExtensions=[".js"],g.encoding="utf8",g.obfuscatedFilePrefix="-obfuscated",a.__decorate([s.initializable(),a.__metadata("design:type",Object)],g.prototype,"commands",void 0),a.__decorate([s.initializable(),a.__metadata("design:type",Object)],g.prototype,"inputCLIOptions",void 0),a.__decorate([s.initializable(),a.__metadata("design:type",String)],g.prototype,"inputPath",void 0),t.JavaScriptObfuscatorCLI=g},function(e,t){e.exports=require("path")},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});!function(e){e[e.FunctionDeclarationCalleeDataExtractor=0]="FunctionDeclarationCalleeDataExtractor",e[e.FunctionExpressionCalleeDataExtractor=1]="FunctionExpressionCalleeDataExtractor",e[e.ObjectExpressionCalleeDataExtractor=2]="ObjectExpressionCalleeDataExtractor"}(t.CalleeDataExtractor||(t.CalleeDataExtractor={}))},function(e,t){e.exports=require("esprima")},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});!function(e){e[e.BinaryExpressionControlFlowReplacer=0]="BinaryExpressionControlFlowReplacer",e[e.CallExpressionControlFlowReplacer=1]="CallExpressionControlFlowReplacer",e[e.LogicalExpressionControlFlowReplacer=2]="LogicalExpressionControlFlowReplacer",e[e.StringLiteralControlFlowReplacer=3]="StringLiteralControlFlowReplacer"}(t.ControlFlowReplacer||(t.ControlFlowReplacer={}))},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var i=function(){function e(e,t){for(var r=0;r1&&void 0!==arguments[1]&&arguments[1];this.storage=new Map([].concat(n(this.storage),n(e.getStorage()))),t&&(this.storageId=e.getStorageId())}},{key:"set",value:function(e,t){this.storage.set(e,t)}}]),e}();c.__decorate([l.initializable(),c.__metadata("design:type",String)],f.prototype,"storageId",void 0),c.__decorate([l.initializable(),c.__metadata("design:type",Map)],f.prototype,"storage",void 0),c.__decorate([s.postConstruct(),c.__metadata("design:type",Function),c.__metadata("design:paramtypes",[]),c.__metadata("design:returntype",void 0)],f.prototype,"initialize",null),f=c.__decorate([s.injectable(),c.__param(0,s.inject(u.ServiceIdentifiers.IRandomGenerator)),c.__metadata("design:paramtypes",[Object])],f),t.MapStorage=f},function(e,t){e.exports=require("fs")},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(17);e.exports=n.JavaScriptObfuscator},function(e,t){e.exports=require("reflect-metadata")},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(13),o=r(0),a=r(1),i=r(33),c=r(45),s=r(46),u=r(47),l=r(48);t.analyzersModule=new o.ContainerModule(function(e){e(a.ServiceIdentifiers.IStackTraceAnalyzer).to(l.StackTraceAnalyzer).inSingletonScope(),e(a.ServiceIdentifiers.ICalleeDataExtractor).to(c.FunctionDeclarationCalleeDataExtractor).whenTargetNamed(i.CalleeDataExtractor.FunctionDeclarationCalleeDataExtractor),e(a.ServiceIdentifiers.ICalleeDataExtractor).to(s.FunctionExpressionCalleeDataExtractor).whenTargetNamed(i.CalleeDataExtractor.FunctionExpressionCalleeDataExtractor),e(a.ServiceIdentifiers.ICalleeDataExtractor).to(u.ObjectExpressionCalleeDataExtractor).whenTargetNamed(i.CalleeDataExtractor.ObjectExpressionCalleeDataExtractor),e(a.ServiceIdentifiers.Factory__ICalleeDataExtractor).toFactory(n.InversifyContainerFacade.getCacheFactory(a.ServiceIdentifiers.ICalleeDataExtractor))})},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var i=function(){function e(e,t){for(var r=0;rr)return"break";var a=e[o];s.traverse(a,{enter:function(r){if(l.NodeGuards.isCallExpressionNode(r))return a.parentNode!==f.NodeUtils.getBlockScopesOfNode(r)[0]?s.VisitorOption.Skip:void t.analyzeCallExpressionNode(n,e,r)}})}(a))break}return n}},{key:"analyzeCallExpressionNode",value:function(e,t,r){var n=this;p.calleeDataExtractorsList.forEach(function(o){var a=n.calleeDataExtractorFactory(o).extract(t,r.callee);a&&e.push(Object.assign({},a,{stackTrace:n.analyzeRecursive(a.callee.body)}))})}}],[{key:"getLimitIndex",value:function(e){var t=e-1,r=p.limitThresholdActivationLength-1,n=t;return t>r&&(n=Math.round(r+t*p.limitThreshold))>t&&(n=t),n}}]),e}();d.calleeDataExtractorsList=[u.CalleeDataExtractor.FunctionDeclarationCalleeDataExtractor,u.CalleeDataExtractor.FunctionExpressionCalleeDataExtractor,u.CalleeDataExtractor.ObjectExpressionCalleeDataExtractor],d.limitThresholdActivationLength=25,d.limitThreshold=.002,d=p=a.__decorate([i.injectable(),a.__param(0,i.inject(c.ServiceIdentifiers.Factory__ICalleeDataExtractor)),a.__metadata("design:paramtypes",[Function])],d),t.StackTraceAnalyzer=d;var p},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(13),o=r(0),a=r(1),i=r(35),c=r(20),s=r(50),u=r(51),l=r(52),f=r(53),d=r(54),p=r(55),y=r(56);t.controlFlowTransformersModule=new o.ContainerModule(function(e){e(a.ServiceIdentifiers.INodeTransformer).to(u.BlockStatementControlFlowTransformer).whenTargetNamed(c.NodeTransformer.BlockStatementControlFlowTransformer),e(a.ServiceIdentifiers.INodeTransformer).to(f.DeadCodeInjectionTransformer).whenTargetNamed(c.NodeTransformer.DeadCodeInjectionTransformer),e(a.ServiceIdentifiers.INodeTransformer).to(d.FunctionControlFlowTransformer).whenTargetNamed(c.NodeTransformer.FunctionControlFlowTransformer),e(a.ServiceIdentifiers.IControlFlowReplacer).to(s.BinaryExpressionControlFlowReplacer).whenTargetNamed(i.ControlFlowReplacer.BinaryExpressionControlFlowReplacer),e(a.ServiceIdentifiers.IControlFlowReplacer).to(l.CallExpressionControlFlowReplacer).whenTargetNamed(i.ControlFlowReplacer.CallExpressionControlFlowReplacer),e(a.ServiceIdentifiers.IControlFlowReplacer).to(p.LogicalExpressionControlFlowReplacer).whenTargetNamed(i.ControlFlowReplacer.LogicalExpressionControlFlowReplacer),e(a.ServiceIdentifiers.IControlFlowReplacer).to(y.StringLiteralControlFlowReplacer).whenTargetNamed(i.ControlFlowReplacer.StringLiteralControlFlowReplacer),e(a.ServiceIdentifiers.Factory__IControlFlowReplacer).toFactory(n.InversifyContainerFacade.getCacheFactory(a.ServiceIdentifiers.IControlFlowReplacer))})},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var i=function(){function e(e,t){for(var r=0;rthis.options.controlFlowFlatteningThreshold||!m.canTransformBlockStatementNode(e))return e;var r=e.body,n=this.arrayUtils.arrayRange(r.length),o=this.arrayUtils.arrayShuffle(n),a=n.map(function(e){return o.indexOf(e)}),i=this.controlFlowCustomNodeFactory(f.ControlFlowCustomNode.BlockStatementControlFlowFlatteningNode);return i.initialize(r,o,a),i.getNode()[0]}}],[{key:"blockStatementHasProhibitedStatements",value:function(e){return e.body.some(function(e){var t=p.NodeGuards.isBreakStatementNode(e)||p.NodeGuards.isContinueStatementNode(e),r=p.NodeGuards.isVariableDeclarationNode(e)&&("const"===e.kind||"let"===e.kind);return p.NodeGuards.isFunctionDeclarationNode(e)||t||r})}},{key:"canTransformBlockStatementNode",value:function(e){var t=!0;return l.traverse(e,{enter:function(e){if(p.NodeGuards.isWhileStatementNode(e))return l.VisitorOption.Skip;p.NodeGuards.isBlockStatementNode(e)&&m.blockStatementHasProhibitedStatements(e)&&(t=!1)}}),e.body.length<=4&&(t=!1),t}}]),t}(d.AbstractNodeTransformer);y=m=c.__decorate([s.injectable(),c.__param(0,s.inject(u.ServiceIdentifiers.Factory__IControlFlowCustomNode)),c.__param(1,s.inject(u.ServiceIdentifiers.IArrayUtils)),c.__param(2,s.inject(u.ServiceIdentifiers.IRandomGenerator)),c.__param(3,s.inject(u.ServiceIdentifiers.IOptions)),c.__metadata("design:paramtypes",[Function,Object,Object,Object])],y),t.BlockStatementControlFlowTransformer=y;var m},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var i=function(){function e(e,t){for(var r=0;rthis.options.deadCodeInjectionThreshold)return e;if(b.NodeUtils.getBlockScopesOfNode(e)[0].type===d.NodeType.Program)return e;var r=this.collectedBlockStatements.length-1,n=this.randomGenerator.getRandomInteger(0,r),o=this.collectedBlockStatements.splice(n,1)[0];return o===e?e:this.replaceBlockStatementNode(e,o)}},{key:"collectBlockStatementNodes",value:function(e,t){var r=this,n=b.NodeUtils.clone(e),o=0,a=!0;f.replace(n,{enter:function(e,t){return y.NodeGuards.isBlockStatementNode(e)&&o++,o>v.maxNestedBlockStatementsCount||y.NodeGuards.isBreakStatementNode(e)||y.NodeGuards.isContinueStatementNode(e)?(a=!1,f.VisitorOption.Break):(y.NodeGuards.isIdentifierNode(e)&&!y.NodeGuards.isMemberExpressionNode(t)&&(e.name=r.randomGenerator.getRandomVariableName(6)),e)}}),a&&t.push(n)}},{key:"replaceBlockStatementNode",value:function(e,t){var r=this.randomGenerator.getMathRandom()>.5,n=this.randomGenerator.getMathRandom()>.5,o=r?"===":"!==",a=this.randomGenerator.getRandomString(3),c=n?a:this.randomGenerator.getRandomString(3),s=r===n?[e,t]:[t,e],u=i(s,2),l=u[0],f=u[1],d=m.Nodes.getBlockStatementNode([m.Nodes.getIfStatementNode(m.Nodes.getBinaryExpressionNode(o,m.Nodes.getLiteralNode(a),m.Nodes.getLiteralNode(c)),l,f)]);return d=b.NodeUtils.parentize(d)}}]),t}(p.AbstractNodeTransformer);g.maxNestedBlockStatementsCount=4,g.minCollectedBlockStatementsCount=5,g=v=s.__decorate([u.injectable(),s.__param(0,u.inject(l.ServiceIdentifiers.IRandomGenerator)),s.__param(1,u.inject(l.ServiceIdentifiers.IOptions)),s.__metadata("design:paramtypes",[Object,Object])],g),t.DeadCodeInjectionTransformer=g;var v},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var i=function(){function e(e,t){for(var r=0;rh.hostNodeSearchMinDepth&&t.splice(0,h.hostNodeSearchMinDepth),t.length>h.hostNodeSearchMaxDepth&&(t.length=h.hostNodeSearchMaxDepth),this.randomGenerator.getRandomGenerator().pickone(t))}},{key:"isVisitedFunctionNode",value:function(e){return(m.NodeGuards.isFunctionDeclarationNode(e)||m.NodeGuards.isFunctionExpressionNode(e)||m.NodeGuards.isArrowFunctionExpressionNode(e))&&this.visitedFunctionNodes.has(e)}},{key:"transformFunctionBody",value:function(e,t){var r=this;l.replace(e,{enter:function(e,n){if(r.isVisitedFunctionNode(e))return l.VisitorOption.Skip;if(!h.controlFlowReplacersMap.has(e.type))return e;if(r.randomGenerator.getMathRandom()>r.options.controlFlowFlatteningThreshold)return e;var o=h.controlFlowReplacersMap.get(e.type);return void 0===o?e:Object.assign({},r.controlFlowReplacerFactory(o).replace(e,n,t),{parentNode:n})}})}}]),t}(y.AbstractNodeTransformer);v.controlFlowReplacersMap=new Map([[p.NodeType.BinaryExpression,d.ControlFlowReplacer.BinaryExpressionControlFlowReplacer],[p.NodeType.CallExpression,d.ControlFlowReplacer.CallExpressionControlFlowReplacer],[p.NodeType.LogicalExpression,d.ControlFlowReplacer.LogicalExpressionControlFlowReplacer],[p.NodeType.Literal,d.ControlFlowReplacer.StringLiteralControlFlowReplacer]]),v.hostNodeSearchMinDepth=0,v.hostNodeSearchMaxDepth=2,v=h=c.__decorate([s.injectable(),c.__param(0,s.inject(u.ServiceIdentifiers.Factory__TControlFlowStorage)),c.__param(1,s.inject(u.ServiceIdentifiers.Factory__IControlFlowReplacer)),c.__param(2,s.inject(u.ServiceIdentifiers.Factory__IControlFlowCustomNode)),c.__param(3,s.inject(u.ServiceIdentifiers.IRandomGenerator)),c.__param(4,s.inject(u.ServiceIdentifiers.IOptions)),c.__metadata("design:paramtypes",[Function,Function,Function,Object,Object])],v),t.FunctionControlFlowTransformer=v;var h},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var i=function(){function e(e,t){for(var r=0;r1){var o=d.Nodes.getBinaryExpressionNode("+",n.shift(),n.shift());return n.forEach(function(e){o=d.Nodes.getBinaryExpressionNode("+",o,e)}),o}return n[0]}}],[{key:"isLiteralNodeWithStringValue",value:function(e){return e&&f.NodeGuards.isLiteralNode(e)&&"string"==typeof e.value}}]),t}(l.AbstractNodeTransformer);p=y=c.__decorate([s.injectable(),c.__param(0,s.inject(u.ServiceIdentifiers.IRandomGenerator)),c.__param(1,s.inject(u.ServiceIdentifiers.IOptions)),c.__metadata("design:paramtypes",[Object,Object])],p),t.TemplateLiteralTransformer=p;var y},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(13),o=r(0),a=r(1),i=r(12),c=r(19),s=r(37),u=r(62),l=r(63),f=r(64),d=r(65),p=r(66),y=r(68),m=r(69),b=r(70),g=r(71),v=r(72),h=r(73),_=r(75),N=r(77),O=r(79),S=r(81),C=r(83),w=r(84),j=r(85),I=r(87),E=r(89),F=r(96),T=r(98),k=r(101),P=r(102);t.customNodesModule=new o.ContainerModule(function(e){e(a.ServiceIdentifiers.ICustomNode).to(h.ConsoleOutputDisableExpressionNode).whenTargetNamed(c.CustomNode.ConsoleOutputDisableExpressionNode),e(a.ServiceIdentifiers.ICustomNode).to(_.DebugProtectionFunctionCallNode).whenTargetNamed(c.CustomNode.DebugProtectionFunctionCallNode),e(a.ServiceIdentifiers.ICustomNode).to(N.DebugProtectionFunctionIntervalNode).whenTargetNamed(c.CustomNode.DebugProtectionFunctionIntervalNode),e(a.ServiceIdentifiers.ICustomNode).to(O.DebugProtectionFunctionNode).whenTargetNamed(c.CustomNode.DebugProtectionFunctionNode),e(a.ServiceIdentifiers.ICustomNode).to(S.DomainLockNode).whenTargetNamed(c.CustomNode.DomainLockNode),e(a.ServiceIdentifiers.ICustomNode).to(j.NodeCallsControllerFunctionNode).whenTargetNamed(c.CustomNode.NodeCallsControllerFunctionNode),e(a.ServiceIdentifiers.ICustomNode).to(I.SelfDefendingUnicodeNode).whenTargetNamed(c.CustomNode.SelfDefendingUnicodeNode),e(a.ServiceIdentifiers.ICustomNode).to(E.StringArrayCallsWrapper).whenTargetNamed(c.CustomNode.StringArrayCallsWrapper),e(a.ServiceIdentifiers.ICustomNode).to(F.StringArrayNode).whenTargetNamed(c.CustomNode.StringArrayNode),e(a.ServiceIdentifiers.ICustomNode).to(T.StringArrayRotateFunctionNode).whenTargetNamed(c.CustomNode.StringArrayRotateFunctionNode),e(a.ServiceIdentifiers.Newable__ICustomNode).toConstructor(y.BinaryExpressionFunctionNode).whenTargetNamed(i.ControlFlowCustomNode.BinaryExpressionFunctionNode),e(a.ServiceIdentifiers.Newable__ICustomNode).toConstructor(m.BlockStatementControlFlowFlatteningNode).whenTargetNamed(i.ControlFlowCustomNode.BlockStatementControlFlowFlatteningNode),e(a.ServiceIdentifiers.Newable__ICustomNode).toConstructor(b.CallExpressionControlFlowStorageCallNode).whenTargetNamed(i.ControlFlowCustomNode.CallExpressionControlFlowStorageCallNode),e(a.ServiceIdentifiers.Newable__ICustomNode).toConstructor(g.CallExpressionFunctionNode).whenTargetNamed(i.ControlFlowCustomNode.CallExpressionFunctionNode),e(a.ServiceIdentifiers.Newable__ICustomNode).toConstructor(v.ControlFlowStorageNode).whenTargetNamed(i.ControlFlowCustomNode.ControlFlowStorageNode),e(a.ServiceIdentifiers.Newable__ICustomNode).toConstructor(C.ExpressionWithOperatorControlFlowStorageCallNode).whenTargetNamed(i.ControlFlowCustomNode.ExpressionWithOperatorControlFlowStorageCallNode),e(a.ServiceIdentifiers.Newable__ICustomNode).toConstructor(w.LogicalExpressionFunctionNode).whenTargetNamed(i.ControlFlowCustomNode.LogicalExpressionFunctionNode),e(a.ServiceIdentifiers.Newable__ICustomNode).toConstructor(P.StringLiteralNode).whenTargetNamed(i.ControlFlowCustomNode.StringLiteralNode),e(a.ServiceIdentifiers.Newable__ICustomNode).toConstructor(k.StringLiteralControlFlowStorageCallNode).whenTargetNamed(i.ControlFlowCustomNode.StringLiteralControlFlowStorageCallNode),e(a.ServiceIdentifiers.ICustomNodeGroup).to(u.ConsoleOutputCustomNodeGroup).whenTargetNamed(s.CustomNodeGroup.ConsoleOutputCustomNodeGroup),e(a.ServiceIdentifiers.ICustomNodeGroup).to(l.DebugProtectionCustomNodeGroup).whenTargetNamed(s.CustomNodeGroup.DebugProtectionCustomNodeGroup),e(a.ServiceIdentifiers.ICustomNodeGroup).to(f.DomainLockCustomNodeGroup).whenTargetNamed(s.CustomNodeGroup.DomainLockCustomNodeGroup),e(a.ServiceIdentifiers.ICustomNodeGroup).to(d.SelfDefendingCustomNodeGroup).whenTargetNamed(s.CustomNodeGroup.SelfDefendingCustomNodeGroup),e(a.ServiceIdentifiers.ICustomNodeGroup).to(p.StringArrayCustomNodeGroup).whenTargetNamed(s.CustomNodeGroup.StringArrayCustomNodeGroup),e(a.ServiceIdentifiers.Factory__ICustomNode).toFactory(n.InversifyContainerFacade.getFactory(a.ServiceIdentifiers.ICustomNode)),e(a.ServiceIdentifiers.Factory__IControlFlowCustomNode).toFactory(n.InversifyContainerFacade.getConstructorFactory(a.ServiceIdentifiers.Newable__ICustomNode,a.ServiceIdentifiers.IRandomGenerator,a.ServiceIdentifiers.IOptions)),e(a.ServiceIdentifiers.Factory__ICustomNodeGroup).toFactory(n.InversifyContainerFacade.getFactory(a.ServiceIdentifiers.ICustomNodeGroup))})},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var i=function(){function e(e,t){for(var r=0;r 0;\n \n switch (isPositive) {\n case true:\n return this.item + '_' + this.value + '_' + i;\n default:\n this.item + '_' + this.value;\n }\n }\n }()\n };\n };\n \n var regExp = new RegExp(\"[{diff}]\", \"g\");\n var domains = \"{domains}\".replace(regExp, \"\").split(\";\");\n var document;\n var domain;\n \n for (var d in that) {\n if (d.length == 8 && d.charCodeAt(7) == 116 && d.charCodeAt(5) == 101 && d.charCodeAt(3) == 117 && d.charCodeAt(0) == 100) {\n document = d;\n \n break;\n }\n }\n\n for (var d1 in that[document]) {\n if (d1.length == 6 && d1.charCodeAt(5) == 110 && d1.charCodeAt(0) == 100) {\n domain = d1;\n \n break;\n }\n }\n \n if ((!document && !domain) || (!that[document] && !that[document][domain])) {\n return;\n }\n \n var currentDomain = that[document][domain];\n\n var ok = false;\n \n for (var i = 0; i < domains.length; i++) {\n var domain = domains[i];\n var position = currentDomain.length - domain.length;\n var lastIndex = currentDomain.indexOf(domain, position);\n var endsWith = lastIndex !== -1 && lastIndex === position;\n \n if (endsWith) {\n if (currentDomain.length == domain.length || domain.indexOf(\".\") === 0) {\n ok = true;\n }\n \n break;\n }\n }\n \n if (!ok) {\n data;\n } else {\n return;\n }\n \n func();\n });\n\n {domainLockFunctionName}();\n "}Object.defineProperty(t,"__esModule",{value:!0}),t.DomainLockNodeTemplate=n},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var i=function(){function e(e,t){for(var r=0;r> 1 + 255 % 0;\n \n if (string.indexOf('i' === i)) {\n recursiveFunc2(string)\n }\n };\n \n var recursiveFunc2 = function (string) {\n var i = ~-4 >> 1 + 255 % 0;\n \n if (string.indexOf((true+\"\")[3]) !== i) {\n recursiveFunc1(string)\n }\n };\n \n if (!test1()) {\n if (!test2()) {\n recursiveFunc1('indеxOf');\n } else {\n recursiveFunc1('indexOf');\n }\n } else {\n recursiveFunc1('indеxOf');\n }\n })\n \n {selfDefendingFunctionName}();\n "}Object.defineProperty(t,"__esModule",{value:!0}),t.SelfDefendingTemplate=n},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var i=function(){function e(e,t){for(var r=0;r> (-2 * bc & 6)) : 0\n ) {\n buffer = chars.indexOf(buffer);\n }\n return output;\n });\n })();\n "}Object.defineProperty(t,"__esModule",{value:!0}),t.AtobTemplate=n},function(e,t,r){"use strict";function n(){return"\n var rc4 = function (str, key) {\n var s = [], j = 0, x, res = '', newStr = '';\n \n str = atob(str);\n \n for (var k = 0, length = str.length; k < length; k++) {\n newStr += '%' + ('00' + str.charCodeAt(k).toString(16)).slice(-2);\n }\n \n str = decodeURIComponent(newStr);\n \t \n\t for (var i = 0; i < 256; i++) {\n s[i] = i;\n }\n \n for (i = 0; i < 256; i++) {\n j = (j + s[i] + key.charCodeAt(i % key.length)) % 256;\n x = s[i];\n s[i] = s[j];\n s[j] = x;\n }\n \n i = 0;\n j = 0;\n \n for (var y = 0; y < str.length; y++) {\n i = (i + 1) % 256;\n j = (j + s[i]) % 256;\n x = s[i];\n s[i] = s[j];\n s[j] = x;\n res += String.fromCharCode(str.charCodeAt(y) ^ s[(s[i] + s[j]) % 256]);\n }\n \n return res;\n }\n "}Object.defineProperty(t,"__esModule",{value:!0}),t.Rc4Template=n},function(e,t,r){"use strict";function n(e){return"\n var StatesClass = function (rc4Bytes) {\n this.rc4Bytes = rc4Bytes;\n this.states = [1, 0, 0];\n this.newState = function(){return 'newState';};\n this.firstState = '"+e.encode("\\w+ *\\(\\) *{\\w+ *",!0)+"';\n this.secondState = '"+e.encode("['|\"].+['|\"];? *}",!0)+"';\n };\n \n StatesClass.prototype.checkState = function () {\n var regExp = new RegExp(this.firstState + this.secondState);\n\n return this.runState(regExp.test(this.newState.toString()) ? --this.states[1] : --this.states[0]);\n };\n \n StatesClass.prototype.runState = function (stateResult) {\n if (!Boolean(~stateResult)) {\n return stateResult;\n }\n \n return this.getState(this.rc4Bytes);\n };\n\n StatesClass.prototype.getState = function (rc4Bytes) {\n for (var i = 0, len = this.states.length; i < len; i++) {\n this.states.push(Math.round(Math.random()));\n len = this.states.length;\n }\n \n return rc4Bytes(this.states[0]);\n };\n\n new StatesClass({stringArrayCallsWrapperName}).checkState();\n "}Object.defineProperty(t,"__esModule",{value:!0}),t.SelfDefendingTemplate=n},function(e,t,r){"use strict";function n(){return" \n if ({stringArrayCallsWrapperName}.initialized === undefined) {\n {atobPolyfill}\n \n {stringArrayCallsWrapperName}.base64DecodeUnicode = function (str) {\n var string = atob(str);\n var newStringChars = [];\n \n for (var i = 0, length = string.length; i < length; i++) {\n newStringChars += '%' + ('00' + string.charCodeAt(i).toString(16)).slice(-2);\n }\n \n return decodeURIComponent(newStringChars);\n };\n \n {stringArrayCallsWrapperName}.data = {};\n \n {stringArrayCallsWrapperName}.initialized = true;\n }\n \n var cachedValue = {stringArrayCallsWrapperName}.data[index];\n \n if (cachedValue === undefined) {\n {selfDefendingCode}\n \n value = {stringArrayCallsWrapperName}.base64DecodeUnicode(value);\n {stringArrayCallsWrapperName}.data[index] = value;\n } else {\n value = cachedValue;\n } \n "}Object.defineProperty(t,"__esModule",{value:!0}),t.StringArrayBase64DecodeNodeTemplate=n},function(e,t,r){"use strict";function n(){return"\n var {stringArrayCallsWrapperName} = function (index, key) {\n index = index - 0;\n \n var value = {stringArrayName}[index];\n \n {decodeNodeTemplate}\n \n return value;\n };\n "}Object.defineProperty(t,"__esModule",{value:!0}),t.StringArrayCallsWrapperTemplate=n},function(e,t,r){"use strict";function n(){return"\n if ({stringArrayCallsWrapperName}.initialized === undefined) {\n {atobPolyfill}\n \n {rc4Polyfill}\n {stringArrayCallsWrapperName}.rc4 = rc4;\n \n {stringArrayCallsWrapperName}.data = {};\n \n {stringArrayCallsWrapperName}.initialized = true;\n }\n \n var cachedValue = {stringArrayCallsWrapperName}.data[index];\n\n if (cachedValue === undefined) {\n if ({stringArrayCallsWrapperName}.once === undefined) {\n {selfDefendingCode}\n \n {stringArrayCallsWrapperName}.once = true;\n }\n \n value = {stringArrayCallsWrapperName}.rc4(value, key);\n {stringArrayCallsWrapperName}.data[index] = value;\n } else {\n value = cachedValue;\n }\n "}Object.defineProperty(t,"__esModule",{value:!0}),t.StringArrayRc4DecodeNodeTemplate=n},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var i=function(){function e(e,t){for(var r=0;r=m.minimumLengthForStringArray&&this.randomGenerator.getMathRandom()<=this.options.stringArrayThreshold}},{key:"getStringArrayHexadecimalIndex",value:function(e,t){if(this.stringLiteralHexadecimalIndexCache.has(e))return{fromCache:!0,index:this.stringLiteralHexadecimalIndexCache.get(e)};var r=p.Utils.decToHex(t),n=""+p.Utils.hexadecimalPrefix+r;return this.stringLiteralHexadecimalIndexCache.set(e,n),{fromCache:!1,index:n}}},{key:"getEncodedValue",value:function(e){var t=void 0,r=null;switch(this.options.stringArrayEncoding){case l.StringArrayEncoding.Rc4:r=this.randomGenerator.getRandomGenerator().pickone(this.rc4Keys),t=this.cryptUtils.btoa(this.cryptUtils.rc4(e,r));break;case l.StringArrayEncoding.Base64:t=this.cryptUtils.btoa(e);break;default:t=e}return{encodedValue:t,key:r}}},{key:"replaceWithLiteralNode",value:function(e){return d.Nodes.getLiteralNode(this.escapeSequenceEncoder.encode(e,this.options.unicodeEscapeSequence))}},{key:"replaceWithStringArrayCallNode",value:function(e){var t=this.getEncodedValue(e),r=t.encodedValue,n=t.key,o=this.escapeSequenceEncoder.encode(r,this.options.unicodeEscapeSequence),a=this.stringArrayStorage.getLength(),i=p.Utils.stringRotate(this.stringArrayStorage.getStorageId(),1),c="_"+p.Utils.hexadecimalPrefix+i,s=this.getStringArrayHexadecimalIndex(o,a),u=s.fromCache,l=s.index;u||this.stringArrayStorage.set(a,o);var f=[m.getHexadecimalLiteralNode(l)];return n&&f.push(m.getRc4KeyLiteralNode(this.escapeSequenceEncoder.encode(n,this.options.unicodeEscapeSequence))),d.Nodes.getCallExpressionNode(d.Nodes.getIdentifierNode(c),f)}}],[{key:"getHexadecimalLiteralNode",value:function(e){var t=d.Nodes.getLiteralNode(e);return t.obfuscatedNode=!0,t}},{key:"getRc4KeyLiteralNode",value:function(e){var t=d.Nodes.getLiteralNode(e);return t.obfuscatedNode=!0,t}}]),t}(f.AbstractObfuscatingReplacer);y.minimumLengthForStringArray=3,y.rc4KeyLength=4,y.rc4KeysCount=50,y=m=c.__decorate([s.injectable(),c.__param(0,s.inject(u.ServiceIdentifiers.TCustomNodeGroupStorage)),c.__param(1,s.inject(u.ServiceIdentifiers.TStringArrayStorage)),c.__param(2,s.inject(u.ServiceIdentifiers.IEscapeSequenceEncoder)),c.__param(3,s.inject(u.ServiceIdentifiers.IRandomGenerator)),c.__param(4,s.inject(u.ServiceIdentifiers.ICryptUtils)),c.__param(5,s.inject(u.ServiceIdentifiers.IOptions)),c.__metadata("design:paramtypes",[Object,Object,Object,Object,Object,Object])],y),t.StringLiteralObfuscatingReplacer=y;var m},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var i=function(){function e(e,t){for(var r=0;r=0?t:null}},{key:"getLength",value:function(){return this.storageLength}},{key:"getStorage",value:function(){return this.storage}},{key:"getStorageId",value:function(){return this.storageId}},{key:"mergeWith",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this.storage=[].concat(n(this.storage),n(e.getStorage())),t&&(this.storageId=e.getStorageId())}},{key:"set",value:function(e,t){e===this.storageLength?this.storage.push(t):this.storage.splice(e,0,t),this.storageLength++}}]),e}();i.__decorate([u.initializable(),i.__metadata("design:type",Array)],l.prototype,"storage",void 0),i.__decorate([u.initializable(),i.__metadata("design:type",String)],l.prototype,"storageId",void 0),i.__decorate([c.postConstruct(),i.__metadata("design:type",Function),i.__metadata("design:paramtypes",[]),i.__metadata("design:returntype",void 0)],l.prototype,"initialize",null),l=i.__decorate([c.injectable(),i.__param(0,c.inject(s.ServiceIdentifiers.IRandomGenerator)),i.__metadata("design:paramtypes",[Object])],l),t.ArrayStorage=l},function(e,t){e.exports=require("md5")},function(e,t){e.exports=require("chance")},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(0),o=r(1),a=r(130),i=r(131),c=r(132),s=r(29);t.utilsModule=new n.ContainerModule(function(e){e(o.ServiceIdentifiers.IArrayUtils).to(a.ArrayUtils).inSingletonScope(),e(o.ServiceIdentifiers.IRandomGenerator).to(s.RandomGenerator).inSingletonScope(),e(o.ServiceIdentifiers.ICryptUtils).to(i.CryptUtils).inSingletonScope(),e(o.ServiceIdentifiers.IEscapeSequenceEncoder).to(c.EscapeSequenceEncoder).inSingletonScope()})},function(e,t,r){"use strict";function n(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t>8-o%1*8)){if((n=e.charCodeAt(o+=.75))>255)throw new Error("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");r=r<<8|n}return t}},{key:"hideString",value:function(e,t){var r=this,n=this.randomGenerator.getRandomGenerator().string({length:t,pool:s.RandomGenerator.randomGeneratorPool}),o=n.replace(new RegExp("["+function(e){return e.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}(e)+"]","g"),""),a=o.split("");return this.randomGenerator.getRandomGenerator().shuffle(a),o=a.join(""),[function(e,t){for(var n=-1,o=-1,a="";n1&&void 0!==arguments[1]?arguments[1]:"";return t&&(e=e.substring(0,e.lastIndexOf("/"))+"/"+t),/\.js\.map$/.test(e)?/\.js$/.test(e)&&(e+=".map"):e=e.split(".")[0]+".js.map",e}},{key:"getPackageConfig",value:function(){return JSON.parse(a.readFileSync(c.join(c.dirname(a.realpathSync(process.argv[1])),"../package.json"),s.JavaScriptObfuscatorCLI.encoding))}},{key:"getUserConfig",value:function(e){var t=void 0;try{t=!function(){var e=new Error('Cannot find module "."');throw e.code="MODULE_NOT_FOUND",e}()}catch(r){try{t=require(e)}catch(e){throw new ReferenceError("Given config path must be a valid file path")}}return t}},{key:"writeFile",value:function(e,t){i.sync(c.dirname(e)),a.writeFileSync(e,t,{encoding:s.JavaScriptObfuscatorCLI.encoding})}}]),e}();t.CLIUtils=u},function(e,t){e.exports=require("mkdirp")},function(e,t){function r(e){throw new Error("Cannot find module '"+e+"'.")}r.keys=function(){return[]},r.resolve=r,e.exports=r,r.id=166},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function e(e,t){for(var r=0;r0&&void 0!==arguments[0]?arguments[0]:"initialize",t=Object.keys(this)[0];return function(r,n){var o={configurable:!0,enumerable:!0},a=r[e];if(!a||"function"!=typeof a)throw new Error("`"+e+"` method with initialization logic not found. `@"+t+"` decorator requires `"+e+"` method");var i="_"+n,c=Object.getOwnPropertyDescriptor(r,i)||o,s=Object.getOwnPropertyDescriptor(r,e)||o,u=s.value;return Object.defineProperty(r,n,Object.assign({},c,{get:function(){if(void 0===this[i])throw new Error("Property `"+n+"` is not initialized! Initialize it first!");return this[i]},set:function(e){this[i]=e}})),Object.defineProperty(r,e,Object.assign({},s,{value:function(){u.apply(this,arguments),this[n]}})),c}}Object.defineProperty(t,"__esModule",{value:!0}),t.initializable=n},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a=function(){function e(e,t){for(var r=0;r1&&void 0!==arguments[1]?arguments[1]:0;if(l.NodeGuards.isNodeHasBlockStatement(e)){if(void 0===e.body[t])throw new ReferenceError("Wrong index `"+t+"`. Block-statement body length is `"+e.body.length+"`");return e.body[t]}throw new TypeError("The specified node have no a block-statement")}},{key:"getBlockScopesOfNode",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],n=t.parentNode;if(!n)throw new ReferenceError("`parentNode` property of given node is `undefined`");if(l.NodeGuards.isBlockStatementNode(n)){if(!n.parentNode)throw new ReferenceError("`parentNode` property of `parentNode` of given node is `undefined`");-1!==e.nodesWithBlockScope.indexOf(n.parentNode.type)&&r.push(n)}return t!==n?e.getBlockScopesOfNode(n,r):(l.NodeGuards.isNodeHasBlockStatement(n)&&r.push(n),r)}},{key:"getNodeBlockScopeDepth",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=t.parentNode;if(!n)throw new ReferenceError("`parentNode` property of given node is `undefined`");return l.NodeGuards.isProgramNode(n)?r:l.NodeGuards.isBlockStatementNode(t)&&-1!==e.nodesWithBlockScope.indexOf(n.type)?e.getNodeBlockScopeDepth(n,++r):e.getNodeBlockScopeDepth(n,r)}},{key:"getUnaryExpressionArgumentNode",value:function(t){return l.NodeGuards.isUnaryExpressionNode(t.argument)?e.getUnaryExpressionArgumentNode(t.argument):t.argument}},{key:"parentize",value:function(t){return s.traverse(t,{enter:e.parentizeNode}),t}},{key:"parentizeNode",value:function(e,t){return e.parentNode=t||e,e.obfuscatedNode=!1,e}},{key:"typedReplace",value:function(t,r,n){e.typedTraverse(t,r,n,"replace")}},{key:"typedTraverse",value:function(e,t,r){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"traverse";s[n](e,{enter:function(e,n){if(e.type===t&&r.enter)return r.enter(e,n)},leave:function(e,n){if(e.type===t&&r.leave)return r.leave(e,n)}})}}]),e}();f.nodesWithBlockScope=[u.NodeType.ArrowFunctionExpression,u.NodeType.FunctionDeclaration,u.NodeType.FunctionExpression,u.NodeType.MethodDefinition,u.NodeType.Program],t.NodeUtils=f},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function e(e,t){for(var r=0;r0&&void 0!==arguments[0]?arguments[0]:[];return{type:i.NodeType.Program,body:e,sourceType:"script",obfuscatedNode:!1}}},{key:"getArrayExpressionNode",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return{type:i.NodeType.ArrayExpression,elements:e}}},{key:"getAssignmentExpressionNode",value:function(e,t,r){return{type:i.NodeType.AssignmentExpression,operator:e,left:t,right:r,obfuscatedNode:!1}}},{key:"getBinaryExpressionNode",value:function(e,t,r){return{type:i.NodeType.BinaryExpression,operator:e,left:t,right:r,obfuscatedNode:!1}}},{key:"getBlockStatementNode",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return{type:i.NodeType.BlockStatement,body:e,obfuscatedNode:!1}}},{key:"getBreakStatement",value:function(e){var t={type:i.NodeType.BreakStatement,obfuscatedNode:!1};return e&&(t.label=e),t}},{key:"getCatchClauseNode",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return{type:i.NodeType.CatchClause,param:e.getIdentifierNode("err"),body:e.getBlockStatementNode(t),obfuscatedNode:!1}}},{key:"getCallExpressionNode",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return{type:i.NodeType.CallExpression,callee:e,arguments:t,obfuscatedNode:!1}}},{key:"getContinueStatement",value:function(e){var t={type:i.NodeType.ContinueStatement,obfuscatedNode:!1};return e&&(t.label=e),t}},{key:"getExpressionStatementNode",value:function(e){return{type:i.NodeType.ExpressionStatement,expression:e,obfuscatedNode:!1}}},{key:"getFunctionDeclarationNode",value:function(t,r,n){return{type:i.NodeType.FunctionDeclaration,id:e.getIdentifierNode(t),params:r,body:n,generator:!1,obfuscatedNode:!1}}},{key:"getFunctionExpressionNode",value:function(e,t){return{type:i.NodeType.FunctionExpression,params:e,body:t,generator:!1,obfuscatedNode:!1}}},{key:"getIfStatementNode",value:function(e,t,r){return Object.assign({type:i.NodeType.IfStatement,test:e,consequent:t},r&&{alternate:r},{obfuscatedNode:!1})}},{key:"getIdentifierNode",value:function(e){return{type:i.NodeType.Identifier,name:e,obfuscatedNode:!1}}},{key:"getLabeledStatement",value:function(e,t){return{type:i.NodeType.LabeledStatement,label:e,body:t,obfuscatedNode:!1}}},{key:"getLiteralNode",value:function(e,t){return t=void 0!==t?t:"'"+e+"'",{type:i.NodeType.Literal,value:e,raw:t,"x-verbatim-property":{content:t,precedence:a.Precedence.Primary},obfuscatedNode:!1}}},{key:"getLogicalExpressionNode",value:function(e,t,r){return{type:i.NodeType.LogicalExpression,operator:e,left:t,right:r,obfuscatedNode:!1}}},{key:"getMemberExpressionNode",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return{type:i.NodeType.MemberExpression,computed:r,object:e,property:t,obfuscatedNode:!1}}},{key:"getObjectExpressionNode",value:function(e){return{type:i.NodeType.ObjectExpression,properties:e,obfuscatedNode:!1}}},{key:"getPropertyNode",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return{type:i.NodeType.Property,key:e,value:t,kind:"init",method:!1,shorthand:!1,computed:r,obfuscatedNode:!1}}},{key:"getUnaryExpressionNode",value:function(e,t){var r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return{type:i.NodeType.UnaryExpression,operator:e,argument:t,prefix:r,obfuscatedNode:!1}}},{key:"getReturnStatementNode",value:function(e){return{type:i.NodeType.ReturnStatement,argument:e,obfuscatedNode:!1}}},{key:"getSwitchStatementNode",value:function(e,t){return{type:i.NodeType.SwitchStatement,discriminant:e,cases:t,obfuscatedNode:!1}}},{key:"getSwitchCaseNode",value:function(e,t){return{type:i.NodeType.SwitchCase,test:e,consequent:t,obfuscatedNode:!1}}},{key:"getUpdateExpressionNode",value:function(e,t){return{type:i.NodeType.UpdateExpression,operator:e,argument:t,prefix:!1,obfuscatedNode:!1}}},{key:"getVariableDeclarationNode",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"var";return{type:i.NodeType.VariableDeclaration,declarations:e,kind:t,obfuscatedNode:!1}}},{key:"getVariableDeclaratorNode",value:function(e,t){return{type:i.NodeType.VariableDeclarator,id:e,init:t,obfuscatedNode:!1}}},{key:"getWhileStatementNode",value:function(e,t){return{type:i.NodeType.WhileStatement,test:e,body:t,obfuscatedNode:!1}}}]),e}();t.Nodes=c},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});!function(e){e.ArrayExpression="ArrayExpression",e.ArrowFunctionExpression="ArrowFunctionExpression",e.AssignmentExpression="AssignmentExpression",e.AssignmentPattern="AssignmentPattern",e.BinaryExpression="BinaryExpression",e.BlockStatement="BlockStatement",e.BreakStatement="BreakStatement",e.CallExpression="CallExpression",e.CatchClause="CatchClause",e.ClassDeclaration="ClassDeclaration",e.ContinueStatement="ContinueStatement",e.ExpressionStatement="ExpressionStatement",e.FunctionDeclaration="FunctionDeclaration",e.FunctionExpression="FunctionExpression",e.Identifier="Identifier",e.IfStatement="IfStatement",e.LabeledStatement="LabeledStatement",e.Literal="Literal",e.LogicalExpression="LogicalExpression",e.MemberExpression="MemberExpression",e.MethodDefinition="MethodDefinition",e.ObjectExpression="ObjectExpression",e.ObjectPattern="ObjectPattern",e.Program="Program",e.Property="Property",e.ReturnStatement="ReturnStatement",e.SwitchCase="SwitchCase",e.SwitchStatement="SwitchStatement",e.TemplateLiteral="TemplateLiteral",e.TryStatement="TryStatement",e.UnaryExpression="UnaryExpression",e.UpdateExpression="UpdateExpression",e.VariableDeclaration="VariableDeclaration",e.VariableDeclarator="VariableDeclarator",e.WhileStatement="WhileStatement"}(t.NodeType||(t.NodeType={}))},function(e,t){e.exports=require("string-template")},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});!function(e){e[e.BinaryExpressionFunctionNode=0]="BinaryExpressionFunctionNode",e[e.BlockStatementControlFlowFlatteningNode=1]="BlockStatementControlFlowFlatteningNode",e[e.CallExpressionControlFlowStorageCallNode=2]="CallExpressionControlFlowStorageCallNode",e[e.CallExpressionFunctionNode=3]="CallExpressionFunctionNode",e[e.ControlFlowStorageNode=4]="ControlFlowStorageNode",e[e.ExpressionWithOperatorControlFlowStorageCallNode=5]="ExpressionWithOperatorControlFlowStorageCallNode",e[e.LogicalExpressionFunctionNode=6]="LogicalExpressionFunctionNode",e[e.StringLiteralControlFlowStorageCallNode=7]="StringLiteralControlFlowStorageCallNode",e[e.StringLiteralNode=8]="StringLiteralNode"}(t.ControlFlowCustomNode||(t.ControlFlowCustomNode={}))},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});!function(e){e.Browser="browser",e.Extension="extension",e.Node="node"}(t.ObfuscationTarget||(t.ObfuscationTarget={}))},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function e(e,t){for(var r=0;r1?t-1:0),n=1;n-1||0===e.indexOf("//")?e.split("/")[2]:e.split("/")[0],t=t.split(":")[0]}},{key:"isCeilNumber",value:function(e){return e%1==0}},{key:"stringRotate",value:function(e,t){if(!e)throw new ReferenceError("Cannot rotate empty string.");for(var r=0;r1&&void 0!==arguments[1]?arguments[1]:{},r=new i.InversifyContainerFacade;r.load(e,t);var n=r.get(a.ServiceIdentifiers.IJavaScriptObfuscator),o=n.obfuscate(e);return r.unload(),o}},{key:"runCLI",value:function(e){var t=new c.JavaScriptObfuscatorCLI(e);t.initialize(),t.run()}}]),e}();t.JavaScriptObfuscator=s},function(e,t,r){"use strict";function n(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t3&&void 0!==arguments[3]?arguments[3]:0,a=void 0;a=t.length?e.getOptimalBlockScope(t,o):r,e.prependNode(a,n)}},{key:"getOptimalBlockScope",value:function(t,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1/0,o=t[r];if(n<=0)throw new Error("Invalid `deep` argument value. Value should be bigger then 0.");return n>1&&o.stackTrace.length?e.getOptimalBlockScope(o.stackTrace,0,--n):o.callee}},{key:"insertNodeAtIndex",value:function(t,r,o){e.validateBodyStatements(r)||(r=[]),r=e.parentizeBodyStatementsBeforeAppend(t,r),t.body=[].concat(n(t.body.slice(0,o)),n(r),n(t.body.slice(o)))}},{key:"prependNode",value:function(t,r){e.validateBodyStatements(r)||(r=[]),r=e.parentizeBodyStatementsBeforeAppend(t,r),t.body=[].concat(n(r),n(t.body))}},{key:"parentizeBodyStatementsBeforeAppend",value:function(e,t){return t.forEach(function(t){t.parentNode=e}),t}},{key:"validateBodyStatements",value:function(e){return e.every(function(e){return!!e&&e.hasOwnProperty("type")})}}]),e}();t.NodeAppender=i},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});!function(e){e[e.ConsoleOutputDisableExpressionNode=0]="ConsoleOutputDisableExpressionNode",e[e.DebugProtectionFunctionCallNode=1]="DebugProtectionFunctionCallNode",e[e.DebugProtectionFunctionIntervalNode=2]="DebugProtectionFunctionIntervalNode",e[e.DebugProtectionFunctionNode=3]="DebugProtectionFunctionNode",e[e.DomainLockNode=4]="DomainLockNode",e[e.NodeCallsControllerFunctionNode=5]="NodeCallsControllerFunctionNode",e[e.SelfDefendingUnicodeNode=6]="SelfDefendingUnicodeNode",e[e.StringArrayCallsWrapper=7]="StringArrayCallsWrapper",e[e.StringArrayNode=8]="StringArrayNode",e[e.StringArrayRotateFunctionNode=9]="StringArrayRotateFunctionNode"}(t.CustomNode||(t.CustomNode={}))},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});!function(e){e[e.BlockStatementControlFlowTransformer=0]="BlockStatementControlFlowTransformer",e[e.ClassDeclarationTransformer=1]="ClassDeclarationTransformer",e[e.DeadCodeInjectionTransformer=2]="DeadCodeInjectionTransformer",e[e.FunctionControlFlowTransformer=3]="FunctionControlFlowTransformer",e[e.CatchClauseTransformer=4]="CatchClauseTransformer",e[e.FunctionDeclarationTransformer=5]="FunctionDeclarationTransformer",e[e.FunctionTransformer=6]="FunctionTransformer",e[e.LabeledStatementTransformer=7]="LabeledStatementTransformer",e[e.LiteralTransformer=8]="LiteralTransformer",e[e.MemberExpressionTransformer=9]="MemberExpressionTransformer",e[e.MethodDefinitionTransformer=10]="MethodDefinitionTransformer",e[e.ObfuscatingGuardsTransformer=11]="ObfuscatingGuardsTransformer",e[e.ObjectExpressionTransformer=12]="ObjectExpressionTransformer",e[e.ParentificationTransformer=13]="ParentificationTransformer",e[e.TemplateLiteralTransformer=14]="TemplateLiteralTransformer",e[e.VariableDeclarationTransformer=15]="VariableDeclarationTransformer"}(t.NodeTransformer||(t.NodeTransformer={}))},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function e(e,t){for(var r=0;r1&&void 0!==arguments[1]?arguments[1]:p.randomGeneratorPool;return this.getRandomGenerator().string({length:e,pool:t})}},{key:"getRandomVariableName",value:function(e){var t="_"+f.Utils.hexadecimalPrefix,r=this.getRandomInteger(1e4,99999999),n=f.Utils.decToHex(r),o=""+t+n.substr(0,e);return this.randomVariableNameSet.has(o)?this.getRandomVariableName(e):(this.randomVariableNameSet.add(o),o)}},{key:"getSeed",value:function(){return this.seed}}]),e}();d.randomGeneratorPool="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",d.randomGeneratorPoolNumbers="0123456789",d.randomGeneratorPoolHexadecimal="abcdef"+p.randomGeneratorPoolNumbers,a.__decorate([l.initializable(),a.__metadata("design:type",Object)],d.prototype,"randomGenerator",void 0),a.__decorate([l.initializable(),a.__metadata("design:type",Number)],d.prototype,"seed",void 0),a.__decorate([i.postConstruct(),a.__metadata("design:type",Function),a.__metadata("design:paramtypes",[]),a.__metadata("design:returntype",void 0)],d.prototype,"initialize",null),d=p=a.__decorate([i.injectable(),a.__param(0,i.inject(c.ServiceIdentifiers.ISourceCode)),a.__param(1,i.inject(c.ServiceIdentifiers.IOptions)),a.__metadata("design:paramtypes",[Object,Object])],d),t.RandomGenerator=d;var p},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(13),o=r(23);t.DEFAULT_PRESET=Object.freeze({compact:!0,config:"",controlFlowFlattening:!1,controlFlowFlatteningThreshold:.75,deadCodeInjection:!1,deadCodeInjectionThreshold:.4,debugProtection:!1,debugProtectionInterval:!1,disableConsoleOutput:!1,domainLock:[],log:!1,mangle:!1,renameGlobals:!1,reservedNames:[],rotateStringArray:!0,seed:0,selfDefending:!1,sourceMap:!1,sourceMapBaseUrl:"",sourceMapFileName:"",sourceMapMode:o.SourceMapMode.Separate,stringArray:!0,stringArrayEncoding:!1,stringArrayThreshold:.75,target:n.ObfuscationTarget.Browser,unicodeEscapeSequence:!1})},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function e(e,t){for(var r=0;r [options]").version(m.CLIUtils.getPackageConfig().version,"-v, --version").option("-o, --output ","Output path for obfuscated code").option("--compact ","Disable one line output code compacting",f.BooleanSanitizer).option("--config ","Name of js / json config file").option("--controlFlowFlattening ","Enables control flow flattening",f.BooleanSanitizer).option("--controlFlowFlatteningThreshold ","The probability that the control flow flattening transformation will be applied to the node",parseFloat).option("--deadCodeInjection ","Enables dead code injection",f.BooleanSanitizer).option("--deadCodeInjectionThreshold ","The probability that the dead code injection transformation will be applied to the node",parseFloat).option("--debugProtection ","Disable browser Debug panel (can cause DevTools enabled browser freeze)",f.BooleanSanitizer).option("--debugProtectionInterval ","Disable browser Debug panel even after page was loaded (can cause DevTools enabled browser freeze)",f.BooleanSanitizer).option("--disableConsoleOutput ","Allow console.log, console.info, console.error and console.warn messages output into browser console",f.BooleanSanitizer).option("--domainLock '' (comma separated)","Blocks the execution of the code in domains that do not match the passed RegExp patterns (comma separated)",l.ArraySanitizer).option("--log ","Enables logging of the information to the console",f.BooleanSanitizer).option("--mangle ","Enables mangling of variable names",f.BooleanSanitizer).option("--reservedNames '' (comma separated)","Disable obfuscation of variable names, function names and names of function parameters that match the passed RegExp patterns (comma separated)",l.ArraySanitizer).option("--renameGlobals ","Allows to enable obfuscation of global variable and function names with declaration.",f.BooleanSanitizer).option("--rotateStringArray ","Disable rotation of unicode array values during obfuscation",f.BooleanSanitizer).option("--seed ","Sets seed for random generator. This is useful for creating repeatable results.",parseFloat).option("--selfDefending ","Disables self-defending for obfuscated code",f.BooleanSanitizer).option("--sourceMap ","Enables source map generation",f.BooleanSanitizer).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",p.SourceMapModeSanitizer).option("--stringArray ","Disables gathering of all literal strings into an array and replacing every literal string with an array call",f.BooleanSanitizer).option("--stringArrayEncoding [true, false, base64, rc4]","Encodes all strings in strings array using base64 or rc4 (this option can slow down your code speed",y.StringArrayEncodingSanitizer).option("--stringArrayThreshold ","The probability that the literal string will be inserted into stringArray (Default: 0.8, Min: 0, Max: 1)",parseFloat).option("--target ","Allows to set target environment for obfuscated code.",d.ObfuscationTargetSanitizer).option("--unicodeEscapeSequence ","Allows to enable/disable string conversion to unicode escape sequence",f.BooleanSanitizer).parse(this.rawArguments)}},{key:"configureHelp",value:function(){this.commands.on("--help",function(){console.log(" Examples:\n"),console.log(" %> javascript-obfuscator input_file_name.js --compact true --selfDefending false"),console.log(" %> javascript-obfuscator input_file_name.js --output output_file_name.js --compact true --selfDefending false"),console.log(" %> javascript-obfuscator input_directory_name --compact true --selfDefending false"),console.log("")})}},{key:"processSourceCodeData",value:function(e){var t=this;if(Array.isArray(e))e.forEach(function(e){var r=e.filePath,n=e.content,o=m.CLIUtils.getOutputCodePath(r);t.processSourceCode(n,o)});else{var r=this.inputCLIOptions.output||m.CLIUtils.getOutputCodePath(this.inputPath);this.processSourceCode(e,r)}}},{key:"processSourceCode",value:function(t,r){var n=this.buildOptions();n.sourceMap?e.processSourceCodeWithSourceMap(t,r,n):e.processSourceCodeWithoutSourceMap(t,r,n)}}],[{key:"filterOptions",value:function(e){var t={};for(var r in e)e.hasOwnProperty(r)&&void 0!==e[r]&&(t[r]=e[r]);return t}},{key:"processSourceCodeWithoutSourceMap",value:function(e,t,r){var n=b.JavaScriptObfuscator.obfuscate(e,r).getObfuscatedCode();m.CLIUtils.writeFile(t,n)}},{key:"processSourceCodeWithSourceMap",value:function(e,t,r){var n=m.CLIUtils.getOutputSourceMapPath(t,r.sourceMapFileName||"");r=Object.assign({},r,{sourceMapFileName:c.basename(n)});var o=b.JavaScriptObfuscator.obfuscate(e,r);m.CLIUtils.writeFile(t,o.getObfuscatedCode()),"separate"===r.sourceMapMode&&o.getSourceMap()&&m.CLIUtils.writeFile(n,o.getSourceMap())}}]),e}();v.availableInputExtensions=[".js"],v.encoding="utf8",v.obfuscatedFilePrefix="-obfuscated",a.__decorate([s.initializable(),a.__metadata("design:type",Object)],v.prototype,"commands",void 0),a.__decorate([s.initializable(),a.__metadata("design:type",Object)],v.prototype,"inputCLIOptions",void 0),a.__decorate([s.initializable(),a.__metadata("design:type",String)],v.prototype,"inputPath",void 0),t.JavaScriptObfuscatorCLI=v},function(e,t){e.exports=require("path")},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});!function(e){e[e.FunctionDeclarationCalleeDataExtractor=0]="FunctionDeclarationCalleeDataExtractor",e[e.FunctionExpressionCalleeDataExtractor=1]="FunctionExpressionCalleeDataExtractor",e[e.ObjectExpressionCalleeDataExtractor=2]="ObjectExpressionCalleeDataExtractor"}(t.CalleeDataExtractor||(t.CalleeDataExtractor={}))},function(e,t){e.exports=require("esprima")},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});!function(e){e[e.BinaryExpressionControlFlowReplacer=0]="BinaryExpressionControlFlowReplacer",e[e.CallExpressionControlFlowReplacer=1]="CallExpressionControlFlowReplacer",e[e.LogicalExpressionControlFlowReplacer=2]="LogicalExpressionControlFlowReplacer",e[e.StringLiteralControlFlowReplacer=3]="StringLiteralControlFlowReplacer"}(t.ControlFlowReplacer||(t.ControlFlowReplacer={}))},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var i=function(){function e(e,t){for(var r=0;r1&&void 0!==arguments[1]&&arguments[1];this.storage=new Map([].concat(n(this.storage),n(e.getStorage()))),t&&(this.storageId=e.getStorageId())}},{key:"set",value:function(e,t){this.storage.set(e,t)}}]),e}();c.__decorate([l.initializable(),c.__metadata("design:type",String)],f.prototype,"storageId",void 0),c.__decorate([l.initializable(),c.__metadata("design:type",Map)],f.prototype,"storage",void 0),c.__decorate([s.postConstruct(),c.__metadata("design:type",Function),c.__metadata("design:paramtypes",[]),c.__metadata("design:returntype",void 0)],f.prototype,"initialize",null),f=c.__decorate([s.injectable(),c.__param(0,s.inject(u.ServiceIdentifiers.IRandomGenerator)),c.__metadata("design:paramtypes",[Object])],f),t.MapStorage=f},function(e,t){e.exports=require("fs")},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(18);e.exports=n.JavaScriptObfuscator},function(e,t){e.exports=require("reflect-metadata")},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(14),o=r(0),a=r(1),i=r(35),c=r(47),s=r(48),u=r(49),l=r(50);t.analyzersModule=new o.ContainerModule(function(e){e(a.ServiceIdentifiers.IStackTraceAnalyzer).to(l.StackTraceAnalyzer).inSingletonScope(),e(a.ServiceIdentifiers.ICalleeDataExtractor).to(c.FunctionDeclarationCalleeDataExtractor).whenTargetNamed(i.CalleeDataExtractor.FunctionDeclarationCalleeDataExtractor),e(a.ServiceIdentifiers.ICalleeDataExtractor).to(s.FunctionExpressionCalleeDataExtractor).whenTargetNamed(i.CalleeDataExtractor.FunctionExpressionCalleeDataExtractor),e(a.ServiceIdentifiers.ICalleeDataExtractor).to(u.ObjectExpressionCalleeDataExtractor).whenTargetNamed(i.CalleeDataExtractor.ObjectExpressionCalleeDataExtractor),e(a.ServiceIdentifiers.Factory__ICalleeDataExtractor).toFactory(n.InversifyContainerFacade.getCacheFactory(a.ServiceIdentifiers.ICalleeDataExtractor))})},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var i=function(){function e(e,t){for(var r=0;rr)return"break";var a=e[o];s.traverse(a,{enter:function(r){if(l.NodeGuards.isCallExpressionNode(r))return a.parentNode!==f.NodeUtils.getBlockScopesOfNode(r)[0]?s.VisitorOption.Skip:void t.analyzeCallExpressionNode(n,e,r)}})}(a))break}return n}},{key:"analyzeCallExpressionNode",value:function(e,t,r){var n=this;p.calleeDataExtractorsList.forEach(function(o){var a=n.calleeDataExtractorFactory(o).extract(t,r.callee);a&&e.push(Object.assign({},a,{stackTrace:n.analyzeRecursive(a.callee.body)}))})}}],[{key:"getLimitIndex",value:function(e){var t=e-1,r=p.limitThresholdActivationLength-1,n=t;return t>r&&(n=Math.round(r+t*p.limitThreshold))>t&&(n=t),n}}]),e}();d.calleeDataExtractorsList=[u.CalleeDataExtractor.FunctionDeclarationCalleeDataExtractor,u.CalleeDataExtractor.FunctionExpressionCalleeDataExtractor,u.CalleeDataExtractor.ObjectExpressionCalleeDataExtractor],d.limitThresholdActivationLength=25,d.limitThreshold=.002,d=p=a.__decorate([i.injectable(),a.__param(0,i.inject(c.ServiceIdentifiers.Factory__ICalleeDataExtractor)),a.__metadata("design:paramtypes",[Function])],d),t.StackTraceAnalyzer=d;var p},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(14),o=r(0),a=r(1),i=r(37),c=r(21),s=r(52),u=r(53),l=r(54),f=r(55),d=r(56),p=r(57),y=r(58);t.controlFlowTransformersModule=new o.ContainerModule(function(e){e(a.ServiceIdentifiers.INodeTransformer).to(u.BlockStatementControlFlowTransformer).whenTargetNamed(c.NodeTransformer.BlockStatementControlFlowTransformer),e(a.ServiceIdentifiers.INodeTransformer).to(f.DeadCodeInjectionTransformer).whenTargetNamed(c.NodeTransformer.DeadCodeInjectionTransformer),e(a.ServiceIdentifiers.INodeTransformer).to(d.FunctionControlFlowTransformer).whenTargetNamed(c.NodeTransformer.FunctionControlFlowTransformer),e(a.ServiceIdentifiers.IControlFlowReplacer).to(s.BinaryExpressionControlFlowReplacer).whenTargetNamed(i.ControlFlowReplacer.BinaryExpressionControlFlowReplacer),e(a.ServiceIdentifiers.IControlFlowReplacer).to(l.CallExpressionControlFlowReplacer).whenTargetNamed(i.ControlFlowReplacer.CallExpressionControlFlowReplacer),e(a.ServiceIdentifiers.IControlFlowReplacer).to(p.LogicalExpressionControlFlowReplacer).whenTargetNamed(i.ControlFlowReplacer.LogicalExpressionControlFlowReplacer),e(a.ServiceIdentifiers.IControlFlowReplacer).to(y.StringLiteralControlFlowReplacer).whenTargetNamed(i.ControlFlowReplacer.StringLiteralControlFlowReplacer),e(a.ServiceIdentifiers.Factory__IControlFlowReplacer).toFactory(n.InversifyContainerFacade.getCacheFactory(a.ServiceIdentifiers.IControlFlowReplacer))})},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var i=function(){function e(e,t){for(var r=0;rthis.options.controlFlowFlatteningThreshold||!m.canTransformBlockStatementNode(e))return e;var r=e.body,n=this.arrayUtils.arrayRange(r.length),o=this.arrayUtils.arrayShuffle(n),a=n.map(function(e){return o.indexOf(e)}),i=this.controlFlowCustomNodeFactory(f.ControlFlowCustomNode.BlockStatementControlFlowFlatteningNode);return i.initialize(r,o,a),i.getNode()[0]}}],[{key:"blockStatementHasProhibitedStatements",value:function(e){return e.body.some(function(e){var t=p.NodeGuards.isBreakStatementNode(e)||p.NodeGuards.isContinueStatementNode(e),r=p.NodeGuards.isVariableDeclarationNode(e)&&("const"===e.kind||"let"===e.kind);return p.NodeGuards.isFunctionDeclarationNode(e)||t||r})}},{key:"canTransformBlockStatementNode",value:function(e){var t=!0;return l.traverse(e,{enter:function(e){if(p.NodeGuards.isWhileStatementNode(e))return l.VisitorOption.Skip;p.NodeGuards.isBlockStatementNode(e)&&m.blockStatementHasProhibitedStatements(e)&&(t=!1)}}),e.body.length<=4&&(t=!1),t}}]),t}(d.AbstractNodeTransformer);y=m=c.__decorate([s.injectable(),c.__param(0,s.inject(u.ServiceIdentifiers.Factory__IControlFlowCustomNode)),c.__param(1,s.inject(u.ServiceIdentifiers.IArrayUtils)),c.__param(2,s.inject(u.ServiceIdentifiers.IRandomGenerator)),c.__param(3,s.inject(u.ServiceIdentifiers.IOptions)),c.__metadata("design:paramtypes",[Function,Object,Object,Object])],y),t.BlockStatementControlFlowTransformer=y;var m},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var i=function(){function e(e,t){for(var r=0;rthis.options.deadCodeInjectionThreshold)return e;if(b.NodeUtils.getBlockScopesOfNode(e)[0].type===d.NodeType.Program)return e;var r=this.collectedBlockStatements.length-1,n=this.randomGenerator.getRandomInteger(0,r),o=this.collectedBlockStatements.splice(n,1)[0];return o===e?e:this.replaceBlockStatementNode(e,o)}},{key:"collectBlockStatementNodes",value:function(e,t){var r=this,n=b.NodeUtils.clone(e),o=0,a=!0;f.replace(n,{enter:function(e,t){return y.NodeGuards.isBlockStatementNode(e)&&o++,o>v.maxNestedBlockStatementsCount||y.NodeGuards.isBreakStatementNode(e)||y.NodeGuards.isContinueStatementNode(e)?(a=!1,f.VisitorOption.Break):(y.NodeGuards.isIdentifierNode(e)&&!y.NodeGuards.isMemberExpressionNode(t)&&(e.name=r.randomGenerator.getRandomVariableName(6)),e)}}),a&&t.push(n)}},{key:"replaceBlockStatementNode",value:function(e,t){var r=this.randomGenerator.getMathRandom()>.5,n=this.randomGenerator.getMathRandom()>.5,o=r?"===":"!==",a=this.randomGenerator.getRandomString(3),c=n?a:this.randomGenerator.getRandomString(3),s=r===n?[e,t]:[t,e],u=i(s,2),l=u[0],f=u[1],d=m.Nodes.getBlockStatementNode([m.Nodes.getIfStatementNode(m.Nodes.getBinaryExpressionNode(o,m.Nodes.getLiteralNode(a),m.Nodes.getLiteralNode(c)),l,f)]);return d=b.NodeUtils.parentize(d)}}]),t}(p.AbstractNodeTransformer);g.maxNestedBlockStatementsCount=4,g.minCollectedBlockStatementsCount=5,g=v=s.__decorate([u.injectable(),s.__param(0,u.inject(l.ServiceIdentifiers.IRandomGenerator)),s.__param(1,u.inject(l.ServiceIdentifiers.IOptions)),s.__metadata("design:paramtypes",[Object,Object])],g),t.DeadCodeInjectionTransformer=g;var v},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var i=function(){function e(e,t){for(var r=0;rh.hostNodeSearchMinDepth&&t.splice(0,h.hostNodeSearchMinDepth),t.length>h.hostNodeSearchMaxDepth&&(t.length=h.hostNodeSearchMaxDepth),this.randomGenerator.getRandomGenerator().pickone(t))}},{key:"isVisitedFunctionNode",value:function(e){return(m.NodeGuards.isFunctionDeclarationNode(e)||m.NodeGuards.isFunctionExpressionNode(e)||m.NodeGuards.isArrowFunctionExpressionNode(e))&&this.visitedFunctionNodes.has(e)}},{key:"transformFunctionBody",value:function(e,t){var r=this;l.replace(e,{enter:function(e,n){if(r.isVisitedFunctionNode(e))return l.VisitorOption.Skip;if(!h.controlFlowReplacersMap.has(e.type))return e;if(r.randomGenerator.getMathRandom()>r.options.controlFlowFlatteningThreshold)return e;var o=h.controlFlowReplacersMap.get(e.type);return void 0===o?e:Object.assign({},r.controlFlowReplacerFactory(o).replace(e,n,t),{parentNode:n})}})}}]),t}(y.AbstractNodeTransformer);v.controlFlowReplacersMap=new Map([[p.NodeType.BinaryExpression,d.ControlFlowReplacer.BinaryExpressionControlFlowReplacer],[p.NodeType.CallExpression,d.ControlFlowReplacer.CallExpressionControlFlowReplacer],[p.NodeType.LogicalExpression,d.ControlFlowReplacer.LogicalExpressionControlFlowReplacer],[p.NodeType.Literal,d.ControlFlowReplacer.StringLiteralControlFlowReplacer]]),v.hostNodeSearchMinDepth=0,v.hostNodeSearchMaxDepth=2,v=h=c.__decorate([s.injectable(),c.__param(0,s.inject(u.ServiceIdentifiers.Factory__TControlFlowStorage)),c.__param(1,s.inject(u.ServiceIdentifiers.Factory__IControlFlowReplacer)),c.__param(2,s.inject(u.ServiceIdentifiers.Factory__IControlFlowCustomNode)),c.__param(3,s.inject(u.ServiceIdentifiers.IRandomGenerator)),c.__param(4,s.inject(u.ServiceIdentifiers.IOptions)),c.__metadata("design:paramtypes",[Function,Function,Function,Object,Object])],v),t.FunctionControlFlowTransformer=v;var h},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var i=function(){function e(e,t){for(var r=0;r1){var o=d.Nodes.getBinaryExpressionNode("+",n.shift(),n.shift());return n.forEach(function(e){o=d.Nodes.getBinaryExpressionNode("+",o,e)}),o}return n[0]}}],[{key:"isLiteralNodeWithStringValue",value:function(e){return e&&f.NodeGuards.isLiteralNode(e)&&"string"==typeof e.value}}]),t}(l.AbstractNodeTransformer);p=y=c.__decorate([s.injectable(),c.__param(0,s.inject(u.ServiceIdentifiers.IRandomGenerator)),c.__param(1,s.inject(u.ServiceIdentifiers.IOptions)),c.__metadata("design:paramtypes",[Object,Object])],p),t.TemplateLiteralTransformer=p;var y},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(14),o=r(0),a=r(1),i=r(12),c=r(20),s=r(39),u=r(64),l=r(65),f=r(66),d=r(67),p=r(68),y=r(70),m=r(73),b=r(74),g=r(75),v=r(76),h=r(77),_=r(79),N=r(81),O=r(83),S=r(87),C=r(89),j=r(90),w=r(91),I=r(93),E=r(95),T=r(102),F=r(104),k=r(107),P=r(108);t.customNodesModule=new o.ContainerModule(function(e){e(a.ServiceIdentifiers.ICustomNode).to(h.ConsoleOutputDisableExpressionNode).whenTargetNamed(c.CustomNode.ConsoleOutputDisableExpressionNode),e(a.ServiceIdentifiers.ICustomNode).to(_.DebugProtectionFunctionCallNode).whenTargetNamed(c.CustomNode.DebugProtectionFunctionCallNode),e(a.ServiceIdentifiers.ICustomNode).to(N.DebugProtectionFunctionIntervalNode).whenTargetNamed(c.CustomNode.DebugProtectionFunctionIntervalNode),e(a.ServiceIdentifiers.ICustomNode).to(O.DebugProtectionFunctionNode).whenTargetNamed(c.CustomNode.DebugProtectionFunctionNode),e(a.ServiceIdentifiers.ICustomNode).to(S.DomainLockNode).whenTargetNamed(c.CustomNode.DomainLockNode),e(a.ServiceIdentifiers.ICustomNode).to(w.NodeCallsControllerFunctionNode).whenTargetNamed(c.CustomNode.NodeCallsControllerFunctionNode),e(a.ServiceIdentifiers.ICustomNode).to(I.SelfDefendingUnicodeNode).whenTargetNamed(c.CustomNode.SelfDefendingUnicodeNode),e(a.ServiceIdentifiers.ICustomNode).to(E.StringArrayCallsWrapper).whenTargetNamed(c.CustomNode.StringArrayCallsWrapper),e(a.ServiceIdentifiers.ICustomNode).to(T.StringArrayNode).whenTargetNamed(c.CustomNode.StringArrayNode),e(a.ServiceIdentifiers.ICustomNode).to(F.StringArrayRotateFunctionNode).whenTargetNamed(c.CustomNode.StringArrayRotateFunctionNode),e(a.ServiceIdentifiers.Newable__ICustomNode).toConstructor(y.BinaryExpressionFunctionNode).whenTargetNamed(i.ControlFlowCustomNode.BinaryExpressionFunctionNode),e(a.ServiceIdentifiers.Newable__ICustomNode).toConstructor(m.BlockStatementControlFlowFlatteningNode).whenTargetNamed(i.ControlFlowCustomNode.BlockStatementControlFlowFlatteningNode),e(a.ServiceIdentifiers.Newable__ICustomNode).toConstructor(b.CallExpressionControlFlowStorageCallNode).whenTargetNamed(i.ControlFlowCustomNode.CallExpressionControlFlowStorageCallNode),e(a.ServiceIdentifiers.Newable__ICustomNode).toConstructor(g.CallExpressionFunctionNode).whenTargetNamed(i.ControlFlowCustomNode.CallExpressionFunctionNode),e(a.ServiceIdentifiers.Newable__ICustomNode).toConstructor(v.ControlFlowStorageNode).whenTargetNamed(i.ControlFlowCustomNode.ControlFlowStorageNode),e(a.ServiceIdentifiers.Newable__ICustomNode).toConstructor(C.ExpressionWithOperatorControlFlowStorageCallNode).whenTargetNamed(i.ControlFlowCustomNode.ExpressionWithOperatorControlFlowStorageCallNode),e(a.ServiceIdentifiers.Newable__ICustomNode).toConstructor(j.LogicalExpressionFunctionNode).whenTargetNamed(i.ControlFlowCustomNode.LogicalExpressionFunctionNode),e(a.ServiceIdentifiers.Newable__ICustomNode).toConstructor(P.StringLiteralNode).whenTargetNamed(i.ControlFlowCustomNode.StringLiteralNode),e(a.ServiceIdentifiers.Newable__ICustomNode).toConstructor(k.StringLiteralControlFlowStorageCallNode).whenTargetNamed(i.ControlFlowCustomNode.StringLiteralControlFlowStorageCallNode),e(a.ServiceIdentifiers.ICustomNodeGroup).to(u.ConsoleOutputCustomNodeGroup).whenTargetNamed(s.CustomNodeGroup.ConsoleOutputCustomNodeGroup),e(a.ServiceIdentifiers.ICustomNodeGroup).to(l.DebugProtectionCustomNodeGroup).whenTargetNamed(s.CustomNodeGroup.DebugProtectionCustomNodeGroup),e(a.ServiceIdentifiers.ICustomNodeGroup).to(f.DomainLockCustomNodeGroup).whenTargetNamed(s.CustomNodeGroup.DomainLockCustomNodeGroup),e(a.ServiceIdentifiers.ICustomNodeGroup).to(d.SelfDefendingCustomNodeGroup).whenTargetNamed(s.CustomNodeGroup.SelfDefendingCustomNodeGroup),e(a.ServiceIdentifiers.ICustomNodeGroup).to(p.StringArrayCustomNodeGroup).whenTargetNamed(s.CustomNodeGroup.StringArrayCustomNodeGroup),e(a.ServiceIdentifiers.Factory__ICustomNode).toFactory(n.InversifyContainerFacade.getFactory(a.ServiceIdentifiers.ICustomNode)),e(a.ServiceIdentifiers.Factory__IControlFlowCustomNode).toFactory(n.InversifyContainerFacade.getConstructorFactory(a.ServiceIdentifiers.Newable__ICustomNode,a.ServiceIdentifiers.IRandomGenerator,a.ServiceIdentifiers.IOptions)),e(a.ServiceIdentifiers.Factory__ICustomNodeGroup).toFactory(n.InversifyContainerFacade.getFactory(a.ServiceIdentifiers.ICustomNodeGroup))})},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var i=function(){function e(e,t){for(var r=0;r 0;\n \n switch (isPositive) {\n case true:\n return this.item + \'_\' + this.value + \'_\' + i;\n default:\n this.item + \'_\' + this.value;\n }\n }\n }()\n };\n };\n \n var regExp = new RegExp("[{diff}]", "g");\n var domains = "{domains}".replace(regExp, "").split(";");\n var document;\n var domain;\n \n for (var d in that) {\n if (d.length == 8 && d.charCodeAt(7) == 116 && d.charCodeAt(5) == 101 && d.charCodeAt(3) == 117 && d.charCodeAt(0) == 100) {\n document = d;\n \n break;\n }\n }\n\n for (var d1 in that[document]) {\n if (d1.length == 6 && d1.charCodeAt(5) == 110 && d1.charCodeAt(0) == 100) {\n domain = d1;\n \n break;\n }\n }\n \n if ((!document && !domain) || (!that[document] && !that[document][domain])) {\n return;\n }\n \n var currentDomain = that[document][domain];\n\n var ok = false;\n \n for (var i = 0; i < domains.length; i++) {\n var domain = domains[i];\n var position = currentDomain.length - domain.length;\n var lastIndex = currentDomain.indexOf(domain, position);\n var endsWith = lastIndex !== -1 && lastIndex === position;\n \n if (endsWith) {\n if (currentDomain.length == domain.length || domain.indexOf(".") === 0) {\n ok = true;\n }\n \n break;\n }\n }\n \n if (!ok) {\n data;\n } else {\n return;\n }\n \n func();\n });\n\n {domainLockFunctionName}();\n '}Object.defineProperty(t,"__esModule",{value:!0}),t.DomainLockNodeTemplate=n},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var i=function(){function e(e,t){for(var r=0;r> 1 + 255 % 0;\n \n if (string.indexOf('i' === i)) {\n recursiveFunc2(string)\n }\n };\n \n var recursiveFunc2 = function (string) {\n var i = ~-4 >> 1 + 255 % 0;\n \n if (string.indexOf((true+\"\")[3]) !== i) {\n recursiveFunc1(string)\n }\n };\n \n if (!test1()) {\n if (!test2()) {\n recursiveFunc1('indеxOf');\n } else {\n recursiveFunc1('indexOf');\n }\n } else {\n recursiveFunc1('indеxOf');\n }\n })\n \n {selfDefendingFunctionName}();\n "}Object.defineProperty(t,"__esModule",{value:!0}),t.SelfDefendingTemplate=n},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var i=function(){function e(e,t){for(var r=0;r> (-2 * bc & 6)) : 0\n ) {\n buffer = chars.indexOf(buffer);\n }\n return output;\n });\n })();\n "}Object.defineProperty(t,"__esModule",{value:!0}),t.AtobTemplate=n},function(e,t,r){"use strict";function n(){return"\n var rc4 = function (str, key) {\n var s = [], j = 0, x, res = '', newStr = '';\n \n str = atob(str);\n \n for (var k = 0, length = str.length; k < length; k++) {\n newStr += '%' + ('00' + str.charCodeAt(k).toString(16)).slice(-2);\n }\n \n str = decodeURIComponent(newStr);\n \t \n\t for (var i = 0; i < 256; i++) {\n s[i] = i;\n }\n \n for (i = 0; i < 256; i++) {\n j = (j + s[i] + key.charCodeAt(i % key.length)) % 256;\n x = s[i];\n s[i] = s[j];\n s[j] = x;\n }\n \n i = 0;\n j = 0;\n \n for (var y = 0; y < str.length; y++) {\n i = (i + 1) % 256;\n j = (j + s[i]) % 256;\n x = s[i];\n s[i] = s[j];\n s[j] = x;\n res += String.fromCharCode(str.charCodeAt(y) ^ s[(s[i] + s[j]) % 256]);\n }\n \n return res;\n }\n "}Object.defineProperty(t,"__esModule",{value:!0}),t.Rc4Template=n},function(e,t,r){"use strict";function n(e){return"\n var StatesClass = function (rc4Bytes) {\n this.rc4Bytes = rc4Bytes;\n this.states = [1, 0, 0];\n this.newState = function(){return 'newState';};\n this.firstState = '"+e.encode("\\w+ *\\(\\) *{\\w+ *",!0)+"';\n this.secondState = '"+e.encode("['|\"].+['|\"];? *}",!0)+"';\n };\n \n StatesClass.prototype.checkState = function () {\n var regExp = new RegExp(this.firstState + this.secondState);\n\n return this.runState(regExp.test(this.newState.toString()) ? --this.states[1] : --this.states[0]);\n };\n \n StatesClass.prototype.runState = function (stateResult) {\n if (!Boolean(~stateResult)) {\n return stateResult;\n }\n \n return this.getState(this.rc4Bytes);\n };\n\n StatesClass.prototype.getState = function (rc4Bytes) {\n for (var i = 0, len = this.states.length; i < len; i++) {\n this.states.push(Math.round(Math.random()));\n len = this.states.length;\n }\n \n return rc4Bytes(this.states[0]);\n };\n\n new StatesClass({stringArrayCallsWrapperName}).checkState();\n "}Object.defineProperty(t,"__esModule",{value:!0}),t.SelfDefendingTemplate=n},function(e,t,r){"use strict";function n(){return" \n if ({stringArrayCallsWrapperName}.initialized === undefined) {\n {atobPolyfill}\n \n {stringArrayCallsWrapperName}.base64DecodeUnicode = function (str) {\n var string = atob(str);\n var newStringChars = [];\n \n for (var i = 0, length = string.length; i < length; i++) {\n newStringChars += '%' + ('00' + string.charCodeAt(i).toString(16)).slice(-2);\n }\n \n return decodeURIComponent(newStringChars);\n };\n \n {stringArrayCallsWrapperName}.data = {};\n \n {stringArrayCallsWrapperName}.initialized = true;\n }\n \n var cachedValue = {stringArrayCallsWrapperName}.data[index];\n \n if (cachedValue === undefined) {\n {selfDefendingCode}\n \n value = {stringArrayCallsWrapperName}.base64DecodeUnicode(value);\n {stringArrayCallsWrapperName}.data[index] = value;\n } else {\n value = cachedValue;\n } \n "}Object.defineProperty(t,"__esModule",{value:!0}),t.StringArrayBase64DecodeNodeTemplate=n},function(e,t,r){"use strict";function n(){return"\n var {stringArrayCallsWrapperName} = function (index, key) {\n index = index - 0;\n \n var value = {stringArrayName}[index];\n \n {decodeNodeTemplate}\n \n return value;\n };\n "}Object.defineProperty(t,"__esModule",{value:!0}),t.StringArrayCallsWrapperTemplate=n},function(e,t,r){"use strict";function n(){return"\n if ({stringArrayCallsWrapperName}.initialized === undefined) {\n {atobPolyfill}\n \n {rc4Polyfill}\n {stringArrayCallsWrapperName}.rc4 = rc4;\n \n {stringArrayCallsWrapperName}.data = {};\n \n {stringArrayCallsWrapperName}.initialized = true;\n }\n \n var cachedValue = {stringArrayCallsWrapperName}.data[index];\n\n if (cachedValue === undefined) {\n if ({stringArrayCallsWrapperName}.once === undefined) {\n {selfDefendingCode}\n \n {stringArrayCallsWrapperName}.once = true;\n }\n \n value = {stringArrayCallsWrapperName}.rc4(value, key);\n {stringArrayCallsWrapperName}.data[index] = value;\n } else {\n value = cachedValue;\n }\n "}Object.defineProperty(t,"__esModule",{value:!0}),t.StringArrayRc4DecodeNodeTemplate=n},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var i=function(){function e(e,t){for(var r=0;r=m.minimumLengthForStringArray&&this.randomGenerator.getMathRandom()<=this.options.stringArrayThreshold}},{key:"getStringArrayHexadecimalIndex",value:function(e,t){if(this.stringLiteralHexadecimalIndexCache.has(e))return{fromCache:!0,index:this.stringLiteralHexadecimalIndexCache.get(e)};var r=p.Utils.decToHex(t),n=""+p.Utils.hexadecimalPrefix+r;return this.stringLiteralHexadecimalIndexCache.set(e,n),{fromCache:!1,index:n}}},{key:"getEncodedValue",value:function(e){var t=void 0,r=null;switch(this.options.stringArrayEncoding){case l.StringArrayEncoding.Rc4:r=this.randomGenerator.getRandomGenerator().pickone(this.rc4Keys),t=this.cryptUtils.btoa(this.cryptUtils.rc4(e,r));break;case l.StringArrayEncoding.Base64:t=this.cryptUtils.btoa(e);break;default:t=e}return{encodedValue:t,key:r}}},{key:"replaceWithLiteralNode",value:function(e){return d.Nodes.getLiteralNode(this.escapeSequenceEncoder.encode(e,this.options.unicodeEscapeSequence))}},{key:"replaceWithStringArrayCallNode",value:function(e){var t=this.getEncodedValue(e),r=t.encodedValue,n=t.key,o=this.escapeSequenceEncoder.encode(r,this.options.unicodeEscapeSequence),a=this.stringArrayStorage.getLength(),i=p.Utils.stringRotate(this.stringArrayStorage.getStorageId(),1),c="_"+p.Utils.hexadecimalPrefix+i,s=this.getStringArrayHexadecimalIndex(o,a),u=s.fromCache,l=s.index;u||this.stringArrayStorage.set(a,o);var f=[m.getHexadecimalLiteralNode(l)];return n&&f.push(m.getRc4KeyLiteralNode(this.escapeSequenceEncoder.encode(n,this.options.unicodeEscapeSequence))),d.Nodes.getCallExpressionNode(d.Nodes.getIdentifierNode(c),f)}}],[{key:"getHexadecimalLiteralNode",value:function(e){var t=d.Nodes.getLiteralNode(e);return t.obfuscatedNode=!0,t}},{key:"getRc4KeyLiteralNode",value:function(e){var t=d.Nodes.getLiteralNode(e);return t.obfuscatedNode=!0,t}}]),t}(f.AbstractObfuscatingReplacer);y.minimumLengthForStringArray=3,y.rc4KeyLength=4,y.rc4KeysCount=50,y=m=c.__decorate([s.injectable(),c.__param(0,s.inject(u.ServiceIdentifiers.TCustomNodeGroupStorage)),c.__param(1,s.inject(u.ServiceIdentifiers.TStringArrayStorage)),c.__param(2,s.inject(u.ServiceIdentifiers.IEscapeSequenceEncoder)),c.__param(3,s.inject(u.ServiceIdentifiers.IRandomGenerator)),c.__param(4,s.inject(u.ServiceIdentifiers.ICryptUtils)),c.__param(5,s.inject(u.ServiceIdentifiers.IOptions)),c.__metadata("design:paramtypes",[Object,Object,Object,Object,Object,Object])],y),t.StringLiteralObfuscatingReplacer=y;var m},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var i=function(){function e(e,t){for(var r=0;r=0?t:null}},{key:"getLength",value:function(){return this.storageLength}},{key:"getStorage",value:function(){return this.storage}},{key:"getStorageId",value:function(){return this.storageId}},{key:"mergeWith",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this.storage=[].concat(n(this.storage),n(e.getStorage())),t&&(this.storageId=e.getStorageId())}},{key:"set",value:function(e,t){e===this.storageLength?this.storage.push(t):this.storage.splice(e,0,t),this.storageLength++}}]),e}();i.__decorate([u.initializable(),i.__metadata("design:type",Array)],l.prototype,"storage",void 0),i.__decorate([u.initializable(),i.__metadata("design:type",String)],l.prototype,"storageId",void 0),i.__decorate([c.postConstruct(),i.__metadata("design:type",Function),i.__metadata("design:paramtypes",[]),i.__metadata("design:returntype",void 0)],l.prototype,"initialize",null),l=i.__decorate([c.injectable(),i.__param(0,c.inject(s.ServiceIdentifiers.IRandomGenerator)),i.__metadata("design:paramtypes",[Object])],l),t.ArrayStorage=l},function(e,t){e.exports=require("md5")},function(e,t){e.exports=require("chance")},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(0),o=r(1),a=r(136),i=r(137),c=r(138),s=r(31);t.utilsModule=new n.ContainerModule(function(e){e(o.ServiceIdentifiers.IArrayUtils).to(a.ArrayUtils).inSingletonScope(),e(o.ServiceIdentifiers.IRandomGenerator).to(s.RandomGenerator).inSingletonScope(),e(o.ServiceIdentifiers.ICryptUtils).to(i.CryptUtils).inSingletonScope(),e(o.ServiceIdentifiers.IEscapeSequenceEncoder).to(c.EscapeSequenceEncoder).inSingletonScope()})},function(e,t,r){"use strict";function n(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t>8-o%1*8)){if((n=e.charCodeAt(o+=.75))>255)throw new Error("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");r=r<<8|n}return t}},{key:"hideString",value:function(e,t){var r=this,n=this.randomGenerator.getRandomGenerator().string({length:t,pool:s.RandomGenerator.randomGeneratorPool}),o=n.replace(new RegExp("["+function(e){return e.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}(e)+"]","g"),""),a=o.split("");return this.randomGenerator.getRandomGenerator().shuffle(a),o=a.join(""),[function(e,t){for(var n=-1,o=-1,a="";n1&&void 0!==arguments[1]?arguments[1]:"";return t&&(e=e.substring(0,e.lastIndexOf("/"))+"/"+t),/\.js\.map$/.test(e)?/\.js$/.test(e)&&(e+=".map"):e=e.split(".")[0]+".js.map",e}},{key:"getPackageConfig",value:function(){return JSON.parse(a.readFileSync(c.join(c.dirname(a.realpathSync(process.argv[1])),"../package.json"),s.JavaScriptObfuscatorCLI.encoding))}},{key:"getUserConfig",value:function(e){var t=void 0;try{t=!function(){var e=new Error('Cannot find module "."');throw e.code="MODULE_NOT_FOUND",e}()}catch(r){try{t=require(e)}catch(e){throw new ReferenceError("Given config path must be a valid file path")}}return t}},{key:"writeFile",value:function(e,t){i.sync(c.dirname(e)),a.writeFileSync(e,t,{encoding:s.JavaScriptObfuscatorCLI.encoding})}}]),e}();t.CLIUtils=u},function(e,t){e.exports=require("mkdirp")},function(e,t){function r(e){throw new Error("Cannot find module '"+e+"'.")}r.keys=function(){return[]},r.resolve=r,e.exports=r,r.id=173},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function e(e,t){for(var r=0;r', + 'Allows to set target environment for obfuscated code.', + ObfuscationTargetSanitizer + ) .option( '--unicodeEscapeSequence ', 'Allows to enable/disable string conversion to unicode escape sequence', diff --git a/src/cli/sanitizers/ObfuscatingTargetSanitizer.ts b/src/cli/sanitizers/ObfuscatingTargetSanitizer.ts new file mode 100644 index 00000000..a828586d --- /dev/null +++ b/src/cli/sanitizers/ObfuscatingTargetSanitizer.ts @@ -0,0 +1,21 @@ +import { TCLISanitizer } from '../../types/cli/TCLISanitizer'; + +import { ObfuscationTarget } from '../../enums/ObfuscationTarget'; + +/** + * @param {string} value + * @returns {string} + */ +export const ObfuscationTargetSanitizer: TCLISanitizer = (value: string): string => { + const isCorrectTarget: boolean = Object + .keys(ObfuscationTarget) + .some((key: any): boolean => { + return ObfuscationTarget[key] === value; + }); + + if (!isCorrectTarget) { + throw new ReferenceError('Invalid value of `--target` option'); + } + + return value; +}; diff --git a/src/cli/sanitizers/SourceMapModeSanitizer.ts b/src/cli/sanitizers/SourceMapModeSanitizer.ts index 51126695..1b90ca47 100644 --- a/src/cli/sanitizers/SourceMapModeSanitizer.ts +++ b/src/cli/sanitizers/SourceMapModeSanitizer.ts @@ -7,13 +7,13 @@ import { SourceMapMode } from '../../enums/source-map/SourceMapMode'; * @returns {string} */ export const SourceMapModeSanitizer: TCLISanitizer = (value: string): string => { - const availableMode: boolean = Object + const isCorrectSourceMapMode: boolean = Object .keys(SourceMapMode) .some((key: any): boolean => { return SourceMapMode[key] === value; }); - if (!availableMode) { + if (!isCorrectSourceMapMode) { throw new ReferenceError('Invalid value of `--sourceMapMode` option'); } diff --git a/src/custom-nodes/AbstractCustomNode.ts b/src/custom-nodes/AbstractCustomNode.ts index a1a343b7..e3fe7d74 100644 --- a/src/custom-nodes/AbstractCustomNode.ts +++ b/src/custom-nodes/AbstractCustomNode.ts @@ -1,14 +1,27 @@ import { injectable, inject } from 'inversify'; import { ServiceIdentifiers } from '../container/ServiceIdentifiers'; +import { TStatement } from '../types/node/TStatement'; + import { ICustomNode } from '../interfaces/custom-nodes/ICustomNode'; import { IOptions } from '../interfaces/options/IOptions'; -import { TStatement } from '../types/node/TStatement'; +import { IRandomGenerator } from '../interfaces/utils/IRandomGenerator'; + +import { GlobalVariableTemplate1 } from '../templates/GlobalVariableTemplate1'; +import { GlobalVariableTemplate2 } from '../templates/GlobalVariableTemplate2'; import { NodeUtils } from '../node/NodeUtils'; @injectable() export abstract class AbstractCustomNode implements ICustomNode { + /** + * @type {string[]} + */ + private static globalVariableTemplateFunctions: string[] = [ + GlobalVariableTemplate1(), + GlobalVariableTemplate2() + ]; + /** * @type {string} */ @@ -25,11 +38,19 @@ export abstract class AbstractCustomNode implements ICustomNode { protected readonly options: IOptions; /** + * @type {IRandomGenerator} + */ + protected readonly randomGenerator: IRandomGenerator; + + /** + * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ constructor ( + @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { + this.randomGenerator = randomGenerator; this.options = options; } @@ -60,6 +81,15 @@ export abstract class AbstractCustomNode implements ICustomNode { return this.cachedNode; } + /** + * @returns {string} + */ + protected getGlobalVariableTemplate (): string { + return this.randomGenerator + .getRandomGenerator() + .pickone(AbstractCustomNode.globalVariableTemplateFunctions); + } + /** * @returns {TStatement[]} */ diff --git a/src/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.ts b/src/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.ts index 54113e04..c477e7c2 100644 --- a/src/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.ts +++ b/src/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.ts @@ -8,7 +8,10 @@ import { TStatement } from '../../types/node/TStatement'; import { IOptions } from '../../interfaces/options/IOptions'; import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator'; -import { ConsoleOutputDisableExpressionTemplate } from '../../templates/custom-nodes/console-output-nodes/console-output-disable-expression-node/ConsoleOutputDisableExpressionTemplate'; +import { ObfuscationTarget } from '../../enums/ObfuscationTarget'; + +import { ConsoleOutputDisableExpressionTemplate } from '../../templates/console-output-nodes/console-output-disable-expression-node/ConsoleOutputDisableExpressionTemplate'; +import { GlobalVariableNoEvalTemplate } from '../../templates/GlobalVariableNoEvalTemplate'; import { initializable } from '../../decorators/Initializable'; @@ -23,11 +26,6 @@ export class ConsoleOutputDisableExpressionNode extends AbstractCustomNode { @initializable() private callsControllerFunctionName: string; - /** - * @type {IRandomGenerator} - */ - private readonly randomGenerator: IRandomGenerator; - /** * @param {IRandomGenerator} randomGenerator * @param {IOptions} options @@ -36,9 +34,7 @@ export class ConsoleOutputDisableExpressionNode extends AbstractCustomNode { @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super(options); - - this.randomGenerator = randomGenerator; + super(randomGenerator, options); } /** @@ -59,8 +55,13 @@ export class ConsoleOutputDisableExpressionNode extends AbstractCustomNode { * @returns {string} */ protected getTemplate (): string { + const globalVariableTemplate: string = this.options.target !== ObfuscationTarget.Extension + ? this.getGlobalVariableTemplate() + : GlobalVariableNoEvalTemplate(); + return format(ConsoleOutputDisableExpressionTemplate(), { consoleLogDisableFunctionName: this.randomGenerator.getRandomVariableName(6), + globalVariableTemplate, singleNodeCallControllerFunctionName: this.callsControllerFunctionName }); } diff --git a/src/custom-nodes/control-flow-flattening-nodes/BinaryExpressionFunctionNode.ts b/src/custom-nodes/control-flow-flattening-nodes/BinaryExpressionFunctionNode.ts index 1cc73079..ec9f7983 100644 --- a/src/custom-nodes/control-flow-flattening-nodes/BinaryExpressionFunctionNode.ts +++ b/src/custom-nodes/control-flow-flattening-nodes/BinaryExpressionFunctionNode.ts @@ -22,11 +22,6 @@ export class BinaryExpressionFunctionNode extends AbstractCustomNode { @initializable() private operator: BinaryOperator; - /** - * @type {IRandomGenerator} - */ - private readonly randomGenerator: IRandomGenerator; - /** * @param {IRandomGenerator} randomGenerator * @param {IOptions} options @@ -35,9 +30,7 @@ export class BinaryExpressionFunctionNode extends AbstractCustomNode { @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super(options); - - this.randomGenerator = randomGenerator; + super(randomGenerator, options); } /** diff --git a/src/custom-nodes/control-flow-flattening-nodes/BlockStatementControlFlowFlatteningNode.ts b/src/custom-nodes/control-flow-flattening-nodes/BlockStatementControlFlowFlatteningNode.ts index 2fc87584..0e227b72 100644 --- a/src/custom-nodes/control-flow-flattening-nodes/BlockStatementControlFlowFlatteningNode.ts +++ b/src/custom-nodes/control-flow-flattening-nodes/BlockStatementControlFlowFlatteningNode.ts @@ -28,11 +28,6 @@ export class BlockStatementControlFlowFlatteningNode extends AbstractCustomNode @initializable() private originalKeysIndexesInShuffledArray: number[]; - /** - * @type {IRandomGenerator} - */ - private readonly randomGenerator: IRandomGenerator; - /** * @type {number[]} */ @@ -47,9 +42,7 @@ export class BlockStatementControlFlowFlatteningNode extends AbstractCustomNode @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super(options); - - this.randomGenerator = randomGenerator; + super(randomGenerator, options); } /** diff --git a/src/custom-nodes/control-flow-flattening-nodes/CallExpressionFunctionNode.ts b/src/custom-nodes/control-flow-flattening-nodes/CallExpressionFunctionNode.ts index 79c15ecc..3726a557 100644 --- a/src/custom-nodes/control-flow-flattening-nodes/CallExpressionFunctionNode.ts +++ b/src/custom-nodes/control-flow-flattening-nodes/CallExpressionFunctionNode.ts @@ -22,11 +22,6 @@ export class CallExpressionFunctionNode extends AbstractCustomNode { @initializable() private expressionArguments: (ESTree.Expression | ESTree.SpreadElement)[]; - /** - * @type {IRandomGenerator} - */ - private readonly randomGenerator: IRandomGenerator; - /** * @param {IRandomGenerator} randomGenerator * @param {IOptions} options @@ -35,9 +30,7 @@ export class CallExpressionFunctionNode extends AbstractCustomNode { @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super(options); - - this.randomGenerator = randomGenerator; + super(randomGenerator, options); } /** diff --git a/src/custom-nodes/control-flow-flattening-nodes/LogicalExpressionFunctionNode.ts b/src/custom-nodes/control-flow-flattening-nodes/LogicalExpressionFunctionNode.ts index 0fbed122..b26012e5 100644 --- a/src/custom-nodes/control-flow-flattening-nodes/LogicalExpressionFunctionNode.ts +++ b/src/custom-nodes/control-flow-flattening-nodes/LogicalExpressionFunctionNode.ts @@ -22,11 +22,6 @@ export class LogicalExpressionFunctionNode extends AbstractCustomNode { @initializable() private operator: LogicalOperator; - /** - * @type {IRandomGenerator} - */ - private readonly randomGenerator: IRandomGenerator; - /** * @param {IRandomGenerator} randomGenerator * @param {IOptions} options @@ -35,9 +30,7 @@ export class LogicalExpressionFunctionNode extends AbstractCustomNode { @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super(options); - - this.randomGenerator = randomGenerator; + super(randomGenerator, options); } /** diff --git a/src/custom-nodes/control-flow-flattening-nodes/StringLiteralNode.ts b/src/custom-nodes/control-flow-flattening-nodes/StringLiteralNode.ts index 24dc783a..c576f8fb 100644 --- a/src/custom-nodes/control-flow-flattening-nodes/StringLiteralNode.ts +++ b/src/custom-nodes/control-flow-flattening-nodes/StringLiteralNode.ts @@ -19,11 +19,6 @@ export class StringLiteralNode extends AbstractCustomNode { @initializable() private literalValue: string; - /** - * @type {IRandomGenerator} - */ - private readonly randomGenerator: IRandomGenerator; - /** * @param {IRandomGenerator} randomGenerator * @param {IOptions} options @@ -32,9 +27,7 @@ export class StringLiteralNode extends AbstractCustomNode { @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super(options); - - this.randomGenerator = randomGenerator; + super(randomGenerator, options); } /** diff --git a/src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/CallExpressionControlFlowStorageCallNode.ts b/src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/CallExpressionControlFlowStorageCallNode.ts index 38306389..454a408d 100644 --- a/src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/CallExpressionControlFlowStorageCallNode.ts +++ b/src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/CallExpressionControlFlowStorageCallNode.ts @@ -41,11 +41,6 @@ export class CallExpressionControlFlowStorageCallNode extends AbstractCustomNode @initializable() private expressionArguments: (ESTree.Expression | ESTree.SpreadElement)[]; - /** - * @type {IRandomGenerator} - */ - private readonly randomGenerator: IRandomGenerator; - /** * @param {IRandomGenerator} randomGenerator * @param {IOptions} options @@ -54,9 +49,7 @@ export class CallExpressionControlFlowStorageCallNode extends AbstractCustomNode @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super(options); - - this.randomGenerator = randomGenerator; + super(randomGenerator, options); } /** diff --git a/src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/ControlFlowStorageNode.ts b/src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/ControlFlowStorageNode.ts index 9b7db695..e539580c 100644 --- a/src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/ControlFlowStorageNode.ts +++ b/src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/ControlFlowStorageNode.ts @@ -24,11 +24,6 @@ export class ControlFlowStorageNode extends AbstractCustomNode { @initializable() private controlFlowStorage: IStorage ; - /** - * @type {IRandomGenerator} - */ - private readonly randomGenerator: IRandomGenerator; - /** * @param {IRandomGenerator} randomGenerator * @param {IOptions} options @@ -37,9 +32,7 @@ export class ControlFlowStorageNode extends AbstractCustomNode { @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super(options); - - this.randomGenerator = randomGenerator; + super(randomGenerator, options); } /** diff --git a/src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/ExpressionWithOperatorControlFlowStorageCallNode.ts b/src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/ExpressionWithOperatorControlFlowStorageCallNode.ts index 46593a0a..869433d6 100644 --- a/src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/ExpressionWithOperatorControlFlowStorageCallNode.ts +++ b/src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/ExpressionWithOperatorControlFlowStorageCallNode.ts @@ -34,11 +34,6 @@ export class ExpressionWithOperatorControlFlowStorageCallNode extends AbstractCu @initializable() private leftValue: Expression; - /** - * @type {IRandomGenerator} - */ - private readonly randomGenerator: IRandomGenerator; - /** * @type {ESTree.Expression} */ @@ -53,9 +48,7 @@ export class ExpressionWithOperatorControlFlowStorageCallNode extends AbstractCu @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super(options); - - this.randomGenerator = randomGenerator; + super(randomGenerator, options); } /** diff --git a/src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/StringLiteralControlFlowStorageCallNode.ts b/src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/StringLiteralControlFlowStorageCallNode.ts index 416e0dca..4b757e02 100644 --- a/src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/StringLiteralControlFlowStorageCallNode.ts +++ b/src/custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/StringLiteralControlFlowStorageCallNode.ts @@ -26,11 +26,6 @@ export class StringLiteralControlFlowStorageCallNode extends AbstractCustomNode @initializable() private controlFlowStorageName: string; - /** - * @type {IRandomGenerator} - */ - private readonly randomGenerator: IRandomGenerator; - /** * @param {IRandomGenerator} randomGenerator * @param {IOptions} options @@ -39,9 +34,7 @@ export class StringLiteralControlFlowStorageCallNode extends AbstractCustomNode @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super(options); - - this.randomGenerator = randomGenerator; + super(randomGenerator, options); } /** diff --git a/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionCallNode.ts b/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionCallNode.ts index 2cd94564..acdd2ca1 100644 --- a/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionCallNode.ts +++ b/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionCallNode.ts @@ -6,10 +6,11 @@ import * as format from 'string-template'; import { TStatement } from '../../types/node/TStatement'; import { IOptions } from '../../interfaces/options/IOptions'; +import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator'; import { initializable } from '../../decorators/Initializable'; -import { DebugProtectionFunctionCallTemplate } from '../../templates/custom-nodes/debug-protection-nodes/debug-protection-function-call-node/DebufProtectionFunctionCallTemplate'; +import { DebugProtectionFunctionCallTemplate } from '../../templates/debug-protection-nodes/debug-protection-function-call-node/DebufProtectionFunctionCallTemplate'; import { AbstractCustomNode } from '../AbstractCustomNode'; import { NodeUtils } from '../../node/NodeUtils'; @@ -23,12 +24,14 @@ export class DebugProtectionFunctionCallNode extends AbstractCustomNode { private debugProtectionFunctionName: string; /** + * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ constructor ( + @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super(options); + super(randomGenerator, options); } /** diff --git a/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionIntervalNode.ts b/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionIntervalNode.ts index 00d1e684..5b7f3e98 100644 --- a/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionIntervalNode.ts +++ b/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionIntervalNode.ts @@ -6,10 +6,11 @@ import * as format from 'string-template'; import { TStatement } from '../../types/node/TStatement'; import { IOptions } from '../../interfaces/options/IOptions'; +import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator'; import { initializable } from '../../decorators/Initializable'; -import { DebugProtectionFunctionIntervalTemplate } from '../../templates/custom-nodes/debug-protection-nodes/debug-protection-function-interval-node/DebugProtectionFunctionIntervalTemplate'; +import { DebugProtectionFunctionIntervalTemplate } from '../../templates/debug-protection-nodes/debug-protection-function-interval-node/DebugProtectionFunctionIntervalTemplate'; import { AbstractCustomNode } from '../AbstractCustomNode'; import { NodeUtils } from '../../node/NodeUtils'; @@ -23,12 +24,14 @@ export class DebugProtectionFunctionIntervalNode extends AbstractCustomNode { private debugProtectionFunctionName: string; /** + * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ constructor ( + @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super(options); + super(randomGenerator, options); } /** diff --git a/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionNode.ts b/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionNode.ts index 85c014c2..8c922d73 100644 --- a/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionNode.ts +++ b/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionNode.ts @@ -6,10 +6,15 @@ import * as format from 'string-template'; import { TStatement } from '../../types/node/TStatement'; import { IOptions } from '../../interfaces/options/IOptions'; +import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator'; + +import { ObfuscationTarget } from '../../enums/ObfuscationTarget'; import { initializable } from '../../decorators/Initializable'; -import { DebugProtectionFunctionTemplate } from '../../templates/custom-nodes/debug-protection-nodes/debug-protection-function-node/DebugProtectionFunctionTemplate'; +import { DebuggerTemplate } from '../../templates/debug-protection-nodes/debug-protection-function-node/DebuggerTemplate'; +import { DebuggerTemplateNoEval } from '../../templates/debug-protection-nodes/debug-protection-function-node/DebuggerTemplateNoEval'; +import { DebugProtectionFunctionTemplate } from '../../templates/debug-protection-nodes/debug-protection-function-node/DebugProtectionFunctionTemplate'; import { AbstractCustomNode } from '../AbstractCustomNode'; import { NodeUtils } from '../../node/NodeUtils'; @@ -23,12 +28,14 @@ export class DebugProtectionFunctionNode extends AbstractCustomNode { private debugProtectionFunctionName: string; /** + * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ constructor ( + @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super(options); + super(randomGenerator, options); } /** @@ -49,7 +56,12 @@ export class DebugProtectionFunctionNode extends AbstractCustomNode { * @returns {string} */ protected getTemplate (): string { + const debuggerTemplate: string = this.options.target !== ObfuscationTarget.Extension + ? DebuggerTemplate() + : DebuggerTemplateNoEval(); + return format(DebugProtectionFunctionTemplate(), { + debuggerTemplate, debugProtectionFunctionName: this.debugProtectionFunctionName }); } diff --git a/src/custom-nodes/domain-lock-nodes/DomainLockNode.ts b/src/custom-nodes/domain-lock-nodes/DomainLockNode.ts index 0e3841f1..eba9207f 100644 --- a/src/custom-nodes/domain-lock-nodes/DomainLockNode.ts +++ b/src/custom-nodes/domain-lock-nodes/DomainLockNode.ts @@ -9,9 +9,12 @@ import { ICryptUtils } from '../../interfaces/utils/ICryptUtils'; import { IOptions } from '../../interfaces/options/IOptions'; import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator'; +import { ObfuscationTarget } from '../../enums/ObfuscationTarget'; + import { initializable } from '../../decorators/Initializable'; -import { DomainLockNodeTemplate } from '../../templates/custom-nodes/domain-lock-nodes/domain-lock-node/DomainLockNodeTemplate'; +import { DomainLockNodeTemplate } from '../../templates/domain-lock-nodes/domain-lock-node/DomainLockNodeTemplate'; +import { GlobalVariableNoEvalTemplate } from '../../templates/GlobalVariableNoEvalTemplate'; import { AbstractCustomNode } from '../AbstractCustomNode'; import { NodeUtils } from '../../node/NodeUtils'; @@ -29,11 +32,6 @@ export class DomainLockNode extends AbstractCustomNode { */ private readonly cryptUtils: ICryptUtils; - /** - * @type {IRandomGenerator} - */ - private readonly randomGenerator: IRandomGenerator; - /** * @param {IRandomGenerator} randomGenerator * @param {ICryptUtils} cryptUtils @@ -44,9 +42,8 @@ export class DomainLockNode extends AbstractCustomNode { @inject(ServiceIdentifiers.ICryptUtils) cryptUtils: ICryptUtils, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super(options); + super(randomGenerator, options); - this.randomGenerator = randomGenerator; this.cryptUtils = cryptUtils; } @@ -73,11 +70,15 @@ export class DomainLockNode extends AbstractCustomNode { domainsString, domainsString.length * 3 ); + const globalVariableTemplate: string = this.options.target !== ObfuscationTarget.Extension + ? this.getGlobalVariableTemplate() + : GlobalVariableNoEvalTemplate(); return format(DomainLockNodeTemplate(), { domainLockFunctionName: this.randomGenerator.getRandomVariableName(6), diff: diff, domains: hiddenDomainsString, + globalVariableTemplate, singleNodeCallControllerFunctionName: this.callsControllerFunctionName }); } diff --git a/src/custom-nodes/node-calls-controller-nodes/NodeCallsControllerFunctionNode.ts b/src/custom-nodes/node-calls-controller-nodes/NodeCallsControllerFunctionNode.ts index 5bbbe9b2..c03a118c 100644 --- a/src/custom-nodes/node-calls-controller-nodes/NodeCallsControllerFunctionNode.ts +++ b/src/custom-nodes/node-calls-controller-nodes/NodeCallsControllerFunctionNode.ts @@ -6,12 +6,13 @@ import * as format from 'string-template'; import { TStatement } from '../../types/node/TStatement'; import { IOptions } from '../../interfaces/options/IOptions'; +import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator'; import { ObfuscationEvent } from '../../enums/event-emitters/ObfuscationEvent'; import { initializable } from '../../decorators/Initializable'; -import { SingleNodeCallControllerTemplate } from '../../templates/custom-nodes/SingleNodeCallControllerTemplate'; +import { SingleNodeCallControllerTemplate } from '../../templates/SingleNodeCallControllerTemplate'; import { NO_CUSTOM_NODES_PRESET } from '../../options/presets/NoCustomNodes'; @@ -34,12 +35,14 @@ export class NodeCallsControllerFunctionNode extends AbstractCustomNode { private appendEvent: ObfuscationEvent; /** + * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ constructor ( + @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super(options); + super(randomGenerator, options); } /** diff --git a/src/custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode.ts b/src/custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode.ts index c1252028..aa40251a 100644 --- a/src/custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode.ts +++ b/src/custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode.ts @@ -13,7 +13,7 @@ import { initializable } from '../../decorators/Initializable'; import { NO_CUSTOM_NODES_PRESET } from '../../options/presets/NoCustomNodes'; -import { SelfDefendingTemplate } from '../../templates/custom-nodes/self-defending-nodes/self-defending-unicode-node/SelfDefendingTemplate'; +import { SelfDefendingTemplate } from '../../templates/self-defending-nodes/self-defending-unicode-node/SelfDefendingTemplate'; import { AbstractCustomNode } from '../AbstractCustomNode'; import { JavaScriptObfuscator } from '../../JavaScriptObfuscatorFacade'; @@ -32,11 +32,6 @@ export class SelfDefendingUnicodeNode extends AbstractCustomNode { @initializable() private callsControllerFunctionName: string; - /** - * @type {IRandomGenerator} - */ - private readonly randomGenerator: IRandomGenerator; - /** * @param {IRandomGenerator} randomGenerator * @param {IEscapeSequenceEncoder} escapeSequenceEncoder @@ -47,9 +42,8 @@ export class SelfDefendingUnicodeNode extends AbstractCustomNode { @inject(ServiceIdentifiers.IEscapeSequenceEncoder) escapeSequenceEncoder: IEscapeSequenceEncoder, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super(options); + super(randomGenerator, options); - this.randomGenerator = randomGenerator; this.escapeSequenceEncoder = escapeSequenceEncoder; } diff --git a/src/custom-nodes/string-array-nodes/StringArrayCallsWrapper.ts b/src/custom-nodes/string-array-nodes/StringArrayCallsWrapper.ts index 6712fe0e..e9d8071e 100644 --- a/src/custom-nodes/string-array-nodes/StringArrayCallsWrapper.ts +++ b/src/custom-nodes/string-array-nodes/StringArrayCallsWrapper.ts @@ -7,20 +7,23 @@ import { TStatement } from '../../types/node/TStatement'; import { IEscapeSequenceEncoder } from '../../interfaces/utils/IEscapeSequenceEncoder'; import { IOptions } from '../../interfaces/options/IOptions'; +import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator'; import { IStorage } from '../../interfaces/storages/IStorage'; +import { ObfuscationTarget } from '../../enums/ObfuscationTarget'; import { StringArrayEncoding } from '../../enums/StringArrayEncoding'; import { initializable } from '../../decorators/Initializable'; import { NO_CUSTOM_NODES_PRESET } from '../../options/presets/NoCustomNodes'; -import { AtobTemplate } from '../../templates/custom-nodes/AtobTemplate'; -import { Rc4Template } from '../../templates/custom-nodes/Rc4Template'; -import { SelfDefendingTemplate } from '../../templates/custom-nodes/string-array-nodes/string-array-calls-wrapper/SelfDefendingTemplate'; -import { StringArrayBase64DecodeNodeTemplate } from '../../templates/custom-nodes/string-array-nodes/string-array-calls-wrapper/StringArrayBase64DecodeNodeTemplate'; -import { StringArrayCallsWrapperTemplate } from '../../templates/custom-nodes/string-array-nodes/string-array-calls-wrapper/StringArrayCallsWrapperTemplate'; -import { StringArrayRc4DecodeNodeTemplate } from '../../templates/custom-nodes/string-array-nodes/string-array-calls-wrapper/StringArrayRC4DecodeNodeTemplate'; +import { AtobTemplate } from '../../templates/AtobTemplate'; +import { GlobalVariableNoEvalTemplate } from '../../templates/GlobalVariableNoEvalTemplate'; +import { Rc4Template } from '../../templates/Rc4Template'; +import { SelfDefendingTemplate } from '../../templates/string-array-nodes/string-array-calls-wrapper/SelfDefendingTemplate'; +import { StringArrayBase64DecodeNodeTemplate } from '../../templates/string-array-nodes/string-array-calls-wrapper/StringArrayBase64DecodeNodeTemplate'; +import { StringArrayCallsWrapperTemplate } from '../../templates/string-array-nodes/string-array-calls-wrapper/StringArrayCallsWrapperTemplate'; +import { StringArrayRc4DecodeNodeTemplate } from '../../templates/string-array-nodes/string-array-calls-wrapper/StringArrayRC4DecodeNodeTemplate'; import { AbstractCustomNode } from '../AbstractCustomNode'; import { JavaScriptObfuscator } from '../../JavaScriptObfuscatorFacade'; @@ -52,14 +55,16 @@ export class StringArrayCallsWrapper extends AbstractCustomNode { private stringArrayCallsWrapperName: string; /** + * @param {IRandomGenerator} randomGenerator * @param {IEscapeSequenceEncoder} escapeSequenceEncoder * @param {IOptions} options */ constructor ( + @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IEscapeSequenceEncoder) escapeSequenceEncoder: IEscapeSequenceEncoder, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super(options); + super(randomGenerator, options); this.escapeSequenceEncoder = escapeSequenceEncoder; } @@ -109,6 +114,11 @@ export class StringArrayCallsWrapper extends AbstractCustomNode { * @returns {string} */ private getDecodeStringArrayTemplate (): string { + const globalVariableTemplate: string = this.options.target !== ObfuscationTarget.Extension + ? this.getGlobalVariableTemplate() + : GlobalVariableNoEvalTemplate(); + const atobPolyfill: string = format(AtobTemplate(), { globalVariableTemplate }); + let decodeStringArrayTemplate: string = '', selfDefendingCode: string = ''; @@ -122,7 +132,7 @@ export class StringArrayCallsWrapper extends AbstractCustomNode { switch (this.options.stringArrayEncoding) { case StringArrayEncoding.Rc4: decodeStringArrayTemplate = format(StringArrayRc4DecodeNodeTemplate(), { - atobPolyfill: AtobTemplate(), + atobPolyfill, rc4Polyfill: Rc4Template(), selfDefendingCode, stringArrayCallsWrapperName: this.stringArrayCallsWrapperName @@ -132,7 +142,7 @@ export class StringArrayCallsWrapper extends AbstractCustomNode { case StringArrayEncoding.Base64: decodeStringArrayTemplate = format(StringArrayBase64DecodeNodeTemplate(), { - atobPolyfill: AtobTemplate(), + atobPolyfill, selfDefendingCode, stringArrayCallsWrapperName: this.stringArrayCallsWrapperName }); diff --git a/src/custom-nodes/string-array-nodes/StringArrayNode.ts b/src/custom-nodes/string-array-nodes/StringArrayNode.ts index 7a8ec8cc..33b1dd54 100644 --- a/src/custom-nodes/string-array-nodes/StringArrayNode.ts +++ b/src/custom-nodes/string-array-nodes/StringArrayNode.ts @@ -6,11 +6,12 @@ import * as format from 'string-template'; import { TStatement } from '../../types/node/TStatement'; import { IOptions } from '../../interfaces/options/IOptions'; +import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator'; import { IStorage } from '../../interfaces/storages/IStorage'; import { initializable } from '../../decorators/Initializable'; -import { StringArrayTemplate } from '../../templates/custom-nodes/string-array-nodes/string-array-node/StringArrayTemplate'; +import { StringArrayTemplate } from '../../templates/string-array-nodes/string-array-node/StringArrayTemplate'; import { AbstractCustomNode } from '../AbstractCustomNode'; import { NodeUtils } from '../../node/NodeUtils'; @@ -37,12 +38,14 @@ export class StringArrayNode extends AbstractCustomNode { private stringArrayRotateValue: number; /** + * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ constructor ( + @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super(options); + super(randomGenerator, options); } /** diff --git a/src/custom-nodes/string-array-nodes/StringArrayRotateFunctionNode.ts b/src/custom-nodes/string-array-nodes/StringArrayRotateFunctionNode.ts index dd9fbd15..22ded60b 100644 --- a/src/custom-nodes/string-array-nodes/StringArrayRotateFunctionNode.ts +++ b/src/custom-nodes/string-array-nodes/StringArrayRotateFunctionNode.ts @@ -14,8 +14,8 @@ import { initializable } from '../../decorators/Initializable'; import { NO_CUSTOM_NODES_PRESET } from '../../options/presets/NoCustomNodes'; -import { SelfDefendingTemplate } from '../../templates/custom-nodes/string-array-nodes/string-array-rotate-function-node/SelfDefendingTemplate'; -import { StringArrayRotateFunctionTemplate } from '../../templates/custom-nodes/string-array-nodes/string-array-rotate-function-node/StringArrayRotateFunctionTemplate'; +import { SelfDefendingTemplate } from '../../templates/string-array-nodes/string-array-rotate-function-node/SelfDefendingTemplate'; +import { StringArrayRotateFunctionTemplate } from '../../templates/string-array-nodes/string-array-rotate-function-node/StringArrayRotateFunctionTemplate'; import { AbstractCustomNode } from '../AbstractCustomNode'; import { JavaScriptObfuscator } from '../../JavaScriptObfuscatorFacade'; @@ -29,11 +29,6 @@ export class StringArrayRotateFunctionNode extends AbstractCustomNode { */ private readonly escapeSequenceEncoder: IEscapeSequenceEncoder; - /** - * @type {IRandomGenerator} - */ - private readonly randomGenerator: IRandomGenerator; - /** * @type {IStorage } */ @@ -62,9 +57,8 @@ export class StringArrayRotateFunctionNode extends AbstractCustomNode { @inject(ServiceIdentifiers.IEscapeSequenceEncoder) escapeSequenceEncoder: IEscapeSequenceEncoder, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { - super(options); + super(randomGenerator, options); - this.randomGenerator = randomGenerator; this.escapeSequenceEncoder = escapeSequenceEncoder; } diff --git a/src/enums/ObfuscationTarget.ts b/src/enums/ObfuscationTarget.ts new file mode 100644 index 00000000..dbd456e5 --- /dev/null +++ b/src/enums/ObfuscationTarget.ts @@ -0,0 +1,5 @@ +export enum ObfuscationTarget { + Browser = 'browser', + Extension = 'extension', + Node = 'node' +} diff --git a/src/interfaces/options/IOptions.d.ts b/src/interfaces/options/IOptions.d.ts index f4a5bef4..16ef665b 100644 --- a/src/interfaces/options/IOptions.d.ts +++ b/src/interfaces/options/IOptions.d.ts @@ -1,6 +1,8 @@ -import { TSourceMapMode } from '../../types/source-map/TSourceMapMode'; import { TStringArrayEncoding } from '../../types/options/TStringArrayEncoding'; +import { ObfuscationTarget } from '../../enums/ObfuscationTarget'; +import { SourceMapMode } from '../../enums/source-map/SourceMapMode'; + export interface IOptions { readonly compact: boolean; readonly controlFlowFlattening: boolean; @@ -21,9 +23,10 @@ export interface IOptions { readonly sourceMap: boolean; readonly sourceMapBaseUrl: string; readonly sourceMapFileName: string; - readonly sourceMapMode: TSourceMapMode; + readonly sourceMapMode: SourceMapMode; readonly stringArray: boolean; readonly stringArrayEncoding: TStringArrayEncoding; readonly stringArrayThreshold: number; + readonly target: ObfuscationTarget; readonly unicodeEscapeSequence: boolean; } diff --git a/src/options/Options.ts b/src/options/Options.ts index 4057abc2..9672f806 100644 --- a/src/options/Options.ts +++ b/src/options/Options.ts @@ -17,11 +17,13 @@ import { } from 'class-validator'; import { TInputOptions } from '../types/options/TInputOptions'; +import { TStringArrayEncoding } from '../types/options/TStringArrayEncoding'; import { IOptions } from '../interfaces/options/IOptions'; -import { TSourceMapMode } from '../types/source-map/TSourceMapMode'; -import { TStringArrayEncoding } from '../types/options/TStringArrayEncoding'; +import { ObfuscationTarget } from '../enums/ObfuscationTarget'; +import { SourceMapMode } from '../enums/source-map/SourceMapMode'; +import { StringArrayEncoding } from '../enums/StringArrayEncoding'; import { DEFAULT_PRESET } from './presets/Default'; @@ -169,10 +171,10 @@ export class Options implements IOptions { public readonly sourceMapFileName: string; /** - * @type {TSourceMapMode} + * @type {SourceMapMode} */ - @IsIn(['inline', 'separate']) - public readonly sourceMapMode: TSourceMapMode; + @IsIn([SourceMapMode.Inline, SourceMapMode.Separate]) + public readonly sourceMapMode: SourceMapMode; /** * @type {boolean} @@ -183,7 +185,7 @@ export class Options implements IOptions { /** * @type {TStringArrayEncoding} */ - @IsIn([true, false, 'base64', 'rc4']) + @IsIn([true, false, StringArrayEncoding.Base64, StringArrayEncoding.Rc4]) public readonly stringArrayEncoding: TStringArrayEncoding; /** @@ -194,6 +196,12 @@ export class Options implements IOptions { @Max(1) public readonly stringArrayThreshold: number; + /** + * @type {ObfuscationTarget} + */ + @IsIn([ObfuscationTarget.Browser, ObfuscationTarget.Extension, ObfuscationTarget.Node]) + public readonly target: ObfuscationTarget; + /** * @type {boolean} */ diff --git a/src/options/normalizer-rules/StringArrayEncodingRule.ts b/src/options/normalizer-rules/StringArrayEncodingRule.ts index bcc828a8..1e795d5a 100644 --- a/src/options/normalizer-rules/StringArrayEncodingRule.ts +++ b/src/options/normalizer-rules/StringArrayEncodingRule.ts @@ -2,6 +2,8 @@ import { TOptionsNormalizerRule } from '../../types/options/TOptionsNormalizerRu import { IOptions } from '../../interfaces/options/IOptions'; +import { StringArrayEncoding } from '../../enums/StringArrayEncoding'; + /** * @param {IOptions} options * @returns {IOptions} @@ -10,7 +12,7 @@ export const StringArrayEncodingRule: TOptionsNormalizerRule = (options: IOption if (options.stringArrayEncoding === true) { options = { ...options, - stringArrayEncoding: 'base64' + stringArrayEncoding: StringArrayEncoding.Base64 }; } diff --git a/src/options/presets/Default.ts b/src/options/presets/Default.ts index 0f82294d..d751bc49 100644 --- a/src/options/presets/Default.ts +++ b/src/options/presets/Default.ts @@ -1,5 +1,6 @@ import { TInputOptions } from '../../types/options/TInputOptions'; +import { ObfuscationTarget } from '../../enums/ObfuscationTarget'; import { SourceMapMode } from '../../enums/source-map/SourceMapMode'; export const DEFAULT_PRESET: TInputOptions = Object.freeze({ @@ -27,5 +28,6 @@ export const DEFAULT_PRESET: TInputOptions = Object.freeze({ stringArray: true, stringArrayEncoding: false, stringArrayThreshold: 0.75, + target: ObfuscationTarget.Browser, unicodeEscapeSequence: false }); diff --git a/src/options/presets/NoCustomNodes.ts b/src/options/presets/NoCustomNodes.ts index e6d7f9b3..16de718c 100644 --- a/src/options/presets/NoCustomNodes.ts +++ b/src/options/presets/NoCustomNodes.ts @@ -1,5 +1,6 @@ import { TInputOptions } from '../../types/options/TInputOptions'; +import { ObfuscationTarget } from '../../enums/ObfuscationTarget'; import { SourceMapMode } from '../../enums/source-map/SourceMapMode'; export const NO_CUSTOM_NODES_PRESET: TInputOptions = Object.freeze({ @@ -26,5 +27,6 @@ export const NO_CUSTOM_NODES_PRESET: TInputOptions = Object.freeze({ stringArray: false, stringArrayEncoding: false, stringArrayThreshold: 0, + target: ObfuscationTarget.Browser, unicodeEscapeSequence: false }); diff --git a/src/templates/custom-nodes/AtobTemplate.ts b/src/templates/AtobTemplate.ts similarity index 67% rename from src/templates/custom-nodes/AtobTemplate.ts rename to src/templates/AtobTemplate.ts index 1a8641b8..b335b2c0 100644 --- a/src/templates/custom-nodes/AtobTemplate.ts +++ b/src/templates/AtobTemplate.ts @@ -4,20 +4,12 @@ export function AtobTemplate (): string { return ` (function () { - var object; - - try { - var getGlobal = Function('return (function() ' + '{}.constructor("return this")( )' + ');'); - - object = getGlobal(); - } catch (e) { - object = window; - } + {globalVariableTemplate} var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; - object.atob || ( - object.atob = function(input) { + that.atob || ( + that.atob = function(input) { var str = String(input).replace(/=+$/, ''); for ( var bc = 0, bs, buffer, idx = 0, output = ''; diff --git a/src/templates/GlobalVariableNoEvalTemplate.ts b/src/templates/GlobalVariableNoEvalTemplate.ts new file mode 100644 index 00000000..ded7e2d0 --- /dev/null +++ b/src/templates/GlobalVariableNoEvalTemplate.ts @@ -0,0 +1,14 @@ +/** + * @returns {string} + */ +export function GlobalVariableNoEvalTemplate (): string { + return ` + var that = (typeof window !== 'undefined' + ? window + : (typeof process === 'object' && + typeof require === 'function' && + typeof global === 'object') + ? global + : this); + `; +} diff --git a/src/templates/GlobalVariableTemplate1.ts b/src/templates/GlobalVariableTemplate1.ts new file mode 100644 index 00000000..377fa1db --- /dev/null +++ b/src/templates/GlobalVariableTemplate1.ts @@ -0,0 +1,16 @@ +/** + * @returns {string} + */ +export function GlobalVariableTemplate1 (): string { + return ` + var that; + + try { + var getGlobal = Function('return (function() ' + '{}.constructor("return this")( )' + ');'); + + that = getGlobal(); + } catch (e) { + that = window; + } + `; +} diff --git a/src/templates/GlobalVariableTemplate2.ts b/src/templates/GlobalVariableTemplate2.ts new file mode 100644 index 00000000..a4733e3f --- /dev/null +++ b/src/templates/GlobalVariableTemplate2.ts @@ -0,0 +1,19 @@ +/** + * @returns {string} + */ +export function GlobalVariableTemplate2 (): string { + return ` + var getGlobal = function () { + var globalObject; + + try { + globalObject = Function('return (function() ' + '{}.constructor("return this")( )' + ');')(); + } catch (e) { + globalObject = window; + } + + return globalObject; + }; + var that = getGlobal(); + `; +} diff --git a/src/templates/custom-nodes/Rc4Template.ts b/src/templates/Rc4Template.ts similarity index 100% rename from src/templates/custom-nodes/Rc4Template.ts rename to src/templates/Rc4Template.ts diff --git a/src/templates/custom-nodes/SingleNodeCallControllerTemplate.ts b/src/templates/SingleNodeCallControllerTemplate.ts similarity index 100% rename from src/templates/custom-nodes/SingleNodeCallControllerTemplate.ts rename to src/templates/SingleNodeCallControllerTemplate.ts diff --git a/src/templates/custom-nodes/console-output-nodes/console-output-disable-expression-node/ConsoleOutputDisableExpressionTemplate.ts b/src/templates/console-output-nodes/console-output-disable-expression-node/ConsoleOutputDisableExpressionTemplate.ts similarity index 81% rename from src/templates/custom-nodes/console-output-nodes/console-output-disable-expression-node/ConsoleOutputDisableExpressionTemplate.ts rename to src/templates/console-output-nodes/console-output-disable-expression-node/ConsoleOutputDisableExpressionTemplate.ts index 7cf46163..126e0b37 100644 --- a/src/templates/custom-nodes/console-output-nodes/console-output-disable-expression-node/ConsoleOutputDisableExpressionTemplate.ts +++ b/src/templates/console-output-nodes/console-output-disable-expression-node/ConsoleOutputDisableExpressionTemplate.ts @@ -5,15 +5,8 @@ export function ConsoleOutputDisableExpressionTemplate (): string { return ` var {consoleLogDisableFunctionName} = {singleNodeCallControllerFunctionName}(this, function () { var func = function () {}; - var that; - try { - var getGlobal = Function('return (function() ' + '{}.constructor("return this")( )' + ');'); - - that = getGlobal(); - } catch (e) { - that = window; - } + {globalVariableTemplate} if (!that.console) { that.console = (function (func){ diff --git a/src/templates/custom-nodes/debug-protection-nodes/debug-protection-function-node/DebugProtectionFunctionTemplate.ts b/src/templates/custom-nodes/debug-protection-nodes/debug-protection-function-node/DebugProtectionFunctionTemplate.ts deleted file mode 100644 index 4aeafc76..00000000 --- a/src/templates/custom-nodes/debug-protection-nodes/debug-protection-function-node/DebugProtectionFunctionTemplate.ts +++ /dev/null @@ -1,31 +0,0 @@ -/** - * @returns {string} - */ -export function DebugProtectionFunctionTemplate (): string { - return ` - function {debugProtectionFunctionName} (ret) { - function debuggerProtection (counter) { - if (typeof counter === 'string') { - return (function (arg) {}.constructor('while (true) {}').apply('counter')); - } else { - if (('' + counter / counter)['length'] !== 1 || counter % 20 === 0) { - (function () {return true;}.constructor('debu' + 'gger').call('action')); - } else { - (function () {return false;}.constructor('debu' + 'gger').apply('stateObject')); - } - - } - - debuggerProtection(++counter); - } - - try { - if (ret) { - return debuggerProtection; - } else { - debuggerProtection(0); - } - } catch (y) {} - } - `; -} diff --git a/src/templates/custom-nodes/debug-protection-nodes/debug-protection-function-call-node/DebufProtectionFunctionCallTemplate.ts b/src/templates/debug-protection-nodes/debug-protection-function-call-node/DebufProtectionFunctionCallTemplate.ts similarity index 100% rename from src/templates/custom-nodes/debug-protection-nodes/debug-protection-function-call-node/DebufProtectionFunctionCallTemplate.ts rename to src/templates/debug-protection-nodes/debug-protection-function-call-node/DebufProtectionFunctionCallTemplate.ts diff --git a/src/templates/custom-nodes/debug-protection-nodes/debug-protection-function-interval-node/DebugProtectionFunctionIntervalTemplate.ts b/src/templates/debug-protection-nodes/debug-protection-function-interval-node/DebugProtectionFunctionIntervalTemplate.ts similarity index 100% rename from src/templates/custom-nodes/debug-protection-nodes/debug-protection-function-interval-node/DebugProtectionFunctionIntervalTemplate.ts rename to src/templates/debug-protection-nodes/debug-protection-function-interval-node/DebugProtectionFunctionIntervalTemplate.ts diff --git a/src/templates/debug-protection-nodes/debug-protection-function-node/DebugProtectionFunctionTemplate.ts b/src/templates/debug-protection-nodes/debug-protection-function-node/DebugProtectionFunctionTemplate.ts new file mode 100644 index 00000000..d59d445d --- /dev/null +++ b/src/templates/debug-protection-nodes/debug-protection-function-node/DebugProtectionFunctionTemplate.ts @@ -0,0 +1,23 @@ +/** + * @returns {string} + */ +export function DebugProtectionFunctionTemplate (): string { + return ` + function {debugProtectionFunctionName} (ret) { + function debuggerProtection (counter) { + + {debuggerTemplate} + + debuggerProtection(++counter); + } + + try { + if (ret) { + return debuggerProtection; + } else { + debuggerProtection(0); + } + } catch (y) {} + } + `; +} diff --git a/src/templates/debug-protection-nodes/debug-protection-function-node/DebuggerTemplate.ts b/src/templates/debug-protection-nodes/debug-protection-function-node/DebuggerTemplate.ts new file mode 100644 index 00000000..7f152083 --- /dev/null +++ b/src/templates/debug-protection-nodes/debug-protection-function-node/DebuggerTemplate.ts @@ -0,0 +1,17 @@ +/** + * @returns {string} + */ +export function DebuggerTemplate (): string { + return ` + if (typeof counter === 'string') { + return (function (arg) {}.constructor('while (true) {}').apply('counter')); + } else { + if (('' + counter / counter)['length'] !== 1 || counter % 20 === 0) { + (function () {return true;}.constructor('debu' + 'gger').call('action')); + } else { + (function () {return false;}.constructor('debu' + 'gger').apply('stateObject')); + } + + } + `; +} diff --git a/src/templates/debug-protection-nodes/debug-protection-function-node/DebuggerTemplateNoEval.ts b/src/templates/debug-protection-nodes/debug-protection-function-node/DebuggerTemplateNoEval.ts new file mode 100644 index 00000000..6aeb7ab7 --- /dev/null +++ b/src/templates/debug-protection-nodes/debug-protection-function-node/DebuggerTemplateNoEval.ts @@ -0,0 +1,21 @@ +/** + * @returns {string} + */ +export function DebuggerTemplateNoEval (): string { + return ` + if (typeof counter === 'string') { + var func = function () { + while (true) {} + }; + + return func(); + } else { + if (('' + counter / counter)['length'] !== 1 || counter % 20 === 0) { + debugger; + } else { + debugger; + } + + } + `; +} diff --git a/src/templates/custom-nodes/domain-lock-nodes/domain-lock-node/DomainLockNodeTemplate.ts b/src/templates/domain-lock-nodes/domain-lock-node/DomainLockNodeTemplate.ts similarity index 86% rename from src/templates/custom-nodes/domain-lock-nodes/domain-lock-node/DomainLockNodeTemplate.ts rename to src/templates/domain-lock-nodes/domain-lock-node/DomainLockNodeTemplate.ts index fed42841..4827fed3 100644 --- a/src/templates/custom-nodes/domain-lock-nodes/domain-lock-node/DomainLockNodeTemplate.ts +++ b/src/templates/domain-lock-nodes/domain-lock-node/DomainLockNodeTemplate.ts @@ -4,18 +4,9 @@ export function DomainLockNodeTemplate (): string { return ` var {domainLockFunctionName} = {singleNodeCallControllerFunctionName}(this, function () { - var getGlobal = function () { - var globalObject; - try { - globalObject = Function('return (function() ' + '{}.constructor("return this")( )' + ');')(); - } catch (e) { - globalObject = window; - } - - return globalObject; - }; - var that = getGlobal(); + {globalVariableTemplate} + var func = function () { return { key: 'item', diff --git a/src/templates/custom-nodes/self-defending-nodes/self-defending-unicode-node/SelfDefendingTemplate.ts b/src/templates/self-defending-nodes/self-defending-unicode-node/SelfDefendingTemplate.ts similarity index 95% rename from src/templates/custom-nodes/self-defending-nodes/self-defending-unicode-node/SelfDefendingTemplate.ts rename to src/templates/self-defending-nodes/self-defending-unicode-node/SelfDefendingTemplate.ts index 79d15ba6..015c029f 100644 --- a/src/templates/custom-nodes/self-defending-nodes/self-defending-unicode-node/SelfDefendingTemplate.ts +++ b/src/templates/self-defending-nodes/self-defending-unicode-node/SelfDefendingTemplate.ts @@ -1,4 +1,4 @@ -import { IEscapeSequenceEncoder } from '../../../../interfaces/utils/IEscapeSequenceEncoder'; +import { IEscapeSequenceEncoder } from '../../../interfaces/utils/IEscapeSequenceEncoder'; /** * 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/string-array-nodes/string-array-calls-wrapper/SelfDefendingTemplate.ts similarity index 94% rename from src/templates/custom-nodes/string-array-nodes/string-array-calls-wrapper/SelfDefendingTemplate.ts rename to src/templates/string-array-nodes/string-array-calls-wrapper/SelfDefendingTemplate.ts index b558d5fd..f3634c99 100644 --- a/src/templates/custom-nodes/string-array-nodes/string-array-calls-wrapper/SelfDefendingTemplate.ts +++ b/src/templates/string-array-nodes/string-array-calls-wrapper/SelfDefendingTemplate.ts @@ -1,4 +1,4 @@ -import { IEscapeSequenceEncoder } from '../../../../interfaces/utils/IEscapeSequenceEncoder'; +import { IEscapeSequenceEncoder } from '../../../interfaces/utils/IEscapeSequenceEncoder'; /** * @param {IEscapeSequenceEncoder} escapeSequenceEncoder diff --git a/src/templates/custom-nodes/string-array-nodes/string-array-calls-wrapper/StringArrayBase64DecodeNodeTemplate.ts b/src/templates/string-array-nodes/string-array-calls-wrapper/StringArrayBase64DecodeNodeTemplate.ts similarity index 100% rename from src/templates/custom-nodes/string-array-nodes/string-array-calls-wrapper/StringArrayBase64DecodeNodeTemplate.ts rename to src/templates/string-array-nodes/string-array-calls-wrapper/StringArrayBase64DecodeNodeTemplate.ts diff --git a/src/templates/custom-nodes/string-array-nodes/string-array-calls-wrapper/StringArrayCallsWrapperTemplate.ts b/src/templates/string-array-nodes/string-array-calls-wrapper/StringArrayCallsWrapperTemplate.ts similarity index 100% rename from src/templates/custom-nodes/string-array-nodes/string-array-calls-wrapper/StringArrayCallsWrapperTemplate.ts rename to src/templates/string-array-nodes/string-array-calls-wrapper/StringArrayCallsWrapperTemplate.ts diff --git a/src/templates/custom-nodes/string-array-nodes/string-array-calls-wrapper/StringArrayRC4DecodeNodeTemplate.ts b/src/templates/string-array-nodes/string-array-calls-wrapper/StringArrayRC4DecodeNodeTemplate.ts similarity index 100% rename from src/templates/custom-nodes/string-array-nodes/string-array-calls-wrapper/StringArrayRC4DecodeNodeTemplate.ts rename to src/templates/string-array-nodes/string-array-calls-wrapper/StringArrayRC4DecodeNodeTemplate.ts diff --git a/src/templates/custom-nodes/string-array-nodes/string-array-node/StringArrayTemplate.ts b/src/templates/string-array-nodes/string-array-node/StringArrayTemplate.ts similarity index 100% rename from src/templates/custom-nodes/string-array-nodes/string-array-node/StringArrayTemplate.ts rename to src/templates/string-array-nodes/string-array-node/StringArrayTemplate.ts diff --git a/src/templates/custom-nodes/string-array-nodes/string-array-rotate-function-node/SelfDefendingTemplate.ts b/src/templates/string-array-nodes/string-array-rotate-function-node/SelfDefendingTemplate.ts similarity index 97% rename from src/templates/custom-nodes/string-array-nodes/string-array-rotate-function-node/SelfDefendingTemplate.ts rename to src/templates/string-array-nodes/string-array-rotate-function-node/SelfDefendingTemplate.ts index 388b0ca6..b0dce18f 100644 --- a/src/templates/custom-nodes/string-array-nodes/string-array-rotate-function-node/SelfDefendingTemplate.ts +++ b/src/templates/string-array-nodes/string-array-rotate-function-node/SelfDefendingTemplate.ts @@ -1,4 +1,4 @@ -import { IEscapeSequenceEncoder } from '../../../../interfaces/utils/IEscapeSequenceEncoder'; +import { IEscapeSequenceEncoder } from '../../../interfaces/utils/IEscapeSequenceEncoder'; /** * SelfDefendingTemplate. Enter code in infinity loop. diff --git a/src/templates/custom-nodes/string-array-nodes/string-array-rotate-function-node/StringArrayRotateFunctionTemplate.ts b/src/templates/string-array-nodes/string-array-rotate-function-node/StringArrayRotateFunctionTemplate.ts similarity index 100% rename from src/templates/custom-nodes/string-array-nodes/string-array-rotate-function-node/StringArrayRotateFunctionTemplate.ts rename to src/templates/string-array-nodes/string-array-rotate-function-node/StringArrayRotateFunctionTemplate.ts diff --git a/src/types/options/TStringArrayEncoding.d.ts b/src/types/options/TStringArrayEncoding.d.ts index 88bc8c96..f477fa1c 100644 --- a/src/types/options/TStringArrayEncoding.d.ts +++ b/src/types/options/TStringArrayEncoding.d.ts @@ -1 +1,3 @@ -export type TStringArrayEncoding = boolean | 'base64' | 'rc4'; +import { StringArrayEncoding } from '../../enums/StringArrayEncoding'; + +export type TStringArrayEncoding = boolean | StringArrayEncoding; diff --git a/test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts b/test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts index f507bc51..6bde6aac 100644 --- a/test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts +++ b/test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts @@ -2,6 +2,9 @@ import { assert } from 'chai'; import { IObfuscationResult } from '../../../src/interfaces/IObfuscationResult'; +import { SourceMapMode } from '../../../src/enums/source-map/SourceMapMode'; +import { StringArrayEncoding } from '../../../src/enums/StringArrayEncoding'; + import { JavaScriptObfuscator } from '../../../src/JavaScriptObfuscatorFacade'; import { NO_CUSTOM_NODES_PRESET } from '../../../src/options/presets/NoCustomNodes'; @@ -113,7 +116,7 @@ describe('JavaScriptObfuscator', () => { { ...NO_CUSTOM_NODES_PRESET, sourceMap: true, - sourceMapMode: 'inline' + sourceMapMode: SourceMapMode.Inline } ); @@ -483,7 +486,7 @@ describe('JavaScriptObfuscator', () => { disableConsoleOutput: false, rotateStringArray: true, stringArray: true, - stringArrayEncoding: 'rc4', + stringArrayEncoding: StringArrayEncoding.Rc4, stringArrayThreshold: 1, unicodeEscapeSequence: false } diff --git a/test/functional-tests/node-transformers/obfuscating-transformers/literal-transformer/LiteralTransformer.spec.ts b/test/functional-tests/node-transformers/obfuscating-transformers/literal-transformer/LiteralTransformer.spec.ts index 7531525e..482d8e4a 100644 --- a/test/functional-tests/node-transformers/obfuscating-transformers/literal-transformer/LiteralTransformer.spec.ts +++ b/test/functional-tests/node-transformers/obfuscating-transformers/literal-transformer/LiteralTransformer.spec.ts @@ -2,6 +2,8 @@ import { assert } from 'chai'; import { IObfuscationResult } from '../../../../../src/interfaces/IObfuscationResult'; +import { StringArrayEncoding } from '../../../../../src/enums/StringArrayEncoding'; + import { NO_CUSTOM_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes'; import { readFileAsString } from '../../../../helpers/readFileAsString'; @@ -202,7 +204,7 @@ describe('LiteralTransformer', () => { { ...NO_CUSTOM_NODES_PRESET, stringArray: true, - stringArrayEncoding: 'base64', + stringArrayEncoding: StringArrayEncoding.Base64, stringArrayThreshold: 1 } ); @@ -231,7 +233,7 @@ describe('LiteralTransformer', () => { { ...NO_CUSTOM_NODES_PRESET, stringArray: true, - stringArrayEncoding: 'rc4', + stringArrayEncoding: StringArrayEncoding.Rc4, stringArrayThreshold: 1 } ); 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 358612e6..47ccbc32 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 @@ -7,7 +7,8 @@ import { ServiceIdentifiers } from '../../../../../src/container/ServiceIdentifi import { ICryptUtils } from '../../../../../src/interfaces/utils/ICryptUtils'; import { IInversifyContainerFacade } from '../../../../../src/interfaces/container/IInversifyContainerFacade'; -import { DomainLockNodeTemplate } from '../../../../../src/templates/custom-nodes/domain-lock-nodes/domain-lock-node/DomainLockNodeTemplate'; +import { DomainLockNodeTemplate } from '../../../../../src/templates/domain-lock-nodes/domain-lock-node/DomainLockNodeTemplate'; +import { GlobalVariableTemplate1 } from '../../../../../src/templates/GlobalVariableTemplate1'; import { InversifyContainerFacade } from '../../../../../src/container/InversifyContainerFacade'; @@ -65,6 +66,7 @@ describe('DomainLockNodeTemplate (): string', () => { domainLockFunctionName: 'domainLockFunction', diff: diff, domains: hiddenDomainsString, + globalVariableTemplate: GlobalVariableTemplate1(), singleNodeCallControllerFunctionName }, singleNodeCallControllerFunctionName, currentDomain); }); @@ -90,6 +92,7 @@ describe('DomainLockNodeTemplate (): string', () => { domainLockFunctionName: 'domainLockFunction', diff: diff, domains: hiddenDomainsString, + globalVariableTemplate: GlobalVariableTemplate1(), singleNodeCallControllerFunctionName }, singleNodeCallControllerFunctionName, currentDomain); }); @@ -115,6 +118,7 @@ describe('DomainLockNodeTemplate (): string', () => { domainLockFunctionName: 'domainLockFunction', diff: diff, domains: hiddenDomainsString, + globalVariableTemplate: GlobalVariableTemplate1(), singleNodeCallControllerFunctionName }, singleNodeCallControllerFunctionName, currentDomain); }); 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 7bb12e8d..477d65d7 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 @@ -7,11 +7,12 @@ import { ServiceIdentifiers } from '../../../../../src/container/ServiceIdentifi import { ICryptUtils } from '../../../../../src/interfaces/utils/ICryptUtils'; import { IInversifyContainerFacade } from '../../../../../src/interfaces/container/IInversifyContainerFacade'; -import { AtobTemplate } from '../../../../../src/templates/custom-nodes/AtobTemplate'; -import { Rc4Template } from '../../../../../src/templates/custom-nodes/Rc4Template'; -import { StringArrayBase64DecodeNodeTemplate } from '../../../../../src/templates/custom-nodes/string-array-nodes/string-array-calls-wrapper/StringArrayBase64DecodeNodeTemplate'; -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 { AtobTemplate } from '../../../../../src/templates/AtobTemplate'; +import { GlobalVariableTemplate1 } from '../../../../../src/templates/GlobalVariableTemplate1'; +import { Rc4Template } from '../../../../../src/templates/Rc4Template'; +import { StringArrayBase64DecodeNodeTemplate } from '../../../../../src/templates/string-array-nodes/string-array-calls-wrapper/StringArrayBase64DecodeNodeTemplate'; +import { StringArrayCallsWrapperTemplate } from '../../../../../src/templates/string-array-nodes/string-array-calls-wrapper/StringArrayCallsWrapperTemplate'; +import { StringArrayRc4DecodeNodeTemplate } from '../../../../../src/templates/string-array-nodes/string-array-calls-wrapper/StringArrayRC4DecodeNodeTemplate'; import { InversifyContainerFacade } from '../../../../../src/container/InversifyContainerFacade'; @@ -29,8 +30,11 @@ describe('StringArrayCallsWrapperNodeTemplate (): string', () => { }); describe('variant #1: `base64` encoding', () => { + const atobPolyfill = format(AtobTemplate(), { + globalVariableTemplate: GlobalVariableTemplate1() + }); const atobDecodeNodeTemplate: string = format(StringArrayBase64DecodeNodeTemplate(), { - atobPolyfill: AtobTemplate(), + atobPolyfill, selfDefendingCode: '', stringArrayCallsWrapperName }); @@ -61,8 +65,11 @@ describe('StringArrayCallsWrapperNodeTemplate (): string', () => { }); describe('variant #2: `rc4` encoding', () => { + const atobPolyfill = format(AtobTemplate(), { + globalVariableTemplate: GlobalVariableTemplate1() + }); const rc4DecodeNodeTemplate: string = format(StringArrayRc4DecodeNodeTemplate(), { - atobPolyfill: AtobTemplate(), + atobPolyfill, rc4Polyfill: Rc4Template(), selfDefendingCode: '', stringArrayCallsWrapperName diff --git a/test/index.spec.ts b/test/index.spec.ts index 2d7275ee..5372d2bb 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -8,6 +8,7 @@ require('source-map-support').install(); import './unit-tests/analyzers/stack-trace-analyzer/StackTraceAnalyzer.spec'; import './unit-tests/cli/sanitizers/ArraySanitizer.spec'; import './unit-tests/cli/sanitizers/BooleanSanitizer.spec'; +import './unit-tests/cli/sanitizers/ObfuscationTargetSanitizer.spec'; import './unit-tests/cli/sanitizers/SourceMapModeSanitizer.spec'; import './unit-tests/cli/sanitizers/StringArrayEncodingSanitizer.spec'; import './unit-tests/cli/utils/CLIUtils.spec'; diff --git a/test/runtime-tests/JavaScriptObfuscatorRuntime.spec.ts b/test/runtime-tests/JavaScriptObfuscatorRuntime.spec.ts index 2165aa5c..edba94e7 100644 --- a/test/runtime-tests/JavaScriptObfuscatorRuntime.spec.ts +++ b/test/runtime-tests/JavaScriptObfuscatorRuntime.spec.ts @@ -2,6 +2,8 @@ import { assert } from 'chai'; import { IObfuscationResult } from '../../src/interfaces/IObfuscationResult'; +import { StringArrayEncoding } from '../../src/enums/StringArrayEncoding'; + import { readFileAsString } from '../helpers/readFileAsString'; import { JavaScriptObfuscator } from '../../src/JavaScriptObfuscatorFacade'; @@ -20,7 +22,7 @@ describe('JavaScriptObfuscator runtime eval', function () { deadCodeInjection: true, debugProtection: true, selfDefending: true, - stringArrayEncoding: 'rc4' + stringArrayEncoding: StringArrayEncoding.Rc4 } ); diff --git a/test/unit-tests/cli/sanitizers/ObfuscationTargetSanitizer.spec.ts b/test/unit-tests/cli/sanitizers/ObfuscationTargetSanitizer.spec.ts new file mode 100644 index 00000000..331d590b --- /dev/null +++ b/test/unit-tests/cli/sanitizers/ObfuscationTargetSanitizer.spec.ts @@ -0,0 +1,36 @@ +import { assert } from 'chai'; + +import { ObfuscationTargetSanitizer } from '../../../../src/cli/sanitizers/ObfuscatingTargetSanitizer'; + +describe('ObfuscationTargetSanitizer', () => { + describe('ObfuscationTargetSanitizer: TCLISanitizer = (value: string): string', () => { + describe('variant #1: valid obfuscation target', () => { + const inputValue: string = 'browser'; + const expectedValue: string = inputValue; + + let value: string; + + before(() => { + value = ObfuscationTargetSanitizer(inputValue); + }); + + it('should sanitize value', () => { + assert.equal(value, expectedValue); + }); + }); + + describe('variant #2: invalid obfuscation target', () => { + const inputValue: string = 'foo'; + + let testFunc: () => void; + + before(() => { + testFunc = () => ObfuscationTargetSanitizer(inputValue); + }); + + it('should throw error', () => { + assert.throw(testFunc, ReferenceError); + }); + }); + }); +}); diff --git a/test/unit-tests/options/OptionsNormalizer.spec.ts b/test/unit-tests/options/OptionsNormalizer.spec.ts index 830f5aa4..a6332d79 100644 --- a/test/unit-tests/options/OptionsNormalizer.spec.ts +++ b/test/unit-tests/options/OptionsNormalizer.spec.ts @@ -4,6 +4,8 @@ import { TInputOptions } from '../../../src/types/options/TInputOptions'; import { IOptions } from '../../../src/interfaces/options/IOptions'; +import { StringArrayEncoding } from '../../../src/enums/StringArrayEncoding'; + import { DEFAULT_PRESET } from '../../../src/options/presets/Default'; import { Options } from '../../../src/options/Options'; @@ -247,7 +249,7 @@ describe('OptionsNormalizer', () => { optionsPreset = getNormalizedOptions({ ...DEFAULT_PRESET, stringArray: false, - stringArrayEncoding: 'rc4', + stringArrayEncoding: StringArrayEncoding.Rc4, stringArrayThreshold: 0.5, rotateStringArray: true }); @@ -275,7 +277,7 @@ describe('OptionsNormalizer', () => { expectedOptionsPreset = { ...DEFAULT_PRESET, - stringArrayEncoding: 'base64' + stringArrayEncoding: StringArrayEncoding.Base64 }; }); diff --git a/test/unit-tests/source-map/SourceMapCorrector.spec.ts b/test/unit-tests/source-map/SourceMapCorrector.spec.ts index f1d6489c..dc796b0b 100644 --- a/test/unit-tests/source-map/SourceMapCorrector.spec.ts +++ b/test/unit-tests/source-map/SourceMapCorrector.spec.ts @@ -2,8 +2,6 @@ import { ServiceIdentifiers } from '../../../src/container/ServiceIdentifiers'; import { assert } from 'chai'; -import { TSourceMapMode } from '../../../src/types/source-map/TSourceMapMode'; - import { IInversifyContainerFacade } from '../../../src/interfaces/container/IInversifyContainerFacade'; import { IObfuscationResult } from '../../../src/interfaces/IObfuscationResult'; import { ISourceMapCorrector } from '../../../src/interfaces/source-map/ISourceMapCorrector'; @@ -24,7 +22,7 @@ function getCorrectedObfuscationResult ( sourceMap: string, sourceMapBaseUrl: string, sourceMapFileName: string, - sourceMapMode: TSourceMapMode + sourceMapMode: SourceMapMode ): IObfuscationResult { const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();