Skip to content

dev.binaries

look inside compiled programs and libraries for Linux, Windows and macOS

Permissions: files.read

Compiled programs and libraries are stored in one of three file formats: ELF on Linux and most other Unix systems, PE on Windows (.exe and .dll files), and Mach-O on macOS and iOS. Reading one gives a map of what the file is and how it was built, without tools like readelf, objdump or otool, and the help page lists the map’s keys. Machine code for x86 and x64 can also be turned back into assembly.

Tags: binary

  • binary read a compiled program or library (ELF, PE or Mach-O) into a map of what it is, what’s inside it and which security protections it was built with
  • disasm disassemble x86 or x64 machine code into assembly, laid out like objdump -d, or with table into a table of addr, bytes and text
  • asm assemble x86 or x64 instructions in Intel syntax into machine code, the reverse of disasm
  • gadgets find ROP gadgets: short runs of instructions ending in ret, the pieces a return-oriented exploit chains together when it can’t run code of its own
  • xrefs find the instructions in a binary that call, jump to or read from an address or symbol
  • va the address a byte of a binary’s file is loaded at, through its segment table
  • offset where in a binary’s file the byte at an address comes from, through its segment table
  • demangle turn a compiler-mangled symbol name back into the Rust or C++ name it came from, like c++filt
binary(file: str|bytes) -> map

read a compiled program or library (ELF, PE or Mach-O) into a map of what it is, what’s inside it and which security protections it was built with

Takes a path or the file’s bytes

Returns a map with:

key type meaning
path str? the file it was read from, nil when given bytes
format str “elf”, “pe” or “macho”
arch str the CPU it’s built for, like “x86_64” or “aarch64”
bits int 32 or 64
endian str byte order, “little” or “big”
entry int the address where the program starts running
sections table the named pieces of the file, like .text for machine code and .data for globals. Columns name, addr, size, offset
segments table how sections are loaded into memory. Columns name, addr, size (in memory), offset, file_size (in the file, with the rest zero-filled) and perm, whether it’s readable, writable or executable, like “r-x”
symbols table the functions and variables the file defines. Columns name, addr, size, kind, global and demangled, the readable name of a Rust or C++ symbol
stripped bool its symbol table was removed, leaving only the names shared libraries need, so symbols may be empty and code is found by address
imports table the functions it borrows from shared libraries. Columns name, library
exports table the functions it offers to other programs. Columns name, addr
relocs table the places the loader or linker patches with an address, like a library function’s slot in the GOT. Columns offset, kind (like “jump_slot”), symbol and addend
got map? each library symbol’s slot in the global offset table, where the loader writes its address. nil for PE and Mach-O
plt map? each library function’s stub in the procedure linkage table, the address the program calls it through. nil for PE and Mach-O
pie bool it loads at a random address each run, so an attacker can’t know where its code is
nx bool memory holding data can’t run as code, so bytes an attacker sneaks in can’t execute
canary bool functions check a guard value next to their locals before returning, catching most stack overflows
relro str? “full”, “partial” or “none”: how much of the library address table is read-only after loading, so it can’t be overwritten to redirect calls. nil for PE and Mach-O, which have no RELRO
1
binary("a.out").arch
2
binary("a.out").imports.name
3
binary(read_bytes("app.exe")).nx
Example outputCtrl+Enter to run

See also read_bytes, strings, hexdump

disasm(code: bytes|map, at?: int|str, table: bool = false, bits: int = 64, syntax: str = “intel”) -> any

disassemble x86 or x64 machine code into assembly, laid out like objdump -d, or with table into a table of addr, bytes and text

Each line has the address, the instruction’s bytes in hex and its text, under a <name>: header where a function or section starts. Raw bytes are decoded from addr, 0 by default, as 64-bit code unless bits is 32 or 16. Given a symbol name instead of an address, the bytes are a whole executable and the function comes from its symbol table, as does binary(path).disasm("main"). binary(path).disasm(addr) decodes the executable’s code from that address, for files stripped of symbols, and binary(path).disasm() all of its code. Intel syntax unless syntax is “att”

