disasm

module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 25, 2026 License: MIT

README

disasm

Go packages for reading executables and disassembling their machine code.

  • objfile opens ELF, Mach-O, PE, WebAssembly (modules and components) and Go compile archives; lists functions with their code, resolves symbols, maps addresses to source positions from the Go pclntab or DWARF, and disassembles into Go and native syntax for amd64, 386, arm64, arm (ARM and Thumb), riscv64/32, ppc64/le, s390x, loong64, avr, xtensa and wasm.
  • thumbasm is a Thumb/Thumb-2 decoder generated from ARM's ISA XML.
  • avrasm, xtensaasm are hand-written decoders for AVR and Xtensa.

objfile.Open memory-maps the file and reads only headers and symbol tables; function bodies, line tables and debug info are read on first use, so a large binary costs what is looked at.

bin, err := objfile.Open("prog")
defer bin.Close()
fn := bin.Func("main.main")
insts, err := bin.Disassemble(fn)
for _, in := range insts {
	file, line := bin.PCToLine(in.Addr)
	fmt.Printf("%#x %s %s:%d\n", in.Addr, in.Text, file, line)
}

Users

lensm and ixdiff are built on these packages.

Testing

objfile/testdata holds binaries for every supported format and architecture; go test ./objfile compares their complete disassembly and line mapping against testdata/golden. After an intended change in output, regenerate with go test ./objfile -update and review the diff. Set OBJFILE_DUMP=dir to write the full dumps for comparing two versions.

Directories

Path Synopsis
Package avrasm disassembles AVR machine code (ATmega, ATtiny, ...), in the syntax of avr-objdump.
Package avrasm disassembles AVR machine code (ATmega, ATtiny, ...), in the syntax of avr-objdump.
Package objfile loads executables into a format-independent representation: the architecture, the functions with their machine code, symbol lookups, source positions from the Go pclntab or DWARF, and a disassembler for the code.
Package objfile loads executables into a format-independent representation: the architecture, the functions with their machine code, symbol lookups, source positions from the Go pclntab or DWARF, and a disassembler for the code.
Package thumbasm disassembles T32 (Thumb and Thumb-2) machine code.
Package thumbasm disassembles T32 (Thumb and Thumb-2) machine code.
gen command
Command gen builds the T32 (Thumb) encoding table for package thumbasm from ARM's AArch32 ISA XML (the "Exploration tools" release of developer.arm.com; see data/download.sh).
Command gen builds the T32 (Thumb) encoding table for package thumbasm from ARM's AArch32 ISA XML (the "Exploration tools" release of developer.arm.com; see data/download.sh).
Package xtensaasm disassembles Xtensa LX machine code (ESP32, ESP8266), in the syntax of xtensa-objdump: the core ISA with the code density, windowed register, loop, multiply/divide, boolean and single-precision floating-point options.
Package xtensaasm disassembles Xtensa LX machine code (ESP32, ESP8266), in the syntax of xtensa-objdump: the core ISA with the code density, windowed register, loop, multiply/divide, boolean and single-precision floating-point options.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL