Files
javascript-obfuscator-javas…/src/custom-nodes/unicode-array-nodes/UnicodeArrayCallsWrapper.ts
T
2016-05-28 14:31:25 +03:00

94 lines
2.3 KiB
TypeScript

import * as esprima from 'esprima';
import { INode } from "../../interfaces/nodes/INode";
import { BlockScopeNode } from "../../types/BlockScopeNode";
import { AppendState } from "../../enums/AppendState";
import { Node } from '../Node';
import { NodeUtils } from "../../NodeUtils";
import { Utils } from "../../Utils";
export class UnicodeArrayCallsWrapper extends Node {
/**
* @type {AppendState}
*/
protected appendState: AppendState = AppendState.AfterObfuscation;
/**
* @type {string[]}
*/
private unicodeArray: string[];
/**
* @type {string}
*/
private unicodeArrayName: string;
/**
* @type {string}
*/
private unicodeArrayCallsWrapperName: string;
/**
* @param unicodeArrayCallsWrapperName
* @param unicodeArrayName
* @param unicodeArray
*/
constructor (
unicodeArrayCallsWrapperName: string,
unicodeArrayName: string,
unicodeArray: string[]
) {
super();
this.unicodeArrayCallsWrapperName = unicodeArrayCallsWrapperName;
this.unicodeArrayName = unicodeArrayName;
this.unicodeArray = unicodeArray;
this.node = this.getNodeStructure();
}
/**
* @param blockScopeNode
*/
public appendNode (blockScopeNode: BlockScopeNode): void {
NodeUtils.insertNodeAtIndex(blockScopeNode.body, this.getNode(), 1);
}
/**
* @returns {string}
*/
public getNodeIdentifier (): string {
return this.unicodeArrayCallsWrapperName;
};
/**
* @returns {INode}
*/
public getNode (): INode {
if (!this.unicodeArray.length) {
return;
}
return super.getNode();
}
/**
* @returns any
*/
protected getNodeStructure (): any {
let keyName: string = Utils.getRandomVariableName(),
node: INode = esprima.parse(`
var ${this.unicodeArrayCallsWrapperName} = function (${keyName}) {
return ${this.unicodeArrayName}[[][${Utils.stringToUnicode('filter')}][${Utils.stringToUnicode('constructor')}](${Utils.stringToUnicode('return this')})()[${Utils.stringToUnicode('parseInt')}](${keyName})]
};
`);
NodeUtils.addXVerbatimPropertyToLiterals(node);
return NodeUtils.getBlockScopeNodeByIndex(node);
}
}