javascript-obfuscator 4.2.2 → 5.0.1

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