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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
Change Log

v3.0.0
---
* **Breaking change:** `ignoreRequireImports` option renamed to `ignoreImports`
* **Breaking change:** `rotateStringArray` option renamed to `stringArrayRotate`
* **Breaking change:** `shuffleStringArray` option renamed to `stringArrayShuffle`
* `ignoreImports` now ignores `dynamic` imports in addition to `require` imports

v2.19.1
---
* Updated `@javascript-obfuscator/escodegen` with fixed parenthesis of `default export` IIFE
Expand Down
56 changes: 28 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ var obfuscationResult = JavaScriptObfuscator.obfuscate(
controlFlowFlatteningThreshold: 1,
numbersToExpressions: true,
simplify: true,
shuffleStringArray: true,
stringArrayShuffle: true,
splitStrings: true,
stringArrayThreshold: 1
}
Expand Down Expand Up @@ -368,10 +368,8 @@ Following options are available for the JS Obfuscator:
renamePropertiesMode: 'safe',
reservedNames: [],
reservedStrings: [],
rotateStringArray: true,
seed: 0,
selfDefending: false,
shuffleStringArray: true,
simplify: true,
sourceMap: false,
sourceMapBaseUrl: '',
Expand All @@ -386,6 +384,8 @@ Following options are available for the JS Obfuscator:
],
stringArrayEncoding: [],
stringArrayIndexShift: true,
stringArrayRotate: true,
stringArrayShuffle: true,
stringArrayWrappersCount: 1,
stringArrayWrappersChainedCalls: true,
stringArrayWrappersParametersMaxCount: 2,
Expand Down Expand Up @@ -421,7 +421,7 @@ Following options are available for the JS Obfuscator:
--identifier-names-generator <string> [dictionary, hexadecimal, mangled, mangled-shuffled]
--identifiers-dictionary '<list>' (comma separated)
--identifiers-prefix <string>
--ignore-require-imports <boolean>
--ignore-imports <boolean>
--log <boolean>
--numbers-to-expressions <boolean>
--options-preset <string> [default, low-obfuscation, medium-obfuscation, high-obfuscation]
Expand All @@ -430,10 +430,8 @@ Following options are available for the JS Obfuscator:
--rename-properties-mode <string> [safe, unsafe]
--reserved-names '<list>' (comma separated)
--reserved-strings '<list>' (comma separated)
--rotate-string-array <boolean>
--seed <string|number>
--self-defending <boolean>
--shuffle-string-array <boolean>
--simplify <boolean>
--source-map <boolean>
--source-map-base-url <string>
Expand All @@ -446,6 +444,8 @@ Following options are available for the JS Obfuscator:
--string-array-indexes-type '<list>' (comma separated) [hexadecimal-number, hexadecimal-numeric-string]
--string-array-encoding '<list>' (comma separated) [none, base64, rc4]
--string-array-index-shift <boolean>
--string-array-rotate <boolean>
--string-array-shuffle <boolean>
--string-array-wrappers-count <number>
--string-array-wrappers-chained-calls <boolean>
--string-array-wrappers-parameters-max-count <number>
Expand Down Expand Up @@ -968,13 +968,6 @@ Example:
}
```

### `rotateStringArray`
Type: `boolean` Default: `true`

##### :warning: [`stringArray`](#stringarray) must be enabled

Shift the `stringArray` array by a fixed and random (generated at the code obfuscation) places. This makes it harder to match the order of the removed strings to their original place.

### `seed`
Type: `string|number` Default: `0`

Expand All @@ -990,13 +983,6 @@ Type: `boolean` Default: `false`

This option makes the output code resilient against formatting and variable renaming. If one tries to use a JavaScript beautifier on the obfuscated code, the code won't work anymore, making it harder to understand and modify it.

### `shuffleStringArray`
Type: `boolean` Default: `true`

##### :warning: [`stringArray`](#stringarray) must be enabled

Randomly shuffles the `stringArray` array items.

### `simplify`
Type: `boolean` Default: `true`

Expand Down Expand Up @@ -1163,6 +1149,20 @@ Type: `boolean` Default: `true`

Enables additional index shift for all string array calls

### `stringArrayRotate`
Type: `boolean` Default: `true`

##### :warning: [`stringArray`](#stringarray) must be enabled

Shift the `stringArray` array by a fixed and random (generated at the code obfuscation) places. This makes it harder to match the order of the removed strings to their original place.

### `stringArrayShuffle`
Type: `boolean` Default: `true`

##### :warning: [`stringArray`](#stringarray) must be enabled

Randomly shuffles the `stringArray` array items.

### `stringArrayWrappersCount`
Type: `number` Default: `1`

Expand Down Expand Up @@ -1435,15 +1435,15 @@ Performance will 50-100% slower than without obfuscation
log: false,
numbersToExpressions: true,
renameGlobals: false,
rotateStringArray: true,
selfDefending: true,
shuffleStringArray: true,
simplify: true,
splitStrings: true,
splitStringsChunkLength: 5,
stringArray: true,
stringArrayEncoding: ['rc4'],
stringArrayIndexShift: true,
stringArrayRotate: true,
stringArrayShuffle: true,
stringArrayWrappersCount: 5,
stringArrayWrappersChainedCalls: true,
stringArrayWrappersParametersMaxCount: 5,
Expand Down Expand Up @@ -1472,15 +1472,15 @@ Performance will 30-35% slower than without obfuscation
log: false,
numbersToExpressions: true,
renameGlobals: false,
rotateStringArray: true,
selfDefending: true,
shuffleStringArray: true,
simplify: true,
splitStrings: true,
splitStringsChunkLength: 10,
stringArray: true,
stringArrayEncoding: ['base64'],
stringArrayIndexShift: true,
stringArrayRotate: true,
stringArrayShuffle: true,
stringArrayWrappersCount: 2,
stringArrayWrappersChainedCalls: true,
stringArrayWrappersParametersMaxCount: 4,
Expand All @@ -1507,14 +1507,14 @@ Performance will slightly slower than without obfuscation
log: false,
numbersToExpressions: false,
renameGlobals: false,
rotateStringArray: true,
selfDefending: true,
shuffleStringArray: true,
simplify: true,
splitStrings: false,
stringArray: true,
stringArrayEncoding: [],
stringArrayIndexShift: true,
stringArrayRotate: true,
stringArrayShuffle: true,
stringArrayWrappersCount: 1,
stringArrayWrappersChainedCalls: true,
stringArrayWrappersParametersMaxCount: 2,
Expand All @@ -1538,14 +1538,14 @@ Performance will slightly slower than without obfuscation
log: false,
numbersToExpressions: false,
renameGlobals: false,
rotateStringArray: true,
selfDefending: false,
shuffleStringArray: true,
simplify: true,
splitStrings: false,
stringArray: true,
stringArrayEncoding: [],
stringArrayIndexShift: true,
stringArrayRotate: true,
stringArrayShuffle: true,
stringArrayWrappersCount: 1,
stringArrayWrappersChainedCalls: true,
stringArrayWrappersParametersMaxCount: 2,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "javascript-obfuscator",
"version": "2.19.1",
"version": "3.0.0",
"description": "JavaScript obfuscator",
"keywords": [
"obfuscator",
Expand Down
18 changes: 9 additions & 9 deletions src/cli/JavaScriptObfuscatorCLI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
ArraySanitizer
)
.option(
'--ignore-require-imports <boolean>', 'Prevents obfuscation of `require` imports',
'--ignore-imports <boolean>', 'Prevents obfuscation of `require` and `dynamic` imports',
BooleanSanitizer
)
.option(
Expand Down Expand Up @@ -312,10 +312,6 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
`Values: ${CLIUtils.stringifyOptionAvailableValues(RenamePropertiesMode)}. ` +
`Default: ${RenamePropertiesMode.Safe}`
)
.option(
'--rotate-string-array <boolean>', 'Enable rotation of string array values during obfuscation',
BooleanSanitizer
)
.option(
'--seed <string|number>',
'Sets seed for random generator. This is useful for creating repeatable results.',
Expand All @@ -326,10 +322,6 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
'Disables self-defending for obfuscated code',
BooleanSanitizer
)
.option(
'--shuffle-string-array <boolean>', 'Randomly shuffles string array items',
BooleanSanitizer
)
.option(
'--simplify <boolean>', 'Enables additional code obfuscation through simplification',
BooleanSanitizer
Expand Down Expand Up @@ -393,6 +385,14 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
'Enables additional index shift for all string array calls',
BooleanSanitizer
)
.option(
'--string-array-rotate <boolean>', 'Enable rotation of string array values during obfuscation',
BooleanSanitizer
)
.option(
'--string-array-shuffle <boolean>', 'Randomly shuffles string array items',
BooleanSanitizer
)
.option(
'--string-array-wrappers-count <number>',
'Sets the count of wrappers for the string array inside each root or function scope',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ConditionalCommentObfuscatingGuard } from '../../../node-transformers/p
import { CustomCodeHelpersTransformer } from '../../../node-transformers/preparing-transformers/CustomCodeHelpersTransformer';
import { EvalCallExpressionTransformer } from '../../../node-transformers/preparing-transformers/EvalCallExpressionTransformer';
import { ForceTransformStringObfuscatingGuard } from '../../../node-transformers/preparing-transformers/obfuscating-guards/ForceTransformStringObfuscatingGuard';
import { IgnoredRequireImportObfuscatingGuard } from '../../../node-transformers/preparing-transformers/obfuscating-guards/IgnoredRequireImportObfuscatingGuard';
import { IgnoredImportObfuscatingGuard } from '../../../node-transformers/preparing-transformers/obfuscating-guards/IgnoredImportObfuscatingGuard';
import { MetadataTransformer } from '../../../node-transformers/preparing-transformers/MetadataTransformer';
import { ObfuscatingGuardsTransformer } from '../../../node-transformers/preparing-transformers/ObfuscatingGuardsTransformer';
import { ParentificationTransformer } from '../../../node-transformers/preparing-transformers/ParentificationTransformer';
Expand Down Expand Up @@ -63,9 +63,9 @@ export const preparingTransformersModule: interfaces.ContainerModule = new Conta
.whenTargetNamed(ObfuscatingGuard.ForceTransformStringObfuscatingGuard);

bind<IObfuscatingGuard>(ServiceIdentifiers.INodeGuard)
.to(IgnoredRequireImportObfuscatingGuard)
.to(IgnoredImportObfuscatingGuard)
.inSingletonScope()
.whenTargetNamed(ObfuscatingGuard.IgnoredRequireImportObfuscatingGuard);
.whenTargetNamed(ObfuscatingGuard.IgnoredImportObfuscatingGuard);

bind<IObfuscatingGuard>(ServiceIdentifiers.INodeGuard)
.to(ReservedStringObfuscatingGuard)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ export enum ObfuscatingGuard {
BlackListObfuscatingGuard = 'BlackListObfuscatingGuard',
ConditionalCommentObfuscatingGuard = 'ConditionalCommentObfuscatingGuard',
ForceTransformStringObfuscatingGuard = 'ForceTransformStringObfuscatingGuard',
IgnoredRequireImportObfuscatingGuard = 'IgnoredRequireImportObfuscatingGuard',
IgnoredImportObfuscatingGuard = 'IgnoredImportObfuscatingGuard',
ReservedStringObfuscatingGuard = 'ReservedStringObfuscatingGuard'
}
6 changes: 3 additions & 3 deletions src/interfaces/options/IOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface IOptions {
readonly identifierNamesGenerator: TTypeFromEnum<typeof IdentifierNamesGenerator>;
readonly identifiersDictionary: string[];
readonly identifiersPrefix: string;
readonly ignoreRequireImports: boolean;
readonly ignoreImports: boolean;
readonly inputFileName: string;
readonly log: boolean;
readonly numbersToExpressions: boolean;
Expand All @@ -37,10 +37,8 @@ export interface IOptions {
readonly renamePropertiesMode: TRenamePropertiesMode;
readonly reservedNames: string[];
readonly reservedStrings: string[];
readonly rotateStringArray: boolean;
readonly seed: string | number;
readonly selfDefending: boolean;
readonly shuffleStringArray: boolean;
readonly simplify: boolean;
readonly sourceMap: boolean;
readonly sourceMapBaseUrl: string;
Expand All @@ -53,6 +51,8 @@ export interface IOptions {
readonly stringArrayEncoding: TStringArrayEncoding[];
readonly stringArrayIndexesType: TStringArrayIndexesType[];
readonly stringArrayIndexShift: boolean;
readonly stringArrayRotate: boolean;
readonly stringArrayShuffle: boolean;
readonly stringArrayWrappersChainedCalls: boolean;
readonly stringArrayWrappersCount: number;
readonly stringArrayWrappersParametersMaxCount: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class ObfuscatingGuardsTransformer extends AbstractNodeTransformer {
ObfuscatingGuard.BlackListObfuscatingGuard,
ObfuscatingGuard.ConditionalCommentObfuscatingGuard,
ObfuscatingGuard.ForceTransformStringObfuscatingGuard,
ObfuscatingGuard.IgnoredRequireImportObfuscatingGuard,
ObfuscatingGuard.IgnoredImportObfuscatingGuard,
ObfuscatingGuard.ReservedStringObfuscatingGuard
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers';
import { NodeGuards } from '../../../node/NodeGuards';

@injectable()
export class IgnoredRequireImportObfuscatingGuard implements IObfuscatingGuard {
export class IgnoredImportObfuscatingGuard implements IObfuscatingGuard {
/**
* @type {IOptions}
*/
Expand All @@ -27,20 +27,36 @@ export class IgnoredRequireImportObfuscatingGuard implements IObfuscatingGuard {
this.options = options;
}

/**
* @param {Node} node
* @returns {boolean}
*/
private static isDynamicImport (node: ESTree.Node): boolean {
return NodeGuards.isImportExpressionNode(node);
}

/**
* @param {Node} node
* @returns {boolean}
*/
private static isRequireImport (node: ESTree.Node): boolean {
return NodeGuards.isCallExpressionNode(node)
&& NodeGuards.isIdentifierNode(node.callee)
&& node.callee.name === 'require';
}

/**
* @param {Node} node
* @returns {ObfuscatingGuardResult}
*/
public check (node: ESTree.Node): ObfuscatingGuardResult {
if (this.options.ignoreRequireImports) {
if (
NodeGuards.isCallExpressionNode(node)
&& NodeGuards.isIdentifierNode(node.callee)
&& node.callee.name === 'require'
) { return ObfuscatingGuardResult.Ignore; }
if (
NodeGuards.isImportExpressionNode(node)
) { return ObfuscatingGuardResult.Ignore; }
if (this.options.ignoreImports) {
const isIgnoredImport = IgnoredImportObfuscatingGuard.isDynamicImport(node)
|| IgnoredImportObfuscatingGuard.isRequireImport(node);

if (isIgnoredImport) {
return ObfuscatingGuardResult.Ignore;
}
}

return ObfuscatingGuardResult.Transform;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class StringArrayRotateFunctionTransformer extends AbstractNodeTransforme
* @returns {IVisitor | null}
*/
public getVisitor (nodeTransformationStage: NodeTransformationStage): IVisitor | null {
if (!this.options.rotateStringArray) {
if (!this.options.stringArrayRotate) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ export class StringArrayTransformer extends AbstractNodeTransformer {
this.stringArrayStorageAnalyzer.analyze(programNode);
}

if (this.options.shuffleStringArray) {
if (this.options.stringArrayShuffle) {
this.stringArrayStorage.shuffleStorage();
}

if (this.options.rotateStringArray) {
if (this.options.stringArrayRotate) {
this.stringArrayStorage.rotateStorage();
}
}
Expand Down
Loading