mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
String array now stored as a function to make self defending possible
This commit is contained in:
@@ -33,6 +33,12 @@ export class StringArrayCodeHelper extends AbstractCustomCodeHelper {
|
||||
@initializable()
|
||||
private stringArrayName!: string;
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
@initializable()
|
||||
private stringArrayFunctionName!: string;
|
||||
|
||||
/**
|
||||
* @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
|
||||
* @param {ICustomCodeHelperFormatter} customCodeHelperFormatter
|
||||
@@ -59,13 +65,16 @@ export class StringArrayCodeHelper extends AbstractCustomCodeHelper {
|
||||
|
||||
/**
|
||||
* @param {IStringArrayStorage} stringArrayStorage
|
||||
* @param {string} stringArrayFunctionName
|
||||
* @param {string} stringArrayName
|
||||
*/
|
||||
public initialize (
|
||||
stringArrayStorage: IStringArrayStorage,
|
||||
stringArrayFunctionName: string,
|
||||
stringArrayName: string
|
||||
): void {
|
||||
this.stringArrayStorage = stringArrayStorage;
|
||||
this.stringArrayFunctionName = stringArrayFunctionName;
|
||||
this.stringArrayName = stringArrayName;
|
||||
}
|
||||
|
||||
@@ -83,6 +92,7 @@ export class StringArrayCodeHelper extends AbstractCustomCodeHelper {
|
||||
protected override getCodeHelperTemplate (): string {
|
||||
return this.customCodeHelperFormatter.formatTemplate(StringArrayTemplate(), {
|
||||
stringArrayName: this.stringArrayName,
|
||||
stringArrayFunctionName: this.stringArrayFunctionName,
|
||||
stringArrayStorageItems: this.getEncodedStringArrayStorageItems()
|
||||
});
|
||||
}
|
||||
|
||||
@@ -122,9 +122,14 @@ export class StringArrayCodeHelperGroup extends AbstractCustomCodeHelperGroup {
|
||||
// stringArray helper initialize
|
||||
const stringArrayCodeHelper: ICustomCodeHelper<TInitialData<StringArrayCodeHelper>> =
|
||||
this.customCodeHelperFactory(CustomCodeHelper.StringArray);
|
||||
const stringArrayFunctionName: string = this.stringArrayStorage.getStorageFunctionName();
|
||||
const stringArrayName: string = this.stringArrayStorage.getStorageName();
|
||||
|
||||
stringArrayCodeHelper.initialize(this.stringArrayStorage, stringArrayName);
|
||||
stringArrayCodeHelper.initialize(
|
||||
this.stringArrayStorage,
|
||||
stringArrayFunctionName,
|
||||
stringArrayName
|
||||
);
|
||||
this.customCodeHelpers.set(CustomCodeHelper.StringArray, stringArrayCodeHelper);
|
||||
|
||||
// stringArrayCallsWrapper helper initialize
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
*/
|
||||
export function StringArrayTemplate (): string {
|
||||
return `
|
||||
const {stringArrayName} = [{stringArrayStorageItems}];
|
||||
const {stringArrayFunctionName} = function () {
|
||||
return [{stringArrayStorageItems}];
|
||||
};
|
||||
|
||||
const {stringArrayName} = {stringArrayFunctionName}();
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,11 @@ export interface IStringArrayStorage extends IMapStorage <string, IStringArraySt
|
||||
*/
|
||||
getStorageName (): string;
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
getStorageFunctionName (): string;
|
||||
|
||||
/**
|
||||
* @param {TStringArrayEncoding | null} stringArrayEncoding
|
||||
* @returns {string}
|
||||
|
||||
@@ -89,6 +89,11 @@ export class StringArrayStorage extends MapStorage <`${string}-${TStringArrayEnc
|
||||
*/
|
||||
private rotationAmount: number = 0;
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
private storageFunctionName!: string;
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
@@ -168,13 +173,6 @@ export class StringArrayStorage extends MapStorage <`${string}-${TStringArrayEnc
|
||||
return this.rotationAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
public getStorageName (): string {
|
||||
return this.getStorageId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
@@ -187,6 +185,25 @@ export class StringArrayStorage extends MapStorage <`${string}-${TStringArrayEnc
|
||||
return this.stringArrayStorageName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
public getStorageName (): string {
|
||||
return this.getStorageId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
public getStorageFunctionName (): string {
|
||||
if (!this.storageFunctionName) {
|
||||
this.storageFunctionName = this.identifierNamesGenerator
|
||||
.generateForGlobalScope(StringArrayStorage.stringArrayNameLength);
|
||||
}
|
||||
|
||||
return this.storageFunctionName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {TStringArrayEncoding | null} stringArrayEncoding
|
||||
* @returns {IStringArrayCallsWrapperNames}
|
||||
|
||||
+5
-2
@@ -30,9 +30,12 @@ import { NO_ADDITIONAL_NODES_PRESET } from '../../src/options/presets/NoCustomNo
|
||||
`,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
compact: false,
|
||||
identifierNamesGenerator: 'mangled',
|
||||
rotateStringArray: true,
|
||||
selfDefending: true,
|
||||
stringArray: true,
|
||||
stringArrayThreshold: 1,
|
||||
selfDefending: true
|
||||
stringArrayThreshold: 1
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user