find function symbol from .a and .so in a directory

I have posted a method to find class symbol from a directory in the previous article. Today i got a question in finding function sysbol. So the fellow script code was created to solve the question.

#!/bin/bash

dotMaxCnt=200
function processLine()
{
	if (( $dotCnt < $dotMaxCnt ));then
		echo -n .
		((dotCnt++))
	else
		cleanLine
	fi
}
function cleanLine()
{
	for((i=0; i<$dotMaxCnt;i++));do
		echo -ne "\b\b\b"
	done
	for((i=0; i<$dotMaxCnt;i++));do
		echo -ne " "
	done
	for((i=0; i<$dotMaxCnt;i++));do
		echo -ne "\b\b\b"
	done

	dotCnt=0

}

function doDir()
{
	findLen=${#2}
	for file in "$1"/*
	do
		if [ -f "$file" ]
		then
			if [[ "$file" =~ .+\.a$ || "$file" =~ .+\.(so)$  ]]
			then
				stringsOutput=( $(strings -n $findLen "$file" | grep $2 ) )
				firstFind=0
				dotCnt=0
				for stringsLine in "${stringsOutput[@]}"
				do
					grepOutput=$(echo $stringsLine | grep $2) 
					if [[ ${grepOutput} != "" ]]
					then

						if [[ $firstFind == 0 ]]
						then
							cleanLine
							echo $file $oFile
							firstFind=1
						fi

						cleanLine
						echo "    ---->" "$grepOutput"

					else
						processLine
					fi
				done
			fi

		elif [ -d "$file" ]
		then
#if "$file" != "." and "$file" != ".."
#			then
				doDir $file $2
#			fi

		fi
	done
}

doDir $1 $2

  

posted @ 2024-03-14 15:44  huorexiaji  阅读(37)  评论(0)    收藏  举报