From 423a616cd7d9980e45fe79e9bb761b5b4232da29 Mon Sep 17 00:00:00 2001 From: sanex Date: Thu, 17 Sep 2020 20:30:10 +0300 Subject: [PATCH] Added example for `stringArrayWrappersType` option --- README.md | 31 +++++++++++++++++++++++++++++++ test/dev/dev.ts | 16 ++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bb889470..a150c656 100644 --- a/README.md +++ b/README.md @@ -1076,6 +1076,37 @@ Available values: * `'function'`: appends function wrappers. More slow performance than with `variable` but allows to additionally shift the `stringArray` index. Highly recommended to use `function` wrappers for higher obfuscation when a performance loss doesn't have a high impact on an obfuscated application. + +Example of the `'function'` option value: +``` +// input +const foo = 'foo'; + +function test () { + const bar = 'bar'; +} + +// output +const a = [ + 'foo', + 'bar' +]; +const b = function (c, d) { + c = c - 0x0; + let e = a[c]; + return e; +}; +const d = function (c, f) { + return b(c - '0x372', f); +}; +const foo = d('0x372'); +function test() { + const e = function (c, f) { + return d(c - -'0x260', f); + }; + const c = e('0x113'); +} +``` ### `stringArrayThreshold` Type: `number` Default: `0.8` Min: `0` Max: `1` diff --git a/test/dev/dev.ts b/test/dev/dev.ts index 140d5c03..03707545 100644 --- a/test/dev/dev.ts +++ b/test/dev/dev.ts @@ -1,17 +1,29 @@ 'use strict'; import { NO_ADDITIONAL_NODES_PRESET } from '../../src/options/presets/NoCustomNodes'; +import { IdentifierNamesGenerator } from '../../src/enums/generators/identifier-names-generators/IdentifierNamesGenerator'; +import { StringArrayWrappersType } from '../../src/enums/node-transformers/string-array-transformers/StringArrayWrappersType'; (function () { const JavaScriptObfuscator: any = require('../../index'); let obfuscatedCode: string = JavaScriptObfuscator.obfuscate( ` - const s = '\0ab cd'; + const foo = 'foo'; + + function test () { + const bar = 'bar'; + } `, { ...NO_ADDITIONAL_NODES_PRESET, - compact: false + compact: false, + identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator, + stringArray: true, + stringArrayThreshold: 1, + stringArrayWrappersChainedCalls: true, + stringArrayWrappersCount: 1, + stringArrayWrappersType: StringArrayWrappersType.Function } ).getObfuscatedCode();