Context
The README mentions Rust symbol demangling as a feature, but the integration is not yet implemented. The project needs to add rustc-demangle as a dependency and integrate it into the existing symbol processing pipeline.
Current State
- ✅ Import/export extraction implemented across all formats (ELF, PE, Mach-O)
- ✅
ImportInfo and ExportInfo structures in src/types.rs
- ✅ Container parsers in
src/container/ (elf.rs, pe.rs, macho.rs)
- ❌
rustc-demangle not in Cargo.toml
- ❌ No demangling logic in symbol processing
- ❌ No
RustSymbol tag in Tag enum
Rust Mangling Schemes
Rust uses two mangling schemes that need to be detected and demangled:
-
Legacy mangling: Symbols start with _ZN (Itanium-style)
- Example:
_ZN4core3fmt3num52_$LT$impl$...
- Same prefix as C++ mangling, but distinct format
-
v0 mangling: Symbols start with _R (Rust-specific)
- Example:
_RNvC6mycratefunction
- Introduced in Rust 1.59+, more compact and efficient
The rustc-demangle crate handles both schemes automatically.
Proposed Solution
1. Add Dependency
Add to Cargo.toml:
[dependencies]
rustc-demangle = "0.1"
2. Extend Tag Enum
Add to src/types.rs in the Tag enum:
#[serde(rename = "rust-symbol")]
RustSymbol,
3. Create Demangler Module
Create src/demangler.rs or add to existing classification:
- Function
detect_rust_symbol(name: &str) -> bool
- Check for
_ZN or _R prefix
- Function
demangle_rust_symbol(name: &str) -> Option<String>
- Use
rustc_demangle::try_demangle()
- Return demangled string or None on failure
4. Integrate into Container Parsers
Modify symbol extraction in:
src/container/elf.rs: extract_imports() and extract_exports()
src/container/pe.rs: extract_imports() and extract_exports()
src/container/macho.rs: extract_imports() and extract_exports()
When processing symbols:
- Detect if symbol is Rust-mangled
- Store original mangled name
- Attempt demangling
- If successful, store demangled version as primary name
- Add
RustSymbol tag to classification
5. Update ImportInfo/ExportInfo
Consider extending structures in src/types.rs:
pub struct ImportInfo {
pub name: String, // Demangled name (if applicable)
pub mangled_name: Option<String>, // Original mangled name
pub library: Option<String>,
pub address: Option<u64>,
}
Or maintain backward compatibility by storing demangled name in name field and preserving mangled name in comments/logs.
6. Scoring Integration
In the string ranking/scoring system:
- Demangled Rust symbols should score higher than mangled symbols
- Human-readable function names (e.g.,
core::fmt::Display::fmt) are more useful than mangled versions
- Consider boost multiplier for demangled symbols
7. Output Format
JSON output should include both versions when demangling succeeds:
{
"name": "core::fmt::Display::fmt",
"mangled_name": "_ZN4core3fmt7Display3fmt17h...",
"tags": ["import", "rust-symbol"]
}
Implementation Notes
- Graceful failure: If demangling fails, use original mangled name
- Performance:
rustc-demangle is fast; minimal overhead
- Testing: Use real Rust binaries (from
cargo build) in integration tests
- Cross-platform: Works on all platforms (ELF, PE, Mach-O can all contain Rust symbols)
Integration Points
Primary Files to Modify
Cargo.toml - Add rustc-demangle dependency
src/types.rs - Add RustSymbol tag, optionally extend ImportInfo/ExportInfo
src/container/elf.rs - Lines 85-146 (import/export extraction)
src/container/pe.rs - Lines 88-120 (import/export extraction)
src/container/macho.rs - Lines 112-195 (import/export extraction)
src/classification/mod.rs or new src/demangler.rs - Demangling logic
Testing
Create tests/integration_rust_demangle.rs:
- Test legacy
_ZN demangling
- Test v0
_R demangling
- Test non-Rust symbols (should pass through unchanged)
- Test malformed symbols (graceful failure)
- Test real Rust binary (e.g., cargo-built executable)
Acceptance Criteria
Example Output
Before (current):
_ZN4core3fmt3num52_$LT$impl$u20$core..fmt..Display$u20$for$u20$i32$GT$3fmt17h1234567890abcdef
After (with demangling):
<core::fmt::num::<impl core::fmt::Display for i32>::fmt>
(mangled: _ZN4core3fmt3num52_$LT$impl$u20$core..fmt..Display$u20$for$u20$i32$GT$3fmt17h1234567890abcdef)
[tags: rust-symbol, import]
References
Related Work
This feature builds on the existing symbol extraction infrastructure and complements:
Context
The README mentions Rust symbol demangling as a feature, but the integration is not yet implemented. The project needs to add
rustc-demangleas a dependency and integrate it into the existing symbol processing pipeline.Current State
ImportInfoandExportInfostructures insrc/types.rssrc/container/(elf.rs, pe.rs, macho.rs)rustc-demanglenot inCargo.tomlRustSymboltag inTagenumRust Mangling Schemes
Rust uses two mangling schemes that need to be detected and demangled:
Legacy mangling: Symbols start with
_ZN(Itanium-style)_ZN4core3fmt3num52_$LT$impl$...v0 mangling: Symbols start with
_R(Rust-specific)_RNvC6mycratefunctionThe
rustc-demanglecrate handles both schemes automatically.Proposed Solution
1. Add Dependency
Add to
Cargo.toml:2. Extend Tag Enum
Add to
src/types.rsin theTagenum:3. Create Demangler Module
Create
src/demangler.rsor add to existing classification:detect_rust_symbol(name: &str) -> bool_ZNor_Rprefixdemangle_rust_symbol(name: &str) -> Option<String>rustc_demangle::try_demangle()4. Integrate into Container Parsers
Modify symbol extraction in:
src/container/elf.rs:extract_imports()andextract_exports()src/container/pe.rs:extract_imports()andextract_exports()src/container/macho.rs:extract_imports()andextract_exports()When processing symbols:
RustSymboltag to classification5. Update ImportInfo/ExportInfo
Consider extending structures in
src/types.rs:Or maintain backward compatibility by storing demangled name in
namefield and preserving mangled name in comments/logs.6. Scoring Integration
In the string ranking/scoring system:
core::fmt::Display::fmt) are more useful than mangled versions7. Output Format
JSON output should include both versions when demangling succeeds:
{ "name": "core::fmt::Display::fmt", "mangled_name": "_ZN4core3fmt7Display3fmt17h...", "tags": ["import", "rust-symbol"] }Implementation Notes
rustc-demangleis fast; minimal overheadcargo build) in integration testsIntegration Points
Primary Files to Modify
Cargo.toml- Add rustc-demangle dependencysrc/types.rs- Add RustSymbol tag, optionally extend ImportInfo/ExportInfosrc/container/elf.rs- Lines 85-146 (import/export extraction)src/container/pe.rs- Lines 88-120 (import/export extraction)src/container/macho.rs- Lines 112-195 (import/export extraction)src/classification/mod.rsor newsrc/demangler.rs- Demangling logicTesting
Create
tests/integration_rust_demangle.rs:_ZNdemangling_RdemanglingAcceptance Criteria
rustc-demangleadded toCargo.tomlRustSymboltag added toTagenum insrc/types.rs_ZNor_Rprefix)rustc_demangle::try_demangle()Example Output
Before (current):
After (with demangling):
References
rustc-demanglecrate: https://crates.io/crates/rustc-demangleRelated Work
This feature builds on the existing symbol extraction infrastructure and complements: