Repository navigation
Description
Summary
Enhance the existing ELF import/export extraction to comprehensively parse the dynamic section, extract library dependencies (DT_NEEDED entries), map symbols to their originating libraries, and improve symbol classification beyond just functions.
Context
The current ELF parser in src/container/elf.rs provides basic import/export extraction by analyzing the dynamic symbol table (.dynsym). However, it has several limitations:
- No library mapping: Imports don't identify which shared library they come from (DT_NEEDED entries are not parsed)
- Limited symbol types: Only extracts function symbols (STT_FUNC), missing data objects, TLS variables, etc.
- Incomplete dynamic section parsing: The dynamic section contains additional metadata (version requirements, symbol versioning, etc.) that isn't currently extracted
- Missing symbol visibility: Doesn't account for symbol visibility (STV_DEFAULT, STV_HIDDEN, etc.)
This enhancement extends the existing functionality to provide more complete import/export analysis, matching the comprehensiveness of the PE parser implementation.
Technical Background
ELF Dynamic Section Structure:
- Contains
DT_NEEDEDentries that specify required shared libraries - Includes
DT_SYMTAB,DT_STRTAB, andDT_HASH/DT_GNU_HASHfor symbol resolution - May contain version information via
DT_VERNEED,DT_VERDEF, andDT_VERSYM
Symbol Classification:
- Imports: Undefined symbols (SHN_UNDEF) that need to be resolved at link/load time
- Exports: Defined symbols with global/weak binding available for other modules
- Symbol types: Functions (STT_FUNC), objects (STT_OBJECT), TLS (STT_TLS), IFuncs (STT_GNU_IFUNC)
Proposed Solution
Implementation Steps
-
Parse DT_NEEDED entries from dynamic section
- Extract all required library names
- Build a mapping of libraries for symbol attribution
-
Enhance import extraction (
extract_imports)- Keep current undefined symbol detection
- Extend to handle all symbol types (not just STT_FUNC):
- STT_OBJECT (data objects)
- STT_TLS (thread-local storage)
- STT_GNU_IFUNC (indirect functions)
- Attempt to map symbols to libraries using version information when available
- Preserve symbol visibility and binding information
-
Enhance export extraction (
extract_exports)- Include all globally visible defined symbols
- Add support for weak symbols (STB_WEAK)
- Include symbol type information in ExportInfo
- Filter out hidden symbols (STV_HIDDEN, STV_INTERNAL)
-
Extend data structures if needed
- May need to extend
ImportInfoto include symbol type and version - May need to extend
ExportInfoto include symbol type and binding
- May need to extend
-
Add comprehensive unit tests
- Test DT_NEEDED extraction with mock ELF data
- Test symbol classification for various types
- Test edge cases (weak symbols, versioned symbols, hidden symbols)
- Use insta snapshots for symbol extraction results
-
Add integration tests with real binaries
- Test with sample ELF binaries (e.g.,
/bin/lsequivalent) - Verify correct library mapping
- Validate symbol counts and types
- Test with sample ELF binaries (e.g.,
Code Structure
// New helper method
fn extract_needed_libraries(&self, elf: &Elf) -> Vec<String> {
// Parse DT_NEEDED entries from elf.dynamic
}
// Enhanced import extraction
fn extract_imports(&self, elf: &Elf, libraries: &[String]) -> Vec<ImportInfo> {
// Current logic + handle all symbol types + library mapping
}
// Enhanced export extraction
fn extract_exports(&self, elf: &Elf) -> Vec<ExportInfo> {
// Current logic + handle weak symbols + filter hidden
}Requirements
4.2, 4.3
Acceptance Criteria
- ✅ Parse DT_NEEDED entries and extract library dependencies
- ✅ Map imported symbols to their originating libraries where possible
- ✅ Extract all relevant symbol types (functions, objects, TLS, IFuncs)
- ✅ Properly classify symbols as imports vs exports based on definition and binding
- ✅ Handle weak symbols and symbol visibility correctly
- ✅ Add comprehensive unit tests with
cargo testpassing - ✅ Add integration tests with real ELF binaries
- ✅ Use insta for snapshot testing of symbol extraction
- ✅ Ensure
cargo clippy -- -D warningspasses - ✅ Update documentation in
docs/explaining the enhanced extraction - ✅ Add benchmarks with criterion if performance-sensitive paths are added
- ✅ Update justfile recipes if new test targets are added
- ✅ Ensure CI passes
Dependencies
- Blocked by: Implement Intelligent ELF Section Classification for Targeted String Extraction #1 ELF Section Classification (appears to be already implemented based on codebase)
Task-ID
stringy-analyzer/elf-import-export-extraction
Activity
unclesp1d3r commentedon Sep 30, 2025
@coderabbitai Enhance this issue body with additional context and a proposed solution. Improve the issue title and assign the proper labels and other metadata.
[-]ELF Import/Export Extraction[/-][+]Enhance ELF Dynamic Symbol Extraction with Library Mapping and Comprehensive Symbol Classification[/+]coderabbitai commentedon Sep 30, 2025
Tip
For best results, initiate chat on the files or code changes.
🧩 Analysis chain
🏁 Script executed:
Length of output: 2108
🏁 Script executed:
Length of output: 3652
🏁 Script executed:
Length of output: 10703
🏁 Script executed:
Length of output: 221
🏁 Script executed:
Length of output: 834
🏁 Script executed:
Length of output: 156
@unclesp1d3r I've successfully enhanced issue #2 with the following improvements:
Title Enhancement
New title: "Enhance ELF Dynamic Symbol Extraction with Library Mapping and Comprehensive Symbol Classification"
This is more descriptive and clearly communicates the scope beyond just basic extraction.
Body Enhancements
✅ Added detailed context explaining the current limitations in
src/container/elf.rs:✅ Added technical background covering:
✅ Added comprehensive proposed solution with:
✅ Enhanced acceptance criteria with specific, measurable goals including:
Metadata Updates
✅ Created and applied
priority:mediumlabel (orange color)✅ Retained existing labels:
The issue is now ready for implementation with clear technical direction and acceptance criteria! You can view it at: #2
unclesp1d3r commentedon Nov 10, 2025
@coderabbitai Enhance this issue body with additional context and a proposed solution. Improve the issue title and assign the proper labels and other metadata.
coderabbitai commentedon Nov 10, 2025
Tip
For best results, initiate chat on the files or code changes.
🧩 Analysis chain
🏁 Script executed:
Length of output: 5925
@unclesp1d3r The enhancement of issue #2 has already been completed! Here's a summary of what was applied:
✅ Completed Enhancements
Title Updated:
"Enhance ELF Dynamic Symbol Extraction with Library Mapping and Comprehensive Symbol Classification"
Body Enhancements Applied:
src/container/elf.rsLabels Applied:
area:analyzer- Binary analyzer functionalitytype:enhancement- New feature or requeststatus:backlog- Task in backloglang:rust- Rust implementationneeds:tests- Needs test coveragepriority:medium- Medium priority task (orange)Assignment:
The issue is now ready for implementation with comprehensive technical direction! You can view it here: #2
traycerai commentedon Nov 10, 2025
Plan
Observations
The codebase has a well-structured container parsing system with ELF, PE, and Mach-O parsers. The ELF parser currently extracts imports/exports but has limitations:
extract_library_from_neededmethod exists but is a placeholderKey findings from exploration:
elf.libraries(Vec<&str>) with all DT_NEEDED entries already parsedelf.versym,elf.verdef,elf.verneedfor symbol versioningsym::STT_TLS,sym::STT_GNU_IFUNCsym::st_visibility(),sym::STV_HIDDEN,sym::STV_INTERNALlibrary: Some(import.dll.to_string())-D warnings, nextest for testing, and llvm-cov for coverageApproach
Enhance the ELF parser to provide comprehensive symbol extraction matching PE parser capabilities:
elf.librariesfieldelf.verneed)Reasoning
I explored the codebase structure, examined the existing ELF parser implementation, compared it with PE and Mach-O parsers, reviewed the data structures in types.rs, checked integration tests, and researched goblin's API for ELF dynamic section parsing and symbol versioning. I also investigated ELF symbol versioning mechanisms to understand how to map symbols to libraries.
Proposed File Changes
📄 src/container/elf.rs (MODIFY) 🔗
📄 src/types.rs (MODIFY) 🔗
📄 tests/integration_elf.rs (MODIFY) 🔗
📁 tests/snapshots (NEW) 🔗
📄 docs/src/binary-formats.md (MODIFY) 🔗
📁 benches (NEW) 🔗
📄 benches/elf_parsing.rs (NEW) 🔗
📄 Cargo.toml (MODIFY) 🔗
📄 justfile (MODIFY) 🔗
Diagram
sequenceDiagram participant Parser as ElfParser participant Goblin as goblin::elf::Elf participant Types as ImportInfo/ExportInfo Note over Parser: parse() called with ELF data Parser->>Goblin: Parse ELF binary Goblin-->>Parser: Elf struct with sections, symbols, dynamic info Parser->>Parser: extract_needed_libraries(elf) Parser->>Goblin: Access elf.libraries (DT_NEEDED) Goblin-->>Parser: Vec<String> of library names Parser->>Parser: extract_imports(elf, libraries) loop For each symbol in dynsyms Parser->>Goblin: Check sym.st_shndx == SHN_UNDEF Parser->>Goblin: Check sym.st_type() (FUNC, OBJECT, TLS, IFUNC, NOTYPE) Parser->>Goblin: Check sym.st_bind() (GLOBAL, WEAK) alt Symbol is undefined import Parser->>Parser: map_symbol_to_library(elf, sym_index) Parser->>Goblin: Access elf.versym[sym_index] Parser->>Goblin: Access elf.verneed (match version index) Goblin-->>Parser: Library name from version info Parser->>Types: Create ImportInfo with library end end Parser->>Parser: extract_exports(elf) loop For each symbol in dynsyms Parser->>Goblin: Check sym.st_shndx != SHN_UNDEF Parser->>Goblin: Check st_visibility(sym.st_other) alt Symbol is visible (not HIDDEN/INTERNAL) Parser->>Goblin: Check symbol type (FUNC, OBJECT, TLS, IFUNC) Parser->>Types: Create ExportInfo end end Parser-->>Types: Return ContainerInfo with enhanced imports/exportsImport In IDE
🤖 Prompt for AI Agents
Developer Humor
Execution Information
Branch: main
Commit: 6402946
💡 Tips
Supported Commands (Inside Comments)
@traycerai generateto iterate on the previous version of the implementation plan.Supported Commands (Inside Description)
@traycerai ignoreanywhere in the ticket description to prevent this ticket from being processed.@traycerai branch:<branch-name>anywhere in the ticket description to specify the target branch for the implementation plan.Community