mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
fixed error when string array variable name and string array calls wrapper name was the same
This commit is contained in:
@@ -106,10 +106,9 @@ export class StringArrayCustomNodeGroup extends AbstractCustomNodeGroup {
|
||||
const stringArrayRotateFunctionNode: ICustomNode = this.customNodeFactory(CustomNodes.StringArrayRotateFunctionNode);
|
||||
|
||||
const stringArrayStorageId: string = this.stringArrayStorage.getStorageId();
|
||||
const reversedStorageId = Array.from(stringArrayStorageId).reverse().join('');
|
||||
|
||||
const stringArrayName: string = `_${Utils.hexadecimalPrefix}${stringArrayStorageId}`;
|
||||
const stringArrayCallsWrapperName: string = `_${Utils.hexadecimalPrefix}${reversedStorageId}a`;
|
||||
const stringArrayCallsWrapperName: string = `_${Utils.hexadecimalPrefix}${Utils.stringRotate(stringArrayStorageId, 2)}`;
|
||||
|
||||
let stringArrayRotateValue: number;
|
||||
|
||||
|
||||
@@ -103,8 +103,8 @@ export class StringLiteralReplacer extends AbstractReplacer {
|
||||
this.stringArrayStorage.set(null, value);
|
||||
}
|
||||
|
||||
const reversedStringArrayId: string = Array.from(this.stringArrayStorage.getStorageId()).reverse().join('');
|
||||
const stringArrayStorageCallsWrapperName: string = `_${Utils.hexadecimalPrefix}${reversedStringArrayId}a`;
|
||||
const rotatedStringArrayStorageId: string = Utils.stringRotate(this.stringArrayStorage.getStorageId(), 2);
|
||||
const stringArrayStorageCallsWrapperName: string = `_${Utils.hexadecimalPrefix}${rotatedStringArrayStorageId}`;
|
||||
const hexadecimalIndex: string = `${Utils.hexadecimalPrefix}${Utils.decToHex(indexOfValue)}`;
|
||||
|
||||
if (this.options.stringArrayEncoding === StringArrayEncoding.rc4) {
|
||||
|
||||
@@ -92,6 +92,15 @@ export class Utils {
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @param times
|
||||
* @returns {string}
|
||||
*/
|
||||
public static stringRotate (string: string, times: number): string {
|
||||
return Utils.arrayRotate(Array.from(string), times).join('');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string
|
||||
* @returns {string}
|
||||
|
||||
@@ -81,6 +81,28 @@ describe('Utils', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('stringRotate (string: string, times: number): string', () => {
|
||||
let string: string;
|
||||
|
||||
beforeEach(() => {
|
||||
string = 'abcdefg';
|
||||
});
|
||||
|
||||
it('should rotate string by a given value', () => {
|
||||
assert.deepEqual(Utils.stringRotate(string, 2), 'fgabcde');
|
||||
});
|
||||
|
||||
|
||||
it('should do nothing if value <= 0', () => {
|
||||
assert.deepEqual(Utils.stringRotate(string, 0), 'abcdefg');
|
||||
assert.deepEqual(Utils.stringRotate(string, -1), 'abcdefg');
|
||||
});
|
||||
|
||||
it('should throw exception if string is empty', () => {
|
||||
assert.throws(() => Utils.stringRotate('', 5), ReferenceError);
|
||||
});
|
||||
});
|
||||
|
||||
describe('stringToJSFuck (string: string): string', () => {
|
||||
let expected: string = `${JSFuck.s} + ${JSFuck.t} + ${JSFuck.r} + ${JSFuck.i} + ${JSFuck.n} + ${JSFuck.g}`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user