dump

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package dump renders a binary's views as plain, non-interactive text for stdout (the `-o` flag), turning exex into a scriptable readelf/nm/objdump-lite. It shares the function-disassembly formatter with the TUI's "copy function" so the two stay identical.

Index

Constants

This section is empty.

Variables

View Source
var ViewNames = []string{"info", "sections", "segments", "symbols", "strings", "libs", "sources", "relocs", "syscalls", "syscalls-all", "cpu-features", "disasm", "disasm-all"}

ViewNames lists the canonical view keywords for help/usage text.

Functions

func AlignAsm

func AlignAsm(text string) string

AlignAsm renders an instruction's text objdump-style: the mnemonic right-aligned in asmMnemWidth, operands left-aligned after a single space (so the mnemonic/operand boundary is a single vertical seam). A mnemonic longer than the field simply overflows it (no truncation). Hex immediates are already produced by the decoder (see disasm.hexImmediates); this only handles layout, so the dump and the TUI disasm view stay identical.

func CPUFeatures

func CPUFeatures(f *binfile.File) (string, error)

CPUFeatures renders the CPU-feature report for the `-o cpu-features` dump.

func ClassifySyscallSite

func ClassifySyscallSite(inst disasm.Inst, symAt func(uint64) (binfile.Symbol, bool)) (site bool, vdso bool)

ClassifySyscallSite reports whether inst is a syscall site and, if so, whether it is a vDSO call. The symAt lookup resolves an instruction's branch target to a symbol for the vDSO heuristic; it may be nil to disable that heuristic.

func DisasmTo

func DisasmTo(w io.Writer, f *binfile.File, all bool) error

DisasmTo streams the disassembly objdump-style to w: a "Disassembly of section <name>:" header per section and a "<addr> <symbol>:" label wherever a symbol begins. When all is false only executable sections are emitted (objdump -d); when true every section with file bytes is (objdump -D).

It streams per instruction (no whole-binary buffer) and demangles labels lazily, so output starts immediately on large binaries and `| head` / `| less` stops early instead of waiting for the entire image to decode. A write error (e.g. the reader closed the pipe) ends the dump cleanly.

func Function

func Function(f *binfile.File, target string) (string, error)

Function resolves target (a symbol name or address) to a function and returns its disassembly as plain text.

func FunctionInsts

func FunctionInsts(f *binfile.File, svc *explorer.DisasmService, sym binfile.Symbol) []disasm.Inst

FunctionInsts decodes the instructions making up sym's extent, fresh from the executable image. Shared with the TUI's "copy function" so both cover the whole function regardless of any visible decode window.

func FunctionText

func FunctionText(sym binfile.Symbol, insts []disasm.Inst, addrW int) string

FunctionText renders a function's instructions as plain, copy-friendly "addr: bytes text" lines under a header naming the symbol and its range.

func Info

func Info(f *binfile.File) string

Info dumps the header plus key triage fields.

func IsDisasm

func IsDisasm(name string) (disasm, all bool)

IsDisasm reports whether name selects a (streaming) disassembly dump, and whether it is the all-sections variant. The CLI routes these to DisasmTo rather than View so output streams instead of buffering.

func IsVDSOName

func IsVDSOName(name string) bool

IsVDSOName reports whether a symbol name is a vDSO / kernel-helper entry point, i.e. a userspace call that services what would otherwise be a system call.

func IsView

func IsView(name string) bool

IsView reports whether name is a known view keyword for `-o`. The CLI uses this to tell `-o sections` (a view) from a bare `-o` whose target is the positional symbol/address — so a symbol literally named "sections" can still be disassembled (as the positional), without colliding with the view.

func Libs

func Libs(f *binfile.File) string

Libs dumps the dynamic library dependencies.

func Relocs

func Relocs(f *binfile.File) string

Relocs dumps the binary's relocation table.

func ResolveSyscallNum

func ResolveSyscallNum(prev []disasm.Inst, a disasm.Arch) (int64, bool)

ResolveSyscallNum recovers the system-call number for the site at prev[len-1]'s successor by scanning the preceding instructions (oldest..newest) for the last immediate written to the architecture's syscall-number register. prev must end just before the syscall instruction. It is best-effort: a number set in a register, computed, or out of the scan window stays unresolved.

func Sections

func Sections(f *binfile.File) string

Sections dumps the section table. An LMA (load/physical address) column is added only when some section's load address differs from its virtual address.

func Segments

func Segments(f *binfile.File) string

Segments dumps the segment (memory-region) table. A PAddr column is added only when some segment's physical address differs from its virtual address.

func Sources

func Sources(f *binfile.File) string

Sources dumps the list of source files referenced by the binary's debug info.

func StreamView

func StreamView(w io.Writer, f *binfile.File, name string) (handled bool, err error)

StreamView writes a view straight to w when it has a streaming form (the large symbol/string tables), returning whether it handled the view. The CLI uses it so those dumps never buffer the whole output; other views fall back to View.

func Strings

func Strings(f *binfile.File) string

Strings dumps the printable strings to a string (with address or file offset). The CLI streams it via StringsTo; this buffered form is for tests.

func StringsTo

func StringsTo(w io.Writer, f *binfile.File) error

StringsTo streams the printable strings to w, one per line. The per-line prefix is formatted into one reused buffer and the text is written straight from the file image (StringBytes is zero-copy), so neither a per-line copy nor a whole- output buffer is allocated. A write error ends the dump cleanly.

func Symbols

func Symbols(f *binfile.File) string

