Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dgilling committed Dec 3, 2019
2 parents e64eed4 + 2ff9f2c commit a6df768
Show file tree
Hide file tree
Showing 34 changed files with 2,408 additions and 1,445 deletions.
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
Change Log
===
v0.18.6
---
* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/355

Thanks to our contributors!
* [Zamotkin](https://github.com/zamotkin)

v0.18.5
---
* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/321

Thanks to our contributors!
* [Zamotkin](https://github.com/zamotkin)

v0.18.4
---
* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/437

Thanks to our contributors!
* [Zamotkin](https://github.com/zamotkin)

v0.18.3
---
* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/424

Thanks to our contributors!
* [Zamotkin](https://github.com/zamotkin)

v0.18.2
---
* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/320
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Example of obfuscated code: [gist.github.com](https://gist.github.com/sanex3339/
[![Join the chat at Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/javascript-obfuscator/General-chat)
[![npm version](https://badge.fury.io/js/javascript-obfuscator.svg)](https://badge.fury.io/js/javascript-obfuscator)
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fjavascript-obfuscator%2Fjavascript-obfuscator.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fjavascript-obfuscator%2Fjavascript-obfuscator?ref=badge_shield)
[![Build Status](https://travis-ci.org/javascript-obfuscator/javascript-obfuscator.svg?branch=master)](https://travis-ci.org/javascript-obfuscator/javascript-obfuscator)
[![Build Status](https://travis-ci.com/javascript-obfuscator/javascript-obfuscator.svg?branch=master)](https://travis-ci.com/javascript-obfuscator/javascript-obfuscator)
[![Coverage Status](https://coveralls.io/repos/github/javascript-obfuscator/javascript-obfuscator/badge.svg?branch=master)](https://coveralls.io/github/javascript-obfuscator/javascript-obfuscator?branch=master)
[![Backers on Open Collective](https://opencollective.com/javascript-obfuscator/backers/badge.svg)](#backers)
[![Sponsors on Open Collective](https://opencollective.com/javascript-obfuscator/sponsors/badge.svg)](#sponsors)
Expand Down
8 changes: 4 additions & 4 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.

76 changes: 40 additions & 36 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "javascript-obfuscator",
"version": "0.18.3",
"version": "0.18.6",
"description": "JavaScript obfuscator",
"keywords": [
"obfuscator",
Expand All @@ -21,63 +21,63 @@
},
"types": "index.d.ts",
"dependencies": {
"@babel/runtime": "7.0.0-rc.1",
"chalk": "2.4.1",
"chance": "1.0.16",
"class-validator": "0.9.1",
"commander": "2.17.1",
"escodegen-wallaby": "1.6.19",
"@babel/runtime": "7.7.4",
"chalk": "3.0.0",
"chance": "1.1.3",
"class-validator": "0.11.0",
"commander": "4.0.1",
"escodegen-wallaby": "1.6.27",
"espree": "4.0.0",
"estraverse": "4.2.0",
"inversify": "4.13.0",
"estraverse": "4.3.0",
"inversify": "5.0.1",
"js-string-escape": "1.0.1",
"md5": "2.2.1",
"mkdirp": "0.5.1",
"multimatch": "2.1.0",
"reflect-metadata": "0.1.12",
"source-map-support": "0.5.8",
"multimatch": "4.0.0",
"reflect-metadata": "0.1.13",
"source-map-support": "0.5.16",
"string-template": "1.0.0",
"tslib": "1.9.3"
"tslib": "1.10.0"
},
"devDependencies": {
"@babel/cli": "7.0.0-rc.1",
"@babel/core": "7.0.0-rc.1",
"@babel/plugin-transform-runtime": "7.0.0-rc.1",
"@babel/preset-env": "7.0.0-rc.1",
"@types/chai": "4.1.4",
"@types/chance": "1.0.1",
"@babel/cli": "7.7.4",
"@babel/core": "7.7.4",
"@babel/plugin-transform-runtime": "7.7.4",
"@babel/preset-env": "7.7.4",
"@types/chai": "4.2.5",
"@types/chance": "1.0.7",
"@types/escodegen": "0.0.6",
"@types/estraverse": "0.0.6",
"@types/estree": "0.0.38",
"@types/md5": "2.1.32",
"@types/md5": "2.1.33",
"@types/mkdirp": "0.5.2",
"@types/mocha": "5.2.5",
"@types/multimatch": "2.1.2",
"@types/node": "10.5.8",
"@types/rimraf": "2.0.2",
"@types/sinon": "5.0.1",
"@types/mocha": "5.2.7",
"@types/multimatch": "4.0.0",
"@types/node": "12.12.14",
"@types/rimraf": "2.0.3",
"@types/sinon": "7.5.1",
"@types/string-template": "1.0.2",
"@types/webpack-env": "1.13.6",
"awesome-typescript-loader": "5.2.0",
"babel-loader": "8.0.0-beta.3",
"chai": "4.1.2",
"coveralls": "3.0.2",
"@types/webpack-env": "1.14.1",
"awesome-typescript-loader": "5.2.1",
"babel-loader": "8.0.6",
"chai": "4.2.0",
"coveralls": "3.0.9",
"istanbul": "1.1.0-alpha.1",
"mocha": "5.2.0",
"mocha": "6.2.2",
"pjson": "1.0.9",
"pre-commit": "1.2.2",
"rimraf": "2.6.2",
"sinon": "6.1.5",
"rimraf": "3.0.0",
"sinon": "7.5.0",
"threads": "0.12.0",
"ts-node": "6.1.0",
"tslint": "5.11.0",
"tslint-eslint-rules": "5.3.1",
"tslint-language-service": "0.9.9",
"tslint-microsoft-contrib": "5.2.0",
"tslint-webpack-plugin": "1.2.2",
"typescript": "3.0.1",
"webpack": "4.16.5",
"webpack-cli": "3.1.0",
"typescript": "3.7.2",
"webpack": "4.41.2",
"webpack-cli": "3.3.10",
"webpack-node-externals": "1.7.2"
},
"repository": {
Expand Down Expand Up @@ -111,5 +111,9 @@
"author": {
"name": "Timofey Kachalov"
},
"contributors": [
"Timofey Kachalov (https://github.com/sanex3339)",
"Zamotkin (https://github.com/zamotkin)"
],
"license": "BSD-2-Clause"
}
3 changes: 2 additions & 1 deletion src/JavaScriptObfuscator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ export class JavaScriptObfuscator implements IJavaScriptObfuscator {
NodeTransformer.ObjectExpressionTransformer,
NodeTransformer.ParentificationTransformer,
NodeTransformer.TemplateLiteralTransformer,
NodeTransformer.VariableDeclarationTransformer
NodeTransformer.VariableDeclarationTransformer,
NodeTransformer.VariablePreserveTransformer
];

/**
Expand Down
2 changes: 1 addition & 1 deletion src/cli/utils/CLIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class CLIUtils {
* @returns {TObject}
*/
public static getUserConfig (configPath: string): TObject {
let config: Object;
let config: TObject;

try {
config = require(configPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { EvalCallExpressionTransformer } from '../../../node-transformers/prepar
import { MetadataTransformer } from '../../../node-transformers/preparing-transformers/MetadataTransformer';
import { ObfuscatingGuardsTransformer } from '../../../node-transformers/preparing-transformers/ObfuscatingGuardsTransformer';
import { ParentificationTransformer } from '../../../node-transformers/preparing-transformers/ParentificationTransformer';
import { VariablePreserveTransformer } from "../../../node-transformers/preparing-transformers/VariablePreserveTransformer";

export const preparingTransformersModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => {
// preparing transformers
Expand Down Expand Up @@ -60,4 +61,8 @@ export const preparingTransformersModule: interfaces.ContainerModule = new Conta
.getCacheFactory<ObfuscatingGuard, IObfuscatingGuard>(
ServiceIdentifiers.INodeGuard
));

bind<INodeTransformer>(ServiceIdentifiers.INodeTransformer)
.to(VariablePreserveTransformer)
.whenTargetNamed(NodeTransformer.VariablePreserveTransformer);
});
3 changes: 2 additions & 1 deletion src/enums/node-transformers/NodeTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ export enum NodeTransformer {
ObjectExpressionTransformer = 'ObjectExpressionTransformer',
ParentificationTransformer = 'ParentificationTransformer',
TemplateLiteralTransformer = 'TemplateLiteralTransformer',
VariableDeclarationTransformer = 'VariableDeclarationTransformer'
VariableDeclarationTransformer = 'VariableDeclarationTransformer',
VariablePreserveTransformer = 'VariablePreserveTransformer',
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export abstract class AbstractIdentifierNamesGenerator implements IIdentifierNam
*/
protected readonly randomGenerator: IRandomGenerator;

/**
* @type {Array}
*/
protected readonly preservedNames: string[] = [];

/**
* @param {IRandomGenerator} randomGenerator
* @param {IOptions} options
Expand All @@ -41,11 +46,27 @@ export abstract class AbstractIdentifierNamesGenerator implements IIdentifierNam
*/
public abstract generateWithPrefix (nameLength?: number): string;

/**
* @param {string} name
* @returns {void}
*/
public preserveName (name: string): void {
this.preservedNames.push(name);
}

/**
* @param {string} name
* @returns {boolean}
*/
public isValidIdentifierName (name: string): boolean {
return this.notReservedName(name) && !this.preservedNames.includes(name);
}

/**
* @param {string} name
* @returns {boolean}
*/
private notReservedName (name: string): boolean {
return this.options.reservedNames.length
? !this.options.reservedNames.some((reservedName: string) =>
new RegExp(reservedName, 'g').exec(name) !== null
Expand Down
7 changes: 3 additions & 4 deletions src/interfaces/analyzers/IAnalyzer.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import * as ESTree from 'estree';
import { TObject } from '../../types/TObject';

export interface IAnalyzer {
export interface IAnalyzer <T> {
/**
* @param {Program} astTree
* @returns {TObject[]}
* @returns {T[]}
*/
analyze (astTree: ESTree.Program): TObject[];
analyze (astTree: ESTree.Program): T[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as ESTree from 'estree';
import { IAnalyzer } from '../IAnalyzer';
import { IStackTraceData } from './IStackTraceData';

export interface IStackTraceAnalyzer extends IAnalyzer {
export interface IStackTraceAnalyzer extends IAnalyzer<IStackTraceData> {
/**
* @param {Program} astTree
* @returns {IStackTraceData[]}
Expand Down
4 changes: 2 additions & 2 deletions src/interfaces/event-emitters/IObfuscationEventEmitter.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Events = NodeJS.Events;
import EventEmitter = NodeJS.EventEmitter;

import { ObfuscationEvent } from '../../enums/event-emitters/ObfuscationEvent';

export interface IObfuscationEventEmitter extends Events {
export interface IObfuscationEventEmitter extends EventEmitter {
/**
* @param event
* @param listener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ export interface IIdentifierNamesGenerator {
* @returns {boolean}
*/
isValidIdentifierName (identifierName: string): boolean;

/**
* @param {string} name
*/
preserveName (name: string): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ export interface IIdentifierObfuscatingReplacer extends IObfuscatingReplacer <ES
* @param {TNodeWithLexicalScope} lexicalScopeNode
*/
storeLocalName (nodeValue: string, lexicalScopeNode: TNodeWithLexicalScope): void;

/**
* @param {string} name
*/
preserveName (name: string): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ export abstract class AbstractPropertiesExtractor implements IPropertiesExtracto
* @returns {propertyValueNode is Pattern}
*/
protected static isProhibitedPattern (node: ESTree.Node): node is ESTree.Pattern {
return NodeGuards.isObjectPatternNode(node)
return !node
|| NodeGuards.isObjectPatternNode(node)
|| NodeGuards.isArrayPatternNode(node)
|| NodeGuards.isAssignmentPatternNode(node)
|| NodeGuards.isRestElementNode(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export class FunctionDeclarationTransformer extends AbstractNodeTransformer {
enter: (node: ESTree.Node, parentNode: ESTree.Node | null): void => {
if (
parentNode
&& (parentNode !== lexicalScopeNode)
&& NodeGuards.isReplaceableIdentifierNode(node, parentNode)
&& !NodeMetadata.isRenamedIdentifier(node)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,21 @@ export class LiteralTransformer extends AbstractNodeTransformer {
case 'boolean':
newLiteralNode = this.literalObfuscatingReplacerFactory(
LiteralObfuscatingReplacer.BooleanLiteralObfuscatingReplacer
).replace(<boolean>literalNode.value);
).replace(literalNode.value);

break;

case 'number':
newLiteralNode = this.literalObfuscatingReplacerFactory(
LiteralObfuscatingReplacer.NumberLiteralObfuscatingReplacer
).replace(<number>literalNode.value);
).replace(literalNode.value);

break;

case 'string':
newLiteralNode = this.literalObfuscatingReplacerFactory(
LiteralObfuscatingReplacer.StringLiteralObfuscatingReplacer
).replace(<string>literalNode.value);
).replace(literalNode.value);

break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ export class BaseIdentifierObfuscatingReplacer extends AbstractObfuscatingReplac
namesMap.set(nodeName, identifierName);
}

/**
* Preserve `name` to protect it from further using.
*
* @param {string} name
*/
public preserveName (name: string): void {
this.identifierNamesGenerator.preserveName(name);
}

/**
* @param {string} name
* @returns {boolean}
Expand Down
Loading

0 comments on commit a6df768

Please sign in to comment.