Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Format:mruby bytecode (RITE)

From ReverseEngineering.wiki
Format
On this wiki Facts · Code · Notes · Topics

mruby's compiled form (.mrb, mrbc output and mrb_dump_irep): a big-endian binary with the 4-byte identifier RITE, a 4-character version (0400 for mruby 4.0 at the cited commit), size and compiler fields, then IREP, optional DBG and LVAR sections and an END footer.

Overview

Library:mruby compiles Ruby to a tree of irep records. mrbc writes them to .mrb files or C arrays, mrb_dump_irep writes them to a buffer, mrb_read_irep_buf and mrb_load_irep_file load them. All integers are big-endian (uint32_to_bin, bin_to_uint16).

Binary header (struct rite_binary_header, 22 bytes)

Offset Size Field
0 4 identifier RITE
4 2 major version ASCII (04)
6 2 minor version ASCII (00)
8 4 total binary size (u32 BE)
12 4 compiler name MATZ
16 4 compiler version 0000

So a current file starts RITE0400 (the major part is incompatible, the minor part upper-compatible, per the comments in dump.h; Unverified: older releases wrote RITE0300, RITE0006 and similar). The reader rejects another major and a minor greater than its own, and a size larger than the buffer.

Sections

Each section starts with a 4-byte ident and a u32 BE size that counts from the start of the section header:

  • IREP: size, then 4 bytes of Rite instruction-set version (0400), then the root irep record, its children recursively.
  • DBG\0: debug info (file names, line tables).
  • LVAR: local variable names.
  • END\0: footer, size field as header.

Unverified: what exactly happens at an unknown ident (load.c lines 736-765 were only skimmed); sections are read in file order.

IREP record

u32 record size, u16 nlocals, u16 nregs (nlocals must not exceed nregs), u16 count of child ireps, u16 count of catch handlers, u32 instruction bytes, the bytecode, the catch table (13 bytes per handler), u16 pool count with tagged entries (tag byte: 0 string, 1 int32, 2 static string, 3 int64, 5 float, 7 bigint; strings carry a u16 length and a trailing NUL, a bigint a u8 length), u16 symbol count with u16 name lengths (0xFFFF marks a null symbol) and the names, then the children. Flags MRB_DUMP_DEBUG_INFO 1, MRB_DUMP_STATIC 2 and MRB_DUMP_NO_LVAR 4 control the writer.

Code & repositories

  • https://github.com/mruby/mruby @ b1cafb966b75d90b081b56853c6c64f9977b66e8 · license: MIT
    mruby source (MIT): include/mruby/dump.h defines the RITE header and section idents, src/load.c reads them.
    Tested on: source read, not run · checked 2026-10-19; last activity 2026-10-19

Pitfalls

  • Unverified: older versions (2.x/3.0) used different record layouts (short instruction forms, no catch table); check the dump.h of the exact mruby version.
  • The loader deals with untrusted size fields but the header advises against mrb_read_irep; use the buffer variant with a size.
  • Unverified: no disassembler or decompiler was evaluated for this page.