Add binary package for native object inspection - #126
Open
andrew wants to merge 1 commit into
Open
Conversation
Inspect(path) reports format, architecture, dynamic dependencies, producer strings, embedded Go build info, and heuristic static-link hints for ELF, Mach-O (thin and universal, including FAT_MAGIC_64), and PE files. Built on debug/elf, debug/macho, debug/pe, and debug/buildinfo with no new module dependencies. ELF: DT_NEEDED, DT_SONAME, .comment, arch derived from Machine plus Class and ByteOrder so riscv64/ppc64le/mips variants are distinguished. Mach-O: LC_LOAD_DYLIB via ImportedLibraries, plus raw load-command decode for LC_ID_DYLIB, LC_LOAD_WEAK_DYLIB, and LC_BUILD_VERSION. The fat header is parsed directly since debug/macho.NewFatFile rejects FAT_MAGIC_64; each slice is bounds-checked against the declared size and Go build info is read from the first slice. PE: DLL names read from IMAGE_IMPORT_DESCRIPTOR entries in the import directory since pe.ImportedLibraries is a stub and pe.ImportedSymbols omits ordinal-only imports. InspectReader confines all reads to an io.SectionReader over the declared size. Tests cross-compile a trivial program to nine GOOS/GOARCH targets at test time so all three formats are exercised without checking binaries into the repository.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Foundation for
brief inspect(see.claude/notes/inspect-binaries.md).binary.Inspect(path)andbinary.InspectReader(r, size)report format, architecture, dynamic dependencies, producer strings, embedded Go build info, and heuristic static-link hints for ELF, Mach-O, and PE. Pure stdlib (debug/elf,debug/macho,debug/pe,debug/buildinfo); no go.mod changes.ELF reports
DT_NEEDED,DT_SONAME, and the.commentsection (GCC, clang, and rustc all write there). Arch is derived fromMachineplusClassandByteOrderso riscv32/riscv64, ppc64/ppc64le, and the four mips variants are distinguished.Mach-O reports
LC_LOAD_DYLIBviaImportedLibrariesplus raw load-command decode forLC_ID_DYLIB,LC_LOAD_WEAK_DYLIB, andLC_BUILD_VERSION. Universal binaries are handled by parsing the fat header directly sincedebug/macho.NewFatFilerejectsFAT_MAGIC_64; each slice is bounds-checked against the declared object size and Go build info is read from the first slice so fat64 Go binaries are covered.PE reads DLL names from
IMAGE_IMPORT_DESCRIPTORentries in the import directory, sincepe.ImportedLibrariesis a stub andpe.ImportedSymbolsomits ordinal-only imports.InspectReaderwraps the input in anio.SectionReaderover the declared size so all parsers are confined to the caller's bounds. Static-link hints come from a starting regex table over.rodata/__cstring/.rdata(zlib, openssl, sqlite viaSQLITE_SOURCE_ID, libcurl, pcre2, libpng, libjpeg-turbo, libwebp, libxml2, brotli, lz4, zstd, libffi, mbedtls, expat, c-ares, boringssl) and are reported as low-confidence.Tests cross-compile
testdata/helloto nine GOOS/GOARCH targets at test time so all three formats are exercised without checking binaries into the repository, plus alipo -fat64fixture on darwin.TestInspectSelfcovers the host format viaos.Executable().Not in this PR: PE Rich header, cargo-auditable
.dep-v0, systemd.note.package, and the soname→purl mapping.