npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@lxandr1/js-vm-guard

v1.0.16

Published

JavaScript VM-based Obfuscator — converts JS to custom VM bytecode to increase reverse engineering difficulty

Readme

js-vm-guard

JavaScript VM-based Obfuscator

Converts JavaScript code into a custom stack-based VM bytecode format to increase reverse engineering difficulty. No eval, no new Function() — all code runs through a switch-based interpreter with randomized opcodes.

Installation

npm install -g js-vm-guard

Or use directly with npx:

npx js-vm-guard input.js -o output.js

CLI Usage

js-vm-guard <input.js> [options]

Options:
  -o, --output <file>    Output file path
  --level <1-5>          Obfuscation level (default: 3)
  --seed <number>        Random seed for deterministic output
  -h, --help             Show help

Obfuscation Levels

| Level | Description | |-------|-------------| | 1 | Opcode randomization only | | 2 | Level 1 + basic transformations | | 3 | Level 2 + full function VM + top-level VM (default) | | 4 | Level 3 + XOR-encoded bytecode | | 5 | Reserved for future improvements |

Example

Input (input.js):

function fibonacci(n) {
  if (n < 2) return n;
  return fibonacci(n - 1) + fibonacci(n - 2);
}
console.log(fibonacci(10));

Output (level 3, simplified):

(function() {
  function $(b,s,t,g){ /* VM interpreter with 55+ opcodes */ }
  var F={};function g(n,v){ /* global lookup */ }
  function fibonacci(){return $([[...]],{...},this,g);}
  F["fibonacci"]=fibonacci;
  $(mainBytecode,{...},this,g);
})();

Programmatic API

const jvg = require('js-vm-guard');

// Parse source to AST
const ast = jvg.parseCode('var x = 1 + 2;');

// Transform AST to bytecode
const result = jvg.transform(ast, 3, 42);
// result.bytecode    — main bytecode array
// result.opcodeMap   — shuffled opcode mapping
// result.functions   — function bytecode table
// result.mainScope   — top-level variable names

// Generate VM runtime code
const vm = jvg.generateVM(result.opcodeMap, result.functions);
// vm.code — string: the $() interpreter function

// Full pipeline
jvg.main(); // runs CLI from API

Low-level exports

  • jvg.createOpcodeMap(seed) — Create shuffled opcode mapping
  • jvg.Transformer — Transformer class for custom usage
  • jvg.BytecodeBuilder — Bytecode builder class
  • jvg.HANDLER — VM handler definitions
  • jvg.getOpcodeNames() — List of all opcode names
  • jvg.seedRng(seed) / jvg.rngNext() — PRNG utilities

How It Works

  1. Parse — Source is parsed to AST via @babel/parser
  2. Transform — AST is compiled to stack-based bytecode (LOAD/STORE/JUMP/CALL etc.)
  3. Shuffle — Opcodes are assigned random numeric values via seeded Fisher-Yates shuffle
  4. Generate — A switch-based VM interpreter function is generated as a JavaScript string
  5. Assemble — Output wraps the VM, function wrappers, and encoded bytecode in an IIFE

Architecture

┌──────────┐    ┌──────────────┐    ┌─────────┐    ┌──────────┐
│  Parser  │ → │  Transformer │ → │  VM Gen │ → │   CLI    │
│ parser.js│    │transformer.js│    │  vm.js  │    │  cli.js  │
└──────────┘    └──────────────┘    └─────────┘    └──────────┘
                      │                   │
                      ↓                   ↓
               BytecodeBuilder     OpcodeMap (shuffled)

Supported constructs

  • Function declarations, expressions, IIFEs
  • Top-level code (all source goes through VM)
  • Control flow: if/else, for, while, do-while, switch, for-in, for-of
  • Expressions: arithmetic, logical, bitwise, ternary, assignment, member access, calls, new, spreads
  • Template literals, regex, update expressions (++/--)
  • Exceptions: try/catch, throw, break/continue

Known Limitations

  • No class/async/generator support (passed through as-is)
  • No arguments object inside VM-compiled functions
  • Function bytecodes in the f array expose string constants (only main bytecode is XOR-encoded at level 4)
  • No control flow flattening or dead code injection (planned)
  • The scope: function(){...} definitions expose variable names
  • new operator uses Reflect.construct which has limitations with VM wrappers

License

MIT