Files
skel/dotfiles/zshrc.d/assemble.zsh
David Tomaschik db2c02bd2d Cleanup
2026-04-21 15:59:38 -07:00

23 lines
603 B
Bash

if have_command nasm && have_command objdump ; then
assemble_shellcode() {
if [ -z "$1" ] ; then echo "Usage: $0 <assembly file>" >&2 ; return 1 ; fi
local NASM=`command which nasm`
local OBJDUMP=`command which objdump`
local TMPF=`mktemp`
local bytes
local byte
local format="elf"
if [[ "$OSTYPE" == darwin* ]]; then
format="macho64"
fi
$NASM -f $format -o $TMPF $1
$OBJDUMP -M intel -d $TMPF | grep '^ ' | cut -f2 | while read -A bytes ; do
for byte in $bytes ; do
echo -n "\\\\x$byte"
done
done
echo
rm $TMPF
}
fi