LoginSignup
3
4

More than 5 years have passed since last update.

オブジェクトのシンボル探し用シェルスクリプト

Posted at

find、nm、grepを使ってシンボル探し。

find_function.sh
#!/bin/bash

target_dir=/lib/modules/`uname -r`/
target_type="ko"
func_name=""

function usage()
{
    echo "usage: $1 -d [directory] -t [objecdt type(e.g. so, ko)] -f [function name]"
    exit -1
}

while getopts d:t:f: option
do
    case $option in
        d)
            target_dir=$OPTARG
            ;;
        t)
            target_type=$OPTARG
            ;;
        f)
            func_name=$OPTARG
            ;;
        \?)
            usage $0
            ;;
    esac
done

if [ "$func_name" = "" ]; then
    usage $0
fi

echo "[-]Directory: $target_dir"
echo "[-]File type: $target_type"
echo "[-]Function : $func_name"

files=`find -L "$target_dir" -name "*.$target_type"`
for f in $files
do
    nm --defined-only $f 2>&1 | grep "$func_name"  > /dev/null 
    if [ $? -eq 0 ]; then
        echo $f
    fi
done

exit 0

.koから探す。

[-]Directory: /lib/modules/3.13.0-rc4-ktest/
[-]File type: ko
[-]Function : ext4_xattr_get
/lib/modules/3.13.0-rc4-ktest/build/fs/ext4/ext4.ko
/lib/modules/3.13.0-rc4-ktest/kernel/fs/ext4/ext4.ko
/lib/modules/3.13.0-rc4-ktest/source/fs/ext4/ext4.ko

.oから探す。

masami@saga:~$ find_function.sh -d ~/linux-kernel/fs -t o -f ext4_xattr_get
[-]Directory: /home/masami/linux-kernel/fs
[-]File type: o
[-]Function : ext4_xattr_get
/home/masami/linux-kernel/fs/ext4/acl.o
/home/masami/linux-kernel/fs/ext4/xattr.o
/home/masami/linux-kernel/fs/ext4/ext4.o

.soから探す。

masami@saga:~$ find_function.sh -d /lib -t so -f printf
[-]Directory: /lib
[-]File type: so
[-]Function : printf
/lib/perl5/core_perl/auto/Devel/PPPort/PPPort.so
/lib/perl5/core_perl/CORE/libperl.so
/lib/libpython2.7.so
/lib/python3.3/config-3.3m/libpython3.3m.so
/lib/libpython3.3m.so
/lib/libc-2.18.so
/lib/libasprintf.so
/lib/libdevmapper.so
/lib/python2.7/config/libpython2.7.so
/lib/libcrypto.so
/lib/ld-2.18.so
/lib/libnss3.so
3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4