8000 `shuffleStringArray` option · sec-js/javascript-obfuscator@1edf96c · GitHub
[go: up one dir, main page]

Skip to content

Commit 1edf96c

Browse files
author
sanex3339
committed
shuffleStringArray option
1 parent b764844 commit 1edf96c

File tree

28 files changed

+392
-88
lines changed

28 files changed

+392
-88
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ Change Log
22

33
v0.23.0
44
---
5+
* **New option:** `shuffleStringArray` randomly shuffles string array items
56
* **Internal change:** switched AST parser from `espree` on `acorn`
7+
* **Internal refactoring:** refactoring of string array storage and related things
68

79
v0.22.1
810
---

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ Following options are available for the JS Obfuscator:
306306
rotateStringArray: true,
307307
seed: 0,
308308
selfDefending: false,
309+
shuffleStringArray: true,
309310
sourceMap: false,
310311
sourceMapBaseUrl: '',
311312
sourceMapFileName: '',
@@ -349,6 +350,7 @@ Following options are available for the JS Obfuscator:
349350
--rotate-string-array <boolean>
350351
--seed <string|number>
351352
--self-defending <boolean>
353+
--shuffle-string-array <boolean>
352354
--source-map <boolean>
353355
--source-map-base-url <string>
354356
--source-map-file-name <string>
@@ -691,6 +693,13 @@ Type: `boolean` Default: `false`
691693

692694
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.
693695

696+
### `shuffleStringArray`
697+
Type: `boolean` Default: `true`
698+
699+
##### :warning: [`stringArray`](#stringarray) must be enabled
700+
701+
Randomly shuffles the `stringArray` array items.
702+
694703
### `sourceMap`
695704
Type: `boolean` Default: `false`
696705

@@ -867,6 +876,7 @@ Performance will 50-100% slower than without obfuscation
867876
renameGlobals: false,
868877
rotateStringArray: true,
869878
selfDefending: true,
879+
shuffleStringArray: true,
870880
splitStrings: true,
871881
splitStringsChunkLength: '5',
872882
stringArray: true,
@@ -896,6 +906,7 @@ Performance will 30-35% slower than without obfuscation
896906
renameGlobals: false,
897907
rotateStringArray: true,
898908
selfDefending: true,
909+
shuffleStringArray: true,
899910
splitStrings: true,
900911
splitStringsChunkLength: '10',
901912
stringArray: true,
@@ -923,6 +934,7 @@ Performance will slightly slower than without obfuscation
923934
renameGlobals: false,
924935
rotateStringArray: true,
925936
selfDefending: true,
937+
shuffleStringArray: true,
926938
splitStrings: false,
927939
stringArray: true,
928940
stringArrayEncoding: false,

dist/index.browser.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.cli.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/analyzers/string-array-storage-analyzer/StringArrayStorageAnalyzer.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
44
import * as estraverse from 'estraverse';
55
import * as ESTree from 'estree';
66

7-
import { TStringArrayStorage } from '../../types/storages/TStringArrayStorage';
8-
97
import { IOptions } from '../../interfaces/options/IOptions';
108
import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
9+
import { IStringArrayStorage } from '../../interfaces/storages/string-array-storage/IStringArrayStorage';
1110
import { IStringArrayStorageAnalyzer } from '../../interfaces/analyzers/string-array-storage-analyzer/IStringArrayStorageAnalyzer';
1211
import { IStringArrayStorageItemData } from '../../interfaces/storages/string-array-storage/IStringArrayStorageItem';
1312

