pysui.sui_move.bin_reader package

Submodules

pysui.sui_move.bin_reader.module_reader module

Move module byte reader class.

class pysui.sui_move.bin_reader.module_reader.ModuleReader(source: str, binary_data: bytes)

Bases: BinaryReader

.

U32_BYTES: int = 4
MAGIC_WORD: str = 'a11ceb0b'
TABLE_HEADER_START: int = 8
__init__(source: str, binary_data: bytes) None

__init__ Instantiate ModuleReader.

Parameters:
  • source (str) – The original source

  • binary_data (bytes) – A bytes string of module content

Raises:

ValueError – If bytes content doesn’t conform to move module standards.

classmethod read_from_file(module: str) ModuleReader | ValueError | OSError

read_from_file instantiates a module byte reader from a file path.

Raises:

ValueError – If file does not exist

Returns:

the instantiated ModuleReader

Return type:

ModuleReader

classmethod read_from_base64(in_base64: str) ModuleReader | Error

read_from_base64 Instantiate a move binary table reader from base64 string.

Returns:

the instantiated ModuleReader

Return type:

ModuleReader

has_table(table_type: TableType) bool

has_table Test if TableType exists in byte code.

Parameters:

table_type (TableType) – The type of table to test for

Returns:

True if it exists, false otherwise

Return type:

bool

position_content_for(table_header: TableHeader) int

position_content_for position the module byte read to a table.

Parameters:

table_header (TableHeader) – The TableHeader representing a table typel

Returns:

the position moved to

Return type:

int

build_content_for(table_type: TableType, handler: Callable[[TableHeader, ModuleReader], list]) list | None

build_content_for builds a decomposed content model for a table_type.

Parameters:
  • table_type (TableType) – The type of table to decompose from byte code stream

  • handler (Callable[[ModuleReader, dict[TableType, TableHeader]], list]) – Function that takes two arguments and returns a list. First argument is the TableType’s TableHeader Second argument is this ModuleReader

Returns:

List of table type contents decomposed

Return type:

Union[list, None]

build_model_list(handler: Callable[[ModuleReader], Any]) list

build_model_list reads a length encoded vector/list into a model component.

Parameters:

handler (Callable[[ModuleReader], Any]) – Function taking the module reader

Returns:

a list of model types read from vector/list

Return type:

list

property self_index: int

self_index Gets the index to the module as self.

Returns:

The self module index

Return type:

int

property table_count: int

table_count Return table counts in module.

Returns:

The number of byte code tables found in module header.

Return type:

int

property cross_reference: dict[TableType, TableHeader]

cross_reference Get the cross reference table.

Returns:

Associative structure of TableType -> TableHeader

Return type:

dict[TableType, TableHeader]

pysui.sui_move.bin_reader.reader module

Byte reader class.

class pysui.sui_move.bin_reader.reader.BinaryReader(source: str, data: bytes)

Bases: object

BinaryReader manages loading and accessing areas of binary file.

__init__(source: str, data: bytes) None

__init__ Initialize reader.

Parameters:

binary_file (str) – The path and file name to load

pos() int

pos Report the current reader position.

Returns:

Current positiion of reader

Return type:

int

move_to(location: int, relative_to: int = 0) int | ValueError

move_to Positions the reader to stream location.

Parameters:
  • location (int) – The location in the stream to position at, may be negative

  • relative_to (int, optional) – 0 from beginning, 1 for current and 2 for end, defaults to 0

Raises:

ValueError – location is invalid

Returns:

the previous location

Return type:

Union[int, ValueError]

read(size: int | None = None) bytes

.

read_as_int(size: int | None = None) int

read_as_int Read in size bytes and convert to int.

Parameters:

size (int, optional) – The number of bytes to read, defaults to None

Returns:

The read bytes converted to little endien int

Return type:

int

read_as_bool() bool

.

read_uleb128() int

read_uleb128 reads a uleb128 value from stream.

read_from_uleb_array() bytes

read_from_uleb_array reads vector with uleb128 count.

Returns:

The bytes read into based on array size

Return type:

bytes

Module contents

Move byte reader.