Repository navigation
Open
Labels
architecture:x86-64x86-64 architecture specific featuresx86-64 architecture specific featuresarea:analyzerBinary analyzer functionalityBinary analyzer functionalityenhancementNew feature or requestNew feature or requestlang:rustRust implementationRust implementationneeds:testsNeeds test coverageNeeds test coveragepriority:mediumMedium priority taskMedium priority taskstatus:backlogTask in backlogTask in backlog
Description
Overview
In x86-64 position-independent code (PIC), string literals and other data are typically referenced using RIP-relative addressing — an addressing mode that encodes memory references as offsets from the instruction pointer rather than absolute addresses. Detecting these references would allow Stringy to:
- Boost scoring for strings that are actively referenced by code
- Filter dead strings that exist in data sections but are never used
- Improve accuracy by distinguishing meaningful strings from padding or artifact data
- Provide provenance information about which code references which strings
Background: RIP-relative Addressing
RIP-relative addressing is the primary addressing mode for accessing data in x86-64 PIC:
- Format:
[RIP + disp32]wheredisp32is a signed 32-bit displacement - Range: Can reference data within ±2GB of the instruction
- Encoding: Appears as displacement-only memory operands (e.g.,
movq symbol(%rip), %rax) - Common instructions:
lea,mov,cmp, and other instructions with memory operands - Benefits: No runtime relocations needed, enables true position-independent code
Example disassembly:
lea 0x2000(%rip), %rdi # Load address of string at RIP+0x2000
mov 0x1ff0(%rip), %rax # Load value from RIP+0x1ff0Proposed Solution
Phase 1: Instruction Scanning (Lightweight)
Add lightweight x86-64 instruction parsing to detect RIP-relative memory references without full disassembly:
- Scan code sections (SectionType::Code) for x86-64 instructions
- Pattern match common RIP-relative encodings:
- ModR/M byte with mod=00, r/m=101 (RIP-relative displacement)
- Common opcodes:
8D(LEA),8B(MOV),48 8B(MOV r64), etc.
- Extract displacement and compute target address:
instruction_addr + instruction_length + disp32 - Map targets to string offsets in data sections
- Increment reference counts for referenced strings
Phase 2: Enhanced Scoring (Integration)
Integrate reference tracking into the existing scoring system:
pub struct ExtractedString {
pub text: String,
pub offset: u64,
pub rva: Option<u64>,
pub section: String,
pub encoding: Encoding,
pub length: usize,
pub tags: Vec<Tag>,
pub score: i32,
pub source: StringSource,
// NEW: Reference tracking
pub reference_count: u32, // Number of code references
pub referencing_addresses: Vec<u64>, // RVAs of referencing instructions
}Scoring adjustments:
- +20 points: String has 1+ code references
- +10 points: String has 3+ code references (highly used)
- -10 points: String in writable section with 0 references (likely runtime buffer)
Phase 3: Optional Full Disassembly (Future)
For advanced use cases, integrate Capstone disassembler as optional feature:
[dependencies]
capstone = { version = "0.12", optional = true }
[features]
disassembly = ["capstone"]Benefits:
- More accurate instruction parsing (handles edge cases, prefixes, etc.)
- Support for other architectures (ARM64, RISC-V)
- Detailed instruction analysis for forensics
Implementation Checklist
- Add x86-64 instruction pattern matching module
- Implement RIP-relative displacement extraction
- Add reference tracking fields to
ExtractedString - Integrate reference counting into scoring algorithm
- Add unit tests with fixture binaries containing RIP-relative references
- Document architecture-specific features in user guide
- (Optional) Add Capstone integration behind feature flag
Related Context
- Mentioned in
docs/src/binary-formats.mdunder "Architecture-Specific Enhancements" - Complements existing section weight system (prioritizes likely string sections)
- Similar to how resource extraction boosts PE string scores
- Cross-references with import/export analysis (symbols are also code references)
Example Use Cases
- Malware Analysis: Identify which strings are used by unpacking/decryption routines
- YARA Rule Generation: Focus on strings that are definitely code-referenced
- Firmware Analysis: Filter out unused strings in embedded binaries
- Binary Diffing: Track which code references changed between versions
Technical Notes
- ELF PIC: Nearly all data references use RIP-relative addressing
- PE x64: Uses RIP-relative for PIC, but also absolute addresses in non-relocatable executables
- Mach-O x64: Similar to ELF, heavy use of RIP-relative in position-independent code
- Static linking: May contain more unused strings than dynamic executables
- Stripped binaries: Reference tracking works even without symbol tables
Alternatives Considered
- Symbol-based: Only track symbol references (not sufficient, misses many string literals)
- Relocation analysis: Parse relocation tables (misses PIC references, platform-specific)
- Full control-flow analysis: Too heavyweight for string extraction use case
Metadata
Metadata
Assignees
Labels
architecture:x86-64x86-64 architecture specific featuresx86-64 architecture specific featuresarea:analyzerBinary analyzer functionalityBinary analyzer functionalityenhancementNew feature or requestNew feature or requestlang:rustRust implementationRust implementationneeds:testsNeeds test coverageNeeds test coveragepriority:mediumMedium priority taskMedium priority taskstatus:backlogTask in backlogTask in backlog
Activity
traycerai commentedon Nov 11, 2025
Plan
Observations
The codebase features a modular Rust library with defined types for binary analysis, including
FoundString(lacking reference fields),ContainerInfowith section metadata (offsets, sizes, RVAs, types), and parsers for ELF, PE, Mach-O using goblin/pelite. Extraction is partially implemented (PE resources), classification and ranking modules exist but are stubs. No analysis module present. Section classification includesSectionType::Codefor .text sections. This setup is ideal for adding lightweight x86-64 RIP-relative reference detection to enhance string scoring without full disassembly.Approach
Introduce an
analysismodule for code reference detection, focusing on x86-64 RIP-relative addressing via pattern matching in code sections. ExtendFoundStringwithreference_countandreferencing_addressesfields. Implement scanning logic to compute target addresses from instruction patterns, match against string RVAs, and update counts/addresses. Integrate scoring boosts: +20 for referenced strings, +10 for highly referenced (>3), -10 for unreferenced writable data strings. Add unit tests for pattern detection and integration tests using ELF fixtures. Document in architecture and extraction guides, with optional Capstone future support.Reasoning
I listed the project directories to map the structure, read
src/types.rsto reviewFoundStringand section types, examinedsrc/container/mod.rsfor parsing API, checkedsrc/extraction/mod.rsfor current extraction state, and confirmed documentation and test presence indocs/src/andtests/to ensure integration points.Proposed File Changes
📄 src/types.rs (MODIFY) 🔗
📄 src/lib.rs (MODIFY) 🔗
📄 src/analysis/mod.rs (NEW) 🔗
📄 src/analysis/rip_relative.rs (NEW) 🔗
📄 tests/integration_elf.rs (MODIFY) 🔗
📄 docs/src/architecture.md (MODIFY) 🔗
📄 docs/src/string-extraction.md (MODIFY) 🔗
Import In IDE
🤖 Prompt for AI Agents
Developer Humor
Execution Information
Branch: main
Commit: 08cd31b
💡 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 11, 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.
[-]x86-64: RIP-relative addressing hints[/-][+]Add x86-64 RIP-relative addressing analysis for string reference tracking[/+]coderabbitai commentedon Nov 11, 2025
Tip
For best results, initiate chat on the files or code changes.
🧩 Analysis chain
🏁 Script executed:
Length of output: 113
🏁 Script executed:
Length of output: 20679
🏁 Script executed:
Length of output: 20678
🌐 Web query:
💡 Result:
Brief summary — x86-64 RIP-relative addressing and how it enables PIC
What it is: a 64-bit-mode addressing form that computes an effective address as RIP (the address of the next instruction) plus a signed 32-bit displacement (rel32). It is encoded as a displacement-only memory operand that is implicitly RIP-relative. [1][2]
Encoding/limits: displacement is 32 bits (signed), so targets must lie within roughly ±2GB of the instruction. RIP-relative is available for memory operands (e.g., lea/mov); control-flow instructions (call/jmp/rel-jcc) already use their own relative encodings. [1][2]
Why it helps PIC: data references encoded as RIP+disp do not contain absolute addresses, so the same code bytes are valid no matter where the module is loaded — the loader needs far fewer runtime relocations and the code can be position independent (or easier to make so). Compilers/assemblers emit syntax like movq symbol(%rip), %rax. [2][3]
Practical notes: you cannot use other registers with the RIP term (e.g., [RIP+RAX] is not supported); for references farther than ±2GB you still need GOT/PLT or runtime fixups. [1][3]
Sources: Intel architecture description of RIP-relative addressing; tutorial/notes on x64 PIC and examples. [1][2][3]
🏁 Script executed:
Length of output: 7013
🏁 Script executed:
Length of output: 5449
🏁 Script executed:
Length of output: 7647
@unclesp1d3r, I've successfully enhanced issue #74 with comprehensive context and metadata. Here's what was updated:
✅ Enhancements Made
Title (improved for clarity)
x86-64: RIP-relative addressing hintsAdd x86-64 RIP-relative addressing analysis for string reference trackingBody (added comprehensive content)
The issue now includes:
Labels (added 4 labels)
enhancement- Feature request classificationarea:analyzer- Relates to binary analysis functionalitypriority:medium- Appropriate priority levelarchitecture:x86-64- New label created for architecture-specific featuresAssignee
unclesp1d3r🔗 View the Enhanced Issue
URL: #74
The issue is now ready for implementation with clear technical guidance, a phased approach, and proper categorization. The RIP-relative addressing feature will significantly improve string scoring by identifying which strings are actively referenced by code, helping distinguish meaningful strings from dead data.
traycerai commentedon Nov 11, 2025
I have updated the Implementation Plan to reflect the recent changes in the ticket.