Skip to content

Instantly share code, notes, and snippets.

@duanckham
Created July 13, 2015 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duanckham/0b9ec0f55b6593cdffb5 to your computer and use it in GitHub Desktop.
Save duanckham/0b9ec0f55b6593cdffb5 to your computer and use it in GitHub Desktop.
objdump-to-shellcode
from subprocess import Popen, PIPE
import sys
def shellcode_from_objdump(obj):
res = ''
p = Popen(['objdump', '-d', obj], stdout=PIPE, stderr=PIPE)
(stdoutdata, stderrdata) = p.communicate()
if p.returncode == 0:
for line in stdoutdata.splitlines():
cols = line.split('\t')
if len(cols) > 2:
for b in [b for b in cols[1].split(' ') if b != '']:
res = res + ('\\x%s' % b)
else:
raise ValueError(stderrdata)
return res
if __name__ == '__main__':
if len(sys.argv) < 2:
print 'Usage: %s <obj_file>' % sys.argv[0]
sys.exit(2)
else:
print 'Shellcode for %s:' % sys.argv[1]
print shellcode_from_objdump(sys.argv[1])
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment