12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- import { injectable, inject } from 'inversify';
- import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
- import * as format from 'string-template';
- import { TStatement } from '../../types/node/TStatement';
- import { IOptions } from '../../interfaces/options/IOptions';
- import { initializable } from '../../decorators/Initializable';
- import { NO_CUSTOM_NODES_PRESET } from '../../options/presets/NoCustomNodes';
- import { SelfDefendingTemplate } from '../../templates/custom-nodes/self-defending-nodes/self-defending-unicode-node/SelfDefendingTemplate';
- import { AbstractCustomNode } from '../AbstractCustomNode';
- import { JavaScriptObfuscator } from '../../JavaScriptObfuscator';
- import { NodeUtils } from '../../node/NodeUtils';
- import { RandomGeneratorUtils } from '../../utils/RandomGeneratorUtils';
- @injectable()
- export class SelfDefendingUnicodeNode extends AbstractCustomNode {
- /**
- * @type {string}
- */
- @initializable()
- protected callsControllerFunctionName: string;
- /**
- * @param options
- */
- constructor (
- @inject(ServiceIdentifiers.IOptions) options: IOptions
- ) {
- super(options);
- }
- /**
- * @param callsControllerFunctionName
- */
- public initialize (callsControllerFunctionName: string): void {
- this.callsControllerFunctionName = callsControllerFunctionName;
- }
- /**
- * @returns {TStatement[]}
- */
- protected getNodeStructure (): TStatement[] {
- return NodeUtils.convertCodeToStructure(this.getTemplate());
- }
- /**
- * @returns {string}
- */
- protected getTemplate (): string {
- return JavaScriptObfuscator.obfuscate(
- format(SelfDefendingTemplate(), {
- selfDefendingFunctionName: RandomGeneratorUtils.getRandomVariableName(6, true, true),
- singleNodeCallControllerFunctionName: this.callsControllerFunctionName
- }),
- {
- ...NO_CUSTOM_NODES_PRESET,
- seed: this.options.seed
- }
- ).getObfuscatedCode();
- }
- }
|