mankee mankee - 7 days ago 5
Python Question

Hexadecimal Memory Address to Assembly

I am following a buffer overflow tutorial. I have set up my NOP block, I also set up my shell code, now I need to append the return address to the end of my string. I know my return address is :

0xbfffef40


however I need to write it in the form:

xd0\xce\xff\xff
(that's just an example address to show what format I need)

I'm not sure how to carry out the conversion between the two.

Answer

You can use struct.pack like this:

import struct
struct.pack('<L', 0xbfffef40)

Check the documentation of struct.pack if you want to change the endianness.