开发者

Find function call in a list of binaries

I have a List of executables which may call a certain function. I need to find out which all execs call that function. I know I can do "strings -a " but is there some other better way to find that 开发者_运维知识库out. Full code is written in C.


You can use the nm utility in conjuction with grep to find which executables reference the symbol, like so:

nm name_of_executable | grep symbol

So, for example, if I had a list of executables that might use "strcat", I could check for that using:

for file in exectuble1 executable2 ... executableN; do
    references_to_strcat=`nm "$file" | grep strcat -c`
    if [ $references_to_strcat -ne 0 ] ; then
       echo "$file"
    fi
done

The little loop above (assuming BASH) would print out the list of all files referencing "strcat". Note that this will only tell you which executable actually linked against the symbol... there is no way that I know of to determine which executables may reference the function using dynamic loading (e.g. dlopen/dlsym/dlcose).

Note that if you have the source code, and not just the executables, you can use Doxygen to generate a complete call graph (in addition to documentation) for your source code, so that is another possibility.


strace and ltrace might be usefull also.


As a variation on Michael Aaron Safyan's answer, you can use objdump -d to generate an assembler listing of the file. You can then grep -wn to determine the line numbers in your assembly listing where the desired function call occurs. Once you have the line numbers, you can view your listing and determine the function/routine in which they are called/used, and how they are used (called, branched to, pushed onto the stack, ...).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