forked from javascript-obfuscator/javascript-obfuscator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringArrayRotateFunctionCodeHelper.spec.ts
More file actions
115 lines (91 loc) · 4.08 KB
/
Copy pathStringArrayRotateFunctionCodeHelper.spec.ts
File metadata and controls
115 lines (91 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import { assert } from 'chai';
import { IdentifierNamesGenerator } from '../../../../src/enums/generators/identifier-names-generators/IdentifierNamesGenerator';
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes';
import { readFileAsString } from '../../../helpers/readFileAsString';
import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscatorFacade';
describe('StringArrayRotateFunctionCodeHelper', () => {
describe('Base behaviour', () => {
const regExp: RegExp = /while *\(!!\[]\) *\{/;
describe('`stringArray` option is set', () => {
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js');
obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
rotateStringArray: true,
stringArray: true,
stringArrayThreshold: 1
}
).getObfuscatedCode();
});
it('should correctly append code helper into the obfuscated code', () => {
assert.match(obfuscatedCode, regExp);
});
});
describe('`stringArray` option isn\'t set', () => {
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js');
obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
rotateStringArray: false,
stringArray: true,
stringArrayThreshold: 1
}
).getObfuscatedCode();
});
it('shouldn\'t append code helper into the obfuscated code', () => {
assert.notMatch(obfuscatedCode, regExp);
});
});
});
describe('Comparison expression', () => {
describe('Should add comparison expression to the code helper', () => {
const comparisonExpressionRegExp: RegExp = /var _0x([a-f0-9]){4,6} *= *-?parseInt\(_0x([a-f0-9]){4,6}\(0x.\)\)/;
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js');
obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
rotateStringArray: true,
stringArray: true,
stringArrayThreshold: 1
}
).getObfuscatedCode();
});
it('should add comparison expression to the code', () => {
assert.match(obfuscatedCode, comparisonExpressionRegExp);
});
});
});
describe('Preserve string array name', () => {
const arrayRotateRegExp: RegExp = /c\['push']\(c\['shift']\(\)\);/;
const comparisonRegExp: RegExp = /if *\(e *=== *d\) *{/;
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js');
obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator,
rotateStringArray: true,
stringArray: true,
stringArrayThreshold: 1
}
).getObfuscatedCode();
});
it('should preserve string array name', () => {
assert.match(obfuscatedCode, arrayRotateRegExp);
});
it('generate valid identifier names', () => {
assert.match(obfuscatedCode, comparisonRegExp);
});
});
});