The .ud ("universal dreams") source language is a C-like surface syntax with first-class directives that pin compiler choices. The directives are what makes the language capable of being a complete, executable specification of a binary.
This document describes the language as it exists today, with the directive vocabulary actually wired up by the parser and emitter. Forward-looking syntax (@reg, @encoding, ABI variants beyond what's used today) is mentioned only where called out.
- Familiar where it can be. Functions, types, expressions, and statements look like C/C++. A reader who knows C should be able to skim a
.udfile and understand control flow at first glance. - Explicit where it must be. Every choice that affects the emitted bytes is either pinned by a directive or determined by a deterministic rule.
- Round-trip first. The pretty-printer is deterministic. The parser is whitespace-tolerant but normalizes to the canonical form on re-emit.
parse(emit(ast)) == astandemit(parse(canonical_text)) == canonical_textare tested invariants. - Escape hatches are first-class.
@asmcarries pinned bytes alongside the textual disassembly;@rawcaptures bytes the analyser couldn't lift to a function. A.udfile is always a complete representation of its binary.
Every .ud file begins with a @module { … } block that pins target context plus the full ELF metadata the lower path needs to reconstruct the binary:
@module {
arch: "x86_64",
abi: "sysv",
format: "elf",
bits: 0x40,
endian: "little",
type: 0x3,
entry: 0x10a0,
build: {
e_ident: [0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x00, …],
e_machine: 0x3e,
e_version: 0x1,
e_phoff: 0x40,
e_shoff: 0x3a78,
e_flags: 0x0,
e_ehsize: 0x40,
e_phentsize: 0x38,
e_phnum: 0xd,
e_shentsize: 0x40,
e_shnum: 0x24,
e_shstrndx: 0x23,
file_size: 0x42b8,
phdrs: [
{ p_type: 0x6, p_flags: 0x4, p_offset: 0x40, p_vaddr: 0x40, … },
…
],
shdrs: [
{ name: "", sh_name: 0x0, sh_type: 0x0, … },
{ name: ".interp", sh_name: 0x1b, sh_type: 0x1, … },
…
],
padding: [
{ offset: 0x334, bytes: [0x00, 0x00, 0x00, 0x00] },
…
],
},
}
The friendly fields at the top (arch, abi, etc.) reflect interpretation of the ELF header. Inside build are every byte of metadata the lower path needs to reconstruct the binary — the program-header table, the section-header table (with each entry's resolved name for matching to @section blocks), the file size, and every interstitial byte the file has between structured regions.
Files that wrap other images (format: "ihex", "srec", "titxt", "gzip", "dtb", "uimage", "mbn", "ar", "tar", "zip", "trx", "lzma", "dfu", "uf2", "android_boot", "xz", "bzip2", "fmap", "cbfs", "pci_rom", "uefi_capsule", "uefi_image", "uefi_fv", "frf", "odx", "sgo", "lha") describe the wrapping in build and nest each payload: build.parts.<name> holds the payload's own @module fields, and @section("<name>", addr) { … } its items. Together they are a complete .ud file of their own — an ELF, a PE, a raw image, another container — lowered as such and placed back by the container:
@module {
arch: "arm",
format: "uimage",
build: {
time: 0x0, load: 0x80008000, entry: 0x80008000,
os: 0x5, cpu: 0x2, type: 0x2, comp: 0x1,
name: "Linux",
parts: {
payload: {
arch: "arm",
format: "gzip",
build: {
flags: 0x0, mtime: 0x0, xfl: 0x2, os: 0x3,
deflate: "gzip", level: 0x9,
parts: { payload: { arch: "arm", format: "raw", load_addr: 0x80008000, … } },
},
},
},
},
}
@section("payload", 0x80008000) {
@section("payload", 0x80008000) {
@addr(0x80008000)
fn code_80008000() { @asm("mov r0,#0x0", [0x00, 0x00, 0xa0, 0xe3]) … }
}
}
Derived values (record checksums, CRCs, lengths, a device tree's block offsets) are written only when the file's differ from what the payload gives, so an edited payload gets fresh ones (an MBN's header words are kept as written). A gzip stream is re-made by the compressor (zlib or GNU gzip, at level) that reproduces it; when none does, it is kept as a deflate part of bytes.
An ar archive (format: "ar", .a and .deb files) lists its members with their header fields as text, and a tar archive ("tar") its entries with their header fields as NUL-padded text (the size and header checksum derived); each member's data is a part, named after it, decompiled as what it is.
A ZIP archive ("zip") lists its entries: the local header's fields (version, flags, method, time, date, extra), the data, the data descriptor (descriptor: 1 with its signature, 0 without, +2 for 8-byte sizes) and the central directory record's (made_by, internal, external, comment, and cd_… for any field that differs from the local one). A deflated entry's data is the inflated payload, a part decompiled as what it is; deflate: "zlib" or "gzip" with a level names the ported compressor that re-makes the stream, else it is kept as part <name>.stream and used while it still inflates to the payload (an edited payload is deflated by zlib at level 6). Stored entries are their bytes; encrypted or other methods' data is kept as raw. CRCs, sizes and offsets are derived (local_sizes: 0 when the local header leaves them zero for a descriptor); bytes before an entry (before), between the entries and the central directory (gap), ZIP64 records (zip64) and after the end record (trailer) are kept.
A Broadcom TRX image ("trx") is its flags and version and its partitions, parts partition_<n> (the offsets, length and CRC derived). An .lzma stream ("lzma", LZMA SDK's 13-byte header) is its properties (lc, lp, pb, dict_size when not EDK2's defaults) and the decompressed payload; codec: "lzma" says the LZMA SDK's encoder re-makes the stream, else it is kept as part stream and used while it still decodes to the payload.
A USB DFU file ("dfu") is its suffix fields (the CRC derived) and the firmware, part firmware; an ST DfuSe file lists its targets, each element a part target_<t>_<e> at its load address. A UF2 file ("uf2") is runs of blocks (address, payload length, count, flags, family ID; block numbers derived) over contiguous segment_<n> parts, as Intel HEX records are.
An Android boot image ("android_boot", header versions 0 to 2) is its header fields (load addresses, page size, command lines; sizes derived) and parts kernel, ramdisk and second at their load addresses; the rest of the header page and what follows the images are kept as bytes. An xz file ("xz") is the decoded payload and the preset (with extreme: 1 for -e) of xz -<preset> that makes it — a port of xz-utils' liblzma encoder in normal mode (presets 4 to 9, and 3 to 9 extreme), one block without sizes as single-threaded xz writes — and its check type when not CRC64; when no preset reproduces the file it is kept as part stream, used while it still decodes to the payload, and an edited payload is compressed at preset 6. A bzip2 file ("bzip2") is its level and the decoded payload, re-made by a port of bzip2 1.0's compressor, or kept as part stream when that doesn't reproduce it. Payloads of xz and bzip2 streams over 4 MiB are shown as bytes.
A Chromium / coreboot flash image ("fmap") is its flash map's header fields and areas, and a layout cut at every area boundary: the map itself (map: 1, written from areas, its size derived), runs of one byte (fill, len), and parts named after the innermost area holding them, decompiled as what they are.
A coreboot file system ("cbfs", inside an fmap's COREBOOT and FW_MAIN_* areas) is its files: each file's name and type, its attributes (a compression attribute as compression, its decompressed_size derived; a stage header as load, entry_offset, memlen; others as tag and data) and its data — a fill run, bytes, or a part named after the file. Compressed data shows the decompressed bytes as the part, codec: "lzma" or "lz4"; a stream is re-made as cbfstool makes it (LZMA: LZMA SDK's encoder at lc 1, pb 0, 273 fast bytes, the dictionary the data's size; LZ4: the LZ4 r131 frame at LZ4HC level 16, independent blocks of up to 4 MiB), otherwise the stream is kept as part <name>.stream and used while it still decodes to the data. A legacy stage is stage: { compression, entry, load, memlen, … }, a payload its segments (type, compression, load_addr, mem_len, data); stages and code segments are placed at their load address, for the CPU the CBFS master header names. Header lengths, offsets and padding to the next 64-byte boundary are derived (name_area, pad, attributes_offset, offset when they differ).
A PCI option ROM ("pci_rom") is its images: a legacy one as part image_<n>, x86 real-mode code (arch: "x86_16"); an EFI one as its header bytes (EFI header and PCIR), the driver as a part decompiled as a PE — codec: "efi" when it is EfiCompress-ed, the stream re-made by the ported compressor or kept as stream — and the padding to the image's length (pad_fill/pad_len or pad); then the bytes after the last image.
Volkswagen group flash files nest too. An ODIS .frf file ("frf") is a ZIP archive under a keystream cipher (a running pair of seeds over a 4095-byte key table, as published in VW_Flash); it is the archive, part archive, and has no fields of its own. The archive's ODX flash container ("odx") is its text as a layout: strings, and a block for each FLASHDATA whose <DATA> holds at least 32 bytes of hex digits of one case — data names the part holding the bytes, lower: 1 when the digits are lower case. A block whose ENCRYPT-COMPRESS-METHOD is 00 is decompiled as what it is (the CPU guessed). One under a published scheme (VW_Flash's) is shown decrypted and decompressed, the method's low digit the encryption — crypt: "aes" with the key (AES-128-CBC under Simos 12, 12.2, 16, 18, 18.10, 18.41 or DQ381's key) or crypt: "xor" (Simos's byte-offset XOR) — and its high digit the compression: compress: "lzss" (Simos LZSS, its 0x11-filled 1023-byte window, re-made by a port of VW_Flash's compressor; tail zero bytes after the stream when not the padding to 16) or compress: "simos" (Simos 8/10's, the stream kept as stream); a scheme counts only when the data decompresses to the data block's UNCOMPRESSED-SIZE (an uncompressed XOR block, 01, when undoing it uncovers erased or zeroed flash). Other compressed or encrypted blocks are bytes. An SGO file ("sgo") is its version, the offsets of its ident and KWP-2000 records, those records' bytes (meta) and its blocks: addr, format (compression in the high nibble, encryption in the low), erase and check ranges, check, and the data with the format's 0xFF XOR undone, part block_<n> — decompiled at addr when format is 0, or inflated when it is a zlib stream re-made at some level (its 2-byte zlib header written); otherwise format is read as an ODX ENCRYPT-COMPRESS-METHOD and unpacked as above. The block table, sizes and the file checksum (the byte sum less one) are derived.
An Award BIOS image ("lha": any file that is a chain of LHA members from its start) lists its items: each member's name, method ("lh5", or "lh0" stored), time (Award's load address, segment and offset) and its data, a part decompiled as what it is — the system BIOS (the first member, or the one loaded at 5000:0000) and .rom modules as real-mode x86 (arch: "x86_16"); then the bytes between members as fill/len runs, inline bytes, or parts — in a BIOS image real-mode code at its offset in the top segment, the boot block entered at the reset vector. A -lh5- stream is re-made by a port of ar002's encoder (Okumura's archiver, which Award's tools descend from) from the text buffer the previous member left — fresh: 1 from a new one, after: <n> from member n's — else kept as part <name>.stream and used while it still decodes to the data. Sizes, header sums and CRC-16s are derived.
UEFI firmware nests three formats. A capsule ("uefi_capsule") is its header fields and the flash image, part image. A flash image ("uefi_image") is a layout of the firmware volumes found in it (parts fv_<n>, at their flash offset), runs of one byte (fill, len), and the bytes between, named after the Intel flash descriptor region they fall in (descriptor, me, gbe, bios, …). A firmware volume ("uefi_fv") is its header fields and its FFS files; each file's sections are a tree in build.files, and each leaf — a PE32 image, a TE image, raw data, a nested volume — is a part named after its place (f12.0: file 12, section 0) decompiled as what it is. A TE image's part is the PE it was cut from (adapter: "te" on its section): PE headers rebuilt to the TE header's stripped size, and on compiling the TE header is taken from the PE's headers and the PE's section table and the rest follow:
files: [{
name: "52C05B14-0B98-496C-BC3B-04B50211D680",
type: 0x7, attributes: 0x0,
sections: [{
type: 0x2, // GUID-defined
guid: "EE4E5898-3914-4259-9D6E-DC7BD79403CF",
attributes: 0x1,
codec: "lzma", // re-made by EDK2's LzmaCompress
sections: [
{ type: 0x13, data: [0x6, 0x8] },
{ type: 0x10, data: "f3.0.1" }, // the PE32 image, a part
{ type: 0x15, ui: "PlatformInfo" },
],
}],
}, …]
Sizes, header and file checksums, a volume's header length and checksum and a CRC-32 section's CRC are derived; a value that differs from the derived one is written. Gaps between files, padding between sections and free space are the erase byte or zeros unless written. A compressed section (codec: "tiano", "efi", "lzma", "lzma_f86"; "lzma_sdk4", "lzma_f86_sdk4" for AMI Aptio IV's LZMA SDK 4.43 streams, which carry an end marker after a known size; "lzma_sdk19", "lzma_f86_sdk19" for LZMA SDK 19.00's, EDK2's since 2019) shows its decompressed sections, and its stream is re-made by the compressor that reproduces it; when none does, the stream is kept as stream (bytes, or a part) and used while it still decodes to the sections, the sections shown alongside.
Every section with on-disk content is emitted as a @section block. The first argument is the section's name (matched against shdrs[].name); the second is its start address (the runtime virtual address for loadable sections, 0x0 for sections without one):
@section(".text", 0x10a0) {
@addr(0x10a0)
fn _start() {
@asm("endbr64", [0xf3, 0x0f, 0x1e, 0xfa])
…
}
@addr(0x10b0)
fn deregister_tm_clones() {
…
}
// alignment padding that doesn't belong to any function
@raw(0x10da, [0x90, 0x90, 0x90, 0x90, 0x90, 0x90])
@addr(0x10e0)
fn register_tm_clones() {
…
}
}
@section(".rodata", 0x2000) {
@raw(0x2000, [0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x00, …])
}
@section(".symtab", 0x0) {
@raw(0x0, [ … ])
}
Inside a section, items must cover the section contiguously: the first item starts at the section's address, and each subsequent item starts exactly where the previous one ended. Gaps and overlaps are hard errors at lower time.
@addr(0x1209)
fn main() -> i32 {
@asm("endbr64", [0xf3, 0x0f, 0x1e, 0xfa])
@asm("push rbp", [0x55])
@asm("mov rbp,rsp", [0x48, 0x89, 0xe5])
@asm("lea rax,[2004h]", [0x48, 0x8d, 0x05, 0x8c, 0x0e, 0x00, 0x00])
@asm("mov rdi,rax", [0x48, 0x89, 0xc7])
@asm("call 0000000000001060h", [0xe8, 0xe0, 0xfe, 0xff, 0xff])
@asm("mov esi,2Ah", [0xbe, 0x2a, 0x00, 0x00, 0x00])
@asm("lea rax,[2011h]", [0x48, 0x8d, 0x05, 0x85, 0x0e, 0x00, 0x00])
@asm("mov rdi,rax", [0x48, 0x89, 0xc7])
@asm("mov eax,0", [0xb8, 0x00, 0x00, 0x00, 0x00])
@asm("call 0000000000001070h", [0xe8, 0xd7, 0xfe, 0xff, 0xff])
@asm("mov eax,0", [0xb8, 0x00, 0x00, 0x00, 0x00])
@asm("pop rbp", [0x5d])
@asm("ret", [0xc3])
}
What's pinned here:
- Function address:
@addr(0x1209)— used by the lower path to slice the function back into its section's coordinate space. Default function name issub_<hex_addr>for any function the discovery layer couldn't put a real name on; that name encodes the address, so even unnamed functions sort correctly. - Typed signature (when DWARF / signatures supplied one):
() -> i32. Signature is optional; without one the form isfn name() { … }. Parameter types and return types use the type vocabulary below. - Per-instruction pinned bytes: every
@asm("text", [bytes])has both a human-readable disassembly and the exact encoded bytes. Bytes are the ground truth for round-trip; text is for humans. Future iterations may drop the bytes when a text assembler can produce byte-identical output.
Block boundaries from the lifted CFG surface as // block: 0x… comments and direct-branch targets as // -> 0x… annotations. They're informational; the parser preserves them through round-trip.
Types appear inside parameter declarations and after -> in function signatures.
| Type | Meaning |
|---|---|
void |
Unit / no value. Default return type when no -> clause. |
i8, i16, i32, i64 |
Signed integers. |
u8, u16, u32, u64 |
Unsigned integers. |
f32, f64 |
Floating-point. |
bool |
C _Bool. |
char |
A single byte representing a character. |
ptr<T> |
Pointer to T. Recursive: ptr<ptr<u8>> is "pointer to pointer to u8" (e.g. char**). |
unknown |
A type we couldn't recover. Round-trips verbatim; parser accepts it. |
Module / section level:
| Directive | Effect |
|---|---|
@module { … } |
Required at the top of every file. Pins the target plus full ELF reconstruction metadata. |
@section(name, addr) { … } |
Group items under an ELF section. Items must cover the section contiguously. |
@raw(addr, [bytes]) |
Pin a slice of bytes at a virtual address (or section-relative offset for sh_addr=0 sections). Used for alignment padding inside .text and for the entire content of non-text sections. |
Function-scoped:
| Directive | Effect |
|---|---|
@addr(0x…) |
Pin the function's address. Used by the lower path to slice bytes from the section. |
Function body:
| Directive | Effect |
|---|---|
@asm("text") |
Instruction in textual assembly form. Bytes derived by a future assembler (not yet implemented). |
@asm("text", [bytes]) |
Instruction with both text and pinned bytes. Bytes are the ground truth on lower today. |
Comments:
| Form | Effect |
|---|---|
// … (top level) |
Free-floating note. Survives round-trip. |
// … (inside section / function) |
Same. |
The decompiler emits // note: … lines at the top level for functions that exist (per discovery) but couldn't be bodied (typically because no source recorded a size and the size-filling pass couldn't infer one). These are informational and survive round-trip.
Input C:
int do_fac(int n) {
if (n <= 1) return 1;
return n * do_fac(n - 1);
}Decompiled:
@addr(0x11da)
fn do_fac(v: i32) -> i32 {
@asm("endbr64", [0xf3, 0x0f, 0x1e, 0xfa])
@asm("push rbp", [0x55])
@asm("mov rbp,rsp", [0x48, 0x89, 0xe5])
@asm("sub rsp,10h", [0x48, 0x83, 0xec, 0x10])
@asm("mov dword ptr [rbp-4],edi", [0x89, 0x7d, 0xfc])
@asm("cmp dword ptr [rbp-4],1", [0x83, 0x7d, 0xfc, 0x01])
@asm("jg short 11F4h", [0x7f, 0x07])
// -> { taken: 0x11f4, fallthrough: 0x11ed }
// block: 0x11ed
@asm("mov eax,1", [0xb8, 0x01, 0x00, 0x00, 0x00])
@asm("jmp short 1206h", [0xeb, 0x14])
// -> 0x1206
// block: 0x11f4
@asm("mov eax,dword ptr [rbp-4]", [0x8b, 0x45, 0xfc])
@asm("sub eax,1", [0x83, 0xe8, 0x01])
@asm("mov edi,eax", [0x89, 0xc7])
@asm("call 00000000000011DAh", [0xe8, 0xdb, 0xff, 0xff, 0xff])
@asm("imul eax,dword ptr [rbp-4]", [0x0f, 0xaf, 0x45, 0xfc])
// block: 0x1206
@asm("leave", [0xc9])
@asm("ret", [0xc3])
}
What's preserved:
- DWARF gave us
(v: i32) -> i32. - The CFG structure is implicit:
// block: 0x…markers show where the lifter decided basic blocks end, and// -> { taken, fallthrough }shows direct-branch targets. - Every byte is pinned via
@asm's second argument. iced's Intel formatter gives the human-readable form; the bytes are the ground truth.
- Structured statements. Function bodies are
@asmlines. Recoveringlet x = a + bfrom the assembly is a future phase. - Edit-aware re-encoding. If you change an
@asmline's text in a way that would alter byte length, the lower path emits the original bytes (which now disagree with the text). A warning for this case is on the near-term list. - No semantic refactoring on emit. The pretty-printer never reorders statements, never renames variables, never simplifies
x = x + 1tox++.
The @ sigil is reserved for directives. Identifiers may not begin with @. Comments are // to end of line. String literals support standard C escapes plus \xNN. Numeric literals: decimal, 0x hex; _ separators allowed.
Keywords that the parser distinguishes from idents: fn, void, i8/i16/i32/i64, u8/u16/u32/u64, f32/f64, bool, char, ptr, unknown.
Punctuation tokens: { } ( ) [ ] , : @ -> < >.