Giter Club home page Giter Club logo

py-cpp-demangle's Introduction

py-cpp-demangle: Demangles C++ linker symbols

image

A package for demangling C++ linker symbol strings

This package provides python bindings for the rust crate cpp_demangle by building a native Python extension using PyO3.

This is mainly an experiment in creating python extensions in Rust. A blog post about this is here.

Usage

To install

pip install cpp-demangle

Building from source requires the nightly version of the rust compiler.

This module exposes a single function that transforms C++ linker symbols to a human readable representation.

from cpp_demangle import demangle

print(demangle('_ZN7mangled3fooEd'))
# prints 'mangled::foo(double)'

Released under the MIT License

py-cpp-demangle's People

Contributors

benfred avatar sach-edna avatar vlaci avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

py-cpp-demangle's Issues

cp37 binary wheel missing for Windows

Hi Ben,

Thanks for the great tool! Simple cross-platform demangling from python without dependencies.
We would like to use this package, but as can be seen on the files list in PyPi, there are no Windows C-python 3.7 wheels available.

I think this is due to the version of cibuildwheel that is used in appveyor.yml. Since version 0.9.3 it has support for python 3.7 on Windows.

Unexpected error on malformed mangled names

Background Info

We've recently come across a binary with what appears to be a malformed symbol name that would trigger the following exception:

thread '<unnamed>' panicked at 'a Display implementation returned an error unexpectedly: Error', /rustc/897e37553bba8b42751c67658967889d11ecd120/library/alloc/src/string.rs:2511:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
pyo3_runtime.PanicException: a Display implementation returned an error unexpectedly: Error

Reproduction

You can reproduce it with the Python lines below:

from cpp_demangle import demangle

demangle('_ZSt11make_sharedI16group_record_msgIRjR22mcast_addr_record_typeR12addr_storageSt3setI6sourceSt4lessIS7_ESaIS7_EE18group_mem_protocolEESt10shared_ptrIT_EDpOT0_')

This symbol name is really close to the other one, but this time it works:

from cpp_demangle import demangle

demangle('_ZSt11make_sharedI16group_record_msgJRjR22mcast_addr_record_typeR12addr_storageSt3setI6sourceSt4lessIS7_ESaIS7_EE18group_mem_protocolEESt10shared_ptrIT_EDpOT0_')

The only difference is the character at index 38 (a J in the valid one, a I in the invalid one, which looks like a bit flip. I'm currently investigating to see if it's the ELF parser or the file that got flipped.

Recommendation

Would it be possible to raise a ValueError instead of the PanicException on such cases ?

Value error triggered on functions that don't need to be demangled.

So this code

exceptions::PyValueError::new_err(("Could not demangle symbol", error.to_string()))

Is throwing a value error on these function names:
'_main', 'ctor_0', 'ctor_1', 'ctor_2', 'ctor_3', 'ctor_4', 'ctor_5', 'ctor_6', 'ctor_7', 'ctor_8', 'ctor_9', 'ctor_10', 'ctor_11', 'ctor_12', 'ctor_13', 'ctor_14', 'ctor_15', 'ctor_16', 'ctor_17', 'ctor_18', 'ctor_19', 'ctor_20', 'ctor_21', 'ctor_22', 'ctor_23', 'ctor_24', 'ctor_25', 'ctor_26'
I'm not entirely sure why c++ constructors are getting numbered like this.
This is my work around:

functionName = f.name
try:
    functionName = demangle(f.name)
except ValueError:
    allFailedFunctionNames.append(f.name)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.