arrow-left

All pages
gitbookPowered by GitBook
1 of 1

Loading...

Packing

Packing with the in-built python struct module is often a pain with loads of unnecessary options to remember. pwntools makes this a breeze, using the context global variable to automatically calculate how the packing should work.

hashtag
p64(addr)

Packs addr depending on context, which by default is little-endian.

circle-info

p64() returns a bytes-like object, so you'll have to form your padding as b'A' instead of just 'A'.

hashtag
u64(data)

Unpacks data depending on context; exact opposite of p64().

hashtag
flat(*args)

Can take a bunch of arguments and packs them all according to context. The full functionality is quite , but essentially:

is equivalent to

triangle-exclamation

flat() uses context, so unless you specify that it is 64 bits it will attempt to pack it as 32 bits.

complexarrow-up-right
p64(0x04030201) == b'\x01\x02\x03\x04'

context.endian = 'big'
p64(0x04030201) == b'\x04\x03\x02\x01'
payload = flat(
    0x01020304,
    0x59549342,
    0x12186354
)
payload = p64(0x01020304) + p64(0x59549342) + p64(0x12186354)