anobis
Version:
JavaScript obfuscator
85 lines (69 loc) • 2.62 kB
text/typescript
import { injectable, inject } from 'inversify';
import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
import * as format from 'string-template';
import { TStatement } from '../../types/node/TStatement';
import { ICryptUtils } from '../../interfaces/utils/ICryptUtils';
import { IOptions } from '../../interfaces/options/IOptions';
import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
import { initializable } from '../../decorators/Initializable';
import { DomainLockNodeTemplate } from '../../templates/custom-nodes/domain-lock-nodes/domain-lock-node/DomainLockNodeTemplate';
import { AbstractCustomNode } from '../AbstractCustomNode';
import { NodeUtils } from '../../node/NodeUtils';
()
export class DomainLockNode extends AbstractCustomNode {
/**
* @type {string}
*/
()
protected callsControllerFunctionName: string;
/**
* @type {ICryptUtils}
*/
private readonly cryptUtils: ICryptUtils;
/**
* @type {IRandomGenerator}
*/
private readonly randomGenerator: IRandomGenerator;
/**
* @param {IRandomGenerator} randomGenerator
* @param {ICryptUtils} cryptUtils
* @param {IOptions} options
*/
constructor (
(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
(ServiceIdentifiers.ICryptUtils) cryptUtils: ICryptUtils,
(ServiceIdentifiers.IOptions) options: IOptions
) {
super(options);
this.randomGenerator = randomGenerator;
this.cryptUtils = cryptUtils;
}
/**
* @param {string} callsControllerFunctionName
*/
public initialize (callsControllerFunctionName: string): void {
this.callsControllerFunctionName = callsControllerFunctionName;
}
/**
* @returns {TStatement[]}
*/
protected getNodeStructure (): TStatement[] {
return NodeUtils.convertCodeToStructure(this.getTemplate());
}
/**
* @returns {string}
*/
protected getTemplate (): string {
const domainsString: string = this.options.domainLock.join(';');
const [hiddenDomainsString, diff]: string[] = this.cryptUtils.hideString(
domainsString,
domainsString.length * 3
);
return format(DomainLockNodeTemplate(), {
domainLockFunctionName: this.randomGenerator.getRandomVariableName(6),
diff: diff,
domains: hiddenDomainsString,
singleNodeCallControllerFunctionName: this.callsControllerFunctionName
});
}
}