import { interfaces, Kernel, KernelModule } from 'inversify';
import { IJavaScriptObfuscator } from "./interfaces/IJavaScriptObfuscator";
import { IObfuscator } from "./interfaces/IObfuscator";
import { IObfuscatorOptions } from "./interfaces/IObfuscatorOptions";
import { IOptions } from "./interfaces/IOptions";
import { KernelTypes } from "./enums/KernelTypes";
import { JavaScriptObfuscatorInternal } from "./JavaScriptObfuscatorInternal";
import { Obfuscator } from "./Obfuscator";
import { Options } from "./options/Options";
export class ObfuscatorCompositor {
/**
* @type {interfaces.Kernel}
*/
private kernel: interfaces.Kernel;
/**
* @type {IObfuscatorOptions}
*/
private obfuscatorOptions: IObfuscatorOptions;
/**
* @type {string}
*/
private sourceCode: string;
/**
* @param sourceCode
* @param obfuscatorOptions
*/
constructor (sourceCode: string, obfuscatorOptions: IObfuscatorOptions) {
this.sourceCode = sourceCode;
this.obfuscatorOptions = obfuscatorOptions;
this.kernel = new Kernel();
}
public composite (): void {
this.kernel.load(
new KernelModule((bind: interfaces.Bind) => {
bind<IJavaScriptObfuscator>(KernelTypes.IJavaScriptObfuscator)
.toConstantValue(
new JavaScriptObfuscatorInternal(this.sourceCode, this.obfuscatorOptions)
);
bind<IObfuscator>(KernelTypes.IObfuscator).to(Obfuscator);
bind<IOptions>(KernelTypes.IOptions).to(Options);
})
);
}
/**
* @returns {interfaces.Kernel}
*/
public getKernel (): interfaces.Kernel {
return this.kernel;
}
}
|