utilities

This modules provides utility functions for a variety of purposes.

Functions

align_down(number, alignment=16)[source]

Subtract from number so it is divisible by alignment.

Parameters:
  • number (int) – The value to decrease.
  • alignment (int) – The value to make number divisible by.
Returns:

The modified value.

Return type:

int

align_up(number, alignment=16)[source]

Add to number so it is divisible by alignment.

Parameters:
  • number (int) – The value to increase.
  • alignment (int) – The value to make number divisible by.
Returns:

The modified value.

Return type:

int

architecture_is_32bit(arch)[source]

Check if the architecture specified in arch is 32-bit.

Parameters:arch (str) – The value to check.
Return type:bool
architecture_is_64bit(arch)[source]

Check if the architecture specified in arch is 64-bit.

Parameters:arch (str) – The value to check.
Return type:bool
eval_number(number)[source]

Evaluate a numerical expressions in different string formats indicating base.

Parameters:number (str) – The string to evaluate.
Returns:The converted value.
Return type:int
print_hexdump(data, address=0, stream=None)[source]

Print data to stdout in a visually pleasant hex format.

Parameters:
  • data (str) – The data to print.
  • address (int) – The base address to display for data.
  • stream – The object to write the data to be displayed to.
struct_pack(structure)[source]

Pack a ctypes.Structure object and convert it to a packed string.

Parameters:structure (ctypes.Structure) – The structure instance to convert
Returns:The structure instance converted to a string.
Return type:str
struct_unpack(structure, raw_data)[source]

Convert raw_data to an instance of structure.

Parameters:
  • structure (ctypes.Structure) – The structure that describes raw_data.
  • raw_data (str) – The binary string which contains the structures data.
Returns:

A new instance of structure.

Return type:

ctypes.Structure