Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Change Log

v0.25.3
---
* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/568

v0.25.2
---
* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/563
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,13 @@ For example:

Kind of variables of inserted nodes will auto-detected, based on most prevailing kind of variables of source code.

## Conflicts of identifier names between different files

During obfuscation of the different files, the same names can be generated for the global identifiers between these files.
To prevent this set the unique prefix for all global identifiers for each obfuscated file with [`identifiersPrefix`](#identifiersPrefix) option.

When using CLI this prefix will be added automatically.

## Antiviruses false positive virus alerts

Some input source code that will obfuscated with some obfuscation options can trigger false positive alerts in a few antiviruses. If you will get this false positive triggers, try to play with obfuscation options.
Expand Down
6 changes: 3 additions & 3 deletions dist/index.browser.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.cli.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "javascript-obfuscator",
"version": "0.25.2",
"version": "0.25.3",
"description": "JavaScript obfuscator",
"keywords": [
"obfuscator",
Expand All @@ -23,7 +23,7 @@
"dependencies": {
"@gradecam/tsenum": "1.2.0",
"@nuxtjs/opencollective": "0.2.2",
"acorn": "7.1.0",
"acorn": "7.1.1",
"acorn-import-meta": "1.0.0",
"chalk": "3.0.0",
"chance": "1.1.4",
Expand All @@ -45,28 +45,28 @@
"tslib": "1.11.1"
},
"devDependencies": {
"@types/chai": "4.2.9",
"@types/chai": "4.2.10",
"@types/chance": "1.0.8",
"@types/escodegen": "0.0.6",
"@types/eslint-scope": "3.7.0",
"@types/estraverse": "0.0.6",
"@types/estree": "0.0.42",
"@types/md5": "2.1.33",
"@types/mkdirp": "1.0.0",
"@types/mocha": "7.0.1",
"@types/mocha": "7.0.2",
"@types/multimatch": "4.0.0",
"@types/node": "12.12.14",
"@types/rimraf": "2.0.3",
"@types/sinon": "7.5.2",
"@types/string-template": "1.0.2",
"@types/webpack-env": "1.15.1",
"@typescript-eslint/eslint-plugin": "2.21.0",
"@typescript-eslint/parser": "2.21.0",
"@typescript-eslint/eslint-plugin": "2.22.0",
"@typescript-eslint/parser": "2.22.0",
"chai": "4.2.0",
"coveralls": "3.0.9",
"eslint": "6.8.0",
"eslint-plugin-import": "2.20.1",
"eslint-plugin-jsdoc": "21.0.0",
"eslint-plugin-jsdoc": "22.0.0",
"eslint-plugin-no-null": "1.0.2",
"eslint-plugin-prefer-arrow": "1.1.7",
"eslint-plugin-unicorn": "16.1.1",
Expand All @@ -81,8 +81,8 @@
"threads": "1.3.0",
"ts-loader": "6.2.1",
"ts-node": "6.1.0",
"typescript": "3.8.2",
"webpack": "4.41.6",
"typescript": "3.8.3",
"webpack": "4.42.0",
"webpack-cli": "3.3.11",
"webpack-node-externals": "1.7.2"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ export class DomainLockCustomCodeHelperGroup extends AbstractCustomCodeHelperGro
const domainLockFunctionName: string = domainLockFunctionLexicalScopeNode
&& NodeGuards.isProgramNode(domainLockFunctionLexicalScopeNode)
? this.identifierNamesGenerator.generate(domainLockFunctionLexicalScopeNode)
: this.randomGenerator.getRandomString(5);
: this.identifierNamesGenerator.generateNext();
const callsControllerFunctionName: string = domainLockFunctionLexicalScopeNode
&& NodeGuards.isProgramNode(domainLockFunctionLexicalScopeNode)
? this.identifierNamesGenerator.generate(domainLockFunctionLexicalScopeNode)
: this.randomGenerator.getRandomString(5);
: this.identifierNamesGenerator.generateNext();

// domainLock helper nodes append
this.appendCustomNodeIfExist(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ export class SelfDefendingCodeHelperGroup extends AbstractCustomCodeHelperGroup

const selfDefendingFunctionName: string = selfDefendingFunctionLexicalScopeNode
? this.identifierNamesGenerator.generate(selfDefendingFunctionLexicalScopeNode)
: this.identifierNamesGenerator.generateForGlobalScope();
: this.identifierNamesGenerator.generateNext();
const callsControllerFunctionName: string = selfDefendingFunctionLexicalScopeNode
? this.identifierNamesGenerator.generate(selfDefendingFunctionLexicalScopeNode)
: this.identifierNamesGenerator.generateForGlobalScope();
: this.identifierNamesGenerator.generateNext();

// selfDefendingUnicode helper nodes append
this.appendCustomNodeIfExist(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ export class StringArrayRotateFunctionCodeHelper extends AbstractCustomCodeHelpe
* @returns {string}
*/
protected getCodeHelperTemplate (): string {
const timesName: string = this.identifierNamesGenerator.generateForGlobalScope();
const whileFunctionName: string = this.identifierNamesGenerator.generateForGlobalScope();
const timesName: string = this.identifierNamesGenerator.generateNext();
const whileFunctionName: string = this.identifierNamesGenerator.generateNext();
const preservedNames: string[] = [`^${this.stringArrayName}$`];

let code: string = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,5 @@ export abstract class AbstractIdentifierNamesGenerator implements IIdentifierNam
* @param {number} nameLength
* @returns {string}
*/
public abstract generateWithPrefix (nameLength?: number): string;
public abstract generateNext (nameLength?: number): string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class DictionaryIdentifierNamesGenerator extends AbstractIdentifierNamesG
return null;
}

public generateForGlobalScope (): string {
public generateNext (): string {
const identifierName: string = this.generateNewDictionaryName();

this.preserveName(identifierName);
Expand All @@ -78,42 +78,42 @@ export class DictionaryIdentifierNamesGenerator extends AbstractIdentifierNamesG
}

/**
* @param {TNodeWithLexicalScope} lexicalScopeNode
* @returns {string}
*/
public generateForLexicalScope (lexicalScopeNode: TNodeWithLexicalScope): string {
const lexicalScopes: TNodeWithLexicalScope[] = [
lexicalScopeNode,
...NodeLexicalScopeUtils.getLexicalScopes(lexicalScopeNode)
];
public generateForGlobalScope (): string {
const prefix: string = this.options.identifiersPrefix ?
`${this.options.identifiersPrefix}`
: '';
const identifierName: string = this.generateNewDictionaryName();
const identifierNameWithPrefix: string = `${prefix}${identifierName}`;

if (!this.isValidIdentifierNameInLexicalScopes(identifierName, lexicalScopes)) {
return this.generateForLexicalScope(lexicalScopeNode);
if (!this.isValidIdentifierName(identifierNameWithPrefix)) {
return this.generateForGlobalScope();
}

this.preserveNameForLexicalScope(identifierName, lexicalScopeNode);
this.preserveName(identifierNameWithPrefix);

return identifierName;
return identifierNameWithPrefix;
}

/**
* @param {TNodeWithLexicalScope} lexicalScopeNode
* @returns {string}
*/
public generateWithPrefix (): string {
const prefix: string = this.options.identifiersPrefix ?
`${this.options.identifiersPrefix}`
: '';
public generateForLexicalScope (lexicalScopeNode: TNodeWithLexicalScope): string {
const lexicalScopes: TNodeWithLexicalScope[] = [
lexicalScopeNode,
...NodeLexicalScopeUtils.getLexicalScopes(lexicalScopeNode)
];
const identifierName: string = this.generateNewDictionaryName();
const identifierNameWithPrefix: string = `${prefix}${identifierName}`;

if (!this.isValidIdentifierName(identifierNameWithPrefix)) {
return this.generateWithPrefix();
if (!this.isValidIdentifierNameInLexicalScopes(identifierName, lexicalScopes)) {
return this.generateForLexicalScope(lexicalScopeNode);
}

this.preserveName(identifierNameWithPrefix);
this.preserveNameForLexicalScope(identifierName, lexicalScopeNode);

return identifierNameWithPrefix;
return identifierName;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class HexadecimalIdentifierNamesGenerator extends AbstractIdentifierNames
* @param {number} nameLength
* @returns {string}
*/
public generateForGlobalScope (nameLength?: number): string {
public generateNext (nameLength?: number): string {
const rangeMinInteger: number = 10000;
const rangeMaxInteger: number = 99_999_999;
const randomInteger: number = this.randomGenerator.getRandomInteger(rangeMinInteger, rangeMaxInteger);
Expand All @@ -45,7 +45,7 @@ export class HexadecimalIdentifierNamesGenerator extends AbstractIdentifierNames
const identifierName: string = `_${Utils.hexadecimalPrefix}${baseIdentifierName}`;

if (!this.isValidIdentifierName(identifierName)) {
return this.generateForGlobalScope(nameLength);
return this.generateNext(nameLength);
}

this.preserveName(identifierName);
Expand All @@ -54,21 +54,21 @@ export class HexadecimalIdentifierNamesGenerator extends AbstractIdentifierNames
}

/**
* @param {TNodeWithLexicalScope} lexicalScopeNode
* @param {number} nameLength
* @returns {string}
*/
public generateForLexicalScope (lexicalScopeNode: TNodeWithLexicalScope, nameLength?: number): string {
return this.generateForGlobalScope(nameLength);
public generateForGlobalScope (nameLength?: number): string {
const identifierName: string = this.generateNext(nameLength);

return `${this.options.identifiersPrefix}${identifierName}`.replace('__', '_');
}

/**
* @param {TNodeWithLexicalScope} lexicalScopeNode
* @param {number} nameLength
* @returns {string}
*/
public generateWithPrefix (nameLength?: number): string {
const identifierName: string = this.generateForGlobalScope(nameLength);

return `${this.options.identifiersPrefix}${identifierName}`.replace('__', '_');
public generateForLexicalScope (lexicalScopeNode: TNodeWithLexicalScope, nameLength?: number): string {
return this.generateNext(nameLength);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene
* @param {number} nameLength
* @returns {string}
*/
public generateForGlobalScope (nameLength?: number): string {
public generateNext (nameLength?: number): string {
const identifierName: string = this.generateNewMangledName(this.previousMangledName);

this.previousMangledName = identifierName;
Expand All @@ -67,6 +67,28 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene
return identifierName;
}

/**
* @param {number} nameLength
* @returns {string}
*/
public generateForGlobalScope (nameLength?: number): string {
const prefix: string = this.options.identifiersPrefix ?
`${this.options.identifiersPrefix}`
: '';
const identifierName: string = this.generateNewMangledName(this.previousMangledName);
const identifierNameWithPrefix: string = `${prefix}${identifierName}`;

this.previousMangledName = identifierName;

if (!this.isValidIdentifierName(identifierNameWithPrefix)) {
return this.generateForGlobalScope(nameLength);
}

this.preserveName(identifierNameWithPrefix);

return identifierNameWithPrefix;
}

/**
* @param {TNodeWithLexicalScope} lexicalScopeNode
* @param {number} nameLength
Expand All @@ -93,28 +115,6 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene
return identifierName;
}

/**
* @param {number} nameLength
* @returns {string}
*/
public generateWithPrefix (nameLength?: number): string {
const prefix: string = this.options.identifiersPrefix ?
`${this.options.identifiersPrefix}`
: '';
const identifierName: string = this.generateNewMangledName(this.previousMangledName);
const identifierNameWithPrefix: string = `${prefix}${identifierName}`;

this.previousMangledName = identifierName;

if (!this.isValidIdentifierName(identifierNameWithPrefix)) {
return this.generateWithPrefix(nameLength);
}

this.preserveName(identifierNameWithPrefix);

return identifierNameWithPrefix;
}

/**
* @param {string} mangledName
* @returns {boolean}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface IIdentifierNamesGenerator {
* @param {number} nameLength
* @returns {string}
*/
generateWithPrefix (nameLength?: number): string;
generateNext (nameLength?: number): string;

/**
* @param {string} identifierName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class BaseIdentifierObfuscatingReplacer extends AbstractObfuscatingReplac
return;
}

const newIdentifierName: string = this.identifierNamesGenerator.generateWithPrefix();
const newIdentifierName: string = this.identifierNamesGenerator.generateForGlobalScope();

if (!this.blockScopesMap.has(lexicalScopeNode)) {
this.blockScopesMap.set(lexicalScopeNode, new Map());
Expand Down
6 changes: 3 additions & 3 deletions src/node/NodeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { NodeMetadata } from './NodeMetadata';

export class NodeUtils {
/**
* @param {T} literalNode
* @returns {T}
* @param {ESTree.Literal} literalNode
* @returns {ESTree.Literal}
*/
public static addXVerbatimPropertyTo (literalNode: ESTree.Literal): ESTree.Literal {
literalNode['x-verbatim-property'] = {
Expand All @@ -32,7 +32,7 @@ export class NodeUtils {

/**
* @param {string} code
* @returns {Statement[]}
* @returns {ESTree.Statement[]}
*/
public static convertCodeToStructure (code: string): ESTree.Statement[] {
const structure: ESTree.Program = ASTParserFacade.parse(
Expand Down
4 changes: 2 additions & 2 deletions src/storages/string-array/StringArrayStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export class StringArrayStorage extends MapStorage <string, IStringArrayStorageI
public getStorageId (): string {
if (!this.stringArrayStorageName) {
this.stringArrayStorageName = this.identifierNamesGenerator
.generateWithPrefix(StringArrayStorage.stringArrayNameLength);
.generateForGlobalScope(StringArrayStorage.stringArrayNameLength);
}

return this.stringArrayStorageName;
Expand All @@ -174,7 +174,7 @@ export class StringArrayStorage extends MapStorage <string, IStringArrayStorageI
public getStorageCallsWrapperName (): string {
if (!this.stringArrayStorageCallsWrapperName) {
this.stringArrayStorageCallsWrapperName = this.identifierNamesGenerator
.generateWithPrefix(StringArrayStorage.stringArrayNameLength);
.generateForGlobalScope(StringArrayStorage.stringArrayNameLength);
}

return this.stringArrayStorageCallsWrapperName;
Expand Down
Loading