This commit is contained in:
sanex3339
2016-05-24 20:59:11 +03:00
parent 47c560ed7a
commit 15eeaa8b41
6 changed files with 62 additions and 70 deletions
+9 -1
View File
@@ -3,6 +3,15 @@ const estraverse = require('estraverse');
const NodeType_1 = require("./enums/NodeType");
const Utils_1 = require("./Utils");
class NodeUtils {
static addXVerbatimPropertyToLiterals(node) {
estraverse.replace(node, {
enter: (node, parentNode) => {
if (NodeUtils.isLiteralNode(node)) {
node['x-verbatim-property'] = node.raw;
}
}
});
}
static appendNode(blockScopeBody, node) {
if (!NodeUtils.validateNode(node)) {
return;
@@ -22,7 +31,6 @@ class NodeUtils {
if (node.parentNode.type === NodeType_1.NodeType.Program) {
return node.parentNode;
}
console.log(node.type, node.parentNode.type);
if (!Utils_1.Utils.arrayContains(NodeUtils.scopeNodes, node.parentNode.type)) {
return NodeUtils.getBlockScopeOfNode(node.parentNode, depth);
}
+13 -2
View File
@@ -26,6 +26,19 @@ export class NodeUtils {
NodeType.MethodDefinition
];
/**
* @param node
*/
public static addXVerbatimPropertyToLiterals (node: INode): void {
estraverse.replace(node, {
enter: (node: INode, parentNode: INode): any => {
if (NodeUtils.isLiteralNode(node)) {
node['x-verbatim-property'] = node.raw;
}
}
});
}
/**
* @param blockScopeBody
* @param node
@@ -65,8 +78,6 @@ export class NodeUtils {
return <BlockScopeNode> node.parentNode;
}
console.log(node.type, node.parentNode.type);
if (!Utils.arrayContains(NodeUtils.scopeNodes, node.parentNode.type)) {
return NodeUtils.getBlockScopeOfNode(node.parentNode, depth);
}
@@ -3,6 +3,7 @@ const esprima = require('esprima');
const AppendState_1 = require("../../enums/AppendState");
const Node_1 = require('../Node');
const NodeUtils_1 = require("../../NodeUtils");
const Utils_1 = require("../../Utils");
class UnicodeArrayRotateFunctionNode extends Node_1.Node {
constructor(unicodeArrayName, unicodeArray, unicodeArrayRotateValue) {
super();
@@ -22,25 +23,22 @@ class UnicodeArrayRotateFunctionNode extends Node_1.Node {
return super.getNode();
}
getNodeStructure() {
return NodeUtils_1.NodeUtils.getBlockScopeNodeByIndex(esprima.parse(`
(function (array, times, reverse) {
if (times < 0) {
return;
}
var temp;
while (times--) {
if (!reverse) {
temp = array.pop();
array.unshift(temp);
} else {
temp = array.shift();
array.push(temp);
}
}
})(${this.unicodeArrayName}, ${this.unicodeArrayRotateValue}, true);
`));
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;
}
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)});
`);
NodeUtils_1.NodeUtils.addXVerbatimPropertyToLiterals(node);
return NodeUtils_1.NodeUtils.getBlockScopeNodeByIndex(node);
}
}
exports.UnicodeArrayRotateFunctionNode = UnicodeArrayRotateFunctionNode;
@@ -40,7 +40,7 @@ export class UnicodeArrayRotateFunctionNode extends Node {
constructor (
unicodeArrayName: string,
unicodeArray: string[],
unicodeArrayRotateValue
unicodeArrayRotateValue: number
) {
super();
@@ -73,52 +73,26 @@ export class UnicodeArrayRotateFunctionNode extends Node {
* @returns any
*/
protected getNodeStructure (): any {
return NodeUtils.getBlockScopeNodeByIndex(
esprima.parse(`
(function (array, times, reverse) {
if (times < 0) {
return;
}
var temp;
while (times--) {
if (!reverse) {
temp = array.pop();
array.unshift(temp);
} else {
temp = array.shift();
array.push(temp);
}
}
})(${this.unicodeArrayName}, ${this.unicodeArrayRotateValue}, true);
`)
);
let arrayName: string = Utils.getRandomVariableName(),
timesName: string = Utils.getRandomVariableName(),
tempArrayName: string = Utils.getRandomVariableName(),
node: INode = esprima.parse(`
(function (${arrayName}, ${timesName}) {
if (${timesName} < 0x${Utils.decToHex(0)}) {
return;
}
/*return new Obfuscator({
rotateUnicodeArray: false
}).obfuscateNode(
NodeUtils.getBlockScopeNodeByIndex(
esprima.parse(`
(function (array, times, reverse) {
if (times < 0) {
return;
}
var temp;
while (times--) {
if (!reverse) {
temp = array.pop();
array.unshift(temp);
} else {
temp = array.shift();
array.push(temp);
}
}
})(${this.unicodeArrayName}, ${this.unicodeArrayRotateValue}, true);
`)
)
);*/
var ${tempArrayName};
while (${timesName}--) {
${tempArrayName} = ${arrayName}[${Utils.stringToUnicode('shift')}]();
${arrayName}[${Utils.stringToUnicode('push')}](${tempArrayName});
}
})(${this.unicodeArrayName}, 0x${Utils.decToHex(this.unicodeArrayRotateValue)});
`);
NodeUtils.addXVerbatimPropertyToLiterals(node);
return NodeUtils.getBlockScopeNodeByIndex(node);
}
}
+1
View File
@@ -48,6 +48,7 @@ let obfuscatedCode = index_1.JavaScriptObfuscator.obfuscate(`
})();
`, {
disableConsoleOutput: false,
rotateUnicodeArray: false
});
console.log(obfuscatedCode);
console.log(eval(obfuscatedCode));
+1 -1
View File
@@ -50,7 +50,7 @@ let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
`,
{
disableConsoleOutput: false,
//rotateUnicodeArray: false
rotateUnicodeArray: false
}
);