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.2
---
* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/563

v0.25.1
---
* Additional fixes of https://github.com/javascript-obfuscator/javascript-obfuscator/issues/550
Expand Down
10 changes: 5 additions & 5 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.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "javascript-obfuscator",
"version": "0.25.1",
"version": "0.25.2",
"description": "JavaScript obfuscator",
"keywords": [
"obfuscator",
Expand Down Expand Up @@ -57,11 +57,11 @@
"@types/multimatch": "4.0.0",
"@types/node": "12.12.14",
"@types/rimraf": "2.0.3",
"@types/sinon": "7.5.1",
"@types/sinon": "7.5.2",
"@types/string-template": "1.0.2",
"@types/webpack-env": "1.15.1",
"@typescript-eslint/eslint-plugin": "2.20.0",
"@typescript-eslint/parser": "2.20.0",
"@typescript-eslint/eslint-plugin": "2.21.0",
"@typescript-eslint/parser": "2.21.0",
"chai": "4.2.0",
"coveralls": "3.0.9",
"eslint": "6.8.0",
Expand All @@ -72,7 +72,7 @@
"eslint-plugin-unicorn": "16.1.1",
"fork-ts-checker-notifier-webpack-plugin": "2.0.0",
"fork-ts-checker-webpack-plugin": "4.0.4",
"mocha": "7.0.1",
"mocha": "7.1.0",
"nyc": "15.0.0",
"pjson": "1.0.9",
"pre-commit": "1.2.2",
Expand Down
2 changes: 2 additions & 0 deletions src/container/InversifyContainerFacade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { customCodeHelpersModule } from './modules/custom-code-helpers/CustomCod
import { customNodesModule } from './modules/custom-nodes/CustomNodesModule';
import { finalizingTransformersModule } from './modules/node-transformers/FinalizingTransformersModule';
import { generatorsModule } from './modules/generators/GeneratorsModule';
import { initializingTransformersModule } from './modules/node-transformers/InitializingTransformersModule';
import { nodeModule } from './modules/node/NodeModule';
import { nodeTransformersModule } from './modules/node-transformers/NodeTransformersModule';
import { obfuscatingTransformersModule } from './modules/node-transformers/ObfuscatingTransformersModule';
Expand Down Expand Up @@ -199,6 +200,7 @@ export class InversifyContainerFacade implements IInversifyContainerFacade {
this.container.load(customNodesModule);
this.container.load(finalizingTransformersModule);
this.container.load(generatorsModule);
this.container.load(initializingTransformersModule);
this.container.load(nodeModule);
this.container.load(nodeTransformersModule);
this.container.load(obfuscatingTransformersModule);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ContainerModule, interfaces } from 'inversify';
import { ServiceIdentifiers } from '../../ServiceIdentifiers';

import { INodeTransformer } from '../../../interfaces/node-transformers/INodeTransformer';

import { NodeTransformer } from '../../../enums/node-transformers/NodeTransformer';

import { CommentsTransformer } from '../../../node-transformers/initializing-transformers/CommentsTransformer';

export const initializingTransformersModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => {
// preparing transformers
bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
.to(CommentsTransformer)
.whenTargetNamed(NodeTransformer.CommentsTransformer);
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { NodeTransformer } from '../../../enums/node-transformers/NodeTransforme
import { ObfuscatingGuard } from '../../../enums/node-transformers/preparing-transformers/obfuscating-guards/ObfuscatingGuard';

import { BlackListObfuscatingGuard } from '../../../node-transformers/preparing-transformers/obfuscating-guards/BlackListObfuscatingGuard';
import { CommentsTransformer } from '../../../node-transformers/preparing-transformers/CommentsTransformer';
import { ConditionalCommentObfuscatingGuard } from '../../../node-transformers/preparing-transformers/obfuscating-guards/ConditionalCommentObfuscatingGuard';
import { CustomCodeHelpersTransformer } from '../../../node-transformers/preparing-transformers/CustomCodeHelpersTransformer';
import { EvalCallExpressionTransformer } from '../../../node-transformers/preparing-transformers/EvalCallExpressionTransformer';
Expand All @@ -21,10 +20,6 @@ import { VariablePreserveTransformer } from '../../../node-transformers/preparin

export const preparingTransformersModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => {
// preparing transformers
bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
.to(CommentsTransformer)
.whenTargetNamed(NodeTransformer.CommentsTransformer);

bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
.to(CustomCodeHelpersTransformer)
.whenTargetNamed(NodeTransformer.CustomCodeHelpersTransformer);
Expand Down Expand Up @@ -61,14 +56,14 @@ export const preparingTransformersModule: interfaces.ContainerModule = new Conta
.inSingletonScope()
.whenTargetNamed(ObfuscatingGuard.ReservedStringObfuscatingGuard);

bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
.to(VariablePreserveTransformer)
.whenTargetNamed(NodeTransformer.VariablePreserveTransformer);

// obfuscating guards factory
bind<IObfuscatingGuard>(ServiceIdentifiers.Factory__INodeGuard)
.toFactory<IObfuscatingGuard>(InversifyContainerFacade
.getCacheFactory<ObfuscatingGuard, IObfuscatingGuard>(
ServiceIdentifiers.INodeGuard
));

bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
.to(VariablePreserveTransformer)
.whenTargetNamed(NodeTransformer.VariablePreserveTransformer);
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ import { IOptions } from '../../interfaces/options/IOptions';
import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
import { IVisitor } from '../../interfaces/node-transformers/IVisitor';

import { NodeTransformer } from '../../enums/node-transformers/NodeTransformer';
import { TransformationStage } from '../../enums/node-transformers/TransformationStage';

import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
import { ConditionalCommentObfuscatingGuard } from '../preparing-transformers/obfuscating-guards/ConditionalCommentObfuscatingGuard';
import { NodeGuards } from '../../node/NodeGuards';
import { ConditionalCommentObfuscatingGuard } from './obfuscating-guards/ConditionalCommentObfuscatingGuard';

@injectable()
export class CommentsTransformer extends AbstractNodeTransformer {
Expand All @@ -25,14 +24,6 @@ export class CommentsTransformer extends AbstractNodeTransformer {
'@preserve'
];

/**
* @type {NodeTransformer.ParentificationTransformer[]}
*/
public readonly runAfter: NodeTransformer[] = [
NodeTransformer.ParentificationTransformer,
NodeTransformer.VariablePreserveTransformer
];

/**
* @param {IRandomGenerator} randomGenerator
* @param {IOptions} options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,18 @@ export class ScopeIdentifiersTransformer extends AbstractNodeTransformer {
lexicalScopeNode: TNodeWithLexicalScope,
isGlobalDeclaration: boolean
): void {
for (const identifier of variable.identifiers) {
if (!this.isReplaceableIdentifierNode(identifier, lexicalScopeNode, variable)) {
continue;
}
const firstIdentifier: ESTree.Identifier | null = variable.identifiers[0] ?? null;

if (!firstIdentifier) {
return;
}

this.storeIdentifierName(identifier, lexicalScopeNode, isGlobalDeclaration);
this.replaceIdentifierName(identifier, lexicalScopeNode, variable);
if (!this.isReplaceableIdentifierNode(firstIdentifier, lexicalScopeNode, variable)) {
return;
}

this.storeIdentifierName(firstIdentifier, lexicalScopeNode, isGlobalDeclaration);
this.replaceIdentifierName(firstIdentifier, lexicalScopeNode, variable);
}

/**
Expand Down Expand Up @@ -173,7 +177,10 @@ export class ScopeIdentifiersTransformer extends AbstractNodeTransformer {
const newIdentifier: ESTree.Identifier = this.identifierObfuscatingReplacer
.replace(identifierNode, lexicalScopeNode);

identifierNode.name = newIdentifier.name;
// rename of identifiers
variable.identifiers.forEach((identifier: ESTree.Identifier) => {
identifier.name = newIdentifier.name;
});

// rename of references
variable.references.forEach((reference: eslintScope.Reference) => {
Expand Down
10 changes: 5 additions & 5 deletions test/dev/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { NO_ADDITIONAL_NODES_PRESET } from '../../src/options/presets/NoCustomNo

let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
`
function foo (bar = {bar: 1}) {
(function(foo){
function foo () {

}
}

function baz (bark = {bark: 1}) {

}
return new foo();
})();
`,
{
...NO_ADDITIONAL_NODES_PRESET,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ describe('ScopeIdentifiersTransformer Function identifiers', () => {
returnStatementIdentifierName = (<RegExpMatchArray>returnStatementIdentifierMatch)[1];
});

it('should generate different names for function parameter identifier and function body identifier with same name', () => {
assert.notEqual(functionParamIdentifierName, functionBodyIdentifierName);
it('should generate same names for function parameter identifier and function body identifier with same name', () => {
assert.equal(functionParamIdentifierName, functionBodyIdentifierName);
});

it('should generate different names for function parameter identifier and variable declaration identifier with same name', () => {
assert.notEqual(functionParamIdentifierName, variableDeclarationIdentifierName);
it('should generate same names for function parameter identifier and variable declaration identifier with same name', () => {
assert.equal(functionParamIdentifierName, variableDeclarationIdentifierName);
});

it('should correctly transform both variable declaration identifier and return statement identifier with same name', () => {
Expand Down Expand Up @@ -112,12 +112,12 @@ describe('ScopeIdentifiersTransformer Function identifiers', () => {
assert.equal(innerFunctionNameIdentifierName, functionObjectIdentifierName);
});

it('shouldn\'t generate same names for function parameter identifiers', () => {
assert.notEqual(functionExpressionParamIdentifierName, innerFunctionNameIdentifierName);
it('should generate same names for function parameter identifiers', () => {
assert.equal(functionExpressionParamIdentifierName, innerFunctionNameIdentifierName);
});

it('shouldn\'t generate same names for function expression parameter and function object identifiers', () => {
assert.notEqual(functionExpressionParamIdentifierName, functionObjectIdentifierName);
it('should generate same names for function expression parameter and function object identifiers', () => {
assert.equal(functionExpressionParamIdentifierName, functionObjectIdentifierName);
});
});

Expand Down
2 changes: 1 addition & 1 deletion test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ import './functional-tests/node-transformers/obfuscating-transformers/scope-iden
import './functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/variable-declaration/VariableDeclaration.spec';
import './functional-tests/node-transformers/obfuscating-transformers/obfuscating-replacers/identifier-obfuscating-replacers/BaseIdentifierObfuscatingReplacer.spec';
import './functional-tests/node-transformers/preparing-transformers/eval-call-expression-transformer/EvalCallExpressionTransformer.spec';
import './functional-tests/node-transformers/preparing-transformers/comments-transformer/CommentsTransformer.spec';
import './functional-tests/node-transformers/initializing-transformers/comments-transformer/CommentsTransformer.spec';
import './functional-tests/node-transformers/preparing-transformers/obfuscating-guards/black-list-obfuscating-guard/BlackListObfuscatingGuard.spec';
import './functional-tests/node-transformers/preparing-transformers/obfuscating-guards/conditional-comment-obfuscating-guard/ConditionalCommentObfuscatingGuard.spec';
import './functional-tests/node-transformers/preparing-transformers/obfuscating-guards/reserved-string-obfuscating-guard/ReservedStringObfuscatingGuard.spec';
Expand Down
70 changes: 35 additions & 35 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,10 @@
"@types/glob" "*"
"@types/node" "*"

"@types/[email protected].1":
version "7.5.1"
resolved "https://registry.yarnpkg.com/@types/sinon/-/sinon-7.5.1.tgz#d27b81af0d1cfe1f9b24eebe7a24f74ae40f5b7c"
integrity sha512-EZQUP3hSZQyTQRfiLqelC9NMWd1kqLcmQE0dMiklxBkgi84T+cHOhnKpgk4NnOWpGX863yE6+IaGnOXUNFqDnQ==
"@types/[email protected].2":
version "7.5.2"
resolved "https://registry.yarnpkg.com/@types/sinon/-/sinon-7.5.2.tgz#5e2f1d120f07b9cda07e5dedd4f3bf8888fccdb9"
integrity sha512-T+m89VdXj/eidZyejvmoP9jivXgBDdkOSBVQjU9kF349NEx10QdPNGxHeZUaj1IlJ32/ewdyXJjnJxyxJroYwg==

"@types/[email protected]":
version "1.0.2"
Expand All @@ -331,40 +331,40 @@
resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.15.1.tgz#c8e84705e08eed430b5e15b39c65b0944e4d1422"
integrity sha512-eWN5ElDTeBc5lRDh95SqA8x18D0ll2pWudU3uWiyfsRmIZcmUXpEsxPU+7+BsdCrO2vfLRC629u/MmjbmF+2tA==

"@typescript-eslint/eslint-plugin@2.20.0":
version "2.20.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.20.0.tgz#a522d0e1e4898f7c9c6a8e1ed3579b60867693fa"
integrity sha512-cimIdVDV3MakiGJqMXw51Xci6oEDEoPkvh8ggJe2IIzcc0fYqAxOXN6Vbeanahz6dLZq64W+40iUEc9g32FLDQ==
"@typescript-eslint/eslint-plugin@2.21.0":
version "2.21.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.21.0.tgz#a34de84a0791cae0357c4dda805c5b4e8203b6c6"
integrity sha512-b5jjjDMxzcjh/Sbjuo7WyhrQmVJg0WipTHQgXh5Xwx10uYm6nPWqN1WGOsaNq4HR3Zh4wUx4IRQdDkCHwyewyw==
dependencies:
"@typescript-eslint/experimental-utils" "2.20.0"
"@typescript-eslint/experimental-utils" "2.21.0"
eslint-utils "^1.4.3"
functional-red-black-tree "^1.0.1"
regexpp "^3.0.0"
tsutils "^3.17.1"

"@typescript-eslint/experimental-utils@2.20.0":
version "2.20.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-2.20.0.tgz#3b6fa5a6b8885f126d5a4280e0d44f0f41e73e32"
integrity sha512-fEBy9xYrwG9hfBLFEwGW2lKwDRTmYzH3DwTmYbT+SMycmxAoPl0eGretnBFj/s+NfYBG63w/5c3lsvqqz5mYag==
"@typescript-eslint/experimental-utils@2.21.0":
version "2.21.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-2.21.0.tgz#71de390a3ec00b280b69138d80733406e6e86bfa"
integrity sha512-olKw9JP/XUkav4lq0I7S1mhGgONJF9rHNhKFn9wJlpfRVjNo3PPjSvybxEldvCXnvD+WAshSzqH5cEjPp9CsBA==
dependencies:
"@types/json-schema" "^7.0.3"
"@typescript-eslint/typescript-estree" "2.20.0"
"@typescript-eslint/typescript-estree" "2.21.0"
eslint-scope "^5.0.0"

"@typescript-eslint/parser@2.20.0":
version "2.20.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-2.20.0.tgz#608e5bb06ba98a415b64ace994c79ab20f9772a9"
integrity sha512-o8qsKaosLh2qhMZiHNtaHKTHyCHc3Triq6aMnwnWj7budm3xAY9owSZzV1uon5T9cWmJRJGzTFa90aex4m77Lw==
"@typescript-eslint/parser@2.21.0":
version "2.21.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-2.21.0.tgz#4f200995517c3d5fc5ef51b17527bc948992e438"
integrity sha512-VrmbdrrrvvI6cPPOG7uOgGUFXNYTiSbnRq8ZMyuGa4+qmXJXVLEEz78hKuqupvkpwJQNk1Ucz1TenrRP90gmBg==
dependencies:
"@types/eslint-visitor-keys" "^1.0.0"
"@typescript-eslint/experimental-utils" "2.20.0"
"@typescript-eslint/typescript-estree" "2.20.0"
"@typescript-eslint/experimental-utils" "2.21.0"
"@typescript-eslint/typescript-estree" "2.21.0"
eslint-visitor-keys "^1.1.0"

"@typescript-eslint/typescript-estree@2.20.0":
version "2.20.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-2.20.0.tgz#90a0f5598826b35b966ca83483b1a621b1a4d0c9"
integrity sha512-WlFk8QtI8pPaE7JGQGxU7nGcnk1ccKAJkhbVookv94ZcAef3m6oCE/jEDL6dGte3JcD7reKrA0o55XhBRiVT3A==
"@typescript-eslint/typescript-estree@2.21.0":
version "2.21.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-2.21.0.tgz#7e4be29f2e338195a2e8c818949ed0ff727cc943"
integrity sha512-NC/nogZNb9IK2MEFQqyDBAciOT8Lp8O3KgAfvHx2Skx6WBo+KmDqlU3R9KxHONaijfTIKtojRe3SZQyMjr3wBw==
dependencies:
debug "^4.1.1"
eslint-visitor-keys "^1.1.0"
Expand Down Expand Up @@ -1064,7 +1064,7 @@ [email protected]:
pathval "^1.1.0"
type-detect "^4.0.5"

[email protected], chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.3.0, chalk@^2.4.1, chalk@^2.4.2:
[email protected], chalk@^2.0.0, chalk@^2.1.0, chalk@^2.3.0, chalk@^2.4.1, chalk@^2.4.2:
version "2.4.2"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424"
integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==
Expand Down Expand Up @@ -3231,12 +3231,12 @@ log-driver@^1.2.7:
resolved "https://registry.yarnpkg.com/log-driver/-/log-driver-1.2.7.tgz#63b95021f0702fedfa2c9bb0a24e7797d71871d8"
integrity sha512-U7KCmLdqsGHBLeWqYlFA0V0Sl6P08EE1ZrmA9cxjUE0WVqT9qnyVDPz1kzpFEP0jdJuFnasWIfSd7fsaNXkpbg==

log-symbols@2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-2.2.0.tgz#5740e1c5d6f0dfda4ad9323b5332107ef6b4c40a"
integrity sha512-VeIAFslyIerEJLXHziedo2basKbMKtTw3vfn5IzG0XTjhAVEJyNHnL2p7vc+wBDSdQuUpNw3M2u6xb9QsAY5Eg==
log-symbols@3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-3.0.0.tgz#f3a08516a5dea893336a7dee14d18a1cfdab77c4"
integrity sha512-dSkNGuI7iG3mfvDzUuYZyvk5dD9ocYCYzNU6CYDE6+Xqd+gwme6Z00NS3dUh8mq/73HaEtT7m6W+yUPtU6BZnQ==
dependencies:
chalk "^2.0.1"
chalk "^2.4.2"

lru-cache@^4.0.1:
version "4.1.5"
Expand Down Expand Up @@ -3460,10 +3460,10 @@ [email protected]:
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.3.tgz#4cf2e30ad45959dddea53ad97d518b6c8205e1ea"
integrity sha512-6uCP4Qc0sWsgMLy1EOqqS/3rjDHOEnsStVr/4vtAIK2Y5i2kA7lFFejYrpIyiN9w0pYf4ckeCYT9f1r1P9KX5g==

mocha@7.0.1:
version "7.0.1"
resolved "https://registry.yarnpkg.com/mocha/-/mocha-7.0.1.tgz#276186d35a4852f6249808c6dd4a1376cbf6c6ce"
integrity sha512-9eWmWTdHLXh72rGrdZjNbG3aa1/3NRPpul1z0D979QpEnFdCG0Q5tv834N+94QEN2cysfV72YocQ3fn87s70fg==
mocha@7.1.0:
version "7.1.0"
resolved "https://registry.yarnpkg.com/mocha/-/mocha-7.1.0.tgz#c784f579ad0904d29229ad6cb1e2514e4db7d249"
integrity sha512-MymHK8UkU0K15Q/zX7uflZgVoRWiTjy0fXE/QjKts6mowUvGxOdPhZ2qj3b0iZdUrNZlW9LAIMFHB4IW+2b3EQ==
dependencies:
ansi-colors "3.2.3"
browser-stdout "1.3.1"
Expand All @@ -3476,7 +3476,7 @@ [email protected]:
growl "1.10.5"
he "1.2.0"
js-yaml "3.13.1"
log-symbols "2.2.0"
log-symbols "3.0.0"
minimatch "3.0.4"
mkdirp "0.5.1"
ms "2.1.1"
Expand Down