1

There is a command like the following:

for i in $(objdump -d binary |grep "^ " |cut -f2); do echo -n '\x'$i; done;echo

How can I use this command in my python code and then deliver the result of the hexdump (print) to the console.

    objdump = "$(objdump -d " + str(_arg_name) + "| grep '^ ' |cut -f2);" + " do echo -n $i; done; echo"
    result = os.popen(objdump).read()
    result = result.replace('"','')
    print(result)
2
  • 3
    Possible duplicate of running bash commands in python Commented Jul 22, 2017 at 10:22
  • It's not the answer for the my commands. Commented Jul 22, 2017 at 10:28

1 Answer 1

2

You can use the following code:

    g1 = "grep '^ '"
    g2 = "cut -f2"

    objdump = "objdump -d " + str(binary) + "|" + g1 + "|" + g2 
    result = os.popen(objdump).read()
    result = result.replace('\n','')
    result = result.replace(' ','')
    length = len(result) - 1
    result = [r'\x' + result[i:i + 2] for i in range(0, length, 2)]
    print(result)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.