-2

i currently pack hex number in little endian with struct.pack() or p32() from pwnlib, i always got bytes object output.

b'\xde\xad\xbe\xef'

i tried str.decode('utf-8') but in some case there is error output. is there a way to decode this ? im using python3 and pwntools 4.3

  • you can decode the bytes the way you show in your question but only if such decoding was possible under the decoding method you specified, utf-8 has a specific structure to it and just a random array of bytes might not adhere to that structure – AntiMatterDynamite Nov 14 '20 at 09:19

1 Answers1

-1

The byte object prefix is important, it is wrong to delete it.

It is just a python-internal representation of the object. If you need it to write a C string containing the same bytes, you should write a function for it, or encode it using hex escapes or octal escapes.

In python 3 bytes is not text. It is a sequence of octets, array of bytes.

Text is a sequence of unicode codepoints, like unicode type in python 2. '\xaa' is just a shorthand for '\u00aa', and the shorthand is only creating confusion, so avoid it if possible. Use bytes objects where you mean binary data and unicode string text objects where you mean text.

See https://github.com/Gallopsled/pwntools-tutorial/blob/master/bytes.md

Arusekk
  • 827
  • 4
  • 22