From 73813257b6f53e7d8d8d83863dd006fb91f502f0 Mon Sep 17 00:00:00 2001 From: sanex3339 Date: Tue, 24 May 2016 16:53:18 +0300 Subject: [PATCH] refactoring --- src/Obfuscator.js | 20 +++++++------- src/Obfuscator.ts | 24 ++++++++--------- src/custom-nodes/Node.ts | 7 +---- .../ConsoleOutputDisableExpressionNode.js | 7 +++-- .../ConsoleOutputDisableExpressionNode.ts | 14 +++++----- .../DebugProtectionFunctionCallNode.js | 7 +++-- .../DebugProtectionFunctionCallNode.ts | 14 +++++----- .../DebugProtectionFunctionIntervalNode.js | 7 +++-- .../DebugProtectionFunctionIntervalNode.ts | 14 +++++----- .../DebugProtectionFunctionNode.js | 12 ++++----- .../DebugProtectionFunctionNode.ts | 26 ++++++++----------- .../unicode-array-nodes/UnicodeArrayNode.js | 7 +++-- .../unicode-array-nodes/UnicodeArrayNode.ts | 11 ++++---- .../UnicodeArrayRotateFunctionCallNode.js | 7 +++-- .../UnicodeArrayRotateFunctionCallNode.ts | 8 ++---- .../UnicodeArrayRotateFunctionNode.js | 7 +++-- .../UnicodeArrayRotateFunctionNode.ts | 10 +++---- src/interfaces/ICustomNode.d.ts | 5 +++- src/node-groups/DebugProtectionNodesGroup.js | 9 +++---- src/node-groups/DebugProtectionNodesGroup.ts | 20 +++----------- src/node-groups/UnicodeArrayNodesGroup.js | 8 +++--- src/node-groups/UnicodeArrayNodesGroup.ts | 8 +----- 22 files changed, 106 insertions(+), 146 deletions(-) diff --git a/src/Obfuscator.js b/src/Obfuscator.js index 6ade223f..4243cc34 100644 --- a/src/Obfuscator.js +++ b/src/Obfuscator.js @@ -36,7 +36,7 @@ class Obfuscator { this.options = options; } obfuscateNode(node) { - this.setNewNodes(node); + this.setNewNodes(); this.beforeObfuscation(node); estraverse.replace(node, { enter: (node, parent) => this.nodeControllerFirstPass(node, parent) @@ -55,33 +55,33 @@ class Obfuscator { this.nodes.set(key, node); }); } - afterObfuscation(node) { + afterObfuscation(astTree) { this.nodes.forEach((node) => { if (node.getAppendState() === AppendState_1.AppendState.AfterObfuscation) { - node.appendNode(); + node.appendNode(astTree); } }); } - beforeObfuscation(node) { + beforeObfuscation(astTree) { this.nodes.forEach((node) => { if (node.getAppendState() === AppendState_1.AppendState.BeforeObfuscation) { - node.appendNode(); + node.appendNode(astTree); } }); } ; - setNewNodes(astTree) { + setNewNodes() { if (this.options['disableConsoleOutput']) { - this.setNode('consoleOutputDisableExpressionNode', new ConsoleOutputDisableExpressionNode_1.ConsoleOutputDisableExpressionNode(astTree)); + this.setNode('consoleOutputDisableExpressionNode', new ConsoleOutputDisableExpressionNode_1.ConsoleOutputDisableExpressionNode()); } if (this.options['debugProtection']) { - this.setNodesGroup(new DebugProtectionNodesGroup_1.DebugProtectionNodesGroup(astTree, this.options)); + this.setNodesGroup(new DebugProtectionNodesGroup_1.DebugProtectionNodesGroup(this.options)); } if (this.options['rotateUnicodeArray']) { - this.setNodesGroup(new UnicodeArrayNodesGroup_1.UnicodeArrayNodesGroup(astTree)); + this.setNodesGroup(new UnicodeArrayNodesGroup_1.UnicodeArrayNodesGroup()); } else { - this.setNode('unicodeArrayNode', new UnicodeArrayNode_1.UnicodeArrayNode(astTree, Utils_1.Utils.getRandomVariableName(UnicodeArrayNode_1.UnicodeArrayNode.UNICODE_ARRAY_RANDOM_LENGTH))); + this.setNode('unicodeArrayNode', new UnicodeArrayNode_1.UnicodeArrayNode(Utils_1.Utils.getRandomVariableName(UnicodeArrayNode_1.UnicodeArrayNode.UNICODE_ARRAY_RANDOM_LENGTH))); } } nodeControllerFirstPass(node, parent) { diff --git a/src/Obfuscator.ts b/src/Obfuscator.ts index b5d1bd32..9725b324 100644 --- a/src/Obfuscator.ts +++ b/src/Obfuscator.ts @@ -63,7 +63,7 @@ export class Obfuscator { * @param node */ public obfuscateNode (node: INode): void { - this.setNewNodes(node); + this.setNewNodes(); this.beforeObfuscation(node); estraverse.replace(node, { @@ -97,48 +97,48 @@ export class Obfuscator { } /** - * @param node + * @param astTree */ - private afterObfuscation (node: INode): void { + private afterObfuscation (astTree: INode): void { this.nodes.forEach((node: ICustomNode) => { if (node.getAppendState() === AppendState.AfterObfuscation) { - node.appendNode(); + node.appendNode(astTree); } }); } /** - * @param node + * @param astTree */ - private beforeObfuscation (node: INode): void { + private beforeObfuscation (astTree: INode): void { this.nodes.forEach((node: ICustomNode) => { if (node.getAppendState() === AppendState.BeforeObfuscation) { - node.appendNode(); + node.appendNode(astTree); } }); }; - private setNewNodes (astTree: INode): void { + private setNewNodes (): void { if (this.options['disableConsoleOutput']) { this.setNode( 'consoleOutputDisableExpressionNode', - new ConsoleOutputDisableExpressionNode(astTree) + new ConsoleOutputDisableExpressionNode() ); } if (this.options['debugProtection']) { - this.setNodesGroup(new DebugProtectionNodesGroup(astTree, this.options)); + this.setNodesGroup(new DebugProtectionNodesGroup(this.options)); } /** * Important to set this nodes latest to prevent runtime errors cause by `rotateUnicodeArray` option */ if (this.options['rotateUnicodeArray']) { - this.setNodesGroup(new UnicodeArrayNodesGroup(astTree)); + this.setNodesGroup(new UnicodeArrayNodesGroup()); } else { this.setNode( 'unicodeArrayNode', - new UnicodeArrayNode(astTree, Utils.getRandomVariableName(UnicodeArrayNode.UNICODE_ARRAY_RANDOM_LENGTH)) + new UnicodeArrayNode(Utils.getRandomVariableName(UnicodeArrayNode.UNICODE_ARRAY_RANDOM_LENGTH)) ); } } diff --git a/src/custom-nodes/Node.ts b/src/custom-nodes/Node.ts index 257bf6c0..489f1575 100644 --- a/src/custom-nodes/Node.ts +++ b/src/custom-nodes/Node.ts @@ -9,11 +9,6 @@ export abstract class Node implements ICustomNode { */ protected appendState: AppendState = AppendState.BeforeObfuscation; - /** - * @type {INode} - */ - protected astTree: INode; - /** * @type {INode} */ @@ -21,7 +16,7 @@ export abstract class Node implements ICustomNode { constructor () {} - public abstract appendNode (): void; + public abstract appendNode (astTree: INode): void; /** * @returns {AppendState} diff --git a/src/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.js b/src/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.js index 64022d90..1ce5847b 100644 --- a/src/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.js +++ b/src/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.js @@ -4,13 +4,12 @@ const estraverse = require('estraverse'); const Node_1 = require('../Node'); const NodeUtils_1 = require("../../NodeUtils"); class ConsoleOutputDisableExpressionNode extends Node_1.Node { - constructor(astTree) { + constructor() { super(); - this.astTree = astTree; this.node = this.getNodeStructure(); } - appendNode() { - estraverse.replace(this.astTree, { + appendNode(astTree) { + estraverse.replace(astTree, { leave: (node, parent) => { if (NodeUtils_1.NodeUtils.isProgramNode(node)) { NodeUtils_1.NodeUtils.prependNode(node.body, this.getNode()); diff --git a/src/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.ts b/src/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.ts index 65c93ec5..08fd3e92 100644 --- a/src/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.ts +++ b/src/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.ts @@ -7,19 +7,17 @@ import { Node } from '../Node'; import { NodeUtils } from "../../NodeUtils"; export class ConsoleOutputDisableExpressionNode extends Node { - /** - * @param astTree - */ - constructor (astTree: INode) { + constructor () { super(); - this.astTree = astTree; - this.node = this.getNodeStructure(); } - public appendNode (): void { - estraverse.replace(this.astTree, { + /** + * @param astTree + */ + public appendNode (astTree: INode): void { + estraverse.replace(astTree, { leave: (node: INode, parent: INode): any => { if (NodeUtils.isProgramNode(node)) { NodeUtils.prependNode(node.body, this.getNode()); diff --git a/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionCallNode.js b/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionCallNode.js index 7c4dfaab..57022c7a 100644 --- a/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionCallNode.js +++ b/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionCallNode.js @@ -4,14 +4,13 @@ const NodeType_1 = require("../../enums/NodeType"); const Node_1 = require('../Node'); const NodeUtils_1 = require("../../NodeUtils"); class DebugProtectionFunctionCallNode extends Node_1.Node { - constructor(astTree, debugProtectionFunctionName) { + constructor(debugProtectionFunctionName) { super(); - this.astTree = astTree; this.debugProtectionFunctionName = debugProtectionFunctionName; this.node = this.getNodeStructure(); } - appendNode() { - estraverse.replace(this.astTree, { + appendNode(astTree) { + estraverse.replace(astTree, { leave: (node, parent) => { if (NodeUtils_1.NodeUtils.isProgramNode(node)) { NodeUtils_1.NodeUtils.appendNode(node.body, this.getNode()); diff --git a/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionCallNode.ts b/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionCallNode.ts index ce5842ac..0e56ace8 100644 --- a/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionCallNode.ts +++ b/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionCallNode.ts @@ -14,23 +14,21 @@ export class DebugProtectionFunctionCallNode extends Node { private debugProtectionFunctionName: string; /** - * @param astTree * @param debugProtectionFunctionName */ - constructor ( - astTree: INode, - debugProtectionFunctionName: string - ) { + constructor (debugProtectionFunctionName: string) { super(); - this.astTree = astTree; this.debugProtectionFunctionName = debugProtectionFunctionName; this.node = this.getNodeStructure(); } - public appendNode (): void { - estraverse.replace(this.astTree, { + /** + * @param astTree + */ + public appendNode (astTree: INode): void { + estraverse.replace(astTree, { leave: (node: INode, parent: INode): any => { if (NodeUtils.isProgramNode(node)) { NodeUtils.appendNode(node.body, this.getNode()); diff --git a/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionIntervalNode.js b/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionIntervalNode.js index ddd4e4a2..61e4f56a 100644 --- a/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionIntervalNode.js +++ b/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionIntervalNode.js @@ -4,14 +4,13 @@ const NodeType_1 = require('../../enums/NodeType'); const Node_1 = require('../Node'); const NodeUtils_1 = require('../../NodeUtils'); class DebugProtectionFunctionIntervalNode extends Node_1.Node { - constructor(astTree, debugProtectionFunctionName) { + constructor(debugProtectionFunctionName) { super(); - this.astTree = astTree; this.debugProtectionFunctionName = debugProtectionFunctionName; this.node = this.getNodeStructure(); } - appendNode() { - estraverse.replace(this.astTree, { + appendNode(astTree) { + estraverse.replace(astTree, { leave: (node, parent) => { if (NodeUtils_1.NodeUtils.isProgramNode(node)) { NodeUtils_1.NodeUtils.appendNode(node.body, this.getNode()); diff --git a/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionIntervalNode.ts b/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionIntervalNode.ts index 58b28b6f..161b78e6 100644 --- a/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionIntervalNode.ts +++ b/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionIntervalNode.ts @@ -14,23 +14,21 @@ export class DebugProtectionFunctionIntervalNode extends Node { private debugProtectionFunctionName: string; /** - * @param astTree * @param debugProtectionFunctionName */ - constructor ( - astTree: INode, - debugProtectionFunctionName: string - ) { + constructor (debugProtectionFunctionName: string) { super(); - this.astTree = astTree; this.debugProtectionFunctionName = debugProtectionFunctionName; this.node = this.getNodeStructure(); } - public appendNode (): void { - estraverse.replace(this.astTree, { + /** + * @param astTree + */ + public appendNode (astTree: INode): void { + estraverse.replace(astTree, { leave: (node: INode, parent: INode): any => { if (NodeUtils.isProgramNode(node)) { NodeUtils.appendNode(node.body, this.getNode()); diff --git a/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionNode.js b/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionNode.js index 99f55ae5..f1deae27 100644 --- a/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionNode.js +++ b/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionNode.js @@ -3,19 +3,19 @@ const esprima = require('esprima'); const estraverse = require('estraverse'); const Node_1 = require('../Node'); const NodeUtils_1 = require('../../NodeUtils'); +const Utils_1 = require("../../Utils"); class DebugProtectionFunctionNode extends Node_1.Node { - constructor(astTree, debugProtectionFunctionName, debugProtectionFunctionIndex) { + constructor(debugProtectionFunctionName) { super(); - this.astTree = astTree; this.debugProtectionFunctionName = debugProtectionFunctionName; - this.debugProtectionFunctionIndex = debugProtectionFunctionIndex; this.node = this.getNodeStructure(); } - appendNode() { - estraverse.replace(this.astTree, { + appendNode(astTree) { + estraverse.replace(astTree, { leave: (node, parent) => { if (NodeUtils_1.NodeUtils.isProgramNode(node)) { - NodeUtils_1.NodeUtils.insertNodeAtIndex(node.body, this.getNode(), this.debugProtectionFunctionIndex); + let programBodyLength = node.body.length, randomIndex = Utils_1.Utils.getRandomInteger(0, programBodyLength); + NodeUtils_1.NodeUtils.insertNodeAtIndex(node.body, this.getNode(), randomIndex); return estraverse.VisitorOption.Break; } return estraverse.VisitorOption.Skip; diff --git a/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionNode.ts b/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionNode.ts index 0d4bddee..a96de225 100644 --- a/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionNode.ts +++ b/src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionNode.ts @@ -5,6 +5,7 @@ import { INode } from '../../interfaces/nodes/INode'; import { Node } from '../Node'; import { NodeUtils } from '../../NodeUtils'; +import { Utils } from "../../Utils"; export class DebugProtectionFunctionNode extends Node { /** @@ -13,34 +14,29 @@ export class DebugProtectionFunctionNode extends Node { private debugProtectionFunctionName: string; /** - * @type {number} - */ - private debugProtectionFunctionIndex: number; - - /** - * @param astTree * @param debugProtectionFunctionName - * @param debugProtectionFunctionIndex */ constructor ( - astTree: INode, - debugProtectionFunctionName: string, - debugProtectionFunctionIndex: number + debugProtectionFunctionName: string ) { super(); - this.astTree = astTree; this.debugProtectionFunctionName = debugProtectionFunctionName; - this.debugProtectionFunctionIndex = debugProtectionFunctionIndex; this.node = this.getNodeStructure(); } - public appendNode (): void { - estraverse.replace(this.astTree, { + /** + * @param astTree + */ + public appendNode (astTree: INode): void { + estraverse.replace(astTree, { leave: (node: INode, parent: INode): any => { if (NodeUtils.isProgramNode(node)) { - NodeUtils.insertNodeAtIndex(node.body, this.getNode(), this.debugProtectionFunctionIndex); + let programBodyLength: number = node.body.length, + randomIndex = Utils.getRandomInteger(0, programBodyLength); + + NodeUtils.insertNodeAtIndex(node.body, this.getNode(), randomIndex); return estraverse.VisitorOption.Break; } diff --git a/src/custom-nodes/unicode-array-nodes/UnicodeArrayNode.js b/src/custom-nodes/unicode-array-nodes/UnicodeArrayNode.js index 25af7765..93dc5416 100644 --- a/src/custom-nodes/unicode-array-nodes/UnicodeArrayNode.js +++ b/src/custom-nodes/unicode-array-nodes/UnicodeArrayNode.js @@ -7,17 +7,16 @@ const Node_1 = require('../Node'); const NodeUtils_1 = require("../../NodeUtils"); const Utils_1 = require('../../Utils'); class UnicodeArrayNode extends Node_1.Node { - constructor(astTree, unicodeArrayName, unicodeArrayRotateValue = 0) { + constructor(unicodeArrayName, unicodeArrayRotateValue = 0) { super(); this.appendState = AppendState_1.AppendState.AfterObfuscation; this.unicodeArray = []; - this.astTree = astTree; this.unicodeArrayName = unicodeArrayName; this.unicodeArrayRotateValue = unicodeArrayRotateValue; this.node = this.getNodeStructure(); } - appendNode() { - estraverse.replace(this.astTree, { + appendNode(astTree) { + estraverse.replace(astTree, { leave: (node, parent) => { if (NodeUtils_1.NodeUtils.isProgramNode(node)) { NodeUtils_1.NodeUtils.prependNode(node.body, this.getNode()); diff --git a/src/custom-nodes/unicode-array-nodes/UnicodeArrayNode.ts b/src/custom-nodes/unicode-array-nodes/UnicodeArrayNode.ts index 2e33f969..f5b51981 100644 --- a/src/custom-nodes/unicode-array-nodes/UnicodeArrayNode.ts +++ b/src/custom-nodes/unicode-array-nodes/UnicodeArrayNode.ts @@ -37,22 +37,23 @@ export class UnicodeArrayNode extends Node { private unicodeArrayRotateValue: number; /** - * @param astTree * @param unicodeArrayName * @param unicodeArrayRotateValue */ - constructor (astTree: INode, unicodeArrayName: string, unicodeArrayRotateValue: number = 0) { + constructor (unicodeArrayName: string, unicodeArrayRotateValue: number = 0) { super(); - this.astTree = astTree; this.unicodeArrayName = unicodeArrayName; this.unicodeArrayRotateValue = unicodeArrayRotateValue; this.node = this.getNodeStructure(); } - public appendNode (): void { - estraverse.replace(this.astTree, { + /** + * @param astTree + */ + public appendNode (astTree: INode): void { + estraverse.replace(astTree, { leave: (node: INode, parent: INode): any => { if (NodeUtils.isProgramNode(node)) { NodeUtils.prependNode(node.body, this.getNode()); diff --git a/src/custom-nodes/unicode-array-nodes/UnicodeArrayRotateFunctionCallNode.js b/src/custom-nodes/unicode-array-nodes/UnicodeArrayRotateFunctionCallNode.js index 8e165f9e..ce0ab000 100644 --- a/src/custom-nodes/unicode-array-nodes/UnicodeArrayRotateFunctionCallNode.js +++ b/src/custom-nodes/unicode-array-nodes/UnicodeArrayRotateFunctionCallNode.js @@ -4,16 +4,15 @@ const NodeType_1 = require("../../enums/NodeType"); const Node_1 = require('../Node'); const NodeUtils_1 = require("../../NodeUtils"); class UnicodeArrayRotateFunctionCallNode extends Node_1.Node { - constructor(astTree, unicodeArrayRotateFunctionName, unicodeArrayName, unicodeArrayRotateValue) { + constructor(unicodeArrayRotateFunctionName, unicodeArrayName, unicodeArrayRotateValue) { super(); - this.astTree = astTree; this.unicodeArrayRotateFunctionName = unicodeArrayRotateFunctionName; this.unicodeArrayName = unicodeArrayName; this.unicodeArrayRotateValue = unicodeArrayRotateValue; this.node = this.getNodeStructure(); } - appendNode() { - estraverse.replace(this.astTree, { + appendNode(astTree) { + estraverse.replace(astTree, { leave: (node, parent) => { if (NodeUtils_1.NodeUtils.isProgramNode(node)) { NodeUtils_1.NodeUtils.prependNode(node.body, this.getNode()); diff --git a/src/custom-nodes/unicode-array-nodes/UnicodeArrayRotateFunctionCallNode.ts b/src/custom-nodes/unicode-array-nodes/UnicodeArrayRotateFunctionCallNode.ts index a9174d47..cf5e83e0 100644 --- a/src/custom-nodes/unicode-array-nodes/UnicodeArrayRotateFunctionCallNode.ts +++ b/src/custom-nodes/unicode-array-nodes/UnicodeArrayRotateFunctionCallNode.ts @@ -24,21 +24,17 @@ export class UnicodeArrayRotateFunctionCallNode extends Node { private unicodeArrayRotateFunctionName: string; /** - * @param astTree * @param unicodeArrayRotateFunctionName * @param unicodeArrayName * @param unicodeArrayRotateValue */ constructor ( - astTree: INode, unicodeArrayRotateFunctionName: string, unicodeArrayName: string, unicodeArrayRotateValue: number ) { super(); - this.astTree = astTree; - this.unicodeArrayRotateFunctionName = unicodeArrayRotateFunctionName; this.unicodeArrayName = unicodeArrayName; this.unicodeArrayRotateValue = unicodeArrayRotateValue; @@ -46,8 +42,8 @@ export class UnicodeArrayRotateFunctionCallNode extends Node { this.node = this.getNodeStructure(); } - public appendNode (): void { - estraverse.replace(this.astTree, { + public appendNode (astTree: INode): void { + estraverse.replace(astTree, { leave: (node: INode, parent: INode): any => { if (NodeUtils.isProgramNode(node)) { NodeUtils.prependNode(node.body, this.getNode()); diff --git a/src/custom-nodes/unicode-array-nodes/UnicodeArrayRotateFunctionNode.js b/src/custom-nodes/unicode-array-nodes/UnicodeArrayRotateFunctionNode.js index 42a88b23..4f935aae 100644 --- a/src/custom-nodes/unicode-array-nodes/UnicodeArrayRotateFunctionNode.js +++ b/src/custom-nodes/unicode-array-nodes/UnicodeArrayRotateFunctionNode.js @@ -5,15 +5,14 @@ const Node_1 = require('../Node'); const NodeUtils_1 = require("../../NodeUtils"); const Utils_1 = require('../../Utils'); class UnicodeArrayRotateFunctionNode extends Node_1.Node { - constructor(astTree, unicodeArrayRotateFunctionName, unicodeArrayName) { + constructor(unicodeArrayRotateFunctionName, unicodeArrayName) { super(); - this.astTree = astTree; this.unicodeArrayRotateFunctionName = unicodeArrayRotateFunctionName; this.unicodeArrayName = unicodeArrayName; this.node = this.getNodeStructure(); } - appendNode() { - estraverse.replace(this.astTree, { + appendNode(astTree) { + estraverse.replace(astTree, { leave: (node, parent) => { if (NodeUtils_1.NodeUtils.isProgramNode(node)) { NodeUtils_1.NodeUtils.appendNode(node.body, this.getNode()); diff --git a/src/custom-nodes/unicode-array-nodes/UnicodeArrayRotateFunctionNode.ts b/src/custom-nodes/unicode-array-nodes/UnicodeArrayRotateFunctionNode.ts index 0bfdf54d..ddc4912d 100644 --- a/src/custom-nodes/unicode-array-nodes/UnicodeArrayRotateFunctionNode.ts +++ b/src/custom-nodes/unicode-array-nodes/UnicodeArrayRotateFunctionNode.ts @@ -20,26 +20,26 @@ export class UnicodeArrayRotateFunctionNode extends Node { private unicodeArrayRotateFunctionName: string; /** - * @param astTree * @param unicodeArrayRotateFunctionName * @param unicodeArrayName */ constructor ( - astTree: INode, unicodeArrayRotateFunctionName: string, unicodeArrayName: string ) { super(); - this.astTree = astTree; this.unicodeArrayRotateFunctionName = unicodeArrayRotateFunctionName; this.unicodeArrayName = unicodeArrayName; this.node = this.getNodeStructure(); } - public appendNode (): void { - estraverse.replace(this.astTree, { + /** + * @param astTree + */ + public appendNode (astTree: INode): void { + estraverse.replace(astTree, { leave: (node: INode, parent: INode): any => { if (NodeUtils.isProgramNode(node)) { NodeUtils.appendNode(node.body, this.getNode()); diff --git a/src/interfaces/ICustomNode.d.ts b/src/interfaces/ICustomNode.d.ts index b4575d9f..c46b4b59 100644 --- a/src/interfaces/ICustomNode.d.ts +++ b/src/interfaces/ICustomNode.d.ts @@ -3,7 +3,10 @@ import { INode } from '../interfaces/nodes/INode'; import { AppendState } from '../enums/AppendState'; export interface ICustomNode { - appendNode (): void; + /** + * @param astTree + */ + appendNode (astTree: INode): void; /** * @returns {AppendState} diff --git a/src/node-groups/DebugProtectionNodesGroup.js b/src/node-groups/DebugProtectionNodesGroup.js index f673643d..3a06cee6 100644 --- a/src/node-groups/DebugProtectionNodesGroup.js +++ b/src/node-groups/DebugProtectionNodesGroup.js @@ -7,24 +7,23 @@ const NodesGroup_1 = require('./NodesGroup'); const NodeUtils_1 = require("../NodeUtils"); const Utils_1 = require('../Utils'); class DebugProtectionNodesGroup extends NodesGroup_1.NodesGroup { - constructor(astTree, options) { + constructor(options) { super(); this.debugProtectionFunctionIdentifier = Utils_1.Utils.getRandomVariableName(); - this.astTree = astTree; this.options = options; this.debugProtectionFunctionIndex = this.getDebugProtectionFunctionIndex(); this.nodes = new Map([ [ 'debugProtectionFunctionNode', - new DebugProtectionFunctionNode_1.DebugProtectionFunctionNode(this.astTree, this.debugProtectionFunctionIdentifier, this.debugProtectionFunctionIndex) + new DebugProtectionFunctionNode_1.DebugProtectionFunctionNode(this.debugProtectionFunctionIdentifier) ], [ 'debugProtectionFunctionCallNode', - new DebugProtectionFunctionCallNode_1.DebugProtectionFunctionCallNode(this.astTree, this.debugProtectionFunctionIdentifier) + new DebugProtectionFunctionCallNode_1.DebugProtectionFunctionCallNode(this.debugProtectionFunctionIdentifier) ] ]); if (this.options['debugProtectionInterval']) { - this.nodes.set('debugProtectionFunctionIntervalNode', new DebugProtectionFunctionIntervalNode_1.DebugProtectionFunctionIntervalNode(this.astTree, this.debugProtectionFunctionIdentifier)); + this.nodes.set('debugProtectionFunctionIntervalNode', new DebugProtectionFunctionIntervalNode_1.DebugProtectionFunctionIntervalNode(this.debugProtectionFunctionIdentifier)); } } getDebugProtectionFunctionIndex() { diff --git a/src/node-groups/DebugProtectionNodesGroup.ts b/src/node-groups/DebugProtectionNodesGroup.ts index 7cd72122..c4dcd84b 100644 --- a/src/node-groups/DebugProtectionNodesGroup.ts +++ b/src/node-groups/DebugProtectionNodesGroup.ts @@ -34,13 +34,11 @@ export class DebugProtectionNodesGroup extends NodesGroup { private options: any; /** - * @param astTree * @param options */ - constructor (astTree: INode, options: any) { + constructor (options: any) { super(); - this.astTree = astTree; this.options = options; this.debugProtectionFunctionIndex = this.getDebugProtectionFunctionIndex(); @@ -48,28 +46,18 @@ export class DebugProtectionNodesGroup extends NodesGroup { this.nodes = new Map ([ [ 'debugProtectionFunctionNode', - new DebugProtectionFunctionNode( - this.astTree, - this.debugProtectionFunctionIdentifier, - this.debugProtectionFunctionIndex - ) + new DebugProtectionFunctionNode(this.debugProtectionFunctionIdentifier) ], [ 'debugProtectionFunctionCallNode', - new DebugProtectionFunctionCallNode( - this.astTree, - this.debugProtectionFunctionIdentifier - ) + new DebugProtectionFunctionCallNode(this.debugProtectionFunctionIdentifier) ] ]); if (this.options['debugProtectionInterval']) { this.nodes.set( 'debugProtectionFunctionIntervalNode', - new DebugProtectionFunctionIntervalNode( - this.astTree, - this.debugProtectionFunctionIdentifier - ) + new DebugProtectionFunctionIntervalNode(this.debugProtectionFunctionIdentifier) ); } } diff --git a/src/node-groups/UnicodeArrayNodesGroup.js b/src/node-groups/UnicodeArrayNodesGroup.js index 45c94c03..41a5b0f8 100644 --- a/src/node-groups/UnicodeArrayNodesGroup.js +++ b/src/node-groups/UnicodeArrayNodesGroup.js @@ -5,22 +5,22 @@ const UnicodeArrayRotateFunctionCallNode_1 = require('../custom-nodes/unicode-ar const UnicodeArrayRotateFunctionNode_1 = require('../custom-nodes/unicode-array-nodes/UnicodeArrayRotateFunctionNode'); const Utils_1 = require('../Utils'); class UnicodeArrayNodesGroup extends NodesGroup_1.NodesGroup { - constructor(astTree) { + constructor() { super(); this.unicodeArrayRotateFunctionIdentifier = Utils_1.Utils.getRandomVariableName(); let unicodeArrayName = Utils_1.Utils.getRandomVariableName(UnicodeArrayNode_1.UnicodeArrayNode.UNICODE_ARRAY_RANDOM_LENGTH), unicodeArrayRotateValue = Utils_1.Utils.getRandomInteger(100, 500); this.nodes = new Map([ [ 'unicodeArrayNode', - new UnicodeArrayNode_1.UnicodeArrayNode(astTree, unicodeArrayName, unicodeArrayRotateValue) + new UnicodeArrayNode_1.UnicodeArrayNode(unicodeArrayName, unicodeArrayRotateValue) ], [ 'unicodeArrayRotateFunctionNode', - new UnicodeArrayRotateFunctionNode_1.UnicodeArrayRotateFunctionNode(astTree, this.unicodeArrayRotateFunctionIdentifier, unicodeArrayName) + new UnicodeArrayRotateFunctionNode_1.UnicodeArrayRotateFunctionNode(this.unicodeArrayRotateFunctionIdentifier, unicodeArrayName) ], [ 'unicodeArrayRotateFunctionCallNode', - new UnicodeArrayRotateFunctionCallNode_1.UnicodeArrayRotateFunctionCallNode(astTree, this.unicodeArrayRotateFunctionIdentifier, unicodeArrayName, unicodeArrayRotateValue) + new UnicodeArrayRotateFunctionCallNode_1.UnicodeArrayRotateFunctionCallNode(this.unicodeArrayRotateFunctionIdentifier, unicodeArrayName, unicodeArrayRotateValue) ] ]); } diff --git a/src/node-groups/UnicodeArrayNodesGroup.ts b/src/node-groups/UnicodeArrayNodesGroup.ts index 062f403e..f21082f2 100644 --- a/src/node-groups/UnicodeArrayNodesGroup.ts +++ b/src/node-groups/UnicodeArrayNodesGroup.ts @@ -14,10 +14,7 @@ export class UnicodeArrayNodesGroup extends NodesGroup { */ private unicodeArrayRotateFunctionIdentifier: string = Utils.getRandomVariableName(); - /** - * @param astTree - */ - constructor (astTree: INode) { + constructor () { super(); let unicodeArrayName: string = Utils.getRandomVariableName(UnicodeArrayNode.UNICODE_ARRAY_RANDOM_LENGTH), @@ -27,7 +24,6 @@ export class UnicodeArrayNodesGroup extends NodesGroup { [ 'unicodeArrayNode', new UnicodeArrayNode( - astTree, unicodeArrayName, unicodeArrayRotateValue ) @@ -35,7 +31,6 @@ export class UnicodeArrayNodesGroup extends NodesGroup { [ 'unicodeArrayRotateFunctionNode', new UnicodeArrayRotateFunctionNode( - astTree, this.unicodeArrayRotateFunctionIdentifier, unicodeArrayName ) @@ -43,7 +38,6 @@ export class UnicodeArrayNodesGroup extends NodesGroup { [ 'unicodeArrayRotateFunctionCallNode', new UnicodeArrayRotateFunctionCallNode( - astTree, this.unicodeArrayRotateFunctionIdentifier, unicodeArrayName, unicodeArrayRotateValue