Symbols dumps the symbol table to a string (nm-like: addr, size, bind, type, name). The CLI streams it via SymbolsTo; this buffered form is for callers that want the whole text (tests).

func SymbolsTo

func SymbolsTo(w io.Writer, f *binfile.File) error

SymbolsTo streams the symbol table to w (one row per symbol), so a table with hundreds of thousands of symbols never buffers the whole output. Each row's fixed columns are formatted into one reused buffer (no boxed Fprintf per row). A write error (e.g. a closed pipe) ends the dump cleanly.

func SyscallName

func SyscallName(f *binfile.File, num int64) (string, bool)

SyscallName resolves a syscall number to its name for f's os/arch, consulting any loaded override tables. Exposed so the TUI's syscall modal resolves names the same way the dump does.

func Syscalls

func Syscalls(f *binfile.File, full bool) string

Syscalls dumps the binary's syscall usage. By default it summarises the *unique* system calls invoked (one row per distinct number, with a count and an example location); with full=true it lists every site with its address, like `objdump`-style output.

func SyscallsArchive

func SyscallsArchive(members []binfile.ArchiveMember, full bool) string

SyscallsArchive summarises the system calls provided by a static-library (ar) archive, scanning every object member and tagging each syscall with the member it came from. With full=false it prints the merged unique list; with full=true it lists every site (its member as the symbol column).

func SyscallsFull

func SyscallsFull(f *binfile.File) string

SyscallsFull summarises the system calls of the binary *and its directly linked libraries* — the real syscall surface of a dynamically linked program, whose own code often makes no direct syscalls (they live in libc). The output is one merged unique list, each row tagged with the originating object(s).

func VDSOSymAt

func VDSOSymAt(f *binfile.File) func(uint64) (binfile.Symbol, bool)

VDSOSymAt returns f.SymbolAt only when the binary actually has vDSO/__kernel_ symbols; otherwise nil, so a scan can skip the per-call-instruction symbol lookup the vDSO heuristic would otherwise do on every call in the image. Exported so the TUI scan can apply the same optimisation.

func View

func View(f *binfile.File, name string) (string, error)

View dumps a named view as plain text, or errors for an unknown name.

func ViewNeedsDemangle

func ViewNeedsDemangle(name string) bool

ViewNeedsDemangle reports whether a view actually displays symbol names, so the CLI can skip the whole-table demangle pass for views that don't (sections, segments, strings, libs, sources, info) — that pass allocates 1+ GB on a large C++/Swift binary and is pure waste for them.

func ViewNeedsLayoutOnly

func ViewNeedsLayoutOnly(name string) bool

ViewNeedsLayoutOnly reports whether a view can be rendered from the cheap layout model (sections/segments/raw bytes) without symbols, imports, relocs, DWARF, or computed overview fields.

Types

type CPUFeatureSet

type CPUFeatureSet struct {
	Counts   map[string]int    // feature → number of instructions using it
	FirstUse map[string]uint64 // feature → address of the first instruction using it
	Total    int               // instructions scanned
	Baseline string            // implied x86-64 microarch level (x86 only), or ""
}

CPUFeatureSet is the result of a feature scan.

func ScanCPUFeatures

func ScanCPUFeatures(f *binfile.File) (CPUFeatureSet, error)

ScanCPUFeatures decodes the executable sections — in parallel chunks across all cores, the same way the syscall scan does — and classifies every instruction into the CPU-feature families it requires. Each chunk decodes a small lead of preceding bytes to re-synchronise the (variable-length x86) decoder, then only counts instructions at or past the chunk's real start so the overlap isn't double-counted.

func ScanCPUFeaturesCancel

func ScanCPUFeaturesCancel(f *binfile.File, done <-chan struct{}) (CPUFeatureSet, error)

ScanCPUFeaturesCancel is ScanCPUFeatures with an optional cancellation channel. When done is closed, workers stop decoding as soon as they observe it. The UI still guards stale results by sequence number; cancellation is to stop wasting CPU after the user dismisses/supersedes the scan.

func (CPUFeatureSet) SortedFeatures

func (s CPUFeatureSet) SortedFeatures() []string

SortedFeatures returns the used features in display order (then by count).

type SyscallSite

type SyscallSite struct {
	Addr   uint64 // address of the instruction
	Text   string // its trimmed assembly text
	Sym    string // enclosing symbol's display name, or ""
	VDSO   bool   // true for a vDSO/__kernel_ call rather than a real syscall insn
	Num    int64  // resolved syscall number, when recoverable
	HasNum bool   // whether Num was recovered
	Name   string // resolved syscall name (os/arch table), when known
	Origin string // object the site came from (full scan), e.g. "libc.so.6"; "" = this binary
}

SyscallSite is one located system-call (or vDSO) site.

func CollectSyscallsFull

func CollectSyscallsFull(f *binfile.File) (sites []SyscallSite, objects int, notes []string)

CollectSyscallsFull scans the binary and its directly linked libraries for syscall sites, tagging each with the object it came from. It returns the sites, the number of objects scanned, and notes about libraries that couldn't be scanned. Shared by the `syscalls-full` dump and the TUI's full scope.

func CollectSyscallsFullCancel

func CollectSyscallsFullCancel(f *binfile.File, done <-chan struct{}) (sites []SyscallSite, objects int, notes []string)

CollectSyscallsFullCancel is CollectSyscallsFull with cooperative cancellation. When done is closed it stops scheduling new library/object work and asks active decode workers to exit early. Partial results may be returned; UI callers guard cancelled results by sequence/file identity.

Jump to

Keyboard shortcuts

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