Repository navigation
Description
Overview
Parse relocation entries from supported binary formats (ELF .rela/.rel, PE relocation table, Mach-O LC_DYLD_INFO) to identify data addresses that are directly referenced by code. Mark extracted strings at these addresses with a "referenced" flag and boost their relevance scores.
Context
When binaries are compiled with position-independent code (PIE/PIC) or are relocatable, the linker generates relocation entries that map virtual addresses to their actual runtime locations. These relocation entries provide a high-confidence signal that specific data addresses (including string literals) are actively used by the code, without requiring expensive disassembly or control-flow analysis.
By parsing these relocation tables, we can:
- Identify strings that are definitely referenced by code (zero false positives)
- Prioritize these strings in the ranking algorithm
- Provide this metadata to analysts for focused triage
- Improve signal-to-noise ratio in stripped binaries where symbol tables are unavailable
This is particularly valuable because relocation data persists even in stripped binaries, making it a reliable source of ground truth about what data the code actually uses.
Benefits
- Zero-cost analysis: No disassembly or emulation required for this subset
- High confidence signal: Relocation entries are ground truth from the linker
- Works on stripped binaries: Relocation info survives stripping
- Format-agnostic approach: Applicable to ELF, PE, and Mach-O
- Improves ranking: Dramatically reduces false positives in string extraction
Technical Details
ELF Relocations
ELF binaries contain relocation sections (, , , ) that specify:
- : Virtual address where the relocation applies
- : Type and symbol index
- : Constant addend (for RELA-type relocations)
Relevant relocation types:
- : Adjust for base address (common in PIE)
- : Global offset table entries
- : Procedure linkage table entries
- : Direct address references
Implementation: Use to parse relocation entries and extract target addresses.
PE Relocations
PE binaries contain a Base Relocation Table (IMAGE_DIRECTORY_ENTRY_BASERELOC) that groups relocations by 4KB pages:
- Each entry specifies a page RVA and a list of offsets within that page
- Type field indicates relocation type (most commonly or )
Implementation: Parse the section via to identify relocated addresses.
Mach-O Relocations
Mach-O binaries use the or load commands to store compressed relocation data:
- Rebase opcodes: Adjust pointers for ASLR
- Binding opcodes: Link to external symbols
- Lazy binding opcodes: Deferred symbol resolution
Implementation: Parse dyld info via and process rebase/bind opcodes to extract referenced addresses.
Proposed Solution
1. Extend type
Add a flag to the struct in :
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FoundString {
// ... existing fields ...
/// Whether this string is directly referenced by code via relocations
#[serde(skip_serializing_if = "Option::is_none")]
pub referenced: Option<bool>,
}2. Add relocation parsing to container parsers
Extend to include relocation data:
pub struct ContainerInfo {
// ... existing fields ...
/// Addresses referenced by relocations
pub relocation_targets: Vec<u64>,
}Implement relocation parsing in:
- : Parse , , , sections
- : Parse section (Base Relocation Table)
- : Parse load command rebase and bind entries
3. Cross-reference strings with relocation targets
During string extraction in :
- Extract all strings as usual
- Build a set of relocation target addresses from
- For each extracted string, check if its RVA/offset is in the relocation target set
- Set for matches
4. Update scoring algorithm
In , boost the score for strings with :
if found_string.referenced == Some(true) {
score += 50; // Significant boost for code-referenced strings
}5. Update output formats
Include the flag in JSON output and consider adding a visual indicator (e.g., prefix) in human-readable output for referenced strings.
Acceptance Criteria
- struct includes field
- includes field
- ELF parser extracts relocation entries from and sections
- PE parser extracts relocation entries from section
- Mach-O parser extracts rebase/bind targets from
- Extraction pipeline cross-references string addresses with relocation targets
- Scoring algorithm boosts referenced strings significantly
- Unit tests for each relocation parser with test binaries
- Integration tests verify referenced strings are correctly flagged
- Documentation updated with examples of relocation-based ranking
Related Work
- Issue Integrate Import/Export Symbol Extraction into String Analysis Pipeline #59: Import/Export Symbol Extraction (complementary metadata source)
- Issue Extract strings from DWARF debug information (.debug_info, .debug_str, .debug_line) #62: DWARF Debug Information (alternative metadata for symbols)
- Issue Parse Mach-O Load Commands for Dynamic Library and Framework Path Extraction #63: Mach-O Load Command Strings (format-specific extraction)
Implementation Notes
- Start with ELF as it has the most straightforward relocation format
- Consider using crate's built-in relocation parsing where available
- For stripped binaries, this may be the only reliable signal about string usage
- Relocation data can be large in some binaries; consider streaming or filtering to reduce memory usage
- Not all strings will be referenced (e.g., embedded data, resources, error messages in unused paths)
Activity
traycerai commentedon Nov 10, 2025
Plan
Observations
The codebase structure supports binary parsing via goblin for ELF, PE, and Mach-O formats.
FoundStringinsrc/types.rslacks areferencedfield, andContainerInfoneedsrelocation_targets. Container parsers extract sections, imports, and exports but not relocations. Extraction and classification modules are stubs. Goblin provides relocation APIs:elf::relocfor ELF,pe::relocationfor PE,mach::relocationfor Mach-O. Tests exist but need relocation-specific cases. Documentation indocs/src/requires ranking updates.Approach
referenced: Option<bool>toFoundStringandrelocation_targets: Vec<u64>toContainerInfo.\n2. Createsrc/container/relocation.rsfor shared utilities.\n3. Implementextract_relocationsin each parser, populatingrelocation_targets.\n4. Insrc/extraction/mod.rs, addmark_referenced_stringsto flag matching strings.\n5. Insrc/classification/mod.rs, add scoring boost for referenced strings.\n6. Update JSON output insrc/output/to include the flag.\n7. Add unit/integration tests for relocation extraction and flagging.\n8. Document indocs/src/ranking.mdandstring-extraction.md.Reasoning
I examined the project directory structure to understand the codebase layout. I reviewed the core types in
src/types.rsto identify necessary extensions. I analyzed the container parsers insrc/container/(elf.rs, pe.rs, macho.rs) to see existing extraction logic. I checked the empty extraction and classification modules. I searched goblin documentation for relocation parsing capabilities across formats. This confirmed the feasibility of adding relocation-based hinting with minimal changes.Proposed File Changes
📄 src/types.rs (MODIFY) 🔗
📄 src/container/mod.rs (MODIFY) 🔗
📄 src/container/relocation.rs (NEW) 🔗
📄 src/container/elf.rs (MODIFY) 🔗
📄 src/container/pe.rs (MODIFY) 🔗
📄 src/container/macho.rs (MODIFY) 🔗
📄 src/extraction/mod.rs (MODIFY) 🔗
📄 src/classification/mod.rs (MODIFY) 🔗
📄 src/output/mod.rs (MODIFY) 🔗
📄 tests/integration_elf.rs (MODIFY) 🔗
📄 tests/integration_pe.rs (MODIFY) 🔗
📄 tests/integration_macho.rs (MODIFY) 🔗
📄 docs/src/ranking.md (MODIFY) 🔗
📄 docs/src/string-extraction.md (MODIFY) 🔗
Import In IDE
🤖 Prompt for AI Agents
Developer Humor
Execution Information
Branch: main
Commit: 37cfc7c
💡 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
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.
[-]Relocation-Based Hinting[/-][+]Add relocation-based string ranking to identify code-referenced addresses[/+]coderabbitai commentedon Nov 10, 2025
Tip
For best results, initiate chat on the files or code changes.
🧩 Analysis chain
🏁 Script executed:
Length of output: 1056
🏁 Script executed:
Length of output: 9289
🏁 Script executed:
Length of output: 7227
🏁 Script executed:
Length of output: 3531
🏁 Script executed:
Length of output: 9440
@unclesp1d3r I've successfully enhanced issue #60 with comprehensive context and technical details. Here's what was updated:
Changes Made:
✅ Title Enhanced
Before: "Relocation-Based Hinting"
After: "Add relocation-based string ranking to identify code-referenced addresses"
✅ Body Enhanced with:
.rela.dyn,.rela.plt,.rel.dyn,.rel.pltsections withgoblin::elf::reloc::Reloc.relocsection) viagoblin::pe::relocationLC_DYLD_INFOload commands with rebase/bind opcodesFoundStringwithreferenced: Option<bool>fieldrelocation_targets: Vec<u64>toContainerInfo✅ Labels Added:
enhancement- New feature requestarea:analyzer- Binary analyzer functionalitylang:rust- Rust implementationneeds:tests- Requires test coveragepriority:high- High priority taskMVP- Minimum viable product feature✅ Assigned to: @unclesp1d3r
You can view the enhanced issue here: #60
The issue now provides a complete roadmap for implementing relocation-based string ranking, which will significantly improve the signal-to-noise ratio in StringyMcStringFace's output, especially for stripped binaries where this may be the only reliable indicator of string usage.
traycerai commentedon Nov 10, 2025
I have updated the Implementation Plan to reflect the recent changes in the ticket.