1
disasm(b"\x55\x48\x89\xe5\xc3")
0: 55 push rbp 1: 48 89 e5 mov rbp,rsp 4: c3 ret
2
disasm(b"\x31\xc0\xc3", 0x401000, syntax: "att")
401000: 31 c0 xor %eax,%eax 401002: c3 ret
3
disasm(b"\x55\x48\x89\xe5\xc3", table: true)table([{addr: 0x0, bytes: b"U", text: "push rbp"}, {addr: 0x1, bytes: b"H\x89\xe5", text: "mov rbp,rsp"}, {addr: 0x4, bytes: b"\xc3", text: "ret"}])
4
binary("a.out").disasm("main")
5
disasm(read_bytes("a.out"), "main")
6
binary("a.out").disasm(table: true).text
Example outputCtrl+Enter to run

See also binary, hexdump

asm(text: str, addr?: int, bits: int = 64) -> any

assemble x86 or x64 instructions in Intel syntax into machine code, the reverse of disasm

Instructions are separated by semicolons or new lines, and each gets its shortest encoding. Memory operands are written like qword ptr [rbp + rax*8 - 0x10], and the size is needed only when no register operand gives it. Jumps and calls take the target address, and [rip + 8] is relative to the next instruction, so the code is assembled at addr, 0 by default, as 64-bit unless bits is 32 or 16. Labels and directives aren’t supported

1
asm("xor eax, eax; push rax; ret")b"1\xc0P\xc3"
2
asm("mov qword ptr [rsp + 8], 0x41")b"H\xc7D$\x08A\0\0\0"
3
asm("jmp 0x401000", 0x401000).disasm(0x401000)"401000: eb fe jmp short 0x401000"
Example outputCtrl+Enter to run

See also disasm, gadgets, patch

gadgets(code: bytes|map, depth: int = 5, jop: bool = false, bits: int = 64, syntax: str = “intel”, *, base?: bool|int) -> table

find ROP gadgets: short runs of instructions ending in ret, the pieces a return-oriented exploit chains together when it can’t run code of its own

Scans the executable code of a binary (or raw x86/x64 bytes) for every clean run of up to depth instructions (5 by default) that ends in a ret, dropping any run a jump or call breaks partway through. Returns a table of addr, bytes and text. With jop, also finds jump-oriented gadgets, which end in a jmp or call through a register. syntax and bits work as in disasm. Raw bytes are addressed from 0, or from base (true means 0x400000). Filter the table for the effect you need, like binary("a.out").gadgets().filter(|g| g.text.contains("pop rdi"))

  • base the address raw bytes start at, true for 0x400000 (a binary’s own addresses are used)
1
gadgets(b"\x5f\xc3")table([{addr: 0x0, bytes: b"_\xc3", text: "pop rdi; ret"}, {addr: 0x1, bytes: b"\xc3", text: "ret"}])
2
binary("a.out").gadgets().text
3
binary("a.out").gadgets(jop: true).len
Example outputCtrl+Enter to run

See also disasm, binary, strings

xrefs(code: bytes|map, target: int|str) -> table

find the instructions in a binary that call, jump to or read from an address or symbol

A linear sweep of the executable code, like disasm(), for each call, jmp, conditional jump or rip-relative operand that lands on the target. A library function is found through its PLT stub, so binary(path).xrefs("puts") finds the calls to puts. Returns a table of addr, bytes and text. Bytes are a whole executable, as in disasm(bytes, "main")

1
binary("a.out").xrefs("puts")
2
binary("a.out").xrefs(0x401136).addr
Example outputCtrl+Enter to run

See also disasm, binary

va(b: map, offset: int) -> any

the address a byte of a binary’s file is loaded at, through its segment table

1
binary("a.out").va(0x1040)
Example outputCtrl+Enter to run

See also offset, binary

offset(b: map, addr: int) -> any

where in a binary’s file the byte at an address comes from, through its segment table

1
binary("a.out").offset(0x401000)
Example outputCtrl+Enter to run

See also va, binary

demangle(sym: str) -> str

turn a compiler-mangled symbol name back into the Rust or C++ name it came from, like c++filt

Names that aren’t mangled come back unchanged

1
demangle("_ZN3foo3barEv")"foo::bar()"
2
demangle("_ZN4core3fmt5write17h0123456789abcdefE")"core::fmt::write"
Example outputCtrl+Enter to run

See also binary

Example results generated on 2026-11-04. Ones using now, today or randomness will differ when you run them.