@@ -35,22 +34,22 @@ export class StringArrayStorageAnalyzer implements IStringArrayStorageAnalyzer {
3534
private readonly randomGenerator: IRandomGenerator;
3635

3736
/**
38-
* @type {TStringArrayStorage}
37+
* @type {IStringArrayStorage}
3938
*/
40-
private readonly stringArrayStorage: TStringArrayStorage;
39+
private readonly stringArrayStorage: IStringArrayStorage;
4140

4241
/**
4342
* @type {Map<ESTree.Literal, IStringArrayStorageItemData>}
4443
*/
4544
private readonly stringArrayStorageData: Map<ESTree.Literal, IStringArrayStorageItemData> = new Map();
4645

4746
/**
48-
* @param {TStringArrayStorage} stringArrayStorage
47+
* @param {IStringArrayStorage} stringArrayStorage
4948
* @param {IRandomGenerator} randomGenerator
5049
* @param {IOptions} options
5150
*/
5251
constructor (
53-
@inject(ServiceIdentifiers.TStringArrayStorage) stringArrayStorage: TStringArrayStorage,
52+
@inject(ServiceIdentifiers.TStringArrayStorage) stringArrayStorage: IStringArrayStorage,
5453
@inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
5554
@inject(ServiceIdentifiers.IOptions) options: IOptions,
5655
) {

src/cli/JavaScriptObfuscatorCLI.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
283283
BooleanSanitizer
284284
)
285285
.option(
286-
'--rotate-string-array <boolean>', 'Disable rotation of unicode array values during obfuscation',
286+
'--rotate-string-array <boolean>', 'Enable rotation of string array values during obfuscation',
287287
BooleanSanitizer
288288
)
289289
.option(
@@ -296,6 +296,10 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
296296
'Disables self-defending for obfuscated code',
297297
BooleanSanitizer
298298
)
299+
.option(
300+
'--shuffle-string-array <boolean>', 'Randomly shuffles string array items',
301+
BooleanSanitizer
302+
)
299303
.option(
300304
'--source-map <boolean>',
301305
'Enables source map generation',

src/container/modules/storages/StoragesModule.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { ServiceIdentifiers } from '../../ServiceIdentifiers';
33

44
import { TControlFlowStorage } from '../../../types/storages/TControlFlowStorage';
55
import { TCustomNodeGroupStorage } from '../../../types/storages/TCustomNodeGroupStorage';
6-
import { TStringArrayStorage } from '../../../types/storages/TStringArrayStorage';
76

87
import { IOptions } from '../../../interfaces/options/IOptions';
98
import { IRandomGenerator } from '../../../interfaces/utils/IRandomGenerator';
9+
import { IStringArrayStorage } from '../../../interfaces/storages/string-array-storage/IStringArrayStorage';
1010

1111
import { ControlFlowStorage } from '../../../storages/control-flow/ControlFlowStorage';
1212
import { CustomNodeGroupStorage } from '../../../storages/custom-node-group/CustomNodeGroupStorage';
@@ -18,7 +18,7 @@ export const storagesModule: interfaces.ContainerModule = new ContainerModule((b
1818
.to(CustomNodeGroupStorage)
1919
.inSingletonScope();
2020

21-
bind<TStringArrayStorage>(ServiceIdentifiers.TStringArrayStorage)
21+
bind<IStringArrayStorage>(ServiceIdentifiers.TStringArrayStorage)
2222
.to(StringArrayStorage)
2323
.inSingletonScope();
2424

src/custom-nodes/string-array-nodes/StringArrayNode.ts

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,33 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
33

44
import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory';
55
import { TStatement } from '../../types/node/TStatement';
6-
import { TStringArrayStorage } from '../../types/storages/TStringArrayStorage';
76

87
import { IOptions } from '../../interfaces/options/IOptions';
98
import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
109
import { ICustomNodeFormatter } from '../../interfaces/custom-nodes/ICustomNodeFormatter';
10+
import { IStringArrayStorage } from '../../interfaces/storages/string-array-storage/IStringArrayStorage';
1111

1212
import { initializable } from '../../decorators/Initializable';
1313

1414
import { StringArrayTemplate } from '../../templates/string-array-nodes/string-array-node/StringArrayTemplate';
1515

1616
import { AbstractCustomNode } from '../AbstractCustomNode';
1717
import { NodeUtils } from '../../node/NodeUtils';
18-
import { StringArrayStorage } from '../../storages/string-array/StringArrayStorage';
1918

2019
@injectable()
2120
export class StringArrayNode extends AbstractCustomNode {
2221
/**
23-
* @type {TStringArrayStorage}
22+
* @type {IStringArrayStorage}
2423
*/
2524
@initializable()
26-
private stringArrayStorage!: TStringArrayStorage;
25+
private stringArrayStorage!: IStringArrayStorage;
2726

2827
/**
2928
* @type {string}
3029
*/
3130
@initializable()
3231
private stringArrayName!: string;
3332

34-
/**
35-
* @type {number}
36-
*/
37-
@initializable()
38-
private stringArrayRotateValue!: number;
39-
4033
/**
4134
* @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
4235
* @param {ICustomNodeFormatter} customNodeFormatter
@@ -54,27 +47,15 @@ export class StringArrayNode extends AbstractCustomNode {
5447
}
5548

5649
/**
57-
* @param {TStringArrayStorage} stringArrayStorage
50+
* @param {IStringArrayStorage} stringArrayStorage
5851
* @param {string} stringArrayName
59-
* @param {number} stringArrayRotateValue
6052
*/
6153
public initialize (
62-
stringArrayStorage: TStringArrayStorage,
63-
stringArrayName: string,
64-
stringArrayRotateValue: number
54+
stringArrayStorage: IStringArrayStorage,
55+
stringArrayName: string
6556
): void {
6657
this.stringArrayStorage = stringArrayStorage;
6758
this.stringArrayName = stringArrayName;
68-
this.stringArrayRotateValue = stringArrayRotateValue;
69-
}
70-
71-
/**
72-
* @returns {TStatement[]}
73-
*/
74-
public getNode (): TStatement[] {
75-
(<StringArrayStorage>this.stringArrayStorage).rotateStorage(this.stringArrayRotateValue);
76-
77-
return super.getNode();
7859
}
7960

8061
/**

src/custom-nodes/string-array-nodes/StringArrayRotateFunctionNode.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class StringArrayRotateFunctionNode extends AbstractCustomNode {
3838
* @param {number}
3939
*/
4040
@initializable()
41-
private stringArrayRotateValue!: number;
41+
private stringArrayRotationAmount!: number;
4242

4343
/**
4444
* @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
@@ -62,14 +62,14 @@ export class StringArrayRotateFunctionNode extends AbstractCustomNode {
6262

6363
/**
6464
* @param {string} stringArrayName
65-
* @param {number} stringArrayRotateValue
65+
* @param {number} stringArrayRotationAmount
6666
*/
6767
public initialize (
6868
stringArrayName: string,
69-
stringArrayRotateValue: number
69+
stringArrayRotationAmount: number
7070
): void {
7171
this.stringArrayName = stringArrayName;
72-
this.stringArrayRotateValue = stringArrayRotateValue;
72+
this.stringArrayRotationAmount = stringArrayRotationAmount;
7373
}
7474

7575
/**
@@ -103,7 +103,7 @@ export class StringArrayRotateFunctionNode extends AbstractCustomNode {
103103
code,
104104
timesName,
105105
stringArrayName: this.stringArrayName,
106-
stringArrayRotateValue: NumberUtils.toHex(this.stringArrayRotateValue),
106+
stringArrayRotationAmount: NumberUtils.toHex(this.stringArrayRotationAmount),
107107
whileFunctionName
108108
}),
109109
{

0 commit comments

Comments
 (0)
0