Skip to content

Instantly share code, notes, and snippets.

@h4sh5
Created March 30, 2021 08:17
Show Gist options
  • Select an option

  • Save h4sh5/1462c149416663f4e5e990f3bdf2d2ee to your computer and use it in GitHub Desktop.

Select an option

Save h4sh5/1462c149416663f4e5e990f3bdf2d2ee to your computer and use it in GitHub Desktop.
objdump dump shellcode from a function of a binary file. Better used with gcc -static -fPIC to compile your C src
#!/bin/bash
# linux only! if on osx, use gpaste and gsed instead of paste and sed
if (( $# != 2 )); then
echo "Usage: $0 <file> <function>"
exit 1
fi
#set -x
FILE=$1
FUNC=$2
echo "disasm:" >2
objdump -d $FILE | awk -v RS= '/^[[:xdigit:]]+ <'$FUNC'>/' 1>&2
objdump -d $FILE | awk -v RS= '/^[[:xdigit:]]+ <'$FUNC'>/' | grep '[0-9a-f]:'|grep -v 'file'|cut -f2 -d:|cut -f1-6 -d' '|tr -s ' '|tr '\t' ' '|sed 's/ $//g'|sed 's/ /\\x/g'|paste -d '' -s |sed 's/^/"/'|sed 's/$/"/g'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment