8000 Merge pull request #466 from javascript-obfuscator/custom-nodes-ident… · sec-js/javascript-obfuscator@248f634 · GitHub
[go: up one dir, main page]

Skip to content

Commit 248f634

Browse files
authored
Merge pull request javascript-obfuscator#466 from javascript-obfuscator/custom-nodes-identifier-names-collision-fix
Custom nodes identifier names collision fix
2 parents 3d4a7f9 + 945e885 commit 248f634

File tree

29 files changed

+363
-156
lines changed

29 files changed

+363
-156
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
Change Log
22

3+
v0.20.1
4+
---
5+
* Fixed identifier names generations for `mangled` and `dictionary` identifier names generators
6+
* Fixed combination of `identifierNamesGenerator: dictionary` and `debugProtection` options
7+
* `seed` option now accepts `string` and `number` values
8+
39
v0.20.0
410
---
511
* **Breaking:** dropped support of Node 8 because of end of maintenance support

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ Following options are available for the JS Obfuscator:
343343
--reserved-names '<list>' (comma separated)
344344
--reserved-strings '<list>' (comma separated)
345345
--rotate-string-array <boolean>
346-
--seed <number>
346+
--seed <string|number>
347347
--self-defending <boolean>
348348
--source-map <boolean>
349 8000 349
--source-map-base-url <string>
@@ -673,7 +673,7 @@ Shift the `stringArray` array by a fixed and random (generated at the code obfus
673673
This option is recommended if your original source code isn't small, as the helper function can attract attention.
674674

675675
### `seed`
676-
Type: `number` Default: `0`
676+
Type: `string|number` Default: `0`
677677

678678
This option sets seed for random generator. This is useful for creating repeatable results.
679679

dist/index.browser.js

Lines changed: 4 additions & 4 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.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "javascript-obfuscator",
3-
"version": "0.20.0",
3+
"version": "0.20.1",
44
"description": "JavaScript obfuscator",
55
"keywords": [
66
"obfuscator",

src/JavaScriptObfuscator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export class JavaScriptObfuscator implements IJavaScriptObfuscator {
127127
const timeStart: number = Date.now();
128128
this.logger.info(LoggingMessage.Version, process.env.VERSION);
129129
this.logger.info(LoggingMessage.ObfuscationStarted);
130-
this.logger.info(LoggingMessage.RandomGeneratorSeed, this.randomGenerator.getSeed());
130+
this.logger.info(LoggingMessage.RandomGeneratorSeed, this.randomGenerator.getInputSeed());
131131

132132
// parse AST tree
133133
const astTree: ESTree.Program = this.parseCode(sourceCode);

src/cli/JavaScriptObfuscatorCLI.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
287287
BooleanSanitizer
288288
)
289289
.option(
290-
'--seed <number>',
290+
'--seed <string|number>',
291291
'Sets seed for random generator. This is useful for creating repeatable results.',
292292
parseFloat
293293
)

src/container/modules/generators/GeneratorsModule.ts

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -28,45 +28,46 @@ export const generatorsModule: interfaces.ContainerModule = new ContainerModule(
2828
.whenTargetNamed(IdentifierNamesGenerator.MangledIdentifierNamesGenerator);
2929

3030
// identifier name generator factory
31+
function identifierNameGeneratorFactory (): (context: interfaces.Context) => (options: IOptions) => IIdentifierNamesGenerator {
32+
let cachedIdentifierNamesGenerator: IIdentifierNamesGenerator | null = null;
33+
34+
return (context: interfaces.Context): (options: IOptions) => IIdentifierNamesGenerator => (options: IOptions) => {
35+
if (cachedIdentifierNamesGenerator) {
36+
return cachedIdentifierNamesGenerator;
37+
}
38+
39+
let identifierNamesGenerator: IIdentifierNamesGenerator;
40+
41+
switch (options.identifierNamesGenerator) {
42+
case IdentifierNamesGenerator.DictionaryIdentifierNamesGenerator:
43+
identifierNamesGenerator = context.container.getNamed<IIdentifierNamesGenerator>(
44+
ServiceIdentifiers.IIdentifierNamesGenerator,
45+
IdentifierNamesGenerator.DictionaryIdentifierNamesGenerator
46+
);
47+
48+
break;
49+
50+
case IdentifierNamesGenerator.MangledIdentifierNamesGenerator:
51+
identifierNamesGenerator = context.container.getNamed<IIdentifierNamesGenerator>(
52+
ServiceIdentifiers.IIdentifierNamesGenerator,
53+
IdentifierNamesGenerator.MangledIdentifierNamesGenerator
54+
);
55+
56+
break;
57+
58+
case IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator:
59+
default:
60+
identifierNamesGenerator = context.container.getNamed<IIdentifierNamesGenerator>(
61+
ServiceIdentifiers.IIdentifierNamesGenerator,
62+
IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator
63+
);
64+
}
65+
66+
cachedIdentifierNamesGenerator = identifierNamesGenerator;
67+
68+
return identifierNamesGenerator;
69+
};
70+
}
3171
bind<IIdentifierNamesGenerator>(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
32-
.toFactory<IIdentifierNamesGenerator>((context: interfaces.Context): (options: IOptions) => IIdentifierNamesGenerator => {
33-
let cachedIdentifierNamesGenerator: IIdentifierNamesGenerator | null = null;
34-
35-
return (options: IOptions) => {
36-
if (cachedIdentifierNamesGenerator) {
37-
return cachedIdentifierNamesGenerator;
38-
}
39-
40-
let identifierNamesGenerator: IIdentifierNamesGenerator;
41-
42-
switch (options.identifierNamesGenerator) {
43-
case IdentifierNamesGenerator.DictionaryIdentifierNamesGenerator:
44-
identifierNamesGenerator = context.container.getNamed<IIdentifierNamesGenerator>(
45-
ServiceIdentifiers.IIdentifierNamesGenerator,
46-
IdentifierNamesGenerator.DictionaryIdentifierNamesGenerator
47-
);
48-
49-
break;
50-
51-
case IdentifierNamesGenerator.MangledIdentifierNamesGenerator:
52-
identifierNamesGenerator = context.container.getNamed<IIdentifierNamesGenerator>(
53-
ServiceIdentifiers.IIdentifierNamesGenerator,
54-
IdentifierNamesGenerator.MangledIdentifierNamesGenerator
55-
);
56-
57-
break;
58-
59-
case IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator:
60-
default:
61-
identifierNamesGenerator = context.container.getNamed<IIdentifierNamesGenerator>(
62-
ServiceIdentifiers.IIdentifierNamesGenerator,
63-
IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator
64-
);
65-
}
66-
67-
cachedIdentifierNamesGenerator = identifierNamesGenerator;
68-
69-
return identifierNamesGenerator;
70-
};
71-
});
72+
.toFactory<IIdentifierNamesGenerator>(identifierNameGeneratorFactory());
7273
});

src/container/modules/node-transformers/PreparingTransformersModule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { BlackListObfuscatingGuard } from '../../../node-transformers/preparing-
1212
import { CommentsTransformer } from '../../../node-transformers/preparing-transformers/CommentsTransformer';
1313
import { ConditionalCommentObfuscatingGuard } from '../../../node-transformers/preparing-transformers/obfuscating-guards/ConditionalCommentObfuscatingGuard';
1414
import { CustomNodesTransformer } from '../../../node-transformers/preparing-transformers/CustomNodesTransformer';
15-
import { EvalCallExpressionTransformer } from '../../../node-transformers/preparing-transformers/EvaCallExpressionTransformer';
15+
import { EvalCallExpressionTransformer } from '../../../node-transformers/preparing-transformers/EvalCallExpressionTransformer';
1616
import { MetadataTransformer } from '../../../node-transformers/preparing-transformers/MetadataTransformer';
1717
import { ObfuscatingGuardsTransformer } from '../../../node-transformers/preparing-transformers/ObfuscatingGuardsTransformer';
1818
import { ParentificationTransformer } from '../../../node-transformers/preparing-transformers/ParentificationTransformer';

0 commit comments

Comments
 (0)
0