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:
@@ -1,5 +1,9 @@
|
||||
Change Log
|
||||
|
||||
v0.27.2
|
||||
---
|
||||
* Fixed identifiers prefix generation for `obfuscateMultiple` method
|
||||
|
||||
v0.27.1
|
||||
---
|
||||
* Dependencies update, fixed https://www.npmjs.com/advisories/1488
|
||||
|
||||
Vendored
+4
-4
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "javascript-obfuscator",
|
||||
"version": "0.27.1",
|
||||
"version": "0.27.2",
|
||||
"description": "JavaScript obfuscator",
|
||||
"keywords": [
|
||||
"obfuscator",
|
||||
|
||||
@@ -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}`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -903,8 +903,8 @@ describe('JavaScriptObfuscator', () => {
|
||||
|
||||
describe('obfuscateMultiple', () => {
|
||||
describe('multiple source codes', () => {
|
||||
const regExp1: RegExp = /var _0x(\w){4,6} *= *0x1;/;
|
||||
const regExp2: RegExp = /var _0x(\w){4,6} *= *'abc';/;
|
||||
const regExp1: RegExp = /var a0_0x(\w){4,6} *= *0x1;/;
|
||||
const regExp2: RegExp = /var a1_0x(\w){4,6} *= *'abc';/;
|
||||
|
||||
let obfuscatedCode1: string;
|
||||
let obfuscatedCode2: string;
|
||||
|
||||
@@ -123,4 +123,40 @@ describe('Utils', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('getIdentifiersPrefixForMultipleSources', () => {
|
||||
describe('Variant #1: should get identifiers prefix for identifiers prefix from options', () => {
|
||||
const expectedIdentifiersPrefix: string = 'foo1';
|
||||
|
||||
let identifiersPrefix: string;
|
||||
|
||||
before(() => {
|
||||
identifiersPrefix = Utils.getIdentifiersPrefixForMultipleSources(
|
||||
'foo',
|
||||
1
|
||||
);
|
||||
});
|
||||
|
||||
it('should return correct identifiers prefix', () => {
|
||||
assert.equal(identifiersPrefix, expectedIdentifiersPrefix);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #2: should get identifiers prefix for base identifiers prefix for multiple sources', () => {
|
||||
const expectedIdentifiersPrefix: string = 'a1';
|
||||
|
||||
let identifiersPrefix: string;
|
||||
|
||||
before(() => {
|
||||
identifiersPrefix = Utils.getIdentifiersPrefixForMultipleSources(
|
||||
undefined,
|
||||
1
|
||||
);
|
||||
});
|
||||
|
||||
it('should return correct identifiers prefix', () => {
|
||||
assert.equal(identifiersPrefix, expectedIdentifiersPrefix);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user