fixed error when string array variable name and string array calls wrapper name was the same

This commit is contained in:
sanex3339
2016-12-18 18:36:55 +03:00
parent da91543f74
commit 3062e761a2
4 changed files with 34 additions and 4 deletions
@@ -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) {
+9
View File
@@ -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}
+22
View File
@@ -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}`;