Changed random identifiers prefix length to 6 characters

This commit is contained in:
sanex3339
2018-01-19 22:40:59 +03:00
parent 6de55d27f3
commit e4f9c100f8
11 changed files with 35 additions and 31 deletions
+2 -2
View File
@@ -573,9 +573,9 @@ Available values:
* `mangled`: short identifier names like `a`, `b`, `c`
### `identifiersPrefix`
Type: `string|boolean` Default: `false`
Type: `string` Default: `''`
Sets prefix for all generated identifiers. If prefix sets to `true` - random prefix will generated. If prefix sets to `false` or empty string - prefix won't generated.
Sets prefix for all generated identifiers. If prefix sets to `true` - random prefix with length of 6 characters will generated. If prefix sets to `false` or empty string - prefix won't generated.
Use this option when you want to obfuscate multiple files. This option helps to avoid conflicts between identifiers of these files. Prefix should be different for every file.
+1 -1
View File
File diff suppressed because one or more lines are too long
+4 -4
View File
@@ -23,7 +23,7 @@
"chance": "1.0.13",
"class-validator": "0.7.3",
"commander": "2.13.0",
"escodegen-wallaby": "1.6.16",
"escodegen-wallaby": "1.6.17",
"esprima": "4.0.0",
"estraverse": "4.2.0",
"inversify": "4.9.0",
@@ -33,9 +33,9 @@
"opencollective": "1.0.3",
"pjson": "1.0.9",
"reflect-metadata": "0.1.12",
"source-map-support": "0.5.1",
"source-map-support": "0.5.2",
"string-template": "1.0.0",
"tslib": "1.8.1"
"tslib": "1.9.0"
},
"devDependencies": {
"@types/chai": "4.1.1",
@@ -64,7 +64,7 @@
"pre-commit": "1.2.2",
"rimraf": "2.6.2",
"sinon": "4.1.6",
"threads": "0.10.0",
"threads": "0.10.1",
"ts-node": "4.1.0",
"tslint": "5.9.1",
"tslint-eslint-rules": "4.1.1",
@@ -34,7 +34,7 @@ export abstract class AbstractIdentifierNamesGenerator implements IIdentifierNam
this.options = options;
this.identifiersPrefix = this.options.identifiersPrefix === true
? this.randomGenerator.getRandomString(3)
? this.randomGenerator.getRandomString(6)
: this.options.identifiersPrefix || '';
}
@@ -103,7 +103,7 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene
*/
public generate (length: number): string {
const prefix: string = this.options.identifiersPrefix ?
`${this.options.identifiersPrefix}_`
`${this.identifiersPrefix}_`
: '';
const newName: string = MangledIdentifierNamesGenerator.generateNewMangledName(this.previousMangledName);
@@ -86,10 +86,10 @@ export class ClassDeclarationTransformer extends AbstractNodeTransformer {
*/
public transformNode (classDeclarationNode: ESTree.ClassDeclaration, parentNode: ESTree.Node): ESTree.Node {
const nodeIdentifier: number = this.nodeIdentifier++;
const blockScopeNode: TNodeWithBlockScope = NodeUtils
.getBlockScopesOfNode(classDeclarationNode)[0];
const blockScopeNode: TNodeWithBlockScope = NodeUtils.getBlockScopesOfNode(classDeclarationNode)[0];
const isGlobalDeclaration: boolean = blockScopeNode.type === NodeType.Program;
if (!this.options.renameGlobals && blockScopeNode.type === NodeType.Program) {
if (!this.options.renameGlobals && isGlobalDeclaration) {
return classDeclarationNode;
}
@@ -88,10 +88,10 @@ export class FunctionDeclarationTransformer extends AbstractNodeTransformer {
*/
public transformNode (functionDeclarationNode: ESTree.FunctionDeclaration, parentNode: ESTree.Node): ESTree.Node {
const nodeIdentifier: number = this.nodeIdentifier++;
const blockScopeNode: TNodeWithBlockScope = NodeUtils
.getBlockScopesOfNode(functionDeclarationNode)[0];
const blockScopeNode: TNodeWithBlockScope = NodeUtils.getBlockScopesOfNode(functionDeclarationNode)[0];
const isGlobalDeclaration: boolean = blockScopeNode.type === NodeType.Program;
if (!this.options.renameGlobals && blockScopeNode.type === NodeType.Program) {
if (!this.options.renameGlobals && isGlobalDeclaration) {
return functionDeclarationNode;
}
@@ -88,10 +88,10 @@ export class VariableDeclarationTransformer extends AbstractNodeTransformer {
* @returns {NodeGuards}
*/
public transformNode (variableDeclarationNode: ESTree.VariableDeclaration, parentNode: ESTree.Node): ESTree.Node {
const blockScopeNode: TNodeWithBlockScope = NodeUtils
.getBlockScopesOfNode(variableDeclarationNode)[0];
const blockScopeNode: TNodeWithBlockScope = NodeUtils.getBlockScopesOfNode(variableDeclarationNode)[0];
const isGlobalDeclaration: boolean = blockScopeNode.type === NodeType.Program;
if (!this.options.renameGlobals && blockScopeNode.type === NodeType.Program) {
if (!this.options.renameGlobals && isGlobalDeclaration) {
return variableDeclarationNode;
}
@@ -77,7 +77,7 @@ describe('HexadecimalIdentifierNamesGenerator', () => {
});
describe('Hexadecimal name with random prefix', () => {
const regExp: RegExp = /^(\w){3}_0x(\w){4,6}$/;
const regExp: RegExp = /^(\w){6}_0x(\w){4,6}$/;
let identifierNamesGenerator: IIdentifierNamesGenerator,
hexadecimalIdentifierName: string;
@@ -188,7 +188,7 @@ describe('MangledIdentifierNamesGenerator', () => {
});
describe('variant #1: initial mangled name', () => {
const expectedMangledIdentifierNameRegExp: RegExp = /(?:\w){3}_a/;
const expectedMangledIdentifierNameRegExp: RegExp = /(\w){6}_a/;
beforeEach(() => {
mangledIdentifierName = identifierNamesGenerator.generate(4);
@@ -200,7 +200,7 @@ describe('MangledIdentifierNamesGenerator', () => {
});
describe('variant #2: second mangled name', () => {
const expectedMangledIdentifierNameRegExp: RegExp = /(?:\w){3}_b/;
const expectedMangledIdentifierNameRegExp: RegExp = /(\w){6}_b/;
beforeEach(() => {
mangledIdentifierName = identifierNamesGenerator.generate(4);
+14 -10
View File
@@ -1446,9 +1446,9 @@ escape-string-regexp@1.0.5, escape-string-regexp@^1.0.2, escape-string-regexp@^1
version "1.0.5"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
escodegen-wallaby@1.6.16:
version "1.6.16"
resolved "https://registry.yarnpkg.com/escodegen-wallaby/-/escodegen-wallaby-1.6.16.tgz#f55b65d1a846d98584f1be18a2bf463f96280527"
escodegen-wallaby@1.6.17:
version "1.6.17"
resolved "https://registry.yarnpkg.com/escodegen-wallaby/-/escodegen-wallaby-1.6.17.tgz#3e1f334884d4214c94309cf734ec7cfa0b3d438d"
dependencies:
esprima "^2.7.1"
estraverse "^1.9.1"
@@ -3392,9 +3392,9 @@ source-map-resolve@^0.5.0:
source-map-url "^0.4.0"
urix "^0.1.0"
source-map-support@0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.1.tgz#72291517d1fd0cb9542cee6c27520884b5da1a07"
source-map-support@0.5.2:
version "0.5.2"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.2.tgz#1a6297fd5b2e762b39688c7fc91233b60984f0a5"
dependencies:
source-map "^0.6.0"
@@ -3623,9 +3623,9 @@ text-encoding@^0.6.4:
version "0.6.4"
resolved "https://registry.yarnpkg.com/text-encoding/-/text-encoding-0.6.4.tgz#e399a982257a276dae428bb92845cb71bdc26d19"
threads@0.10.0:
version "0.10.0"
resolved "https://registry.yarnpkg.com/threads/-/threads-0.10.0.tgz#a6b0bc5d916fa75434b166c612769684b65fead5"
threads@0.10.1:
version "0.10.1"
resolved "https://registry.yarnpkg.com/threads/-/threads-0.10.1.tgz#637765dc434ab3373d3c14754c8f7ac6515d6815"
dependencies:
eventemitter3 "^2.0.2"
native-promise-only "^0.8.1"
@@ -3709,7 +3709,11 @@ tsconfig@^7.0.0:
strip-bom "^3.0.0"
strip-json-comments "^2.0.0"
tslib@1.8.1, tslib@^1.0.0, tslib@^1.7.1, tslib@^1.8.0:
tslib@1.9.0:
version "1.9.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.0.tgz#e37a86fda8cbbaf23a057f473c9f4dc64e5fc2e8"
tslib@^1.0.0, tslib@^1.7.1, tslib@^1.8.0:
version "1.8.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.8.1.tgz#6946af2d1d651a7b1863b531d6e5afa41aa44eac"