added Utils static property with pool for random generator

This commit is contained in:
sanex3339
2016-11-22 20:22:43 +03:00
parent a8deef5056
commit 5bb5012185
5 changed files with 27 additions and 16 deletions
+10 -7
View File
@@ -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
View File
@@ -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 randomString: string = Utils.randomGenerator.string({length: length, pool: customPool}),
randomStringDiff: string = randomString.replace(
new RegExp('[' + escapeRegExp(str) + ']', 'g'),
''),
randomStringDiffArray: string[] = randomStringDiff.split('');
let randomStringDiff: string = randomString.replace(
new RegExp('[' + escapeRegExp(str) + ']', 'g'),
'');
const randomStringDiffArray: string[] = randomStringDiff.split('');
Utils.randomGenerator.shuffle(randomStringDiffArray);
randomStringDiff = randomStringDiffArray.join('');
+1 -1
View File
@@ -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;
}
@@ -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
});
}
@@ -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 = '';