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.
┌──────────────────────────────────────────┐
│ Bundle file (JSON) │
├──────────┬───────────┬───────────────────┤
│ [String] │ bytecode │ compressed opcode │
├──────────┼───────────┼───────────────────┤
│ [ List ] │ strings │ string constants │
└──────────┴───────────┴───────────────────┘
┌──────────────────────────────────────────┐
│ 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 │
└──────────────────────────────────────────┘
- vmStack: runtime data storage
- programCounter: current opcode index
- dependencies: external objects
yarn
yarn build
yarn protect -i sourcefile.js -o bundle.js
- https://github.com/Kechinator/jsvm (ISC)
- https://github.com/babel/babel (MIT)
- https://github.com/estools/escodegen (BSD 2-Clause)