11

I am writing a script for the IDA Pro disassembler in Python using the idapython plugin. Using this, I am able to fill in the gaps where IDA's auto-analysis falls short.

One area that has me stumped is naming locations/functions with (for want of a better term) "pretty names". An example of what I mean is illustrated below:

IDA pretty names sample screenshot

idapython and IDA Pro itself only allow me to enter basic C-ish function names. If I enter disallowed symbols (e.g. the scope resolution operator), they're replaced with underscores. However, if I enter a mangled name by hand (e.g. __ZN9IOService15powerChangeDoneEm), IDA Pro will prettify this for me.

Hence my question: how can I generate mangled names to pass through idapython? Is there a name-mangling library available? Is one available in Python? Is my only hope to tear the mangling functionality out of g++ and work around that?

user1354557
  • 2,413
  • 19
  • 29
Aidan Steele
  • 10,999
  • 6
  • 38
  • 59

4 Answers4

6

I finally got around to dig a little.

Unfortunately I could not find tool, I did find resources though.

If all you want is mangle names in the gcc3 fashion, then know that gcc3 use the Itanium C++ ABI, which has a standardized name mangling scheme. I found two documents:

For reference, both come from the Wikipedia page on Name Mangling.

Matthieu M.
  • 287,565
  • 48
  • 449
  • 722
  • @ShafikYaghmour: Thanks, I've replaced it with a link to another website (linux-foundation.org). – Matthieu M. Jul 24 '13 at 06:10
  • I came upon your question b/c of this question: http://stackoverflow.com/questions/11335624/what-is-linux-utility-to-mangle-a-c-symbol-name?lq=1 which is similar – Shafik Yaghmour Jul 24 '13 at 09:31
3

One simple (alebit hacky) method would be to compile a C++ file with the symbol you want in it, then extract the necessary symbols from the .o file's symbol table. With a bit of work this might be nicely scriptable.

bdonlan
  • 224,562
  • 31
  • 268
  • 324
  • 1
    I did this on my first C++ program, while at high school. Didn't knew that it wasn't santard or anything else. That helped me implement a module system, allowing the soft (game) to be extended easily. I wasn't even aware that this kind of thing were not trivial. – Klaim Jan 12 '11 at 12:31
1

Here is an article that explains how mangling is done by Visual compiler. For mangling done by gcc, I think you can find the information in the source of the binutils package.

Sylvain Defresne
  • 42,429
  • 12
  • 75
  • 85
0

You can use the Clang AST library, which has a MangleContext class.

http://clang.llvm.org/doxygen/classclang_1_1CodeGen_1_1MangleContext.html

João Matos
  • 1,515
  • 2
  • 11
  • 11