Tool:Bytenode
| License | MIT |
|---|---|
| Website | https://github.com/bytenode/bytenode |
| On this wiki | Facts · Code · Notes · Topics |
bytenode (MIT) compiles JavaScript to a V8 code cache (.jsc) that Node.js or Electron loads through vm.Script with a dummy source, so the shipped app has bytecode instead of readable source.
bytenode ships JavaScript as Format:V8 code cache blobs. The loader needs the same V8 version and flags as the compiler, so a .jsc only runs inside the Node.js or Electron build it was made for.
Recognising it
- Files ending in
.jsc; a small.jsstub that callsrequire('bytenode')and loads a.jsc; the stringsbytenodeand.jscin the app bundle or its package.json. - The file begins with a V8 code cache header: bytes 2-3 are
DE C0(magic 0xC0DE0000 xor table size); bytenode checks exactly that inisBufferV8Bytecodeand, if it is absent, tries Brotli decompression (compressoption). See Fact:V8 code cache/magic/Magic 0xC0DE0000 xor table size.
How it works (lib/index.js at 5562c8f)
- Compile:
new vm.Script(code, {produceCachedData: true})thencreateCachedData(); V8 flags--no-lazy(so every function is compiled eagerly) and--no-flush-bytecodeare set first. - Load: read the source length from the header (offset 8, the legacy length-based source hash), build a dummy source of that length (
"+ zero-width spaces +"), and runnew vm.Script(dummy, {cachedData, filename}). V8 only compares the length-derived source hash, so the dummy is accepted, and then executes the cached bytecode;script.cachedDataRejectedsignals a mismatch. - Fix-up: because the compile may have run in another process,
fixBytecodecopies the flag hash (bytes 12-16) from a freshly compiled dummy into the .jsc. Older Node 9-11 also patched bytes 16-20; Electron needs bytecode compiled inside Electron itself.
The layout comment in bytenode (source hash == source length, 4 bytes) is the older header; V8 main has a 32-byte source hash and can be set to SHA-256 mode, see Format:V8 code cache. Unverified: which V8 versions switched on SHA-256 by default (and so make the dummy-source trick fail).
Reversing
The function source text is not in the file, but string literals, identifiers and constants of every function are in the serialized payload, so strings shows much of the program. Decompiling needs a disassembler for the exact V8 bytecode version (Ignition); the V8 version hash in the header (offset 4) identifies the build. See Technique:Reversing bundled JavaScript.
Code & repositories
See the linked repository below.
- https://github.com/bytenode/bytenode @
5562c8f31ce64cfbb4664ada71281feffe8172b9· license: MIT (declared by the contributor for the files used; GitHub reports MIT (read from LICENSE; GitHub's API was busy) for the repository)
bytenode: compileCode, fixBytecode, readSourceHash, generateScript in lib/index.js (magic DE C0, dummy source of the original length, flag hash patch).
Tested on: source read, not run · checked 2026-10-19