Javascript Bytenode JSC Decompilation & Monkey Patching
A guide to decompiling bytenode jsc output in electron and nodejs apps
What is a JSC? What is bytenode?
There is an ever increasing trend of apps being built in JS and running using electron rather than being native executables using platform ABIs and platform specific graphics libaries. This has the advantage of allowing the app to be run on different OSes without any extra work, and allows the ease of web design to be used in desktop apps. The downsides (among more), are requiring the app to bundle often an entire electron framework or chrome browser each, with all/most libraries being statically linked, this obviously leads to greatly bloated binaries and giant duplication across a system with multiple electron apps.
The advantage for us as security professionals however, is that the app is written in JS (mostly, sometimes a native library is bundled too). As you’ll know from web engineering and if you’ve ever modded a website to add your own features in, reading and patching JS is often light work as you are only dealing with minified and sometimes obsfucated source code (and sometimes just plain source code).
This isn’t favourable to app developers who want to keep their code private to avoid their project being cloned, so what do they do?
Bytenode
Bytenode is the answer to their calls. It’s a ‘minimalist bytecode compiler for Node.js’.
This means that you give bytenode your source code, and bytenode uses the V8 engine to compile the source code into bytecode (just as is done before execution). Bytenode saves this bytecode and you ship that instead, hiding all your nice code in a compiled lump of binary.
However, this means we can no longer just open a .js in a text editor and audit or patch however we like. We now have a much harder job.
Bytenode bytecode back to code? (bytecode decompilation)
As only the bytecode is shipped, you can no longer open a plaintext file to find what you want, you can’t open electron devtools and search through sourcecode or add breakpoints.
And decompiling the bytecode is no easy feat either, there exists a ghidra plugin for JSC bytecode decompilation on Github (also see their article: ptswarm). However, that only supports a couple version of NodeJS, and you must match the version number exactly (along with the flags too…)
So, we are left with insanely expensive online tools like JSC decompiler, or running View8 and jsc2js locally.
View8 and jsc2js
‘View8 is a static analysis tool designed to decompile serialized V8 bytecode objects (JSC files) into high-level readable code ’ ‘jsc2js reverses V8 generated bytecode into readable approximate javascript`.
View8 requires a V8 decompiler, and comes bundled with 3 pre-built available in the GitHub releases, however if your JSC wasn’t built with one of these V8 versions (or V8 was built with different flags) then you will need your own decompiler.
The jsc2js repo is a gold-mine for JSC decompilation. The releases section contains patched d8 binaries for every V8 version for both linux and windows, and the repo contains a patched View8 for better decompilation support.
Decompilation
To start with decompilation, it is necessary to first determine the version of V8 used to build your JSC.
Determining the V8 version
- View8 contains a binary for this, however it isn’t very accurate at reversing the hash due to collisions in the hashing algorithm. (Mine produced
4.42.47.212instead of11.6.189.22) - j4k0xb produced v8-version-analyzer which reads the header and gives you the version locally in your browser. (And helpfully lists nodejs and electron versions associated).
- Using
-p process.versionsor (if electron)ELECTRON_RUN_AS_NODE=1 ./binary -p process.versionsas found here v8dasm - Manually by reading the JSC header
- With the patched fork below:
python3 view8.py --inp app.jsc --detect-versionprints the V8 version plus matching Node.js and Electron releases (see the fork section).
Manually reading the JSC header
The format of the header is widely available (although it depends on the V8 version too):
Legacy:
| Offset | Size | Field Name |
|---|---|---|
| 0x00 | 4 B | magic_number |
| 0x04 | 4 B | version_hash (Important for us) |
| 0x08 | 4 B | source_hash |
| 0x0C | 4 B | flag_hash (Important for us) |
| 0x10 | 4 B | payload_length |
| 0x14 | 4 B | checksum |
or
Modern:
| Offset | Size | Field Name |
|---|---|---|
| 0x00 | 4 B | magic_number |
| 0x04 | 4 B | version_hash (Important for us) |
| 0x08 | 4 B | source_hash |
| 0x0C | 4 B | flag_hash (Important for us) |
| 0x10 | 4 B | ro_snapshot_checksum |
| 0x14 | 4 B | payload_length |
| 0x18 | 4 B | checksum |
Confirming the version and hash match
V8 Version Hash Verifier
Computed Hash: 0x00E4C20B
Determining the V8 build flags
jsc2js includes patches which bypass the version, source and flags hashes to support d8, electron and node which use different build flags.
You may be lucky and jsc2js works out of the box for you, but unfortunately for me, I received an error due to mismatched magic_number caused by some build flags (specifically sandbox=true in jsc2js which appeared to be false in my app).
If this is the case for you and jsc2js fails, you will need to download and patch v8 yourself (or with the help of AI) and set the correct flags. (Note: I found this a trial and error process and tested many different flag combinations in order to find the working one.)
Sandbox
For the sandbox flag, we found that:
The magic number is 0xC0DE0000 ^ ExternalReferenceTable::kSize. The kSize changes based on v8_enable_sandbox:
- sandbox=true → kSize=1516 → magic 0xC0DE05EC
- sandbox=false → kSize=1510 → magic 0xC0DE05E6
Determining flags from the .jsc header
The good news is that you don’t need to guess or trial-and-error the build flags. The .jsc file header tells you exactly what was used.
The magic number is a compile-time constant computed in V8 as 0xC0DE0000 ^ ExternalReferenceTable::kSize, where kSize is the COUNT of external-reference entries (not a byte size). You can see the constant in snapshot-data.h and the count and entry-width definitions in external-reference-table.h. For V8 11.6, the sandbox setting is what changes that count:
sandbox=false → count=1510 → magic 0xC0DE05E6
sandbox=true → count=1516 → magic 0xC0DE05EC
Pointer compression is a separate match you have to set yourself. It changes the width of each table entry rather than the number of them, so the magic looks the same either way. On x64 V8 11.6 it is enabled, and deserialization fails without it, but you can’t read it off the magic.
So by reading the magic number from your .jsc header, you can determine the sandbox setting that was used. No trial and error needed for sandbox.
The flags hash (offset 0x0C) is a separate concern. It’s computed at runtime by FlagList::Hash(), which only includes non-default runtime flags (like --enable-sharedarraybuffer-per-context). jsc2js bypasses this check entirely, so you don’t need to match it. But if you’re building d8 yourself, the flags hash tells you what non-default runtime flags the original build used.
The version hash (offset 0x04) is computed from major, minor, build, patch using a 64-bit hash_combine (MurmurHash variant). This has known collisions between different V8 major versions, so always cross-reference with the app’s Electron or Node.js version to confirm.
Practical workflow
# 1. Read the header
python3 -c "
import struct
with open('index.jsc', 'rb') as f:
h = f.read(24)
magic, ver, src, flags, pay, chk = struct.unpack('<6I', h)
print(f'Magic: 0x{magic:08X} (kSize={magic ^ 0xC0DE0000})')
print(f'Version: 0x{ver:08X}')
print(f'Flags: 0x{flags:08X}')
"
# 2. Magic tells you compile-time flags
# 0xC0DE05E6 → sandbox=false, pointer_compression=true
# 3. Build d8 with matching flags
gn gen out/match --args='
is_debug = false
target_cpu = "x64"
v8_enable_pointer_compression = true
v8_enable_sandbox = false
v8_enable_disassembler = true
v8_enable_object_print = true
'
ninja -C out/match d8
Building V8
First check the jsc2js releases page for a prebuilt d8 matching your exact V8 version, you might get lucky and skip this whole section. I didn’t get lucky, the prebuilt d8 failed on the magic number because it was built with sandbox=true and my app used sandbox=false.
If the prebuilt doesn’t work for you either, you will need to fetch V8, patch it, and build d8 yourself with the flags you read out of the header above.
1. Fetch V8
Do not just git clone V8, you need depot_tools and the pinned dependencies. This takes a lot of disk (around 10 GB for the checkout, plus another 5 to 10 GB for the build output) and took 30 to 60 minutes to build on my machine, so use something with at least 8 GB RAM. Linking d8 will just die with no error on small VPS instances from resource exhaustion.
I use nix, not apt, so everything below runs from a shell with the build tools on PATH (run this once and stay in it for the whole build):
nix-shell -p git python3 pkg-config ccache clang curl
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git ~/depot_tools
export PATH="$HOME/depot_tools:$PATH"
mkdir -p ~/v8build && cd ~/v8build
fetch v8
cd v8
git fetch --tags
git checkout 11.6.189.22
gclient sync -D
Do not run ./build/install-build-deps.sh, that script is apt-based and doesn’t work on NixOS. The nix-shell above already provides what it would have installed.
Replace 11.6.189.22 with whatever version your JSC uses. Always run gclient sync after the checkout, otherwise you end up building with the wrong Clang toolchain and get weird failures. Check you are actually on the right tag with git describe, building main and hoping it reads an old JSC will not work.
2. Apply the jsc2js patch
Clone jsc2js somewhere next to your V8 checkout. For V8 11.6 you want the legacy patcher, not a diff file. The repo has three patch tracks (see patches/README.md): a source-aware script for 5.1 to 11.9, plain diffs for 12.0 to 14.7.83, and another script for 14.7.84 onwards. 11.6 falls in the first group, so the command is:
git clone https://github.com/xqy2006/jsc2js.git ~/jsc2js
python3 ~/jsc2js/patches/legacy/apply_legacy_patch.py --root ~/v8build/v8
This is a semantic patcher, not a fuzzy diff. It detects the source API in your exact checkout and edits the files in place (d8.cc, d8.h, code-serializer.cc and the string printer). It adds a loadjsc() function to d8 (which loads a .jsc and prints the bytecode), and bypasses the version, source and flags hashes. That bypass is needed because d8, electron and node all use different flags even on the same V8 version.
Note what it does not touch: the magic number, checksum, payload length and deserializer checks are all left alone. So the compile-time flags (sandbox, pointer compression) must still match what you read out of the header, the patch won’t save you there.
Check it actually applied (it writes a report with success true, and you can grep for the marker):
cat ~/v8build/v8/jsc2js_legacy_patch_report.json
grep -r "LoadJSC" ~/v8build/v8/src/d8/ | head
If it errors, you probably have the wrong tag checked out. Run git reset —hard inside the v8 dir and try again (and double check the version against the app’s electron or node version, the version hash has collisions).
One more patch on top. The jsc2js patch alone is not quite enough: when I ran the freshly built d8 on the real JSC it segfaulted after printing the first function. The problem is SharedFunctionInfoPrint calls PrintSourceCode, which tries to read source text that isn’t in a .jsc cache. The fix is the View8 printer patch: don’t print source, and dump the bytecode from inside the printer instead. I built the whole from-scratch run twice to confirm, and put the fix in a patch file so you don’t have to hand-edit:
Download v8-11.6.189.22-printer.patch
Apply it inside the v8 checkout, after the legacy patcher (the d8.cc hunk touches the patcher’s LoadJSC, so order matters):
cd ~/v8build/v8
git apply /path/to/v8-11.6.189.22-printer.patch
git status --short
Leave everything else the patcher did alone. In particular, do not bypass the magic number or checksum checks in code-serializer.cc, you don’t need to as long as your compile-time flags match the header.
3. Configure with your flags
This is just the GN args from the practical workflow above, with a couple extra options to keep the build small. The important part is pointer_compression and sandbox matching the magic you decoded (for 0xC0DE05E6 that is true and false).
gn gen out/match --args='
is_debug = false
target_cpu = "x64"
v8_target_cpu = "x64"
is_component_build = false
symbol_level = 1
v8_enable_pointer_compression = true
v8_enable_sandbox = false
v8_enable_disassembler = true
v8_enable_object_print = true
'
is_debug=false so you get a release d8 that is fast enough to dump large bundles. target_cpu is x64, change it only if your app is arm64. is_component_build=false and symbol_level=1 just save disk. disassembler and object_print have to be true or loadjsc builds fine but prints nothing useful. (If gn complains about v8_enable_object_print being unknown on your tag, check BUILD.gn, on some versions the same option is called v8_object_print.)
4. Build d8
You only need d8, not all of V8:
ninja -C out/match d8
ls -lh out/match/d8 out/match/snapshot_blob.bin
Keep snapshot_blob.bin next to the d8 binary, d8 needs it at runtime. If you copy d8 somewhere else, take that file with it.
If you are going to rebuild a few times with different flags (I did), set up ccache first:
export CC="ccache clang"
export CXX="ccache clang++"
If the link dies, run it again with fewer jobs (ninja -j4 -C out/match d8) or add swap, it ran out of RAM.
5. Test it on your JSC
./out/match/d8 -e "loadjsc('index.jsc')" > dump.txt
wc -l dump.txt && head -50 dump.txt
You should get a long listing of SharedFunctionInfo blocks and bytecode. If not:
- Magic or external reference table error means your sandbox or pointer_compression flags are still wrong. Re-read the magic and rebuild.
- Version or flags hash error means the patch didn’t apply. Grep for LoadJSC and re-apply.
- Segfault after the first function prints means the printer edit from step 2 is missing. PrintSourceCode crashes on caches with no source text, double check it is deleted and rebuild.
- Empty output or a crash on node-compiled JSC might not be your fault, jsc2js works well on electron output but node caches without the embedder context often fail. Try another file from the bundle before rebuilding again.
Decompiling and disassembling with patched View8
Now that you have a bytecode dump, you feed it into View8 to get approximate JavaScript back. Use the View8 that ships inside jsc2js (you already cloned it in step 2, it is the View8/ directory). It is a modified fork of suleram/View8 with better support for newer bytecode.
The stock View8 bundled with jsc2js needs the parse package. The patched fork further down does not. On nix:
nix-shell -p python3 python3Packages.parse
(Outside nix that is pip install parse. Everything below runs in that shell.)
Before running it, apply two small performance patches. Stock View8 has two bottlenecks that make it unusable on large bundles, I measured both on my 12 MB target:
cd ~/jsc2js
git apply /path/to/view8-replace-const-pool.patch
git apply /path/to/view8-inline-cap.patch
The first fixes replace_const_pool, which does one string replace per constant per line. That is fine for small functions but hangs for hours on big ones (my largest function is 76k lines with a 17k constant pool). The fix does it in a single regex pass instead. Output is byte-identical on normal functions, and the big one finishes in under 4 seconds.
The second caps textual inlining at 1000 characters. View8 substitutes register values into later lines as text with no size limit, so long register chains compound until a 445-line function eats 10 GB of RAM and gets OOM-killed. With the cap, values longer than that just stay as register references. Again byte-identical on normal functions, and the problem function finishes in under a second with a 6 KB result.
Then run it on your dump:
cd ~/jsc2js/View8
python3 view8.py --disassembled dump.txt out.js
You should see Parsing disassembled file, Parsing completed successfully, Decompiling N functions, then Done. My bundle gave over 22k functions and a 12 MB, 500k+ line out.js in under a minute, in a single process.
What you get back is approximate JavaScript, not the original source. Function and variable names are gone (everything is func_sfi_address and registers like r0), and the code is full of redundant ACCU temporaries. But the parts that matter for reversing survive intact: string literals, property accesses and API calls.
If you want the lower-level views instead of (or next to) the decompiled output, View8 has export formats for that:
python3 view8.py --disassembled dump.txt out.txt --export-format v8_opcode
python3 view8.py --disassembled dump.txt out.txt --export-format translated
If you’d rather skip the two performance patches and the parse install above, the author’s patched fork in the next section handles both automatically.
My custom patched fork: NullString1/View8
Upstream suleram/View8 gets you most of the way, and the copy bundled in jsc2js handles newer bytecode better. But both still leave you with a pile of <unknown> slots, func_unknown_<addr> names, and a Windows-only version detector. So I asked OpenCode with Muse Spark 1.3 Contributor to build me a patched fork, using the tricks it had already worked out while building jsc-edit.
NullString1/View8 on GitHub (upstream: suleram/View8)
What it improves:
- Header parsing. I replaced the Windows-only VersionDetector with a pure Python header reader, so it just runs on Linux, macOS and Windows. It reads both the legacy 24-byte and the modern 28-byte layout. You can also skip the guessing and ask it directly:
python3 view8.py --inp app.jsc --detect-versionprints the V8 version plus the matching Node.js and Electron releases. - Pool enrichment. Most of the
<unknown>slots in the constant pool now resolve to what you’d actually expect: console, process, Math, the read-only heap strings like log and length, and constants like undefined, null, true, false and NaN. Point it at a Node binary on the same V8 major/minor and it resolves the leftover ro-heap references through a deserialization oracle. If the versions don’t line up it falls back to the static tables instead of falling over. - Real function names. Instead of everything turning into func_unknown plus an address, it pulls the real name out of the SharedFunctionInfo metadata and the string pool, so names like check, alpha and beta actually survive. You can hand it the raw .jsc pool data too, and there’s a decompile_dump API if you want to script it.
- Cleaner output. Type tests come out as normal typeof checks. Property access uses dot notation (process.argv[2], a0.length, console.log) rather than pool lookups, and standalone temporaries fold into direct calls. A simplification pass then drops the dead assignments and the redundant scope bookkeeping.
- Simpler setup. The fork is stdlib-only, so you can skip the parse install from the last section completely. There’s nothing to pip. You get the full CLI too:
--d8and--nodeto pin your toolchain,--detect-version,--normalizewith a CSV map,--treewith depth and branch controls, raw/serialized/disassembled inputs, and decompiled/v8_opcode/translated/serialized outputs. - Large-bundle speed. The single-pass constant-pool fix is built in, so my 76k-line, 17k-constant function decompiles in seconds without me applying that patch. The 1000-character inline cap is not in the fork, though in my testing I never ended up needing it. If you do hit that runaway inlining case, apply view8-inline-cap.patch yourself.
Before (stock View8) vs after (this fork) on the same dump:
// before
ACCU = func_unknown_0x1338ca92fa49(process["argv"][2])
if (!(typeof(a0) == string)) || (a0[<unknown>] === 0) {
ACCU = <unknown>[<unknown>]("usage: node check.js <input")
}
// after
func_check_0x1338ca92fa49(process.argv[2])
if (!(typeof a0 === 'string') || (a0.length === 0)) {
console.log("usage: node check.js <input>");
}
Drop-in replacement for the previous section:
git clone https://github.com/NullString1/View8.git ~/View8
cd ~/View8
# raw .jsc straight to JS (auto d8/node if on PATH):
python3 view8.py --inp index.jsc --out out.js
# or from an existing d8 dump, with explicit toolchain:
python3 view8.py --inp dump.txt --input_format disassembled --out out.js
# version check only:
python3 view8.py --inp index.jsc --detect-version
# with matching toolchain pinned:
python3 view8.py --inp app.jsc --d8 /path/to/d8-13.6 --node /path/to/node-v24 --out app.decompiled.js
Patching…
Instructions and tools for patching .jsc bytecode files seem to be unheard of, which lead me to believe it wasn’t practical.
However, using a lot more Muse Spark 1.3 Contributor and Gemini 3.8 Flash I managed to make a lot of breakthroughs and create a tool for easy
jsc instruction swapping, constant editing, and even full rebuilding allowing the insertion of new constants into the pool and new functions.
A link to that project will appear here in the short future when I have finished cleaning up the quickly made and probably buggy code..