浏览代码

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

sanex3339 8 年之前
父节点
当前提交
3062e761a2

+ 1 - 2
src/custom-nodes/string-array-nodes/group/StringArrayCustomNodeGroup.ts

@@ -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;
 

+ 2 - 2
src/node-transformers/node-obfuscators/replacers/StringLiteralReplacer.ts

@@ -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 - 0
src/utils/Utils.ts

@@ -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 - 0
test/unit-tests/utils/Utils.spec.ts

@@ -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}`;