From f85757701b6d533bbf8f8d74dd1e34e84f10717c Mon Sep 17 00:00:00 2001 From: sanex3339 Date: Sat, 4 Jun 2016 16:33:27 +0300 Subject: [PATCH] selfDefending test implementation --- .../SelfDefendingUnicodeNode.js | 2 +- .../UnicodeArrayRotateFunctionNode.js | 41 +++++++++++----- .../SelfDefendingUnicodeNode.ts | 2 +- .../UnicodeArrayRotateFunctionNode.ts | 47 ++++++++++++++----- 4 files changed, 67 insertions(+), 25 deletions(-) diff --git a/dist/src/custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode.js b/dist/src/custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode.js index 40d9469f..2a61c271 100644 --- a/dist/src/custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode.js +++ b/dist/src/custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode.js @@ -29,7 +29,7 @@ class SelfDefendingUnicodeNode extends Node_1.Node { if ( !/(\\\\\[x|u](\\w){2,4})+/.test(func.toString()) ) { - console.log('LOL'); + []["filter"]["constructor"]((+(32))["toString"](33) + (+(101))["toString"](21)[1] + ([false]+undefined)[10] + (false+"")[2] + (true+"")[3] + '(!![]){}')(); } })(); `, NoCustomNodesPreset_1.NO_CUSTOM_NODES_PRESET)); diff --git a/dist/src/custom-nodes/unicode-array-nodes/UnicodeArrayRotateFunctionNode.js b/dist/src/custom-nodes/unicode-array-nodes/UnicodeArrayRotateFunctionNode.js index 85fd6e7e..c934bf74 100644 --- a/dist/src/custom-nodes/unicode-array-nodes/UnicodeArrayRotateFunctionNode.js +++ b/dist/src/custom-nodes/unicode-array-nodes/UnicodeArrayRotateFunctionNode.js @@ -1,6 +1,8 @@ "use strict"; const esprima = require('esprima'); const AppendState_1 = require("../../enums/AppendState"); +const NoCustomNodesPreset_1 = require("../../preset-options/NoCustomNodesPreset"); +const JavaScriptObfuscator_1 = require("../../JavaScriptObfuscator"); const Node_1 = require('../Node'); const NodeUtils_1 = require("../../NodeUtils"); const Utils_1 = require("../../Utils"); @@ -23,20 +25,37 @@ class UnicodeArrayRotateFunctionNode extends Node_1.Node { return super.getNode(); } getNodeStructure() { - let arrayName = Utils_1.Utils.getRandomVariableName(), timesName = Utils_1.Utils.getRandomVariableName(), tempArrayName = Utils_1.Utils.getRandomVariableName(), node = esprima.parse(` - (function (${arrayName}, ${timesName}) { - if (${timesName} < 0x${Utils_1.Utils.decToHex(0)}) { - return; + let arrayName = Utils_1.Utils.getRandomVariableName(), code = '', timesName = Utils_1.Utils.getRandomVariableName(), tempArrayName = Utils_1.Utils.getRandomVariableName(), node; + if (this.options['selfDefending']) { + code = JavaScriptObfuscator_1.JavaScriptObfuscator.obfuscate(` + (function () { + var func = function () { + return '\x77\x69\x6e\x64\x6f\x77'; + }; + + if ( + !/(\\\\\[x|u](\\w){2,4})+/.test(func.toString()) + ) { + []["filter"]["constructor"]((+(32))["toString"](33) + (+(101))["toString"](21)[1] + ([false]+undefined)[10] + (false+"")[2] + (true+"")[3] + '(!![]){}')(); } + })(); + `, NoCustomNodesPreset_1.NO_CUSTOM_NODES_PRESET); + } + node = esprima.parse(` + (function (${arrayName}, ${timesName}) { + if (${timesName} < 0x${Utils_1.Utils.decToHex(0)}) { + return; + } - var ${tempArrayName}; + var ${tempArrayName}; - while (${timesName}--) { - ${tempArrayName} = ${arrayName}[${Utils_1.Utils.stringToUnicode('shift')}](); - ${arrayName}[${Utils_1.Utils.stringToUnicode('push')}](${tempArrayName}); - } - })(${this.unicodeArrayName}, 0x${Utils_1.Utils.decToHex(this.unicodeArrayRotateValue)}); - `); + while (${timesName}--) { + ${code} + ${tempArrayName} = ${arrayName}[${Utils_1.Utils.stringToUnicode('shift')}](); + ${arrayName}[${Utils_1.Utils.stringToUnicode('push')}](${tempArrayName}); + } + })(${this.unicodeArrayName}, 0x${Utils_1.Utils.decToHex(this.unicodeArrayRotateValue)}); + `); NodeUtils_1.NodeUtils.addXVerbatimPropertyToLiterals(node); return NodeUtils_1.NodeUtils.getBlockScopeNodeByIndex(node); } diff --git a/src/custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode.ts b/src/custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode.ts index 0d7aa929..bc5526b7 100644 --- a/src/custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode.ts +++ b/src/custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode.ts @@ -57,7 +57,7 @@ export class SelfDefendingUnicodeNode extends Node { if ( !/(\\\\\[x|u](\\w){2,4})+/.test(func.toString()) ) { - console.log('LOL'); + []["filter"]["constructor"]((+(32))["toString"](33) + (+(101))["toString"](21)[1] + ([false]+undefined)[10] + (false+"")[2] + (true+"")[3] + '(!![]){}')(); } })(); `, NO_CUSTOM_NODES_PRESET) diff --git a/src/custom-nodes/unicode-array-nodes/UnicodeArrayRotateFunctionNode.ts b/src/custom-nodes/unicode-array-nodes/UnicodeArrayRotateFunctionNode.ts index 28ef5be4..aa93d88f 100644 --- a/src/custom-nodes/unicode-array-nodes/UnicodeArrayRotateFunctionNode.ts +++ b/src/custom-nodes/unicode-array-nodes/UnicodeArrayRotateFunctionNode.ts @@ -7,6 +7,9 @@ import { TBlockScopeNode } from "../../types/TBlockScopeNode"; import { AppendState } from "../../enums/AppendState"; +import { NO_CUSTOM_NODES_PRESET } from "../../preset-options/NoCustomNodesPreset"; + +import { JavaScriptObfuscator } from "../../JavaScriptObfuscator"; import { Node } from '../Node'; import { NodeUtils } from "../../NodeUtils"; import { Utils } from "../../Utils"; @@ -76,22 +79,42 @@ export class UnicodeArrayRotateFunctionNode extends Node { */ protected getNodeStructure (): INode { let arrayName: string = Utils.getRandomVariableName(), + code: string = '', timesName: string = Utils.getRandomVariableName(), tempArrayName: string = Utils.getRandomVariableName(), - node: INode = esprima.parse(` - (function (${arrayName}, ${timesName}) { - if (${timesName} < 0x${Utils.decToHex(0)}) { - return; - } + node: INode; - var ${tempArrayName}; - - while (${timesName}--) { - ${tempArrayName} = ${arrayName}[${Utils.stringToUnicode('shift')}](); - ${arrayName}[${Utils.stringToUnicode('push')}](${tempArrayName}); + if (this.options['selfDefending']) { + code = JavaScriptObfuscator.obfuscate(` + (function () { + var func = function () { + return '\x77\x69\x6e\x64\x6f\x77'; + }; + + if ( + !/(\\\\\[x|u](\\w){2,4})+/.test(func.toString()) + ) { + []["filter"]["constructor"]((+(32))["toString"](33) + (+(101))["toString"](21)[1] + ([false]+undefined)[10] + (false+"")[2] + (true+"")[3] + '(!![]){}')(); } - })(${this.unicodeArrayName}, 0x${Utils.decToHex(this.unicodeArrayRotateValue)}); - `); + })(); + `, NO_CUSTOM_NODES_PRESET); + } + + node = esprima.parse(` + (function (${arrayName}, ${timesName}) { + if (${timesName} < 0x${Utils.decToHex(0)}) { + return; + } + + var ${tempArrayName}; + + while (${timesName}--) { + ${code} + ${tempArrayName} = ${arrayName}[${Utils.stringToUnicode('shift')}](); + ${arrayName}[${Utils.stringToUnicode('push')}](${tempArrayName}); + } + })(${this.unicodeArrayName}, 0x${Utils.decToHex(this.unicodeArrayRotateValue)}); + `); NodeUtils.addXVerbatimPropertyToLiterals(node);