Skip to content

Commit 423a616

Browse files
committed
Added example for stringArrayWrappersType option
1 parent a22eea0 commit 423a616

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,37 @@ Available values:
10761076
* `'function'`: appends function wrappers. More slow performance than with `variable` but allows to additionally shift the `stringArray` index.
10771077

10781078
Highly recommended to use `function` wrappers for higher obfuscation when a performance loss doesn't have a high impact on an obfuscated application.
1079+
1080+
Example of the `'function'` option value:
1081+
```
1082+
// input
1083+
const foo = 'foo';
1084+
1085+
function test () {
1086+
const bar = 'bar';
1087+
}
1088+
1089+
// output
1090+
const a = [
1091+
'foo',
1092+
'bar'
1093+
];
1094+
const b = function (c, d) {
1095+
c = c - 0x0;
1096+
let e = a[c];
1097+
return e;
1098+
};
1099+
const d = function (c, f) {
1100+
return b(c - '0x372', f);
1101+
};
1102+
const foo = d('0x372');
1103+
function test() {
1104+
const e = function (c, f) {
1105+
return d(c - -'0x260', f);
1106+
};
1107+
const c = e('0x113');
1108+
}
1109+
```
10791110

10801111
### `stringArrayThreshold`
10811112
Type: `number` Default: `0.8` Min: `0` Max: `1`

test/dev/dev.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
'use strict';
22

33
import { NO_ADDITIONAL_NODES_PRESET } from '../../src/options/presets/NoCustomNodes';
4+
import { IdentifierNamesGenerator } from '../../src/enums/generators/identifier-names-generators/IdentifierNamesGenerator';
5+
import { StringArrayWrappersType } from '../../src/enums/node-transformers/string-array-transformers/StringArrayWrappersType';
46

57
(function () {
68
const JavaScriptObfuscator: any = require('../../index');
79

810
let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
911
`
10-
const s = '\0ab cd';
12+
const foo = 'foo';
13+
14+
function test () {
15+
const bar = 'bar';
16+
}
1117
`,
1218
{
1319
...NO_ADDITIONAL_NODES_PRESET,
14-
compact: false
20+
compact: false,
21+
identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator,
22+
stringArray: true,
23+
stringArrayThreshold: 1,
24+
stringArrayWrappersChainedCalls: true,
25+
stringArrayWrappersCount: 1,
26+
stringArrayWrappersType: StringArrayWrappersType.Function
1527
}
1628
).getObfuscatedCode();
1729

0 commit comments

Comments
 (0)