packing – Data (un)packing

pwnypack.packing.pack(fmt, v1, v2, ..., endian=None, target=None)[source]

Return a string containing the values v1, v2, … packed according to the given format. The actual packing is performed by struct.pack but the byte order will be set according to the given endian, target or byte order of the global target.

Parameters:
  • fmt (str) – The format string.
  • v1,v2,.. – The values to pack.
  • endian (Endian) – Override the default byte order. If None, it will look at the byte order of the target argument.
  • target (Target) – Override the default byte order. If None, it will look at the byte order of the global target.
Returns:

The provided values packed according to the format.

Return type:

bytes

pwnypack.packing.unpack(fmt, data, endian=None, target=None)[source]

Unpack the string (presumably packed by pack(fmt, …)) according to the given format. The actual unpacking is performed by struct.unpack but the byte order will be set according to the given endian, target or byte order of the global target.

Parameters:
  • fmt (str) – The format string.
  • data (bytes) – The data to unpack.
  • endian (Endian) – Override the default byte order. If None, it will look at the byte order of the target argument.
  • target (Target) – Override the default byte order. If None, it will look at the byte order of the global target.
Returns:

The unpacked values according to the format.

Return type:

list

pwnypack.packing.pack_size(fmt, endian=None, target=None)[source]
pwnypack.packing.P(value, bits=None, endian=None, target=None)[source]

Pack an unsigned pointer for a given target.

Parameters:
  • value (int) – The value to pack.
  • bits (Bits) – Override the default word size. If None it will look at the word size of target.
  • endian (Endian) – Override the default byte order. If None, it will look at the byte order of the target argument.
  • target (Target) – Override the default byte order. If None, it will look at the byte order of the global target.
pwnypack.packing.p(value, bits=None, endian=None, target=None)[source]

Pack a signed pointer for a given target.

Parameters:
  • value (int) – The value to pack.
  • bits (pwnypack.target.Target.Bits) – Override the default word size. If None it will look at the word size of target.
  • endian (Endian) – Override the default byte order. If None, it will look at the byte order of the target argument.
  • target (Target) – Override the default byte order. If None, it will look at the byte order of the global target.
pwnypack.packing.U(data, bits=None, endian=None, target=None)[source]

Unpack an unsigned pointer for a given target.

Parameters:
  • data (bytes) – The data to unpack.
  • bits (pwnypack.target.Target.Bits) – Override the default word size. If None it will look at the word size of target.
  • endian (Endian) – Override the default byte order. If None, it will look at the byte order of the target argument.
  • target (Target) – Override the default byte order. If None, it will look at the byte order of the global target.
Returns:

The pointer value.

Return type:

int

pwnypack.packing.u(data, bits=None, endian=None, target=None)[source]

Unpack a signed pointer for a given target.

Parameters:
  • data (bytes) – The data to unpack.
  • bits (pwnypack.target.Target.Bits) – Override the default word size. If None it will look at the word size of target.
  • endian (Endian) – Override the default byte order. If None, it will look at the byte order of the target argument.
  • target (Target) – Override the default byte order. If None, it will look at the byte order of the global target.
Returns:

The pointer value.

Return type:

int

pwnypack.packing.p8(value, endian=None, target=None)

Pack signed 8 bit integer. Alias for pack('b', ...).

pwnypack.packing.P8(value, endian=None, target=None)

Pack unsigned 8 bit integer. Alias for pack('B', ...).

pwnypack.packing.u8(data, endian=None, target=None)

Unpack signed 8 bit integer. Alias for unpack('b', ...).

pwnypack.packing.U8(data, endian=None, target=None)

Unpack unsigned 8 bit integer. Alias for unpack('B', ...).

pwnypack.packing.p16(value, endian=None, target=None)

Pack signed 16 bit integer. Alias for pack('h', ...).

pwnypack.packing.P16(value, endian=None, target=None)

Pack unsigned 16 bit integer. Alias for pack('H', ...).

pwnypack.packing.u16(data, endian=None, target=None)

Unpack signed 16 bit integer. Alias for unpack('h', ...).

pwnypack.packing.U16(data, endian=None, target=None)

Unpack unsigned 16 bit integer. Alias for unpack('H', ...).

pwnypack.packing.p32(value, endian=None, target=None)

Pack signed 32 bit integer. Alias for pack('l', ...).

pwnypack.packing.P32(value, endian=None, target=None)

Pack unsigned 32 bit integer. Alias for pack('L', ...).

pwnypack.packing.u32(data, endian=None, target=None)

Unpack signed 32 bit integer. Alias for unpack('l', ...).

pwnypack.packing.U32(data, endian=None, target=None)

Unpack unsigned 32 bit integer. Alias for unpack('L', ...).

pwnypack.packing.p64(value, endian=None, target=None)

Pack signed 64 bit integer. Alias for pack('q', ...).

pwnypack.packing.P64(value, endian=None, target=None)

Pack unsigned 64 bit integer. Alias for pack('Q', ...).

pwnypack.packing.u64(data, endian=None, target=None)

Unpack signed 64 bit integer. Alias for unpack('q', ...).

pwnypack.packing.U64(data, endian=None, target=None)

Unpack unsigned 64 bit integer. Alias for unpack('Q', ...).