javascript-obfuscator 4.2.1 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +1 -1
- package/CHANGELOG.md +4 -0
- package/README.md +203 -0
- package/dist/index.browser.js +1 -1
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cli.js +1 -1
- package/dist/index.cli.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
- package/typings/index.d.ts +7 -0
- package/typings/src/JavaScriptObfuscatorFacade.d.ts +4 -0
- package/typings/src/interfaces/pro-api/IProApiClient.d.ts +22 -0
- package/typings/src/pro-api/ApiError.d.ts +5 -0
- package/typings/src/pro-api/ProApiClient.d.ts +9 -0
- package/typings/src/pro-api/ProApiObfuscationResult.d.ts +11 -0
package/.eslintrc.js
CHANGED
|
@@ -271,7 +271,7 @@ module.exports = {
|
|
|
271
271
|
'prefer-const': 'error',
|
|
272
272
|
'prefer-object-spread': 'error',
|
|
273
273
|
'prefer-template': 'error',
|
|
274
|
-
'quote-props': ['
|
|
274
|
+
'quote-props': ['off', 'as-needed'],
|
|
275
275
|
'quotes': 'off',
|
|
276
276
|
'radix': 'error',
|
|
277
277
|
'space-before-function-paren': 'off',
|
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -17,6 +17,7 @@ Huge thanks to all supporters!
|
|
|
17
17
|
JavaScript Obfuscator is a powerful free obfuscator for JavaScript, containing a variety of features which provide protection for your source code.
|
|
18
18
|
|
|
19
19
|
**Key features:**
|
|
20
|
+
- VM obfuscation (via [JavaScript Obfuscator Pro](https://obfuscator.io/))
|
|
20
21
|
- variables renaming
|
|
21
22
|
- strings extraction and encryption
|
|
22
23
|
- dead code injection
|
|
@@ -259,6 +260,103 @@ Returns a map object which keys are identifiers of source codes and values are `
|
|
|
259
260
|
|
|
260
261
|
Returns an options object for the passed options preset name.
|
|
261
262
|
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
## :shield: Pro API Methods (VM Obfuscation)
|
|
266
|
+
|
|
267
|
+
The Pro API methods provide access to **VM-based bytecode obfuscation** through the [obfuscator.io](https://obfuscator.io) cloud service. VM obfuscation is the most advanced and secure form of code protection available, transforming your JavaScript functions into custom bytecode that runs on an embedded virtual machine.
|
|
268
|
+
|
|
269
|
+
**Why VM Obfuscation?**
|
|
270
|
+
- **Strongest protection**: Code is converted to bytecode that cannot be directly understood
|
|
271
|
+
- **Anti-decompilation**: No standard JavaScript to reverse engineer
|
|
272
|
+
- **Customizable VM**: Each obfuscation generates unique opcodes and VM structure
|
|
273
|
+
- **Layered security**: Combine with other obfuscation options for defense in depth
|
|
274
|
+
|
|
275
|
+
### Getting an API Token
|
|
276
|
+
|
|
277
|
+
To use Pro API methods, you need a valid API token from [obfuscator.io](https://obfuscator.io):
|
|
278
|
+
|
|
279
|
+
1. Create an account at [obfuscator.io](https://obfuscator.io)
|
|
280
|
+
2. Subscribe to a Pro, Team, or Business plan that includes API access
|
|
281
|
+
3. Generate your API token at [obfuscator.io/dashboard](https://obfuscator.io/dashboard)
|
|
282
|
+
|
|
283
|
+
### `obfuscatePro(sourceCode, options, proApiConfig, onProgress?)` :new:
|
|
284
|
+
|
|
285
|
+
**Async method** that obfuscates code using the Pro API with VM-based bytecode obfuscation.
|
|
286
|
+
|
|
287
|
+
```javascript
|
|
288
|
+
const JavaScriptObfuscator = require('javascript-obfuscator');
|
|
289
|
+
|
|
290
|
+
const result = await JavaScriptObfuscator.obfuscatePro(
|
|
291
|
+
`function hello() { console.log("Hello World"); }`,
|
|
292
|
+
{
|
|
293
|
+
vmObfuscation: true, // Required!
|
|
294
|
+
vmObfuscationThreshold: 1,
|
|
295
|
+
compact: true
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
apiToken: 'your_javascript_obfuscator_pro_api_token'
|
|
299
|
+
}
|
|
300
|
+
);
|
|
301
|
+
|
|
302
|
+
console.log(result.getObfuscatedCode());
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
**Parameters:**
|
|
306
|
+
|
|
307
|
+
* `sourceCode` (`string`) – source code to obfuscate
|
|
308
|
+
* `options` (`Object`) – obfuscation options. **Must include `vmObfuscation: true`**
|
|
309
|
+
* `apiConfig` (`Object`) – Pro API configuration:
|
|
310
|
+
* `apiToken` (`string`, required) – your API token from obfuscator.io
|
|
311
|
+
* `timeout` (`number`, optional) – request timeout in ms (default: `300000` - 5 minutes)
|
|
312
|
+
* `onProgress` (`function`, optional) – callback for progress updates during obfuscation
|
|
313
|
+
|
|
314
|
+
**Returns:** `Promise<ObfuscationResult>`
|
|
315
|
+
|
|
316
|
+
**Throws:** `ApiError` if:
|
|
317
|
+
- `vmObfuscation` is not enabled in options
|
|
318
|
+
- API token is invalid or expired
|
|
319
|
+
- API request fails
|
|
320
|
+
|
|
321
|
+
### Pro API with Progress Updates
|
|
322
|
+
|
|
323
|
+
The API uses streaming mode to provide real-time progress updates during obfuscation:
|
|
324
|
+
|
|
325
|
+
```javascript
|
|
326
|
+
const result = await JavaScriptObfuscator.obfuscatePro(
|
|
327
|
+
sourceCode,
|
|
328
|
+
{
|
|
329
|
+
vmObfuscation: true,
|
|
330
|
+
vmObfuscationThreshold: 1
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
apiToken: 'your_javascript_obfuscator_pro_api_token'
|
|
334
|
+
},
|
|
335
|
+
(message) => {
|
|
336
|
+
console.log('Progress:', message);
|
|
337
|
+
// Output: "Validating request...", "Authenticating...", "Obfuscating...", etc.
|
|
338
|
+
}
|
|
339
|
+
);
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
### Error Handling
|
|
343
|
+
|
|
344
|
+
```javascript
|
|
345
|
+
const { ApiError } = require('javascript-obfuscator');
|
|
346
|
+
|
|
347
|
+
try {
|
|
348
|
+
const result = await JavaScriptObfuscator.obfuscatePro(sourceCode, options, config);
|
|
349
|
+
} catch (error) {
|
|
350
|
+
if (error instanceof ApiError) {
|
|
351
|
+
console.error(`API Error (${error.statusCode}): ${error.message}`);
|
|
352
|
+
} else {
|
|
353
|
+
throw error;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
---
|
|
359
|
+
|
|
262
360
|
## CLI usage
|
|
263
361
|
|
|
264
362
|
See [CLI options](#cli-options).
|
|
@@ -1640,6 +1738,111 @@ The performance will be at a relatively normal level
|
|
|
1640
1738
|
|
|
1641
1739
|
<!-- ##options-end## -->
|
|
1642
1740
|
|
|
1741
|
+
## JavaScript Obfuscator Pro VM options
|
|
1742
|
+
|
|
1743
|
+
### `vmObfuscation`
|
|
1744
|
+
Type: `boolean` Default: `false`
|
|
1745
|
+
|
|
1746
|
+
Enables VM-based bytecode obfuscation. When enabled, JavaScript functions are compiled into custom bytecode that runs on an embedded virtual machine. This provides the highest level of protection as the original code logic is completely transformed.
|
|
1747
|
+
|
|
1748
|
+
**Warning:** This significantly increases code size and may impact performance. Use `vmObfuscationThreshold` to control which root-level functions are transformed.
|
|
1749
|
+
|
|
1750
|
+
### `vmObfuscationThreshold`
|
|
1751
|
+
Type: `number` Default: `1`
|
|
1752
|
+
|
|
1753
|
+
The probability (from 0 to 1) that a function will be transformed to VM bytecode when `vmObfuscation` is enabled.
|
|
1754
|
+
|
|
1755
|
+
- `0` - no functions will be transformed
|
|
1756
|
+
- `0.5` - 50% of functions will be transformed
|
|
1757
|
+
- `1` - all functions will be transformed
|
|
1758
|
+
|
|
1759
|
+
### `vmTargetFunctions`
|
|
1760
|
+
Type: `string[]` Default: `[]`
|
|
1761
|
+
|
|
1762
|
+
Array of root-level function names to target for VM obfuscation. When specified, only these functions will be transformed (subject to `vmObfuscationThreshold`). Empty array means all functions are candidates.
|
|
1763
|
+
|
|
1764
|
+
### `vmExcludeFunctions`
|
|
1765
|
+
Type: `string[]` Default: `[]`
|
|
1766
|
+
|
|
1767
|
+
Array of root-level function names to exclude from VM obfuscation. These functions will never be transformed regardless of other settings.
|
|
1768
|
+
|
|
1769
|
+
### `vmOpcodeShuffle`
|
|
1770
|
+
Type: `boolean` Default: `false`
|
|
1771
|
+
|
|
1772
|
+
Randomizes the opcode mapping for each obfuscation run. Makes static analysis more difficult as opcode meanings change between builds.
|
|
1773
|
+
|
|
1774
|
+
### `vmBytecodeEncoding`
|
|
1775
|
+
Type: `boolean` Default: `false`
|
|
1776
|
+
|
|
1777
|
+
Encodes the bytecode instructions using XOR encryption. The decoding key is derived at runtime, adding another layer of protection.
|
|
1778
|
+
|
|
1779
|
+
### `vmBytecodeArrayEncoding`
|
|
1780
|
+
Type: `boolean` Default: `false`
|
|
1781
|
+
|
|
1782
|
+
Applies additional encoding to the bytecode array, making it harder to identify bytecode patterns through static analysis.
|
|
1783
|
+
|
|
1784
|
+
### `vmJumpsEncoding`
|
|
1785
|
+
Type: `boolean` Default: `false`
|
|
1786
|
+
|
|
1787
|
+
Encodes jump targets and offsets in the bytecode. This obscures control flow and makes it harder to follow program execution.
|
|
1788
|
+
|
|
1789
|
+
### `vmDecoyOpcodes`
|
|
1790
|
+
Type: `boolean` Default: `false`
|
|
1791
|
+
|
|
1792
|
+
Inserts fake opcodes into the dispatcher that are never executed. Increases code complexity and confuses reverse engineering attempts.
|
|
1793
|
+
|
|
1794
|
+
### `vmDeadCodeInjection`
|
|
1795
|
+
Type: `boolean` Default: `false`
|
|
1796
|
+
|
|
1797
|
+
Injects dead code sequences into the VM bytecode. These sequences are valid but unreachable, adding noise to analysis.
|
|
1798
|
+
|
|
1799
|
+
### `vmSplitDispatcher`
|
|
1800
|
+
Type: `boolean` Default: `false`
|
|
1801
|
+
|
|
1802
|
+
Splits the VM dispatcher into multiple smaller dispatchers. Makes the execution flow harder to follow.
|
|
1803
|
+
|
|
1804
|
+
### `vmMacroOps`
|
|
1805
|
+
Type: `boolean` Default: `false`
|
|
1806
|
+
|
|
1807
|
+
Combines common instruction sequences into single macro opcodes. This creates unique instruction patterns that are harder to recognize.
|
|
1808
|
+
|
|
1809
|
+
### `vmDebugProtection`
|
|
1810
|
+
Type: `boolean` Default: `false`
|
|
1811
|
+
|
|
1812
|
+
Adds anti-debugging measures to the VM runtime. Detects debugger presence and alters behavior when debugging is detected.
|
|
1813
|
+
|
|
1814
|
+
### `vmRuntimeOpcodeDerivation`
|
|
1815
|
+
Type: `boolean` Default: `false`
|
|
1816
|
+
|
|
1817
|
+
Derives opcode values at runtime through mathematical operations rather than using static values. Makes static analysis significantly harder.
|
|
1818
|
+
|
|
1819
|
+
### `vmStatefulOpcodes`
|
|
1820
|
+
Type: `boolean` Default: `false`
|
|
1821
|
+
|
|
1822
|
+
Makes opcode interpretation depend on VM state. The same opcode can have different meanings based on execution history.
|
|
1823
|
+
|
|
1824
|
+
### `vmStackEncoding`
|
|
1825
|
+
Type: `boolean` Default: `false`
|
|
1826
|
+
|
|
1827
|
+
Encodes values pushed to and popped from the VM stack. Adds protection against memory inspection during execution.
|
|
1828
|
+
|
|
1829
|
+
### `vmRandomizeKeys`
|
|
1830
|
+
Type: `boolean` Default: `false`
|
|
1831
|
+
|
|
1832
|
+
Randomizes encryption keys and other constants used by the VM. Each build produces unique key values.
|
|
1833
|
+
|
|
1834
|
+
### `vmIndirectDispatch`
|
|
1835
|
+
Type: `boolean` Default: `false`
|
|
1836
|
+
|
|
1837
|
+
Uses indirect function calls for opcode dispatch instead of direct switch/case. Makes control flow analysis more difficult.
|
|
1838
|
+
|
|
1839
|
+
### `vmBytecodeFormat`
|
|
1840
|
+
Type: `string` Default: `binary`
|
|
1841
|
+
|
|
1842
|
+
Specifies the format used to embed bytecode in the output:
|
|
1843
|
+
- `binary` - Compact binary representation (smaller size)
|
|
1844
|
+
- `json` - JSON format (easier debugging, larger size)
|
|
1845
|
+
|
|
1643
1846
|
## Frequently Asked Questions
|
|
1644
1847
|
|
|
1645
1848
|
### What javascript versions are supported?
|