Skip to content

Instantly share code, notes, and snippets.

@betamaoIS
Created July 30, 2022 06:30
Show Gist options
  • Save betamaoIS/4298e9e32106d51942a08851798e3f14 to your computer and use it in GitHub Desktop.
Save betamaoIS/4298e9e32106d51942a08851798e3f14 to your computer and use it in GitHub Desktop.
查找外部函数的定义位置
#!/usr/bin/env bash
hexdump_path=hexdump
cache_path=.symbol_cache
key_word="$1"
function process_one() {
file_path=$1
if $hexdump_path -n 4 "$file_path" | grep -i '457f 464c' &>/dev/null; then
readelf -s "$file_path" | awk "\$4 ~ /FUNC/ && \$7 ~ /[0-9]+/ {print \"$file_path:\" \$8}" >>$cache_path
fi
}
function walk_all() {
echo '' >$cache_path
files=$(find / -path /sys -prune -o -path /proc -prune -o -type f)
files=($files)
for ((i = 0; i < "${#files[@]}"; i++)); do
process_one "${files[i]}"
done
}
if [ ! -e "$cache_path" ]; then
echo "索引数据库 $cache_path 不存在,开始创建索引数据库..."
walk_all
else
echo "使用索引数据库 $cache_path ,若要重新构建数据库可直接删除该文件..."
fi
grep "$key_word" "$cache_path"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment