Virtual Machine Context#

pairipcore.context.decode_address(enc_address: int, code_length: int) addr_t[source]#

Resolves an encoded address and returns the corresponding file offset.

Parameters:
  • enc_address (int) – The encoded address to be resolved.

  • code_length (int) – The length of the bytecode file.

Returns:

The decoded address as an absolute file offset.

Return type:

int

class pairipcore.context.VMMemory[source]#

Internal memory manager for the VM.

This class keeps track of objects that are allocated on the heap using malloc(..).

alloc(ty: Type, *args, **kwargs) tuple[ptr_t, T][source]#

Simulates memory allocation by instantiating an object of the given type.

This function stores a reference to the created object in the internal object map and resturns the target address together with the created object.

Parameters:

ty (Type)

Return type:

tuple[ptr_t, T]

malloc(size: int) tuple[ptr_t, bytearray][source]#

Simulates memory allocation by creating a bytearray using the given size.

Parameters:

size (int)

Return type:

tuple[ptr_t, bytearray]

__init__(base_address: ptr_t) None[source]#
Parameters:

base_address (ptr_t)

Return type:

None

objects: dict[ptr_t, Any]#

INternal map that stores all objects that should be accessible.

variables: dict[addr_t, VMVariable]#

Memory variables

base_address: ptr_t#

Base address for this memory manager

class pairipcore.context.VMContext[source]#

Contains a reference to the bytecode data and maintains the current instruction position

__init__(bytecode: bytes, pc: addr_t) None[source]#
Parameters:
  • bytecode (bytes)

  • pc (addr_t)

Return type:

None

u32(addr: addr_t = -1) int[source]#

Reads an unsigned 32bit integer.

Reads the integer from the current program counter if address is -1.

Parameters:

addr (int, optional) – the target address. Defaults to -1.

Returns:

the parsed int

Return type:

int

i32(addr: addr_t = -1) int[source]#

Reads a signed 32bit integer.

Reads the integer from the current program counter if address is -1.

Parameters:

addr (int, optional) – the target address. Defaults to -1.

Returns:

the parsed int

Return type:

int

u64(addr: addr_t = -1) int[source]#

Reads an unsigned 64bit integer.

Reads the integer from the current program counter if address is -1.

Parameters:

addr (int, optional) – the target address. Defaults to -1.

Returns:

the parsed int

Return type:

int

double(addr: addr_t = -1) float[source]#

Reads a 64bit floating point value.

Reads the value from the current program counter if address is -1.

Parameters:

addr (int, optional) – the target address. Defaults to -1.

Returns:

the parsed double

Return type:

float

u16(addr: addr_t = -1, decode=False) int[source]#

Reads an unsigned 16bit integer.

Reads the integer from the current program counter if address is -1.

Parameters:

addr (int, optional) – the target address. Defaults to -1.

Returns:

the parsed int

Return type:

int

addr(off: int, rel=True, decode=True) addr_t[source]#

Reads an encoded address relative to the current addres (default)

Parameters:
  • off (int) – relative offset (absolute if rel=False)

  • rel (bool, optional) – whether off is relative. Defaults to True.

  • decode (bool, optional) – decodes the address after parsing. Defaults to True.

Returns:

the parsed address

Return type:

int

class pairipcore.context.VMState[source]#

Tracks the internal state of the VM and stores environment options

__init__(verbose: bool = False, writer: ~typing.Any = <built-in function print>, comment: str | None = None, **kwargs) None[source]#
Parameters:
  • verbose (bool)

  • writer (Any)

  • comment (str | None)

Return type:

None

verbose: bool#

whether to print decompiled or disassembled output

writer: Any#

Output writer (may be null)

should_exit: bool#

controls whether the VM should stop execution

comment: str#

comment start character

psection(name: str, *comments) None[source]#

Writes a line to the terminal.

Parameters:

name (str) – the section name

Return type:

None

pinsn(insn: str, args: str, *comments: str, indent: int = 1) None[source]#

Writes an instruction to the terminal.

Parameters:
  • name (str) – the line to write

  • insn (str)

  • args (str)

  • comments (str)

  • indent (int)

Return type:

None

pline(line, *args) None[source]#

Writes a line to the terminal.

Parameters:

name (str) – the line to write

Return type:

None