Skip to content

Commit 6a31817

Browse files
committed
Update VM options
1 parent ea26067 commit 6a31817

1 file changed

Lines changed: 46 additions & 28 deletions

File tree

README.md

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,8 +1871,8 @@ Specify exactly which root-level functions should get VM protection by name.
18711871
**Example:**
18721872
```javascript
18731873
{
1874-
vmObfuscation: true,
1875-
vmTargetFunctions: ['someFunctionName']
1874+
vmObfuscation: true,
1875+
vmTargetFunctions: ['someFunctionName']
18761876
}
18771877
```
18781878

@@ -1886,8 +1886,8 @@ Specify root-level functions that should never get VM protection. Takes preceden
18861886
**Example:**
18871887
```javascript
18881888
{
1889-
vmObfuscation: true,
1890-
vmExcludeFunctions: ['someFunctionName']
1889+
vmObfuscation: true,
1890+
vmExcludeFunctions: ['someFunctionName']
18911891
}
18921892
```
18931893

@@ -1907,28 +1907,28 @@ Controls how functions/methods are selected for VM obfuscation.
19071907
```javascript
19081908
// Source code
19091909
function regularFunction() {
1910-
return 'not virtualized';
1910+
return 'not virtualized';
19111911
}
19121912

19131913
/* javascript-obfuscator:vm */
19141914
function sensitiveFunction() {
1915-
return 'this will be VM-protected';
1915+
return 'this will be VM-protected';
19161916
}
19171917

19181918
function outer() {
1919-
/* javascript-obfuscator:vm */
1920-
function nestedSensitive() {
1921-
return 'nested but still VM-protected';
1922-
}
1923-
return nestedSensitive();
1919+
/* javascript-obfuscator:vm */
1920+
function nestedSensitive() {
1921+
return 'nested but still VM-protected';
1922+
}
1923+
return nestedSensitive();
19241924
}
19251925
```
19261926

19271927
```javascript
19281928
// Obfuscator options
19291929
{
1930-
vmObfuscation: true,
1931-
vmTargetFunctionsMode: 'comment'
1930+
vmObfuscation: true,
1931+
vmTargetFunctionsMode: 'comment'
19321932
}
19331933
```
19341934

@@ -2021,10 +2021,10 @@ vmBytecodeArrayEncodingKeyGetter: "window.config.encryption.key"
20212021
```ts
20222022
// Build time
20232023
JavaScriptObfuscator.obfuscate(code, {
2024-
vmObfuscation: true,
2025-
vmBytecodeArrayEncoding: true,
2026-
vmBytecodeArrayEncodingKey: 'mySecretKey123',
2027-
vmBytecodeArrayEncodingKeyGetter: 'window.__VM_KEY__'
2024+
vmObfuscation: true,
2025+
vmBytecodeArrayEncoding: true,
2026+
vmBytecodeArrayEncodingKey: 'mySecretKey123',
2027+
vmBytecodeArrayEncodingKeyGetter: 'window.__VM_KEY__'
20282028
});
20292029

20302030
// Runtime - key must be set before obfuscated code runs
@@ -2046,26 +2046,24 @@ Type: `boolean` Default: `false`
20462046

20472047
Injects fake bytecode sequences that are never executed. These look like real instructions but are skipped during runtime, confusing analysis tools that process them.
20482048

2049-
### `vmCompactDispatcher`
2049+
### `vmMacroOps`
20502050
Type: `boolean` Default: `false`
20512051

2052-
Uses a single unified dispatcher (generator-based) for both sync and async/generator code execution. By default (`false`), the VM generates two separate dispatchers: a non-generator version for sync code (faster) and a generator version for async/generator code. When enabled, only the generator-based dispatcher is used for all execution.
2052+
Combines common instruction sequences into single "macro" opcodes. For example, `LOAD + ADD + STORE` might become a single `MACRO_ADD_TO_VAR` instruction. This breaks pattern recognition and can improve performance.
20532053

2054-
**Trade-offs:**
2055-
- `false` (default): Larger code size due to dual dispatchers, but faster sync execution (no generator overhead)
2056-
- `true`: Smaller code size with single dispatcher, but sync code has generator protocol overhead
2054+
### `vmDebugProtection`
2055+
Type: `boolean` Default: `false`
20572056

2058-
Use this when code size is more important than sync execution speed.
2057+
Adds multi-layered anti-debugging, anti-analysis, and anti-LLM defenses to the VM runtime. For best results, allow `unsafe-eval` in your Content Security Policy. Works best with `browser`/`browser-no-eval` targets.
20592058

2060-
### `vmMacroOps`
2059+
### `vmSelfDefending`
20612060
Type: `boolean` Default: `false`
20622061

2063-
Combines common instruction sequences into single "macro" opcodes. For example, `LOAD + ADD + STORE` might become a single `MACRO_ADD_TO_VAR` instruction. This breaks pattern recognition and can improve performance.
2062+
Adds multi-layered tamper detection, anti-hooking, and anti-reverse-engineering protection to the VM runtime.
20642063

2065-
### `vmDebugProtection`
2066-
Type: `boolean` Default: `false`
2064+
> :warning: This option force-enables [`vmBytecodeArrayEncoding`](#vmbytecodeArrayEncoding).
20672065
2068-
Adds anti-debugging measures to the VM runtime. Detects debugger presence and alters behavior when debugging is detected.
2066+
Strongly recommended to use together with [`vmDebugProtection`](#vmDebugProtection), [`vmBytecodeArrayEncodingKey`](#vmbytecodeArrayEncodingKey), and [`vmBytecodeArrayEncodingKeyGetter`](#vmbytecodeArrayEncodingKeyGetter).
20692067

20702068
### `vmStatefulOpcodes`
20712069
Type: `boolean` Default: `false`
@@ -2079,6 +2077,26 @@ Encrypts values on the VM stack during execution. Values are encoded when pushed
20792077

20802078
This option heavily affects performance.
20812079

2080+
### `vmCompactDispatcher`
2081+
Type: `boolean` Default: `false`
2082+
2083+
Uses a single VM executor instead of dual executors (sync + generator). Reduces obfuscated code size but adds ~20% performance overhead on recursion-heavy code.
2084+
2085+
- `false` (default): dual executors — optimal performance, larger output
2086+
- `true`: single executor — smaller output, slightly slower
2087+
2088+
### `vmStringArrayBytecodeOnly`
2089+
Type: `boolean` Default: `false`
2090+
2091+
When enabled, the string array will **only** extract strings from bytecode data — no other strings in the code are transformed. This force-enables `stringArray` even if it's not explicitly set.
2092+
2093+
**Why use this:** Extracting all VM runtime strings to a string array is slow. This option targets only bytecode content for string array extraction, improving performance while still protecting bytecode constants.
2094+
2095+
- When `vmBytecodeArrayEncoding: false` — strings inside bytecode constant pools (`c` arrays) are extracted
2096+
- When `vmBytecodeArrayEncoding: true` — top-level base64 encoded bytecode strings are extracted
2097+
- `stringArrayThreshold` still controls what percentage of those bytecode strings are extracted
2098+
2099+
20822100
### `strictMode`
20832101
Type: `boolean | null` Default: `null`
20842102

0 commit comments

Comments
 (0)