Browse Source

added Utils static property with pool for random generator

sanex3339 8 years ago
parent
commit
5bb5012185

+ 10 - 7
dist/index.js

@@ -225,10 +225,12 @@ var Utils = function () {
                 }
                 return result;
             };
-            var customPool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
-            var randomString = Utils.randomGenerator.string({ length: length, pool: customPool }),
-                randomStringDiff = randomString.replace(new RegExp('[' + escapeRegExp(str) + ']', 'g'), ''),
-                randomStringDiffArray = randomStringDiff.split('');
+            var randomString = Utils.randomGenerator.string({
+                length: length,
+                pool: Utils.randomGeneratorPool
+            });
+            var randomStringDiff = randomString.replace(new RegExp('[' + escapeRegExp(str) + ']', 'g'), '');
+            var randomStringDiffArray = randomStringDiff.split('');
             Utils.randomGenerator.shuffle(randomStringDiffArray);
             randomStringDiff = randomStringDiffArray.join('');
             return [randomMerge(str, randomStringDiff), randomStringDiff];
@@ -340,6 +342,7 @@ var Utils = function () {
     return Utils;
 }();
 
+Utils.randomGeneratorPool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
 Utils.randomGenerator = new chance_1.Chance();
 exports.Utils = Utils;
 
@@ -1222,7 +1225,7 @@ var StringLiteralReplacer = function (_AbstractReplacer_1$A) {
         value: function replaceStringLiteralWithStringArrayCall(value) {
             var stringArrayNode = this.nodes.get('stringArrayNode');
             if (!stringArrayNode) {
-                throw new ReferenceError('`stringArrayNode` node is not found in Map with custom node.');
+                throw new ReferenceError('`stringArrayNode` node is not found in Map with custom nodes.');
             }
             var rc4Key = '';
             switch (this.options.stringArrayEncoding) {
@@ -3120,11 +3123,11 @@ var AbstractControlFlowReplacer = function () {
     }
 
     _createClass(AbstractControlFlowReplacer, null, [{
-        key: 'getStorageKey',
+        key: "getStorageKey",
         value: function getStorageKey() {
             return Utils_1.Utils.getRandomGenerator().string({
                 length: 3,
-                pool: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
+                pool: Utils_1.Utils.randomGeneratorPool
             });
         }
     }]);

+ 14 - 6
src/Utils.ts

@@ -5,6 +5,11 @@ import { JSFuck } from './enums/JSFuck';
 const isEqual = require('is-equal');
 
 export class Utils {
+    /**
+     * @type {string}
+     */
+    public static randomGeneratorPool: string = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
+
     /**
      * @type {Chance.Chance | Chance.SeededChance}
      */
@@ -180,13 +185,16 @@ export class Utils {
             return result;
         };
 
-        const customPool: string = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
+        const randomString: string = Utils.randomGenerator.string({
+            length: length,
+            pool: Utils.randomGeneratorPool
+        });
+
+        let randomStringDiff: string = randomString.replace(
+            new RegExp('[' + escapeRegExp(str) + ']', 'g'),
+        '');
 
-        let randomString: string = Utils.randomGenerator.string({length: length, pool: customPool}),
-            randomStringDiff: string = randomString.replace(
-                new RegExp('[' + escapeRegExp(str) + ']', 'g'),
-            ''),
-            randomStringDiffArray: string[] = randomStringDiff.split('');
+        const randomStringDiffArray: string[] = randomStringDiff.split('');
 
         Utils.randomGenerator.shuffle(randomStringDiffArray);
         randomStringDiff = randomStringDiffArray.join('');

+ 1 - 1
src/interfaces/IStorage.d.ts

@@ -2,7 +2,7 @@ export interface IStorage <T> {
     get (key: string | number): T;
     getKeyOf (value: T): string | number | null;
     getLength (): number;
-    getStorage (): Map <string | number, T> | T[];
+    getStorage (): any;
     set (key: string | number | null, value: T): void;
     toString (): string;
 }

+ 1 - 1
src/node-transformers/node-control-flow-transformers/control-flow-replacers/AbstractControlFlowReplacer.ts

@@ -33,7 +33,7 @@ export abstract class AbstractControlFlowReplacer implements IControlFlowReplace
     protected static getStorageKey (): string {
         return Utils.getRandomGenerator().string({
             length: 3,
-            pool: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
+            pool: Utils.randomGeneratorPool
         });
     }
 

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

@@ -45,7 +45,7 @@ export class StringLiteralReplacer extends AbstractReplacer {
         const stringArrayNode: ICustomNodeWithData = <ICustomNodeWithData>this.nodes.get('stringArrayNode');
 
         if (!stringArrayNode) {
-            throw new ReferenceError('`stringArrayNode` node is not found in Map with custom node.');
+            throw new ReferenceError('`stringArrayNode` node is not found in Map with custom nodes.');
         }
 
         let rc4Key: string = '';