tags:

views:

129

answers:

4

I don't have the source code but have the binary. With command "nm binary_name" I could know the functions inside the binary.

Can I know how many parameters a function has? Under solaris, is there anyway to do that?

e.g, if the function is: func1(a int,b int,c int), then there are 3 parameters.

Thanks Daniel

+1  A: 

Assuming this is C code, then no there is not - the compiler/linker elides that information. If it is C++ code, it is just possible that the mangled name of the function is retained and includes the parameters in encoded form.

anon
+3  A: 

No. Neil Butterworth's suggestion to examine the function signature is a good one for C++ (since the parameters are often encoded into the function so the linker can tell the difference between "int x(int)" and "int x(float)" for example) but, for C, you're going to have to get your hands dirty and disassemble the function, taking particular note of how the stack frames are built and used in your environment.

Keep in mind that SPARC has a rotating window stack rather than regular grow-down stack. You're really going to delve deep into the way the CPU works. If you're talking Solaris for Intel, the rotating stack is not there, of course.

paxdiablo
A: 

At the lowest level, if you emulate the function running on the machine, then it will read some information either from registers or the stack which it has not written. If you compare these reads to the ABI of the platform ( You don't say whether it's Sparc Solaris or Intel Solaris ) then some of them should correspond to the registers/stack locations of the parameters of the function. Of course, there's no guarantee that a function will read all its parameters.

For Solaris, elfdump might give more information than nm ( a quick google for elfdump signature indicates support was requested and added, but you'd need to check what version you've got )

Pete Kirkham
Thanks Pete,To be complete, if we can run the binary, then pstack the running process could show the number of parameters of a function and also show the value of these parameters.
Daniel
A: 

IDA Pro (http://www.hex-rays.com/idapro/) is a disassembler which is pretty clever at infering parameters of a function from object code; maybe there is also symbolic information you can use; eg. on Win32 the symbol _function@8 reveals that 8 bytes (2 parameters) are passed one can also demangle C++ names to get the parameters and types

pmeerw