Skip to content

Instantly share code, notes, and snippets.

@lecram
Last active January 2, 2016 22:49
Show Gist options
  • Save lecram/8372173 to your computer and use it in GitHub Desktop.
Save lecram/8372173 to your computer and use it in GitHub Desktop.
A wrapper to use objdump for raw i8086 disassembling with intel syntax.
#! /bin/bash
if [ $# -lt 1 ] || [ $# -gt 3 ]
then
printf 'usage:\n %s <file> [offset [limit|(+|-)length]]\n' `basename $0`
exit 1
fi
IN="$1"
START=0
STOP=`du -b $IN | cut -f1`
if [ $# -gt 1 ]
then
START=$2
if [ $# -gt 2 ]
then
if [ ${3:0:1} == '+' ]
then
STOP=$(($START + ${3:1}))
elif [ ${3:0:1} == '-' ]
then
STOP=$START
START=$(($STOP - ${3:1}))
else
STOP=$3
fi
STOPOPT="--stop-address=$STOP"
fi
STARTOPT="--start-address=$START"
fi
printf '%s 0x%x:0x%x (%d)\n' $IN $START $STOP $(($STOP - $START))
objdump -D -b binary -m i8086 -M intel $STARTOPT $STOPOPT $IN | sed '1,7d'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment