padlock-dwarf
DWARF, BTF, and PDB binary analysis backend for padlock — a struct memory layout analyzer for C, C++, Rust, Go, and Zig.
This crate reads compiled binaries and extracts exact struct layouts as produced by the compiler:
- DWARF (ELF on Linux, Mach-O on macOS) — reads
DW_TAG_structure_typeandDW_TAG_memberentries viagimli+object. Bitfield members (DW_AT_bit_sizepresent) are grouped into synthetic[a:3|b:5]storage-unit fields sized fromDW_AT_byte_size; groups with no storage-unit size are added toStructLayout::uncertain_fields. - BTF (eBPF object files and
/sys/kernel/btf/vmlinux) — reads the.BTFELF section or a raw BTF blob. Supports all stable BTF kinds includingSTRUCT,UNION,ENUM,ARRAY, bitfields, and packed structs. - PDB (Windows MSVC debug databases) — reads the TPI stream via the
pdbcrate. ExtractsClass,Union, andEnumerationtype records; resolves field lists including bitfield grouping; surfaces unknown bitfield storage units asuncertain_fields. detect_arch_from_host()— returns theArchConfigfor the current build target.
Unlike source analysis, binary-based layouts are compiler-verified: offsets, sizes, and padding are exactly what the compiler produced. This is useful for structs with alignas, __attribute__((packed)), conditional compilation, complex type aliases, or C++ templates that source analysis cannot fully resolve.
Usage
padlock-dwarf is an internal library crate. To analyze a binary, use the CLI:
Part of padlock
padlock-cli— CLI (padlock+cargo-padlockbinaries)padlock-core— IR, analysis passes, findingspadlock-source— Source analysis (C/C++/Rust/Go)padlock-dwarf— Binary analysis (DWARF/PDB) (this crate)padlock-output— Output formatters (terminal/JSON/SARIF/diff)padlock-macros— Compile-time layout assertions