tags:

views:

120

answers:

4

Given a .so file and function name, is there any simple way to find the function's signature through bash?

Return example:

@_ZN9CCSPlayer10SwitchTeamEi

Thank you.

A: 

Try

strings <library.so>
Raghuram
+5  A: 

My compiler mangles things a little different to yours (OSX g++) but changing your leading @ to an underscore and passing the result to c++filt gives me the result that I think you want:

bash> echo __ZN9CCSPlayer10SwitchTeamEi | c++filt
CCSPlayer::SwitchTeam(int)

doing the reverse is trickier as CCSPlayer could be a namespace or a class (and I suspect they're mangled differently). However since you have the .so you can do this:

bash> nm library.so | c++filt | grep CCSPlayer::SwitchTeam
000ca120 S CCSPlayer::SwitchTeam
bash> nm library.so | grep 000ca120
000ca120 S __ZN9CCSPlayer10SwitchTeamEi

Though you might need to be a bit careful about getting some extra results. ( There are some funny symbols in those .so files sometimes)

Michael Anderson
No, I want my input to be `SwitchTeam` and output `@_ZN9CCSPlayer10SwitchTeamEi`
TTT
Updated to show how you can do the reverse.
Michael Anderson
Or simply `c++filt __ZN9CCSPlayer10SwitchTeamEi`
Potatoswatter
Keep in mind that the arguments (and class , in case of a member function) are part of a C++ function signature. There might be many results for `SwitchTeam` if the function is overloaded (or inherited)
nos
A: 
nm -D library.so | grep FuncName
shodanex
A: 

nm has a useful --demangle flag that can demangle your .so all at once

nm --demangle library.so
Paul Rubel