Skip to content

Instantly share code, notes, and snippets.

@lenerd
Created October 28, 2015 21:08
Show Gist options
  • Save lenerd/26e553ac18384ad239d8 to your computer and use it in GitHub Desktop.
Save lenerd/26e553ac18384ad239d8 to your computer and use it in GitHub Desktop.
#!/bin/sh
elf="$(mktemp)"
bin="$(mktemp)"
(echo ".intel_syntax noprefix"; cat "$1") | gcc -x assembler -m32 -masm=intel -c -o "$elf" -
objcopy -O binary --only-section=.text "$elf" "$bin"
echo -e "Assembly:\n"
echo -e "Raw Hex:\n"
od -A none -tx1 "$bin" | tr -d '\n '
echo -e '\n'
echo -e "String Constant:\n"
echo -n '"'
od -A none -tx1 "$bin" | tr -d '\n' | sed -e 's/ /\\x/g'
echo -e '"\n'
echo -e "\nDisassembly:\n"
objdump -d -M intel "$elf" | tail -n +8
rm -f "$elf" "$bin"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment