mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Replaced ObfuscationResult and SourceMapCorrector classes by ObfuscatedCode class
This commit is contained in:
+17
-19
@@ -5,13 +5,14 @@ import * as escodegen from 'escodegen-wallaby';
|
||||
import * as espree from 'espree';
|
||||
import * as ESTree from 'estree';
|
||||
|
||||
import { TObfuscatedCodeFactory } from './types/container/source-code/TObfuscatedCodeFactory';
|
||||
|
||||
import { IGeneratorOutput } from './interfaces/IGeneratorOutput';
|
||||
import { IJavaScriptObfuscator } from './interfaces/IJavaScriptObfsucator';
|
||||
import { ILogger } from './interfaces/logger/ILogger';
|
||||
import { IObfuscationResult } from './interfaces/IObfuscationResult';
|
||||
import { IObfuscatedCode } from './interfaces/source-code/IObfuscatedCode';
|
||||
import { IOptions } from './interfaces/options/IOptions';
|
||||
import { IRandomGenerator } from './interfaces/utils/IRandomGenerator';
|
||||
import { ISourceMapCorrector } from './interfaces/source-map/ISourceMapCorrector';
|
||||
import { ITransformersRunner } from './interfaces/node-transformers/ITransformersRunner';
|
||||
|
||||
import { LoggingMessage } from './enums/logger/LoggingMessage';
|
||||
@@ -79,6 +80,11 @@ export class JavaScriptObfuscator implements IJavaScriptObfuscator {
|
||||
*/
|
||||
private readonly logger: ILogger;
|
||||
|
||||
/**
|
||||
* @type {TObfuscatedCodeFactory}
|
||||
*/
|
||||
private readonly obfuscatedCodeFactory: TObfuscatedCodeFactory;
|
||||
|
||||
/**
|
||||
* @type {IOptions}
|
||||
*/
|
||||
@@ -89,11 +95,6 @@ export class JavaScriptObfuscator implements IJavaScriptObfuscator {
|
||||
*/
|
||||
private readonly randomGenerator: IRandomGenerator;
|
||||
|
||||
/**
|
||||
* @type {ISourceMapCorrector}
|
||||
*/
|
||||
private readonly sourceMapCorrector: ISourceMapCorrector;
|
||||
|
||||
/**
|
||||
* @type {ITransformersRunner}
|
||||
*/
|
||||
@@ -101,30 +102,30 @@ export class JavaScriptObfuscator implements IJavaScriptObfuscator {
|
||||
|
||||
/**
|
||||
* @param {ITransformersRunner} transformersRunner
|
||||
* @param {ISourceMapCorrector} sourceMapCorrector
|
||||
* @param {IRandomGenerator} randomGenerator
|
||||
* @param {TObfuscatedCodeFactory} obfuscatedCodeFactory
|
||||
* @param {ILogger} logger
|
||||
* @param {IOptions} options
|
||||
*/
|
||||
constructor (
|
||||
@inject(ServiceIdentifiers.ITransformersRunner) transformersRunner: ITransformersRunner,
|
||||
@inject(ServiceIdentifiers.ISourceMapCorrector) sourceMapCorrector: ISourceMapCorrector,
|
||||
@inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
|
||||
@inject(ServiceIdentifiers.Factory__IObfuscatedCode) obfuscatedCodeFactory: TObfuscatedCodeFactory,
|
||||
@inject(ServiceIdentifiers.ILogger) logger: ILogger,
|
||||
@inject(ServiceIdentifiers.IOptions) options: IOptions
|
||||
) {
|
||||
this.transformersRunner = transformersRunner;
|
||||
this.sourceMapCorrector = sourceMapCorrector;
|
||||
this.randomGenerator = randomGenerator;
|
||||
this.obfuscatedCodeFactory = obfuscatedCodeFactory;
|
||||
this.logger = logger;
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} sourceCode
|
||||
* @returns {IObfuscationResult}
|
||||
* @returns {IObfuscatedCode}
|
||||
*/
|
||||
public obfuscate (sourceCode: string): IObfuscationResult {
|
||||
public obfuscate (sourceCode: string): IObfuscatedCode {
|
||||
const timeStart: number = Date.now();
|
||||
this.logger.info(LoggingMessage.Version, process.env.VERSION);
|
||||
this.logger.info(LoggingMessage.ObfuscationStarted);
|
||||
@@ -142,7 +143,7 @@ export class JavaScriptObfuscator implements IJavaScriptObfuscator {
|
||||
const obfuscationTime: number = (Date.now() - timeStart) / 1000;
|
||||
this.logger.success(LoggingMessage.ObfuscationCompleted, obfuscationTime);
|
||||
|
||||
return this.getObfuscationResult(generatorOutput);
|
||||
return this.getObfuscatedCode(generatorOutput);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -215,13 +216,10 @@ export class JavaScriptObfuscator implements IJavaScriptObfuscator {
|
||||
|
||||
/**
|
||||
* @param {IGeneratorOutput} generatorOutput
|
||||
* @returns {IObfuscationResult}
|
||||
* @returns {IObfuscatedCode}
|
||||
*/
|
||||
private getObfuscationResult (generatorOutput: IGeneratorOutput): IObfuscationResult {
|
||||
return this.sourceMapCorrector.correct(
|
||||
generatorOutput.code,
|
||||
generatorOutput.map
|
||||
);
|
||||
private getObfuscatedCode (generatorOutput: IGeneratorOutput): IObfuscatedCode {
|
||||
return this.obfuscatedCodeFactory(generatorOutput.code, generatorOutput.map);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,7 +6,7 @@ import { TInputOptions } from './types/options/TInputOptions';
|
||||
|
||||
import { IInversifyContainerFacade } from './interfaces/container/IInversifyContainerFacade';
|
||||
import { IJavaScriptObfuscator } from './interfaces/IJavaScriptObfsucator';
|
||||
import { IObfuscationResult } from './interfaces/IObfuscationResult';
|
||||
import { IObfuscatedCode } from './interfaces/source-code/IObfuscatedCode';
|
||||
|
||||
import { InversifyContainerFacade } from './container/InversifyContainerFacade';
|
||||
|
||||
@@ -19,20 +19,20 @@ class JavaScriptObfuscatorFacade {
|
||||
/**
|
||||
* @param {string} sourceCode
|
||||
* @param {TInputOptions} inputOptions
|
||||
* @returns {IObfuscationResult}
|
||||
* @returns {IObfuscatedCode}
|
||||
*/
|
||||
public static obfuscate (sourceCode: string, inputOptions: TInputOptions = {}): IObfuscationResult {
|
||||
public static obfuscate (sourceCode: string, inputOptions: TInputOptions = {}): IObfuscatedCode {
|
||||
const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
|
||||
|
||||
inversifyContainerFacade.load(sourceCode, inputOptions);
|
||||
inversifyContainerFacade.load(sourceCode, '', inputOptions);
|
||||
|
||||
const javaScriptObfuscator: IJavaScriptObfuscator = inversifyContainerFacade
|
||||
.get<IJavaScriptObfuscator>(ServiceIdentifiers.IJavaScriptObfuscator);
|
||||
const obfuscationResult: IObfuscationResult = javaScriptObfuscator.obfuscate(sourceCode);
|
||||
const obfuscatedCode: IObfuscatedCode = javaScriptObfuscator.obfuscate(sourceCode);
|
||||
|
||||
inversifyContainerFacade.unload();
|
||||
|
||||
return obfuscationResult;
|
||||
return obfuscatedCode;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
import { injectable } from 'inversify';
|
||||
|
||||
import { IObfuscationResult } from './interfaces/IObfuscationResult';
|
||||
|
||||
import { initializable } from './decorators/Initializable';
|
||||
|
||||
@injectable()
|
||||
export class ObfuscationResult implements IObfuscationResult {
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
@initializable()
|
||||
private obfuscatedCode!: string;
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
@initializable()
|
||||
private sourceMap!: string;
|
||||
|
||||
/**
|
||||
* @param {string} obfuscatedCode
|
||||
* @param {string} sourceMap
|
||||
*/
|
||||
public initialize (obfuscatedCode: string, sourceMap: string): void {
|
||||
this.obfuscatedCode = obfuscatedCode;
|
||||
this.sourceMap = sourceMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
public getObfuscatedCode (): string {
|
||||
return this.obfuscatedCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
public getSourceMap (): string {
|
||||
return this.sourceMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
public toString (): string {
|
||||
return this.obfuscatedCode;
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
import { ISourceCode } from './interfaces/ISourceCode';
|
||||
|
||||
export class SourceCode implements ISourceCode {
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
private readonly sourceCode: string;
|
||||
|
||||
/**
|
||||
* @param {string} sourceCode
|
||||
*/
|
||||
constructor (sourceCode: string) {
|
||||
this.sourceCode = sourceCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
public getSourceCode (): string {
|
||||
return this.sourceCode;
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import { TSourceCodeData } from '../types/cli/TSourceCodeData';
|
||||
|
||||
import { IFileData } from '../interfaces/cli/IFileData';
|
||||
import { IInitializable } from '../interfaces/IInitializable';
|
||||
import { IObfuscationResult } from '../interfaces/IObfuscationResult';
|
||||
import { IObfuscatedCode } from '../interfaces/source-code/IObfuscatedCode';
|
||||
|
||||
import { initializable } from '../decorators/Initializable';
|
||||
|
||||
@@ -131,12 +131,12 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
|
||||
sourceMapFileName: path.basename(outputSourceMapPath)
|
||||
};
|
||||
|
||||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(sourceCode, options);
|
||||
const obfuscatedCode: IObfuscatedCode = JavaScriptObfuscator.obfuscate(sourceCode, options);
|
||||
|
||||
CLIUtils.writeFile(outputCodePath, obfuscationResult.getObfuscatedCode());
|
||||
CLIUtils.writeFile(outputCodePath, obfuscatedCode.getObfuscatedCode());
|
||||
|
||||
if (options.sourceMapMode === 'separate' && obfuscationResult.getSourceMap()) {
|
||||
CLIUtils.writeFile(outputSourceMapPath, obfuscationResult.getSourceMap());
|
||||
if (options.sourceMapMode === 'separate' && obfuscatedCode.getSourceMap()) {
|
||||
CLIUtils.writeFile(outputSourceMapPath, obfuscatedCode.getSourceMap());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,17 +20,15 @@ import { IInversifyContainerFacade } from '../interfaces/container/IInversifyCon
|
||||
import { IJavaScriptObfuscator } from '../interfaces/IJavaScriptObfsucator';
|
||||
import { ILogger } from '../interfaces/logger/ILogger';
|
||||
import { IObfuscationEventEmitter } from '../interfaces/event-emitters/IObfuscationEventEmitter';
|
||||
import { IObfuscationResult } from '../interfaces/IObfuscationResult';
|
||||
import { ISourceCode } from '../interfaces/ISourceCode';
|
||||
import { ISourceMapCorrector } from '../interfaces/source-map/ISourceMapCorrector';
|
||||
import { IObfuscatedCode } from '../interfaces/source-code/IObfuscatedCode';
|
||||
import { ISourceCode } from '../interfaces/source-code/ISourceCode';
|
||||
import { ITransformersRunner } from '../interfaces/node-transformers/ITransformersRunner';
|
||||
|
||||
import { JavaScriptObfuscator } from '../JavaScriptObfuscator';
|
||||
import { Logger } from '../logger/Logger';
|
||||
import { ObfuscationEventEmitter } from '../event-emitters/ObfuscationEventEmitter';
|
||||
import { ObfuscationResult } from '../ObfuscationResult';
|
||||
import { SourceCode } from '../SourceCode';
|
||||
import { SourceMapCorrector } from '../source-map/SourceMapCorrector';
|
||||
import { ObfuscatedCode } from '../source-code/ObfuscatedCode';
|
||||
import { SourceCode } from '../source-code/SourceCode';
|
||||
import { TransformersRunner } from '../node-transformers/TransformersRunner';
|
||||
|
||||
export class InversifyContainerFacade implements IInversifyContainerFacade {
|
||||
@@ -140,12 +138,13 @@ export class InversifyContainerFacade implements IInversifyContainerFacade {
|
||||
|
||||
/**
|
||||
* @param {string} sourceCode
|
||||
* @param {string} sourceMap
|
||||
* @param {TInputOptions} options
|
||||
*/
|
||||
public load (sourceCode: string, options: TInputOptions): void {
|
||||
public load (sourceCode: string, sourceMap: string, options: TInputOptions): void {
|
||||
this.container
|
||||
.bind<ISourceCode>(ServiceIdentifiers.ISourceCode)
|
||||
.toDynamicValue(() => new SourceCode(sourceCode))
|
||||
.toDynamicValue(() => new SourceCode(sourceCode, sourceMap))
|
||||
.inSingletonScope();
|
||||
|
||||
this.container
|
||||
@@ -169,28 +168,22 @@ export class InversifyContainerFacade implements IInversifyContainerFacade {
|
||||
.inSingletonScope();
|
||||
|
||||
this.container
|
||||
.bind<IObfuscationResult>(ServiceIdentifiers.IObfuscationResult)
|
||||
.to(ObfuscationResult)
|
||||
.inSingletonScope();
|
||||
.bind<IObfuscatedCode>(ServiceIdentifiers.IObfuscatedCode)
|
||||
.to(ObfuscatedCode);
|
||||
|
||||
this.container
|
||||
.bind<IObfuscationResult>(ServiceIdentifiers.Factory__IObfuscationResult)
|
||||
.toFactory<IObfuscationResult>((context: interfaces.Context) => {
|
||||
return (obfuscatedCode: string, sourceMap: string) => {
|
||||
const obfuscationResult: IObfuscationResult = context.container
|
||||
.get<IObfuscationResult>(ServiceIdentifiers.IObfuscationResult);
|
||||
.bind<IObfuscatedCode>(ServiceIdentifiers.Factory__IObfuscatedCode)
|
||||
.toFactory<IObfuscatedCode>((context: interfaces.Context) => {
|
||||
return (obfuscatedCodeAsString: string, sourceMapAsString: string) => {
|
||||
const obfuscatedCode: IObfuscatedCode = context.container
|
||||
.get<IObfuscatedCode>(ServiceIdentifiers.IObfuscatedCode);
|
||||
|
||||
obfuscationResult.initialize(obfuscatedCode, sourceMap);
|
||||
obfuscatedCode.initialize(obfuscatedCodeAsString, sourceMapAsString);
|
||||
|
||||
return obfuscationResult;
|
||||
return obfuscatedCode;
|
||||
};
|
||||
});
|
||||
|
||||
this.container
|
||||
.bind<ISourceMapCorrector>(ServiceIdentifiers.ISourceMapCorrector)
|
||||
.to(SourceMapCorrector)
|
||||
.inSingletonScope();
|
||||
|
||||
this.container
|
||||
.bind<IObfuscationEventEmitter>(ServiceIdentifiers.IObfuscationEventEmitter)
|
||||
.to(ObfuscationEventEmitter)
|
||||
|
||||
@@ -9,7 +9,7 @@ export enum ServiceIdentifiers {
|
||||
Factory__IIdentifierObfuscatingReplacer = 'Factory<IIdentifierObfuscatingReplacer>',
|
||||
Factory__INodeGuard = 'Factory<INodeGuard>',
|
||||
Factory__INodeTransformer = 'Factory<INodeTransformer[]>',
|
||||
Factory__IObfuscationResult = 'Factory<IObfuscationResult>',
|
||||
Factory__IObfuscatedCode = 'Factory<IObfuscatedCode>',
|
||||
Factory__IObfuscatingReplacer = 'Factory<IObfuscatingReplacer>',
|
||||
Factory__IPropertiesExtractor = 'Factory<IPropertiesExtractor>',
|
||||
Factory__TControlFlowStorage = 'Factory<TControlFlowStorage>',
|
||||
@@ -27,7 +27,7 @@ export enum ServiceIdentifiers {
|
||||
INodeGuard = 'INodeGuard',
|
||||
INodeTransformer = 'INodeTransformer',
|
||||
IObfuscationEventEmitter = 'IObfuscationEventEmitter',
|
||||
IObfuscationResult = 'IObfuscationResult',
|
||||
IObfuscatedCode = 'IObfuscatedCode',
|
||||
IOptions = 'IOptions',
|
||||
IOptionsNormalizer = 'IOptionsNormalizer',
|
||||
IObfuscatingReplacer = 'IObfuscatingReplacer',
|
||||
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
import { IObfuscationResult } from './IObfuscationResult';
|
||||
import { IObfuscatedCode } from './source-code/IObfuscatedCode';
|
||||
|
||||
export interface IJavaScriptObfuscator {
|
||||
/**
|
||||
* @param sourceCode
|
||||
* @returns IObfuscationResult
|
||||
* @returns IObfuscatedCode
|
||||
*/
|
||||
obfuscate (sourceCode: string): IObfuscationResult;
|
||||
obfuscate (sourceCode: string): IObfuscatedCode;
|
||||
}
|
||||
|
||||
+4
-3
@@ -15,10 +15,11 @@ export interface IInversifyContainerFacade {
|
||||
getNamed <T> (serviceIdentifier: interfaces.ServiceIdentifier<T>, named: string | number | symbol): T;
|
||||
|
||||
/**
|
||||
* @param sourceCode
|
||||
* @param options
|
||||
* @param {string} sourceCode
|
||||
* @param {string} sourceMap
|
||||
* @param {TInputOptions} options
|
||||
*/
|
||||
load (sourceCode: string, options: TInputOptions): void;
|
||||
load (sourceCode: string, sourceMap: string, options: TInputOptions): void;
|
||||
|
||||
unload (): void;
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
import { IInitializable } from './IInitializable';
|
||||
import { IInitializable } from '../IInitializable';
|
||||
|
||||
export interface IObfuscationResult extends IInitializable {
|
||||
export interface IObfuscatedCode extends IInitializable {
|
||||
/**
|
||||
* @return {string}
|
||||
*/
|
||||
@@ -3,4 +3,9 @@ export interface ISourceCode {
|
||||
* @returns string
|
||||
*/
|
||||
getSourceCode (): string;
|
||||
|
||||
/**
|
||||
* @returns string
|
||||
*/
|
||||
getSourceMap (): string;
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
import { IObfuscationResult } from '../IObfuscationResult';
|
||||
|
||||
export interface ISourceMapCorrector {
|
||||
/**
|
||||
* @param {string} obfuscatedCode
|
||||
* @param {string} sourceMap
|
||||
* @returns {IObfuscationResult}
|
||||
*/
|
||||
correct (obfuscatedCode: string, sourceMap: string): IObfuscationResult;
|
||||
}
|
||||
@@ -1,26 +1,25 @@
|
||||
import { inject, injectable } from 'inversify';
|
||||
import { ServiceIdentifiers } from '../container/ServiceIdentifiers';
|
||||
|
||||
import { TObfuscationResultFactory } from '../types/container/TObfuscationResultFactory';
|
||||
|
||||
import { ICryptUtils } from '../interfaces/utils/ICryptUtils';
|
||||
import { IObfuscationResult } from '../interfaces/IObfuscationResult';
|
||||
import { IOptions } from '../interfaces/options/IOptions';
|
||||
import { ISourceMapCorrector } from '../interfaces/source-map/ISourceMapCorrector';
|
||||
import { IObfuscatedCode } from '../interfaces/source-code/IObfuscatedCode';
|
||||
|
||||
import { initializable } from '../decorators/Initializable';
|
||||
import { SourceMapMode } from '../enums/source-map/SourceMapMode';
|
||||
import { IOptions } from '../interfaces/options/IOptions';
|
||||
|
||||
@injectable()
|
||||
export class SourceMapCorrector implements ISourceMapCorrector {
|
||||
export class ObfuscatedCode implements IObfuscatedCode {
|
||||
/**
|
||||
* @type {ICryptUtils}
|
||||
*/
|
||||
private readonly cryptUtils: ICryptUtils;
|
||||
|
||||
/**
|
||||
* @type {TObfuscationResultFactory}
|
||||
* @type {string}
|
||||
*/
|
||||
private readonly obfuscationResultFactory: TObfuscationResultFactory;
|
||||
@initializable()
|
||||
private obfuscatedCode!: string;
|
||||
|
||||
/**
|
||||
* @type {IOptions}
|
||||
@@ -28,16 +27,15 @@ export class SourceMapCorrector implements ISourceMapCorrector {
|
||||
private readonly options: IOptions;
|
||||
|
||||
/**
|
||||
* @param {TObfuscationResultFactory} obfuscationResultFactory
|
||||
* @param {ICryptUtils} cryptUtils
|
||||
* @param {IOptions} options
|
||||
* @type {string}
|
||||
*/
|
||||
@initializable()
|
||||
private sourceMap!: string;
|
||||
|
||||
constructor (
|
||||
@inject(ServiceIdentifiers.Factory__IObfuscationResult) obfuscationResultFactory: TObfuscationResultFactory,
|
||||
@inject(ServiceIdentifiers.ICryptUtils) cryptUtils: ICryptUtils,
|
||||
@inject(ServiceIdentifiers.IOptions) options: IOptions
|
||||
) {
|
||||
this.obfuscationResultFactory = obfuscationResultFactory;
|
||||
this.cryptUtils = cryptUtils;
|
||||
this.options = options;
|
||||
}
|
||||
@@ -45,23 +43,39 @@ export class SourceMapCorrector implements ISourceMapCorrector {
|
||||
/**
|
||||
* @param {string} obfuscatedCode
|
||||
* @param {string} sourceMap
|
||||
* @returns {IObfuscationResult}
|
||||
*/
|
||||
public correct (obfuscatedCode: string, sourceMap: string): IObfuscationResult {
|
||||
return this.obfuscationResultFactory(
|
||||
this.correctObfuscatedCode(obfuscatedCode, sourceMap),
|
||||
sourceMap
|
||||
);
|
||||
public initialize (obfuscatedCode: string, sourceMap: string): void {
|
||||
this.obfuscatedCode = obfuscatedCode;
|
||||
this.sourceMap = sourceMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} obfuscatedCode
|
||||
* @param {string} sourceMap
|
||||
* @returns {string}
|
||||
*/
|
||||
private correctObfuscatedCode (obfuscatedCode: string, sourceMap: string): string {
|
||||
if (!sourceMap) {
|
||||
return obfuscatedCode;
|
||||
public getObfuscatedCode (): string {
|
||||
return this.correctObfuscatedCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
public getSourceMap (): string {
|
||||
return this.sourceMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
public toString (): string {
|
||||
return this.obfuscatedCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
private correctObfuscatedCode (): string {
|
||||
if (!this.sourceMap) {
|
||||
return this.obfuscatedCode;
|
||||
}
|
||||
|
||||
const sourceMapUrl: string = this.options.sourceMapBaseUrl + this.options.sourceMapFileName;
|
||||
@@ -70,19 +84,19 @@ export class SourceMapCorrector implements ISourceMapCorrector {
|
||||
|
||||
switch (this.options.sourceMapMode) {
|
||||
case SourceMapMode.Inline:
|
||||
sourceMappingUrl += `data:application/json;base64,${this.cryptUtils.btoa(sourceMap)}`;
|
||||
sourceMappingUrl += `data:application/json;base64,${this.cryptUtils.btoa(this.sourceMap)}`;
|
||||
|
||||
break;
|
||||
|
||||
case SourceMapMode.Separate:
|
||||
default:
|
||||
if (!sourceMapUrl) {
|
||||
return obfuscatedCode;
|
||||
return this.obfuscatedCode;
|
||||
}
|
||||
|
||||
sourceMappingUrl += sourceMapUrl;
|
||||
}
|
||||
|
||||
return `${obfuscatedCode}\n${sourceMappingUrl}`;
|
||||
return `${this.obfuscatedCode}\n${sourceMappingUrl}`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { ISourceCode } from '../interfaces/source-code/ISourceCode';
|
||||
|
||||
export class SourceCode implements ISourceCode {
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
private readonly sourceCode: string;
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
private readonly sourceMap: string;
|
||||
|
||||
/**
|
||||
* @param {string} sourceCode
|
||||
* @param {string} sourceMap
|
||||
*/
|
||||
constructor (sourceCode: string, sourceMap: string) {
|
||||
this.sourceCode = sourceCode;
|
||||
this.sourceMap = sourceMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
public getSourceCode (): string {
|
||||
return this.sourceCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
public getSourceMap (): string {
|
||||
return this.sourceMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
public toString (): string {
|
||||
return this.sourceCode;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
import { IObfuscationResult } from '../../interfaces/IObfuscationResult';
|
||||
|
||||
export type TObfuscationResultFactory = (obfuscatedCode: string, sourceMap: string) => IObfuscationResult;
|
||||
@@ -0,0 +1,3 @@
|
||||
import { IObfuscatedCode } from '../../../interfaces/source-code/IObfuscatedCode';
|
||||
|
||||
export type TObfuscatedCodeFactory = (obfuscatedCode: string, sourceMap: string) => IObfuscatedCode;
|
||||
-1
@@ -1 +0,0 @@
|
||||
export type TSourceMapMode = 'inline' | 'separate';
|
||||
@@ -7,7 +7,7 @@ import { Chance } from 'chance';
|
||||
import { IInitializable } from '../interfaces/IInitializable';
|
||||
import { IOptions } from '../interfaces/options/IOptions';
|
||||
import { IRandomGenerator } from '../interfaces/utils/IRandomGenerator';
|
||||
import { ISourceCode } from '../interfaces/ISourceCode';
|
||||
import { ISourceCode } from '../interfaces/source-code/ISourceCode';
|
||||
|
||||
import { initializable } from '../decorators/Initializable';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user