0

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?

Grazosi
  • 603
  • 1
  • 10

1 Answers1

0

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

Daweo
  • 31,313
  • 3
  • 12
  • 25
  • Thanks a lot, theres only one thing thats still annoying me though. It should be pretty simple. Since I am getting the address as a string, I need to convert it to int, so doing something like ` address = int("0x80491d6") ` which doesnt parse. What can I do to parse this properly? – Grazosi Feb 04 '22 at 10:37
  • 1
    @Grazosi `int("0x80491d6",base=16)` – Daweo Feb 04 '22 at 11:16