SOAdvancedDissector/SOAdvancedDissector.sh
2021-05-08 18:57:54 +02:00

76 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
function check_tool()
{
tool=$1
cmd=$2
a=`${cmd} 2>/dev/null`
if [ ! $? -eq 0 ] ; then
echo "${tool} is missing"
exit 1
fi
}
function check_tools()
{
check_tool "readelf" "readelf --version"
check_tool "objdump" "objdump --version"
check_tool "c++filt" "c++filt --version"
if [ ! -e ./vtable-dumper ] ; then
check_tool "git" "git --version"
check_tool "make" "make --version"
check_tool "g++" "g++ --version"
fi
}
TARGET=$1
target=`basename ${TARGET}`
readelf_target="${target}.readelf"
sections_target="${target}.sections"
vtable_target="${target}.vtable"
if [ ! -f "${TARGET}" ] ; then
echo "$0 <target>"
exit 1
fi
check_tools
if [ ${TARGET} -nt ${readelf_target} ] ; then
echo "Regenerating ${readelf_target}"
readelf -sW ${TARGET}|c++filt > ${readelf_target}
fi
if [ ${TARGET} -nt ${sections_target} ] ; then
echo "Regenerating ${sections_target}"
readelf --sections ${TARGET}|c++filt > ${sections_target}
fi
VTABLE_ARG="-V ${vtable_target}"
if [ ${TARGET} -nt ${vtable_target} ] ; then
echo objdump -d ${TARGET}
objdump -d ${TARGET} >/dev/null 2>&1
if [ ! $? -eq 0 ]; then
echo "Unable to do objdump, maybe ${TARGET} is for another platform"
VTABLE_ARG=""
else
if [ ! -e ./vtable-dumper/vtable-dumper ] ; then
git clone https://github.com/soutade/vtable-dumper.git || exit 1
cd ./vtable-dumper
make
cd -
fi
if [ -x ./vtable-dumper/vtable-dumper ] ; then
echo "Regenerating ${vtable_target}"
./vtable-dumper/vtable-dumper -demangled ${TARGET}|c++filt > ${vtable_target}
else
echo "./vtable-dumper not available"
VTABLE_ARG=""
fi
fi
fi
./SOAdvancedDissector.py -f ${TARGET} -S ${readelf_target} -s ${sections_target} ${VTABLE_ARG} -c