← Hermes bytecode
Hermes·Bytecode format
All tools

How a React Native app's JavaScript is stored

React Native apps built with the Hermes engine (the default since React Native 0.70) don't ship JavaScript source. At build time, Metro bundles all modules into one script and the Hermes compiler turns it into Hermes bytecode (HBC): a compact, memory-mappable file the engine runs directly. This page describes that format as the Hermes tool reads it.

A file that starts with readable JavaScript (var __BUNDLE_START_TIME__…) is a plain Metro bundle, not bytecode: open it in a text editor instead.

The format is defined in the facebook/hermes sources: include/hermes/BCGen/HBC/BytecodeFileFormat.h (file layout), BytecodeList.def (instructions) and Builtins.def (built-in functions). It changes between engine releases; each change bumps the bytecode version in the header.

Contents

  1. Bytecode versions
  2. File header
  3. Section layout
  4. Function headers
  5. String tables
  6. Literal buffers
  7. BigInts, regexps, modules, sources
  8. The register machine
  9. Instruction encoding
  10. Common patterns
  11. Metro modules
  12. Opcode reference
  13. Built-in functions
  14. What the tool shows, and its limits
  15. The Hermes libraries

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).

VersionEngineLayout
≤ 96Classic Hermes. v96 is React Native 0.73 – 0.8x.Legacy
98Hermes V1 (hermes-v250829098), React Native 0.82+ when Hermes V1 is enabled.Modern
99Hermes V1 (hermes-v260318099).Modern

Two things change with the version:

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.

#TableSize
1Function headersfunctionCount × 16 (legacy) / 12 (modern)
2String kindsstringKindCount × 4
3Identifier hashesidentifierCount × 4
4Small string tablestringCount × 4
5Overflow string tableoverflowStringCount × 8
6String storagestringStorageSize
7Legacy: 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
8BigInt table, BigInt storagebigIntCount × 8, bigIntStorageSize
9RegExp table, RegExp storageregExpCount × 8, regExpStorageSize
10CommonJS module tablecjsModuleCount × 8
11Function source tablefunctionSourceCount × 8
12Bytecode of all functions, function info (large headers, exception tables, debug offsets)located through the function headers
13Debug 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

BitsMeaning
0–1prohibitInvoke: 0 callable and constructible, 1 call only, 2 construct only (e.g. class constructors)
2strictMode
3hasExceptionHandler
4hasDebugInfo
5overflowed (large header elsewhere)
6–7Modern 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)
TypeValuePayload per element
0null—
1true—
2false—
3numberf64
4stringstring ID, u32
5stringstring ID, u16
6legacy: string · modern: undefinedlegacy: string ID, u8 · modern: —
7integeri32

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

TableEntryContent
BigInt tableoffset u32 · length u32Into BigInt storage: the value's bytes, little-endian two's complement. Loaded by LoadConstBigInt.
RegExp tableoffset u32 · length u32Into 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 tabletwo u32Module 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 tablefunctionId u32 · stringId u32Source text kept for functions whose toString() must return the original code ('show source' directive).
Debug infoat debugInfoOffsetFile 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.

9Instruction encoding

An instruction is a 1-byte opcode followed by its operands, with no alignment. Operand types and sizes:

TypeBytesMeaning
Reg8 · Reg321 · 4Register number
UInt8 · UInt16 · UInt321 · 2 · 4Unsigned immediate: counts, cache indices, string / function / buffer IDs
Addr8 · Addr321 · 4Signed jump offset, relative to the start of this instruction
Imm324Signed 32-bit immediate
Double8f64 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

JavaScriptBytecode
x.fooGetById r1, r0, 1, "foo"
x.foo = vPutById 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 functiona 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.

OpcodeMnemonicOperandsSize

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

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)

MethodWhat 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.operandSizesBytes 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.

MethodWhat 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.sourceHashThe header fields under their Hermes names (functionCount, stringCount, globalCodeIndex, objShapeTableCount, …); whether the file uses the legacy (≤ 96) layout; the source hash in hex.
file.sectionsStart and end offset of every table: functionHeaders, stringKinds, smallStringTable, stringStorage, literalBuffer or arrayBuffer, objectKeyBuffer, … with …End.
file.opcodes, file.builtins, file.tableVersionThe 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)

MethodWhat 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));
}