Thread overview
Disassemble binary.
May 08, 2018
vital.fadeev
May 08, 2018
vital.fadeev
May 08, 2018
vital.fadeev
May 08, 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

May 08, 2018
example:

./dasm opcode.o opcode.op_eq_s

Disassembly of section .text._D6opcode7op_eq_sFZi:
0000000000000000 <_D6opcode7op_eq_sFZi>:
   0:   55                      push   %rbp
   1:   48 8b ec                mov    %rsp,%rbp
   4:   48 39 d1                cmp    %rdx,%rcx
   7:   75 0a                   jne    13 <_D6opcode7op_eq_sFZi+0x13>
   9:   48 85 c9                test   %rcx,%rcx
   c:   74 0c                   je     1a <_D6opcode7op_eq_sFZi+0x1a>
   e:   fc                      cld
   f:   f3 a6                   repz cmpsb %es:(%rdi),%ds:(%rsi)
  11:   74 07                   je     1a <_D6opcode7op_eq_sFZi+0x1a>
  13:   b8 00 00 00 00          mov    $0x0,%eax
  18:   eb 05                   jmp    1f <_D6opcode7op_eq_sFZi+0x1f>
  1a:   b8 01 00 00 00          mov    $0x1,%eax
  1f:   90                      nop
  20:   5d                      pop    %rbp
  21:   c3                      retq
        ...

May 08, 2018
Source code: https://github.com/vitalfadeev/dasm