Rust Demangler
A package for demangling Rust symbols, written in Python. It provides a simple interface to convert Rust's compiler-generated symbol names into human-readable forms. The current version is 1.0, last updated in April 2021, suggesting a low release cadence.
Common errors
-
ModuleNotFoundError: No module named 'rust_demangler'
cause The `rust-demangler` package is not installed in the current Python environment.fixRun `pip install rust-demangler` to install the library. -
AttributeError: module 'rust_demangler' has no attribute 'demangle'
cause The `demangle` function is imported incorrectly. It is available directly from the `rust_demangler` package, not as an attribute of a submodule or the package itself when imported as `import rust_demangler`.fixChange your import statement to `from rust_demangler import demangle`. -
Mangled symbol not correctly demangled (output is still mangled or partially demangled).
cause The input symbol uses a Rust mangling scheme (e.g., a very new 'v0' variant) that the `rust-demangler` library's current version (1.0, last updated 2021) does not fully support.fixVerify that the `rust-demangler` library is the most up-to-date available. If the issue persists with modern Rust binaries, consider that the library might not support the latest mangling standards due to its last update date. Alternative tools like `rustfilt` (a Rust CLI tool) may offer more up-to-date demangling capabilities.
Warnings
- gotcha Rust's symbol mangling scheme has evolved (e.g., from legacy to v0). This Python wrapper was last updated in April 2021, and might not fully support all newer mangling formats or edge cases introduced or stabilized in Rust since then, potentially leading to incorrect or incomplete demangling for recent binaries.
- gotcha Users might encounter incomplete demangling for symbols specifically from certain target architectures (e.g., i686-pc-windows-msvc) on stable Rust versions. This can be due to platform-specific symbol prefixes or conventions that the demangler might not fully handle.
- gotcha The Python `rust-demangler` library has not been updated since April 2021. While the underlying Rust `rustc-demangle` crate is actively maintained by the Rust project, this Python binding may lag behind, potentially missing updates for new Rust symbol mangling formats, performance improvements, or bug fixes from the Rust side.
Install
-
pip install rust-demangler
Imports
- demangle
import rust_demangler.demangle
from rust_demangler import demangle
Quickstart
from rust_demangler import demangle
mangled_name_v0 = '_ZN3foo3barE'
mangled_name_legacy = '_ZN4core3fmt9Arguments9new_const17hf7eafdf6c5e03508E'
demangled_v0 = demangle(mangled_name_v0)
demangled_legacy = demangle(mangled_name_legacy)
print(f"Original mangled (v0): {mangled_name_v0} -> Demangled: {demangled_v0}")
print(f"Original mangled (legacy): {mangled_name_legacy} -> Demangled: {demangled_legacy}")
# Example of expected output for '_ZN3foo3barE' is 'foo::bar'