反汇编及连接工具

 

######################################################################
#
# this is a disassembly tool,convenient to debug
#
# input Params:
#       $1: filename    :*.dll that you want disassembly module
#       $2: address     :entrypoint address that *.efi entry point address of low 32 bit,if 64 bit will error
#       $3: gcc version :our platform support gcc44 or gcc49

# output file:
#       a:filename.asm     :asm file that original deal with *.dll file
#       b:filename.asm.ld :asm file that link entry point address
#
# note:
#     if the module type is Sec the entry point address is 9fc11094
#     if the module type is't Sec please find this module(*.efi) entry point address that low 32 bit address as $2 params.
#
# sample:
#       ./DebugTool SecMain.dll 9fc11094 gcc44
#       ./DebugTool BootparamsDxe.dll 0E647240 gcc49
#
#######################################################################


!/bin/sh

BINFILE=$1.bin
ASMFILE=$1.asm

if  [[ ! -f `find ./ -name $ASMFILE` || ! -f `find ./ -name $ASMFILE.ld` ]];then
echo
else
echo $ASMFILE.ld already exiting will rm it.
  rm -rf $ASMFILE
  rm -rf $ASMFILE.ld
fi

if [ "$3" == "gcc44" ]; then
/opt/gcc-4.4.0-pmon/bin/mipsel-linux-objcopy -O binary $1 $BINFILE
/opt/gcc-4.4.0-pmon/bin/mipsel-linux-objdump -D -b binary -m mips $BINFILE > $ASMFILE
elif [ "$3" == "gcc49" ]; then
/opt/cross-gcc-4.9.3-n64-loongson-rc6.1/usr/bin/mips64el-loongson-linux-objcopy -O binary $1 $BINFILE
/opt/cross-gcc-4.9.3-n64-loongson-rc6.1/usr/bin/mips64el-loongson-linux-objdump -D -b binary -m mips $BINFILE > $ASMFILE
fi

cat $ASMFILE | while read LINE
do
  if [[ `echo $LINE |grep ':' |wc -l` -ne 0 && `echo $LINE |grep '<.data>:' |wc -l` -le 0 ]];
  then
    a=`echo ${LINE}|cut -d ':' -f1`
    if [[ $a == *[0-9]* ]]; then
    let b=0x$a
    let plus=0x$2
    ((c=$b+$plus))
    d=`echo "obase=16;$c"|bc`
    e=`tr '[A-Z]' '[a-z]' <<<"$d"`
    mm=`echo ${LINE}|cut -d ':' -f2`
    new="${e}:${mm}"
    echo $new >> $ASMFILE.ld
  fi
  else
    echo $LINE >> $ASMFILE.ld
  fi
done

rm -rf $BINFILE

exit $?

 

©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页