Skip to content
yang-zhongtianPublic

About

Stack-based JavaScript virtual machine

Topics

Resources

Stars

72 stars

Watchers

4 watching

Forks

Repository files navigation

Kernel Protect

Test

Kernel Protect (K-Protect for short), is a stack-based virtual machine written in Typescript. It can compile ECMAScript(JavaScript) files to opcode, and execute them using the VM. This project can be used to protect ECMAScript-written algorithms that are used in front-end webpage to block spiders and secure website API.

This VM is inspired by VMProtect and RISC architecture. It is currently experimental and SHOULD not be used in any production environment.

Structure

Bundle file

┌──────────────────────────────────────────┐
│            Bundle file (JSON)            │
├──────────┬───────────┬───────────────────┤
│ [String] │  bytecode │ compressed opcode │
├──────────┼───────────┼───────────────────┤
│ [ List ] │  strings  │ string constants  │
└──────────┴───────────┴───────────────────┘

IR structure

┌──────────────────────────────────────────┐
│                 IR (Dict)                │
├──────────────────────────────────────────┤
│ [String] key: the name of this block     │
│ [ Dict ] val: the data of this block     │
│  ├── [String] key: 'instructions'        │
│  │ + [ List ] val: instruction list      │
│  │    └── [ Dict ] item: instruction     │
│  │         ├── [String] key: 'opcode'    │
│  │         │ + [Number] val: opcode      │
│  │         └── [String] key: 'args'      │
│  │           + [ List ] val: arguments   │
│  │              └── [ Dict ] item: arg   │
│  │                   ├── key: 'type'     │
│  │                   │ + val: [Number]   │
│  │                   └── key: 'value'    │
│  │                     + val: [ Any ]    │
│  └── [String] key: 'inheritsContext'     │
│    + [ Bool ] val: true, not used        │
└──────────────────────────────────────────┘

VM architecture

Global

  • vmStack: runtime data storage
  • programCounter: current opcode index
  • dependencies: external objects

Usage

Install dependency

yarn

Build all libraries

yarn build

Protect JS file

yarn protect -i sourcefile.js -o bundle.js

Acknowledgement

Contributors

Avatars

About

Stack-based JavaScript virtual machine

Topics

Resources

Stars

72 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages