mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
selfDefending test implementation
This commit is contained in:
@@ -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));
|
||||
|
||||
+30
-11
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user