Repository navigation
Description
Background
StringyMcStringFace aims to extract meaningful strings from binaries by being data-structure aware and prioritizing high-value strings over arbitrary byte sequences. A critical enhancement to string relevance scoring is identifying which strings are actually referenced by executable code versus those that are dead data, padding, or artifacts.
By performing disassembly of executable sections using the Capstone framework, we can:
- Distinguish active strings from dead data by identifying instruction-level references
- Improve ranking accuracy by boosting strings that are demonstrably used in the code
- Provide context about how strings are accessed (direct reference, computed offset, etc.)
- Enhance analysis value for malware analysis, reverse engineering, and YARA rule generation
Objective
Implement a Capstone disassembly pass that performs linear sweep disassembly of executable sections (.text, __TEXT,__text, etc.) to identify and flag strings that are directly referenced by machine code instructions.
Technical Approach
1. Disassembly Engine Integration
- Add capstone-rs dependency to Cargo.toml for multi-architecture disassembly support
- Support architectures: x86, x86-64, ARM, ARM64, as indicated by binary format headers
- Perform linear sweep disassembly of executable sections identified by container parsers
2. Instruction Analysis
Target instruction patterns that commonly reference string data:
- x86/x64:
lea rax, [rip+offset],mov rax, offset,push offset - ARM/ARM64:
adr,adrp,ldrwith PC-relative addressing, immediate loads - Extract effective addresses from operands (handle RIP-relative, absolute, register-indirect)
3. Cross-Referencing
- Maintain a map of extracted string offsets/RVAs from string extraction passes
- For each instruction with a data reference:
- Resolve the target address (accounting for relocations, base addresses, RIP-relative calculations)
- Check if the target address overlaps with any extracted string offset
- If match found, tag the string with
CodeReferencedor increment reference count
4. Scoring Integration
- Strings flagged as code-referenced receive a significant scoring boost in the ranking algorithm
- Potentially add metadata to
FoundString:referenced_by: Vec<u64>to track instruction addresses - Consider tracking reference frequency (multiple instructions referencing the same string)
Implementation Steps
-
Add Capstone dependency
- Add
capstone = "0.12"to Cargo.toml - Create
src/analysis/disasm.rsmodule
- Add
-
Implement DisassemblyAnalyzer
- Trait or struct to encapsulate disassembly logic
- Method:
analyze_code_sections(&self, container_info: &ContainerInfo, sections: &[SectionInfo]) -> Result<Vec<CodeReference>> - Detect architecture from container format (ELF e_machine, PE Machine, Mach-O cputype)
- Initialize Capstone engine with appropriate architecture and mode
-
Linear Sweep Disassembly
- Iterate through executable sections (identified by container parser)
- Disassemble instruction stream from section start to end
- Handle disassembly errors gracefully (skip bad instructions, continue)
-
Reference Extraction
- For each instruction, analyze operands for data references:
- Immediate values that could be addresses
- Memory operands with displacement/offset
- PC-relative references (x86-64 RIP-relative, ARM PC-relative)
- Resolve addresses accounting for section RVA/virtual address
- Emit
CodeReference { instruction_addr: u64, target_addr: u64, ref_type: ReferenceType }
- For each instruction, analyze operands for data references:
-
Integration with String Extraction
- After string extraction phase, run disassembly analysis
- Cross-reference
CodeReference.target_addrwithFoundString.offset/rva - Tag matching strings or update scoring metadata
-
Testing
- Create test binaries (ELF, PE, Mach-O) with known string references
- Verify strings referenced by
lea,mov,adrinstructions are correctly flagged - Benchmark performance impact on large binaries
- Add integration tests in
tests/integration_disasm.rs
Dependencies
- capstone-rs (v0.12+): Rust bindings for the Capstone disassembly framework
- Supports x86, x64, ARM, ARM64, and other architectures
- Provides instruction-level analysis and operand information
- Existing: goblin for binary format parsing and section identification
Success Criteria
- Capstone-rs integrated and architecture detection working for ELF, PE, Mach-O
- Linear sweep disassembly successfully processes .text sections in test binaries
- Data reference instructions (lea, mov, adr, etc.) correctly extract target addresses
- Cross-referencing identifies strings referenced by code with high accuracy
-
FoundStringmetadata enhanced with code reference information - Integration tests verify correct flagging on test binaries with known references
- Documentation explains disassembly analysis and its impact on scoring
Related Issues
- Add relocation-hinted string reference detection with Capstone disassembly #41 - Epic: Add relocation-hinted string reference detection with Capstone disassembly (broader scope)
- Add relocation-based string ranking to identify code-referenced addresses #60 - Relocation-Based Hinting (complementary approach using relocation tables)
Notes
- This is a linear sweep approach (disassemble sequentially), not recursive traversal
- False positives possible (immediate values that happen to match string offsets but aren't references)
- Consider making disassembly pass optional via CLI flag (
--disassemble) due to performance cost - For obfuscated or packed binaries, disassembly may be unreliable (acceptable limitation)
- Future enhancement: combine with relocation table analysis (Add relocation-based string ranking to identify code-referenced addresses #60) for higher confidence
Activity
traycerai commentedon Nov 10, 2025
Plan
Observations
The codebase provides complete container parsing for ELF, PE, and Mach-O formats via goblin, with robust type definitions in
types.rsincludingContainerInfo,SectionInfo, andFoundString. Theextractionmodule is currently a stub, ready for implementation. No disassembly functionality exists, and Capstone is not a dependency. Architecture detection needs to be added to parsers. The project structure supports modular addition of an analysis module for disassembly.Approach
Introduce a new
analysismodule with Capstone integration for linear sweep disassembly of executable sections. Detect architecture from binary headers, initialize Capstone accordingly, extract data references from instructions (e.g., LEA, MOV, ADR), resolve addresses to file offsets, and cross-reference with extracted strings to flag code-referenced ones. ExtendFoundStringwith reference metadata and integrate into the extraction pipeline for scoring boost. Add optional CLI flag for performance.Reasoning
I examined the project root and source directory structure, reviewed the Cargo.toml for dependencies, analyzed the types.rs for core data structures like FoundString and ContainerInfo, inspected the lib.rs for module organization, checked the extraction module which is currently a stub, and reviewed container parser files to understand section identification and parsing logic.
Proposed File Changes
📄 Cargo.toml (MODIFY) 🔗
📄 src/types.rs (MODIFY) 🔗
📄 src/container/elf.rs (MODIFY) 🔗
📄 src/container/pe.rs (MODIFY) 🔗
📄 src/container/macho.rs (MODIFY) 🔗
📄 src/lib.rs (MODIFY) 🔗
📄 src/analysis/mod.rs (NEW) 🔗
📄 src/analysis/reference_extractor.rs (NEW) 🔗
📄 src/analysis/address_resolver.rs (NEW) 🔗
📄 src/analysis/linear_sweep.rs (NEW) 🔗
📄 src/extraction/mod.rs (MODIFY) 🔗
📄 src/main.rs (MODIFY) 🔗
📄 tests/integration_disasm.rs (NEW) 🔗
📄 README.md (MODIFY) 🔗
📄 docs/src/architecture.md (MODIFY) 🔗
Diagram
sequenceDiagram participant B as Binary Data participant C as Container Parser participant E as Extraction Module participant A as Analysis Module participant S as Strings B->>C: Parse format & sections C->>C: Detect architecture C-->>E: ContainerInfo (w/ arch) E->>E: Extract raw strings from sections E-->>S: Vec<FoundString> alt Disassembly enabled E->>A: Initialize DisassemblyAnalyzer(arch) A->>A: Linear sweep executable sections A->>A: Extract & resolve references A-->>E: Vec<CodeReference> E->>E: Cross-ref & flag strings E->>E: Boost scores for referenced end E-->>User: Ranked FoundStrings w/ metadataImport 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.
[-]Capstone Disassembly Pass[/-][+]Implement Capstone Disassembly Pass to Identify Code-Referenced Strings[/+]coderabbitai commentedon Nov 10, 2025
Tip
For best results, initiate chat on the files or code changes.
🧩 Analysis chain
🏁 Script executed:
Length of output: 8022
🏁 Script executed:
Length of output: 22751
🏁 Script executed:
Length of output: 185
@unclesp1d3r I've successfully enhanced issue #61! Here's what was updated:
📝 Changes Made
Title
Before: "Capstone Disassembly Pass"
After: "Implement Capstone Disassembly Pass to Identify Code-Referenced Strings"
Issue Body
Added comprehensive sections including:
Metadata
enhancement,dependencies,lang:rust,needs:tests(retains existingarea:analyzer)The issue is now ready for implementation with clear technical guidance and success criteria! 🎯
traycerai commentedon Nov 10, 2025
I have updated the Implementation Plan to reflect the recent changes in the ticket.