1Bytecode versions
The bytecode version is a u32 at offset 8. The engine refuses a file whose version differs from its own, so an app's bundle always matches the Hermes build inside it (libhermes.so on Android, hermes.framework on iOS).
| Version | Engine | Layout |
| ≤ 96 | Classic Hermes. v96 is React Native 0.73 – 0.8x. | Legacy |
| 98 | Hermes V1 (hermes-v250829098), React Native 0.82+ when Hermes V1 is enabled. | Modern |
| 99 | Hermes V1 (hermes-v260318099). | Modern |
Two things change with the version:
- The file layout. From version 97 the function headers shrink from 16 to 12 bytes, and the array and object-value buffers are replaced by one literal-value buffer plus an object shape table. The tool picks the layout with
version < 97.
- The opcode table. Opcode numbers and operands are reassigned between versions. The tool has exact tables for v96, v98 and v99, and uses the nearest one for other versions, which may decode some instructions wrongly.
3Section layout
The header has no section offsets: the tables follow it in a fixed order, each starting at a 4-byte boundary, and their sizes come from the header counts. Reading a modern file with the legacy layout shifts every table after the function headers by 4 × functionCount bytes, so the layout must be chosen correctly.
| # | Table | Size |
| 1 | Function headers | functionCount × 16 (legacy) / 12 (modern) |
| 2 | String kinds | stringKindCount × 4 |
| 3 | Identifier hashes | identifierCount × 4 |
| 4 | Small string table | stringCount × 4 |
| 5 | Overflow string table | overflowStringCount × 8 |
| 6 | String storage | stringStorageSize |
| 7 | Legacy: array buffer, object key buffer, object value buffer Modern: literal value buffer, object key buffer, shape table | sizes from the header shape table: objShapeTableCount × 8 |
| 8 | BigInt table, BigInt storage | bigIntCount × 8, bigIntStorageSize |
| 9 | RegExp table, RegExp storage | regExpCount × 8, regExpStorageSize |
| 10 | CommonJS module table | cjsModuleCount × 8 |
| 11 | Function source table | functionSourceCount × 8 |
| 12 | Bytecode of all functions, function info (large headers, exception tables, debug offsets) | located through the function headers |
| 13 | Debug info (file names, line tables) | at debugInfoOffset |
4Function headers
Every JavaScript function (including arrow functions, methods, class constructors and the top-level code) gets one function header. Headers are packed into bit fields to keep them small; a function whose values don't fit sets the overflowed flag and stores a full-size header elsewhere.
Legacy layout (16 bytes)
word 0 bits 0–24 offset bytecode start (file offset)
bits 25–31 paramCount including `this`
word 1 bits 0–14 bytecodeSizeInBytes
bits 15–31 functionName string ID
word 2 bits 0–24 infoOffset exception table / debug offsets
bits 25–31 frameSize number of registers
byte 12 environmentSize
bytes 13–14 read / write property-cache sizes
byte 15 flags
When overflowed, the large header is at (infoOffset << 16) | offset and holds the same fields as full u32s; the exception table follows it at the next 4-byte boundary.
Modern layout (12 bytes)
word 0 bits 0–24 offset
bits 25–29 paramCount
bits 30–31 loopDepth
word 1 bits 0–13 bytecodeSizeInBytes
bits 14–21 functionName string ID
byte 8 frameSize
bytes 9–10 other small counters
byte 11 flags
When overflowed, the large header is at (functionName << 24) | (offset & 0xffffff): 37 bytes in v98, 36 from v99. The exception table follows it at the next 4-byte boundary.
Flags
| Bits | Meaning |
| 0–1 | prohibitInvoke: 0 callable and constructible, 1 call only, 2 construct only (e.g. class constructors) |
| 2 | strictMode |
| 3 | hasExceptionHandler |
| 4 | hasDebugInfo |
| 5 | overflowed (large header elsewhere) |
| 6–7 | Modern only — function kind: 0 normal, 1 generator, 2 async |
Exception table
count u32
entries[count] start u32 · end u32 · target u32 (bytecode offsets in the function)
An exception thrown at an offset in [start, end) jumps to target, where a Catch instruction stores the exception in a register. Entries are ordered innermost first. finally blocks are compiled into duplicated code plus a catch-all handler that rethrows.
5String tables
All strings in the program (identifiers, property names, string literals) are in one deduplicated table, referred to by string ID. Each entry of the small string table is one u32:
bit 0 isUTF16
bits 1–23 offset into string storage
bits 24–31 length (characters); 255 = look in the overflow table
With length 255, offset is instead an index into the overflow table, whose entries are {offset u32, length u32}. Characters are Latin-1 (one byte each) or, when isUTF16 is set, UTF-16LE (two bytes each).
String kinds
The string kinds table is run-length encoded: each u32 entry is count in bits 0–30 and kind in bit 31 (1 = identifier, 0 = plain string), covering the next count string IDs. Identifiers come first and have a precomputed hash in the identifier hash table, so the engine can turn them into property keys without hashing at startup.
Strings are the quickest way into an unknown bundle: API endpoints, keys, feature flags and error messages are all here. The tool's Strings section lists them and shows which functions use each one.
6Literal buffers
Constant array and object literals ([1, 2, "a"], {x: 1, y: "b"}) aren't built element by element; their values are serialized into buffers and created in one instruction (NewArrayWithBuffer, NewObjectWithBuffer).
Serialized values
Values are stored in runs of the same type. Each run starts with a tag byte:
bit 7 long run: the length is 12 bits, low 4 bits of the tag + the next byte
bits 4–6 type
bits 0–3 length (short run)
| Type | Value | Payload per element |
| 0 | null | — |
| 1 | true | — |
| 2 | false | — |
| 3 | number | f64 |
| 4 | string | string ID, u32 |
| 5 | string | string ID, u16 |
| 6 | legacy: string · modern: undefined | legacy: string ID, u8 · modern: — |
| 7 | integer | i32 |
Legacy layout
Three buffers: array buffer (array literal elements), object key buffer and object value buffer. NewObjectWithBuffer gives the key offset, the value offset and the property count.
Modern layout
One literal value buffer holds array elements and object values. Objects with the same keys share a shape: the shape table has entries {keyBufferOffset u32, numProps u32}, and NewObjectWithBuffer gives a shape index and a value offset.
7BigInts, regexps, modules, sources
| Table | Entry | Content |
| BigInt table | offset u32 · length u32 | Into BigInt storage: the value's bytes, little-endian two's complement. Loaded by LoadConstBigInt. |
| RegExp table | offset u32 · length u32 | Into RegExp storage: the regular expression compiled to Hermes's regex bytecode. Created by CreateRegExp, which also carries the pattern and flags as string IDs. |
| CommonJS module table | two u32 | Module ID → function, used when the compiler resolved CommonJS modules itself. Metro bundles usually leave this empty and register modules at run time (see Metro modules). |
| Function source table | functionId u32 · stringId u32 | Source text kept for functions whose toString() must return the original code ('show source' directive). |
| Debug info | at debugInfoOffset | File names and line/column tables. Release React Native builds strip it to the bundle's own name, so there are no original file names or lines. |
8The register machine
Hermes is a register-based VM. Each function runs in a frame of frameSize registers (r0, r1, …); instructions name their registers explicitly.
- Parameters are read with
LoadParam rD, n. Parameter 0 is this; the declared parameters start at 1, so paramCount includes this.
- Calls:
Call1 – Call4 name the callee, this and the arguments directly. The general Call rD, rCallee, argc (and Construct, CallBuiltin, and in classic Hermes CallDirect) takes the arguments from the top of the frame: this is in register frameSize − 1 − extra and the next arguments go downwards, where extra is the number of reserved call registers (6 in the legacy layout, 7 in the modern one).
- Closures and environments: variables captured by inner functions don't live in registers but in an environment object.
CreateEnvironment makes one for the current scope; StoreToEnvironment env, slot, rV / LoadFromEnvironment rD, env, slot access its slots; GetEnvironment rD, n walks n levels up the scope chain (Hermes V1 adds the starting environment as an operand). CreateClosure rD, env, functionId makes a function object that remembers its environment.
- Properties:
GetById rD, rObj, cacheIdx, stringId reads obj.name (with an inline cache slot), PutById writes it (split into PutByIdLoose / PutByIdStrict in Hermes V1), GetByVal / PutByVal handle computed keys (obj[k]). TryGetById on the global object throws a ReferenceError for undefined globals.
- Globals:
GetGlobalObject loads the global object; top-level vars become its properties (DeclareGlobalVar).
- Return and throw:
Ret rV, Throw rV.
9Instruction encoding
An instruction is a 1-byte opcode followed by its operands, with no alignment. Operand types and sizes:
| Type | Bytes | Meaning |
| Reg8 · Reg32 | 1 · 4 | Register number |
| UInt8 · UInt16 · UInt32 | 1 · 2 · 4 | Unsigned immediate: counts, cache indices, string / function / buffer IDs |
| Addr8 · Addr32 | 1 · 4 | Signed jump offset, relative to the start of this instruction |
| Imm32 | 4 | Signed 32-bit immediate |
| Double | 8 | f64 constant |
Most instructions have a short form and a …Long form with wider operands (Jmp / JmpLong, LoadConstString / LoadConstStringLongIndex, Mov / MovLong); the compiler picks the short one when the values fit.
Example
bytes instruction meaning
xx 01 05 00 LoadConstString r1, "Hello" r1 = string #5 (Reg8, UInt16)
xx 02 GetGlobalObject r2 r2 = globalThis (Reg8)
Opcode numbers (shown as xx above) differ between bytecode versions. Use the opcode reference for the exact numbers of each version.
Switch tables
SwitchImm (classic) / UIntSwitchImm (Hermes V1) for dense integer cases, and in Hermes V1 StringSwitchImm for string cases, point at a jump table stored after the function's bytecode, at a 4-byte boundary. Integer tables have one i32 target per value from min to max; string tables have {stringId u32, target i32} pairs. Targets are relative to the switch instruction.
10Common patterns
| JavaScript | Bytecode |
| x.foo | GetById r1, r0, 1, "foo" |
| x.foo = v | PutById r0, r2, 1, "foo" (V1: PutByIdLoose / PutByIdStrict) |
| f(a, b) | Call3 r3, rF, rUndefined, rA, rB |
| obj.m(a) | GetById rF, rObj, …, "m" Call2 r3, rF, rObj, rA |
| new C(a) | GetById rP, rC, …, "prototype" CreateThis (V1: CreateThisForNew), then Construct |
| const f = () => … | CreateClosure r1, rEnv, #123 |
| async function | a generator function wrapped by HermesBuiltin.spawnAsync (classic) or an async function kind (Hermes V1) |
| if (a < b) … | JNotLess Lelse, rA, rB |
| "" + x, `${x}` | AddEmptyString / Add |
| Math.max(a, b) | CallBuiltin r1, Math.max, 3 (with staticBuiltins) |
The exact sequences depend on the version and optimization; the tool's Bytecode tab shows them as compiled, with string, function and literal operands resolved.
11Metro modules
Metro wraps every source file in a factory function and registers it with a global __d call in the bundle's top-level code:
__d(function (global, require, importDefault, importAll, module, exports, dependencyMap) {
const React = importDefault(dependencyMap[0]);
…
}, 42, [17, 3, 91]); // module ID 42, depends on modules 17, 3, 91
In bytecode, the factory is a CreateClosure and the dependency list a NewArrayWithBuffer. Inside the factory, require and its variants are parameters 2–4 and dependencyMap is parameter 7, so require(dependencyMap[n]) loads module deps[n].
The tool finds these calls, tags each function with its module ID, and resolves require(dependencyMap[n]) to the target module's factory, so you can follow imports between modules. Module and file names are not in a release bundle; only the numeric IDs are.
12Opcode reference
Generated from the tool's own opcode tables (taken from BytecodeList.def of each Hermes release). Operands marked →string or →function are IDs into the string table or the function headers.
| Opcode | Mnemonic | Operands | Size |
13Built-in functions
With the staticBuiltins option, calls to common built-ins are compiled to CallBuiltin rD, index, argc instead of a property lookup. The index refers to this list (Builtins.def) for the selected version; HermesBuiltin.* are internal helpers the compiler emits for spreads, templates, async functions and so on.
14What the tool shows, and its limits
- Overview: the header fields, version and engine, counts, options and the number of Metro modules.
- Functions: every function with its name, size, parameters and flags. Opening one shows it decompiled to JavaScript or as the raw bytecode, with links to called functions and back to callers.
- Strings: every string, with the functions that use it.
The decompiler produces readable pseudocode, not the original source: local variable names, comments and types are gone, and some control flow falls back to labels and goto. Versions other than 96, 98 and 99 are decoded with the nearest opcode table and may show wrong instructions.
15The Hermes libraries
The tool is built on three JavaScript modules in lib/ with no user interface, which can be reused in another page, a module Web Worker or jsc. Each imports what it needs (hermes-decompiler.js imports hermes.js, which imports hermes-opcodes.js):
import { HermesOpcodes } from "../lib/hermes-opcodes.js"; // opcode tables
import { HermesFile, HermesBytecode } from "../lib/hermes.js"; // file reader and disassembler
import { HermesDecompiler, CrossReferenceIndex } from "../lib/hermes-decompiler.js"; // analysis and decompiler
HermesOpcodes (lib/hermes-opcodes.js)
| Method | What it does |
| HermesOpcodes.forVersion(version) | The opcode table of the nearest known version (96, 98, 99; on a tie the older one): { opcodes, builtins, tableVersion }. Each opcode, at the index of its byte value, is { name, operandTypes, references }; references maps an operand index to "string", "function" or "bigint". |
| HermesOpcodes.tables[version], .builtins[version] | The raw tables: opcodes and the built-in function names, by version. |
| HermesOpcodes.operandSizes | Bytes per operand type: Reg8, UInt8, Addr8 1; UInt16 2; Reg32, UInt32, Addr32, Imm32 4; Double 8. |
HermesFile and HermesBytecode (lib/hermes.js)
HermesFile is an opened file; HermesBytecode holds the disassembler and the helpers that read instructions.
| Method | What it does |
| HermesFile.isHermes(bytes) | Whether the bytes start with the Hermes magic c6 1f bc 03 c1 03 19 1f. |
| HermesFile.open(arrayBuffer) | Reads the header and section layout; throws on a file that isn't Hermes bytecode or whose tables run past its end. Returns a HermesFile, file below. |
| file.header, file.version, file.isLegacy, file.sourceHash | The header fields under their Hermes names (functionCount, stringCount, globalCodeIndex, objShapeTableCount, …); whether the file uses the legacy (≤ 96) layout; the source hash in hex. |
| file.sections | Start and end offset of every table: functionHeaders, stringKinds, smallStringTable, stringStorage, literalBuffer or arrayBuffer, objectKeyBuffer, … with …End. |
| file.opcodes, file.builtins, file.tableVersion | The opcode table used for this file (each opcode with its operandOffsets and size), the built-in names, and which table version that is. |
| file.getString(index), file.stringKind(index) | A string ("" when out of range), and whether it is an "identifier" or a "string". |
| file.functionHeader(index), file.functionHeaders() | One or every function header, with large headers followed: { index, offset, paramCount, bytecodeSize, functionName, frameSize, flags, strictMode, hasExceptionHandler, hasDebugInfo, overflowed, exceptionTableOffset }, plus infoOffset and envSize (legacy) or loopDepth and kind ("normal", "generator", "async"; modern). |
| file.functionName(index) | The function's name, "" when anonymous. |
| file.exceptionHandlers(header) | The exception table: [{ start, end, target }] as bytecode offsets. |
| file.arrayLiteral(offset, count), file.objectLiteral(keys, valueOffset, count) | Decoded literal buffers. Literals are { type: "null" | "undefined" | "boolean" | "number" | "string", value }, a string's value being its string index. Objects return [[key, value]]; keys is the key offset (legacy, with count) or the shape index (modern). |
| file.bigInt(index) | A BigInt from the bigint table, or null. |
| HermesBytecode.disassemble(file, header) | { instructions, targets, error }. An instruction is { offset, opcode, name, size, info, operands } with raw operand values; switches carry switchTable: { defaultTarget, cases: [{ key or stringIndex, target }] }; an unknown byte is { invalid: true }. targets is the Set of jump targets. |
| HermesBytecode.callArguments(file, instruction, functionIndex) | For a call: { callee, args } as registers, args[0] being this, taken from the top of the frame for Call, Construct, CallDirect and CallBuiltin (see the register machine), plus isNew, newTarget, direct, builtin or require. null for other instructions. |
| HermesBytecode.definedRegisters(instruction) | The registers an instruction writes. |
| HermesBytecode.readOperand(view, position, type) | One operand from a DataView. |
| HermesBytecode.literalText(file, literal), HermesBytecode.typeofMaskText(mask), HermesBytecode.formatNumber(number) | A literal as JavaScript text; a TypeOfIs mask as "string|number"; a number keeping -0. |
| HermesBytecode.optionNames(file), HermesBytecode.describeVersion(version, tableVersion) | The names of the header options that are set; which Hermes and React Native produce a bytecode version. |
HermesDecompiler and CrossReferenceIndex (lib/hermes-decompiler.js)
| Method | What it does |
| new CrossReferenceIndex(file) | An index to fill with index.scanFunction(i) for every function (the tool does it in 30 ms chunks), then index.finish(). It then has ready, stringReferences(stringIndex) (the functions using a string), callers (Map: function → Set of callers), moduleOfFunction (Map: factory → { id, deps }, from Metro __d calls), factoryOfModule, closureParent, closureScope, resolveScope(scope), slotFunction(id, slot) and slotLabel(id, slot). |
| HermesDecompiler.createContext(file, functionIndex, disassembly, crossReferences) | What the decompiler needs about one function: the abstract register state before every instruction (registersAtInstruction), the exception handlers, its Metro module, and scopeSlot(scope, slot), a display name for an environment slot. crossReferences may be null or not ready; names are then less precise. |
| HermesDecompiler.decompile(context) | JavaScript pseudocode: { lines: [{ indent, html }], usedGoto, failed, hasTry, structuredTry, truncated }. The HTML is escaped program text with highlighting spans (kw, str, num, mem, cm, lbl, ty) and function names as <span class="fnref" data-fn="N"> links. |
| HermesDecompiler.listing(file, functionIndex, disassembly, crossReferences) | The bytecode listing: { lines: [html], text, total } with labels, try markers, switch tables and comments that decode literal buffers, built-ins, call targets and environment slots. String operands are data-str links, functions data-fn links. |
| HermesDecompiler.functionLabel(file, functionIndex, crossReferences) | The function's name, else "module N" for a Metro factory, else "fn#N". |
| HermesDecompiler.trackRegisters(file, functionIndex, instruction, registers, recorder) | One step of the abstract register tracking the analysis uses (linear, ignoring control flow): values are { kind, … } with kind from HermesDecompiler.ValueKind (CLOSURE, ENVIRONMENT, PARAMETER, GLOBAL_NAME, DEPENDENCY, …). |
| HermesDecompiler.usesThis(file, functionIndex) | Whether a function ever reads this, arguments or calls eval (cached per file). |
import { HermesFile, HermesBytecode } from "../lib/hermes.js";
import { HermesDecompiler, CrossReferenceIndex } from "../lib/hermes-decompiler.js";
const file = HermesFile.open(arrayBuffer);
console.log("HBC v" + file.version, file.header.functionCount, "functions");
const index = new CrossReferenceIndex(file);
for (let functionIndex = 0; functionIndex < file.header.functionCount; functionIndex++) {
index.scanFunction(functionIndex);
}
index.finish();
const functionIndex = file.header.globalCodeIndex;
const disassembly = HermesBytecode.disassemble(file, file.functionHeader(functionIndex));
const javascript = HermesDecompiler.decompile(HermesDecompiler.createContext(file, functionIndex, disassembly, index));
console.log(javascript.lines.map(line => " ".repeat(line.indent) + line.html.replace(/<[^>]+>/g, "")).join("\n"));
for (const [factory, module] of index.moduleOfFunction) {
console.log("Metro module", module.id, "→ function", factory, file.functionName(factory));
}