Skip to main content
function Memory.grow
def Memory.grow(
by: int,
/
) -> int
function Memory.read
def Memory.read(
offset: int,
length: int,
/
) -> bytes
Reads bytes from wasm linear memory.

Example

# Get pointer and length from a wasm function
result = wasm_instance.exports.get_data()
ptr = result & 0xFFFFFFFF
length = (result >> 32) & 0xFFFFFFFF

# Read the data from wasm memory
data = memory.read(ptr, length)
print(str(data))
Parameters
  • offset: - The byte offset in wasm memory to start reading from
  • length: - The number of bytes to read
function Memory.read_cstring
def Memory.read_cstring(
ptr: int,
/,
*,
max_len: int = 4096
) -> str
Read a null-terminated C string from memory. Parameters
  • ptr: - The byte offset in wasm memory to start reading from
  • max_len: - Maximum number of bytes to scan for null terminator (default: 4096)
function Memory.read_string
def Memory.read_string(
ptr: int,
len: int,
/
) -> str
Read a UTF-8 string from memory with explicit length. Parameters
  • ptr: - The byte offset in wasm memory to start reading from
  • len: - The number of bytes to read
function Memory.write
def Memory.write(
offset: int,
buffer: typing.Any,
/
) -> None
function Memory.write_string
def Memory.write_string(
ptr: int,
s: str,
/
) -> int
Write a string to memory at the given pointer. Parameters
  • ptr: - The byte offset in wasm memory to write to
  • s: - The string to write