mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Fixed identifiers prefix generation for obfuscateMultiple method
This commit is contained in:
@@ -11,6 +11,7 @@ import { IJavaScriptObfuscator } from './interfaces/IJavaScriptObfsucator';
|
||||
import { IObfuscatedCode } from './interfaces/source-code/IObfuscatedCode';
|
||||
|
||||
import { InversifyContainerFacade } from './container/InversifyContainerFacade';
|
||||
import { Utils } from './utils/Utils';
|
||||
|
||||
class JavaScriptObfuscatorFacade {
|
||||
/**
|
||||
@@ -53,12 +54,25 @@ class JavaScriptObfuscatorFacade {
|
||||
return Object
|
||||
.keys(sourceCodesObject)
|
||||
.reduce(
|
||||
(acc: TObfuscationResultsObject<TSourceCodesObject>, sourceCodeIdentifier: keyof TSourceCodesObject) => {
|
||||
(
|
||||
acc: TObfuscationResultsObject<TSourceCodesObject>,
|
||||
sourceCodeIdentifier: keyof TSourceCodesObject,
|
||||
index: number
|
||||
) => {
|
||||
const identifiersPrefix: string = Utils.getIdentifiersPrefixForMultipleSources(
|
||||
inputOptions.identifiersPrefix,
|
||||
index
|
||||
);
|
||||
|
||||
const sourceCode: string = sourceCodesObject[sourceCodeIdentifier];
|
||||
const sourceCodeOptions: TInputOptions = {
|
||||
...inputOptions,
|
||||
identifiersPrefix
|
||||
};
|
||||
|
||||
return {
|
||||
...acc,
|
||||
[sourceCodeIdentifier]: JavaScriptObfuscatorFacade.obfuscate(sourceCode, inputOptions)
|
||||
[sourceCodeIdentifier]: JavaScriptObfuscatorFacade.obfuscate(sourceCode, sourceCodeOptions)
|
||||
};
|
||||
},
|
||||
<TObfuscationResultsObject<TSourceCodesObject>>{}
|
||||
|
||||
@@ -46,11 +46,6 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
|
||||
*/
|
||||
public static readonly obfuscatedFilePrefix: string = '-obfuscated';
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
private static readonly baseIdentifiersPrefix: string = 'a';
|
||||
|
||||
/**
|
||||
* @type {string[]}
|
||||
*/
|
||||
@@ -413,9 +408,10 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
|
||||
);
|
||||
|
||||
if (sourceCodeIndex !== null) {
|
||||
const baseIdentifiersPrefix: string = this.inputCLIOptions.identifiersPrefix
|
||||
?? JavaScriptObfuscatorCLI.baseIdentifiersPrefix;
|
||||
const identifiersPrefix: string = `${baseIdentifiersPrefix}${sourceCodeIndex}`;
|
||||
const identifiersPrefix: string = Utils.getIdentifiersPrefixForMultipleSources(
|
||||
this.inputCLIOptions.identifiersPrefix,
|
||||
sourceCodeIndex
|
||||
);
|
||||
|
||||
options = {
|
||||
...options,
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
export class Utils {
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
public static readonly baseMultipleSourcesIdentifiersPrefix: string = 'a';
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
@@ -36,4 +41,20 @@ export class Utils {
|
||||
|
||||
return domain;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string | undefined} identifiersPrefix
|
||||
* @param {number} sourceCodeIndex
|
||||
* @returns {string}
|
||||
*/
|
||||
public static getIdentifiersPrefixForMultipleSources (
|
||||
identifiersPrefix: string | undefined,
|
||||
sourceCodeIndex: number
|
||||
): string {
|
||||
const baseIdentifiersPrefix: string = !!identifiersPrefix
|
||||
? identifiersPrefix
|
||||
: Utils.baseMultipleSourcesIdentifiersPrefix;
|
||||
|
||||
return `${baseIdentifiersPrefix}${sourceCodeIndex}`;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user