pythonpwntools

Is there a way to convert memory adress string to little endian input?


this thing could easily be solves by writing a function that builds the string that I want. But it would be a bit nicer, and a bit more concise if there is something that I can just import and use, it seems lik there should be. I have a python script that uses python pwntools.

It reads a memory leak from a executable that consists of a string that basically just looks like this:

0x80491d6

and I need to inject it back into the program in little endian form, so like this:

\xd6\x91\x04\x08

So that is basically just what I need to do, reverse all the chars in pairs of two.

Does anyone know of a resource that does this? perhaps in pwntools, that I am quite new to?


Solution

  • python3 itself is sufficent for that task

    address = 0x80491d6
    little = address.to_bytes(length=4,byteorder="little")
    print(little)
    

    output

    b'\xd6\x91\x04\x08'
    

    Disclaimer: .to_bytes requires python3.2 or newer