1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- import * as format from 'string-template';
- import { TNodeWithBlockStatement } from '../../types/node/TNodeWithBlockStatement';
- import { TObfuscationEvent } from '../../types/event-emitters/TObfuscationEvent';
- import { IOptions } from '../../interfaces/options/IOptions';
- import { IStackTraceData } from '../../interfaces/stack-trace-analyzer/IStackTraceData';
- import { ObfuscationEvents } from '../../enums/ObfuscationEvents';
- import { NO_CUSTOM_NODES_PRESET } from '../../preset-options/NoCustomNodesPreset';
- import { SelfDefendingTemplate } from '../../templates/custom-nodes/self-defending-nodes/self-defending-unicode-node/SelfDefendingTemplate';
- import { AbstractCustomNode } from '../AbstractCustomNode';
- import { NodeAppender } from '../../node/NodeAppender';
- import { JavaScriptObfuscator } from '../../JavaScriptObfuscator';
- import { Utils } from '../../Utils';
- export class SelfDefendingUnicodeNode extends AbstractCustomNode {
- /**
- * @type {TObfuscationEvent}
- */
- protected readonly appendEvent: TObfuscationEvent = ObfuscationEvents.AfterObfuscation;
- /**
- * @type {string}
- */
- protected callsControllerFunctionName: string;
- /**
- * @type {number}
- */
- protected randomStackTraceIndex: number;
- /**
- * @type {IStackTraceData[]}
- */
- protected stackTraceData: IStackTraceData[];
- /**
- * @param stackTraceData
- * @param callsControllerFunctionName
- * @param randomStackTraceIndex
- * @param options
- */
- constructor (
- stackTraceData: IStackTraceData[],
- callsControllerFunctionName: string,
- randomStackTraceIndex: number,
- options: IOptions
- ) {
- super(options);
- this.stackTraceData = stackTraceData;
- this.callsControllerFunctionName = callsControllerFunctionName;
- this.randomStackTraceIndex = randomStackTraceIndex;
- }
- /**
- * @param blockScopeNode
- */
- public appendNode (blockScopeNode: TNodeWithBlockStatement): void {
- NodeAppender.appendNodeToOptimalBlockScope(
- this.stackTraceData,
- blockScopeNode,
- this.getNode(),
- this.randomStackTraceIndex
- );
- }
- /**
- * @returns {string}
- */
- public getCode (): string {
- return JavaScriptObfuscator.obfuscate(
- format(SelfDefendingTemplate(), {
- selfDefendingFunctionName: Utils.getRandomVariableName(),
- singleNodeCallControllerFunctionName: this.callsControllerFunctionName
- }),
- Object.assign({}, NO_CUSTOM_NODES_PRESET, {
- seed: this.options.seed
- })
- ).getObfuscatedCode();
- }
- }
|