8000 Merge pull request #652 from javascript-obfuscator/base64-improvements · sec-js/javascript-obfuscator@f54ed68 · GitHub
[go: up one dir, main page]

Skip to content

Commit f54ed68

Browse files
authored
Merge pull request javascript-obfuscator#652 from javascript-obfuscator/base64-improvements
Base64 improvements
2 parents 79d639f + 7eb25bb commit f54ed68

File tree

22 files changed

+112
-60
lines changed

22 files changed

+112
-60
lines changed

CHANGELOG.md

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

3+
v1.3.0
4+
---
5+
* Improvements of `stringArrayEncoding`: `base64` and `rc4`
6+
37
v1.2.2
48
---
59
* Fixed performance regression of `Initializing` stage after `1.2.0`

dist/index.browser.js

Lines changed: 7 additions & 7 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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "javascript-obfuscator",
3-
"version": "1.2.2",
3+
"version": "1.3.0",
44
"description": "JavaScript obfuscator",
55
"keywords": [
66
"obfuscator",
@@ -77,7 +77,7 @@
7777
"pre-commit": "< 10000 /span>1.2.2",
7878
"rimraf": "3.0.2",
7979
"sinon": "9.0.2",
80-
"threads": "1.6.2",
80+
"threads": "1.6.3",
8181
"ts-loader": "7.0.5",
8282
"ts-node": "8.10.2",
8383
"typescript": "3.9.5",

src/constants/AlphabetString.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const alphabetString: string = 'abcdefghijklmnopqrstuvwxyz';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { alphabetString } from './AlphabetString';
2+
3+
export const alphabetStringUppercase: string = alphabetString.toUpperCase();

src/constants/NumbersString.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const numbersString: string = '0123456789';

src/custom-code-helpers/string-array/StringArrayCallsWrapperCodeHelper.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ import { IEscapeSequenceEncoder } from '../../interfaces/utils/IEscapeSequenceEn
1010
import { IOptions } from '../../interfaces/options/IOptions';
1111
import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
1212

13-
import { ObfuscationTarget } from '../../enums/ObfuscationTarget';
1413
import { StringArrayEncoding } from '../../enums/StringArrayEncoding';
1514

1615
import { initializable } from '../../decorators/Initializable';
1716

1817
import { AtobTemplate } from './templates/string-array-calls-wrapper/AtobTemplate';
19-
import { GlobalVariableNoEvalTemplate } from '../common/templates/GlobalVariableNoEvalTemplate';
2018
import { Rc4Template } from './templates/string-array-calls-wrapper/Rc4Template';
2119
import { SelfDefendingTemplate } from './templates/string-array-calls-wrapper/SelfDefendingTemplate';
2220
import { StringArrayBase64DecodeTemplate } from './templates/string-array-calls-wrapper/StringArrayBase64DecodeTemplate';
@@ -28,6 +26,12 @@ import { NodeUtils } from '../../node/NodeUtils';
2826

2927
@injectable()
3028
export class StringArrayCallsWrapperCodeHelper extends AbstractCustomCodeHelper {
29+
/**
30+
* @type {string}
31+
*/
32+
@initializable()
33+
private atobFunctionName!: string;
34+
3135
/**
3236
* @type {string}
3337
*/
@@ -76,13 +80,16 @@ export class StringArrayCallsWrapperCodeHelper extends AbstractCustomCodeHelper
7680
/**
7781
* @param {string} stringArrayName
7882
* @param {string} stringArrayCallsWrapperName
83+
* @param {string} atobFunctionName
7984
*/
8085
public initialize (
8186
stringArrayName: string,
82-
stringArrayCallsWrapperName: string
87+
stringArrayCallsWrapperName: string,
88+
atobFunctionName: string
8389
): void {
8490
this.stringArrayName = stringArrayName;
8591
this.stringArrayCallsWrapperName = stringArrayCallsWrapperName;
92+
this.atobFunctionName = atobFunctionName;
8693
}
8794

8895
/**
@@ -117,10 +124,12 @@ export class StringArrayCallsWrapperCodeHelper extends AbstractCustomCodeHelper
117124
* @returns {string}
118125
*/
119126
private getDecodeStringArrayTemplate (): string {
120-
const globalVariableTemplate: string = this.options.target !== ObfuscationTarget.BrowserNoEval
121-
? this.getGlobalVariableTemplate()
122-
: GlobalVariableNoEvalTemplate();
123-
const atobPolyfill: string = this.customCodeHelperFormatter.formatTemplate(AtobTemplate(), { globalVariableTemplate });
127+
const atobPolyfill: string = this.customCodeHelperFormatter.formatTemplate(AtobTemplate(), {
128+
atobFunctionName: this.atobFunctionName
129+
});
130+
const rc4Polyfill: string = this.customCodeHelperFormatter.formatTemplate(Rc4Template(), {
131+
atobFunctionName: this.atobFunctionName
132+
});
124133

125134
let decodeStringArrayTemplate: string = '';
126135
let selfDefendingCode: string = '';
@@ -144,8 +153,8 @@ export class StringArrayCallsWrapperCodeHelper extends AbstractCustomCodeHelper
144153
StringArrayRC4DecodeTemplate(this.randomGenerator),
145154
{
146155
atobPolyfill,
156+
rc4Polyfill,
147157
selfDefendingCode,
148-
rc4Polyfill: Rc4Template(),
149158
stringArrayCallsWrapperName: this.stringArrayCallsWrapperName
150159
}
151160
);
@@ -157,6 +166,7 @@ export class StringArrayCallsWrapperCodeHelper extends AbstractCustomCodeHelper
157166
StringArrayBase64DecodeTemplate(this.randomGenerator),
158167
{
159168
atobPolyfill,
169+
atobFunctionName: this.atobFunctionName,
160170
selfDefendingCode,
161171
stringArrayCallsWrapperName: this.stringArrayCallsWrapperName
162172
}

src/custom-code-helpers/string-array/group/StringArrayCodeHelperGroup.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,10 @@ export class StringArrayCodeHelperGroup extends AbstractCustomCodeHelperGroup {
118118
const stringArrayName: string = this.stringArrayStorage.getStorageName();
119119
const stringArrayCallsWrapperName: string = this.stringArrayStorage.getStorageCallsWrapperName();
120120
const stringArrayRotationAmount: number = this.stringArrayStorage.getRotationAmount();
121+
const atobFunctionName: string = this.randomGenerator.getRandomString(6);
121122

122123
stringArrayCodeHelper.initialize(this.stringArrayStorage, stringArrayName);
123-
stringArrayCallsWrapperCodeHelper.initialize(stringArrayName, stringArrayCallsWrapperName);
124+
stringArrayCallsWrapperCodeHelper.initialize(stringArrayName, stringArrayCallsWrapperName, atobFunctionName);
124125
stringArrayRotateFunctionCodeHelper.initialize(stringArrayName, stringArrayRotationAmount);
125126

126127
this.customCodeHelpers.set(CustomCodeHelper.StringArray, stringArrayCodeHelper);

0 commit comments

Comments
 (0)
0