Disassemble binary.

vital.fadeev vital.fadeev at gmail.com
Tue May 8 11:55:35 UTC 2018


Just share.
Script for disassemble binary.
And script for bash completion. Complete symbol names.


Files:
./dasm
/etc/bash_completion.d/dasm


file <./dasm>

#!/bin/bash
# Author: abu, vital
# Description: puts disassembled objectfile to std-out

if [ $# = 2 ]; then
         sstrg="^[[:xdigit:]]{2,}+.*<$2>:$"
         objdump -d $1 | awk -F"\n" -v RS="\n\n" '$1 ~ /'$2'/'
elif [ $# = 1 ]; then
         objdump -d $1 | awk -F"\n" -v RS="\n\n" '{ print $1 }'
else
     echo "You have to add argument(s)"
     echo "Usage:   "$0 " arg1 arg2"
     echo "Description: print disassembled label to std-out"
     echo "             arg1: name of object file"
     echo "             arg2: name of function to be disassembled"
     echo "         "$0 " arg1    ... print labels and their rel. 
addresses"
fi


file </etc/bash_completion.d/dasm>

# bash completion for dasm
_dasm()
{
     local cur=${COMP_WORDS[COMP_CWORD]}

     if [[ $COMP_CWORD -eq 1 ]] ; then
	# files
	COMPREPLY=( $( command ls *.o -F 2>/dev/null | grep "^$cur" ) )

     elif [[ $COMP_CWORD -eq 2 ]] ; then
	# functions
	OBJFILE=${COMP_WORDS[COMP_CWORD-1]}

	COMPREPLY=( $( command nm --demangle=dlang $OBJFILE | grep " W " 
| cut -d " " -f 3 | tr "()" "  " | grep "$cur" ) )

     else
	COMPREPLY=($(compgen -W "" -- "$cur"));
     fi


}

complete -F _dasm dasm



More information about the Digitalmars-d mailing list