Skip to content

Commit dd7c1df

Browse files
author
sanex3339
committed
Fixed wrong names generation for the custom nodes
1 parent daba144 commit dd7c1df

File tree

17 files changed

+188
-119
lines changed

17 files changed

+188
-119
lines changed

dist/index.browser.js

Lines changed: 5 additions & 5 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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@
6969
"eslint-plugin-jsdoc": "21.0.0",
7070
"eslint-plugin-no-null": "1.0.2",
7171
"eslint-plugin-prefer-arrow": "1.1.7",
72-
"eslint-plugin-unicorn": "16.1.0",
72+
"eslint-plugin-unicorn": "16.1.1",
7373
"fork-ts-checker-notifier-webpack-plugin": "2.0.0",
74-
"fork-ts-checker-webpack-plugin": "4.0.3",
74+
"fork-ts-checker-webpack-plugin": "4.0.4",
7575
"mocha": "7.0.1",
7676
"nyc": "15.0.0",
7777
"pjson": "1.0.9",
@@ -81,7 +81,7 @@
8181
"threads": "1.1.0",
8282
"ts-loader": "6.2.1",
8383
"ts-node": "6.1.0",
84-
"typescript": "3.8.0-beta",
84+
"typescript": "3.8.1-rc",
8585
"webpack": "4.41.6",
8686
"webpack-cli": "3.3.11",
8787
"webpack-node-externals": "1.7.2"

src/custom-nodes/CustomNodeObfuscator.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import { ICustomNodeObfuscator } from '../interfaces/custom-nodes/ICustomNodeObf
77
import { IOptions } from '../interfaces/options/IOptions';
88
import { IRandomGenerator } from '../interfaces/utils/IRandomGenerator';
99

10-
import { IdentifierNamesGenerator } from '../enums/generators/identifier-names-generators/IdentifierNamesGenerator';
11-
1210
import { NO_ADDITIONAL_NODES_PRESET } from '../options/presets/NoCustomNodes';
1311

1412
import { JavaScriptObfuscator } from '../JavaScriptObfuscatorFacade';
@@ -43,24 +41,8 @@ export class CustomNodeObfuscator implements ICustomNodeObfuscator {
4341
* @returns {string}
4442
*/
4543
public obfuscateTemplate (template: string, additionalOptions: TInputOptions = {}): string {
46-
/**
47-
* During the first pass we should rename all identifiers to a random one
48-
*/
49-
const firstPassObfuscatedCode = JavaScriptObfuscator.obfuscate(
44+
return JavaScriptObfuscator.obfuscate(
5045
template,
51-
{
52-
...NO_ADDITIONAL_NODES_PRESET,
53-
identifierNamesGenerator: IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator,
54-
seed: 1
55-
}
56-
).getObfuscatedCode();
57-
58-
/**
59-
* During the seconds pass we should obfuscate template to the same format as the main code
60-
* Also, we should add additional transformations that depends on the custom node
61-
*/
62-
const secondPassObfuscatedCode = JavaScriptObfuscator.obfuscate(
63-
firstPassObfuscatedCode,
6446
{
6547
...NO_ADDITIONAL_NODES_PRESET,
6648
identifierNamesGenerator: this.options.identifierNamesGenerator,
@@ -69,7 +51,5 @@ export class CustomNodeObfuscator implements ICustomNodeObfuscator {
6951
...additionalOptions
7052
}
7153
).getObfuscatedCode();
72-
73-
return secondPassObfuscatedCode;
7454
}
7555
}

src/custom-nodes/domain-lock-nodes/DomainLockNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export class DomainLockNode extends AbstractCustomNode {
9090
: GlobalVariableNoEvalTemplate();
9191

9292
return this.customNodeFormatter.formatTemplate(DomainLockNodeTemplate(), {
93-
domainLockFunctionName: this.randomGenerator.getRandomString(5),
93+
domainLockFunctionName: this.identifierNamesGenerator.generate(),
9494
diff,
9595
domains: hiddenDomainsString,
9696
globalVariableTemplate,

src/custom-nodes/domain-lock-nodes/group/DomainLockCustomNodeGroup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export class DomainLockCustomNodeGroup extends AbstractCustomNodeGroup {
9191
return;
9292
}
9393

94-
const callsControllerFunctionName: string = this.randomGenerator.getRandomString(5);
94+
const callsControllerFunctionName: string = this.identifierNamesGenerator.generate();
9595

9696
const domainLockNode: ICustomNode<TInitialData<DomainLockNode>> =
9797
this.customNodeFactory(CustomNode.DomainLockNode);

src/custom-nodes/object-expression-keys-transformer-nodes/ObjectExpressionVariableDeclarationHostNode.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
1414

1515
import { AbstractCustomNode } from '../AbstractCustomNode';
1616
import { NodeFactory } from '../../node/NodeFactory';
17+
import { NodeGuards } from '../../node/NodeGuards';
1718

1819
@injectable()
1920
export class ObjectExpressionVariableDeclarationHostNode extends AbstractCustomNode {
@@ -60,12 +61,14 @@ export class ObjectExpressionVariableDeclarationHostNode extends AbstractCustomN
6061
* @returns {TStatement[]}
6162
*/
6263
protected getNodeStructure (nodeTemplate: string): TStatement[] {
64+
const variableDeclarationName: string = NodeGuards.isProgramNode(this.lexicalScopeNode)
65+
? this.identifierNamesGenerator.generate()
66+
: this.identifierNamesGenerator.generateForLexicalScope(this.lexicalScopeNode);
67+
6368
const structure: TStatement = NodeFactory.variableDeclarationNode(
6469
[
6570
NodeFactory.variableDeclaratorNode(
66-
NodeFactory.identifierNode(
67-
this.identifierNamesGenerator.generateForLexicalScope(this.lexicalScopeNode)
68-
),
71+
NodeFactory.identifierNode(variableDeclarationName),
6972
NodeFactory.objectExpressionNode(this.properties)
7073
)
7174
],

src/custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export class SelfDefendingUnicodeNode extends AbstractCustomNode {
7979
protected getNodeTemplate (): string {
8080
return this.customNodeObfuscator.obfuscateTemplate(
8181
this.customNodeFormatter.formatTemplate(SelfDefendingTemplate(this.escapeSequenceEncoder), {
82-
selfDefendingFunctionName: this.randomGenerator.getRandomString(5),
82+
selfDefendingFunctionName: this.identifierNamesGenerator.generate(),
8383
singleNodeCallControllerFunctionName: this.callsControllerFunctionName
8484
}),
8585
{

src/custom-nodes/self-defending-nodes/group/SelfDefendingCustomNodeGroup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export class SelfDefendingCustomNodeGroup extends AbstractCustomNodeGroup {
9191
return;
9292
}
9393

94-
const callsControllerFunctionName: string = this.randomGenerator.getRandomString(5);
94+
const callsControllerFunctionName: string = this.identifierNamesGenerator.generate();
9595

9696
const selfDefendingUnicodeNode: ICustomNode<TInitialData<SelfDefendingUnicodeNode>> =
9797
this.customNodeFactory(CustomNode.SelfDefendingUnicodeNode);

0 commit comments

Comments
 (0)