Hook¶
For worked examples see Hooks.
- class memobj.hook.Hook(process: Process)[source]¶
Bases:
object- get_code() list[Instruction][source]¶
Called when the hook is activated to get the code to put in the hook
- allocate_variable(name: str, size: int, *, preferred_start: int | None = None) Allocation[source]¶
Allocate a variable of the specified size for use in the hook, retrievable with get_variable.
- Parameters:
name – str The name of the variable to allocate.
size – int The size of the memory block to allocate.
preferred_start – The preferred start address of the allocation
- Returns:
- Allocation
An Allocation object representing the allocated memory block.
- Raises:
ValueError – If a variable with the specified name has already been allocated.
- get_variable(name: str) Allocation[source]¶
Retrieves the allocated variable by its name.
This method attempts to fetch the variable associated with the provided name from the internal allocation storage. If the requested variable does not exist, an error is raised to indicate that it has not been allocated.
- Parameters:
name (str) – The name of the variable to retrieve.
- Returns:
The allocated variable corresponding to the given name.
- Return type:
- Raises:
ValueError – If the variable with the specified name does not exist.
- wait_variable_non_zero(name: str, *, timeout: float | None = None) int[source]¶
Waits for a variable to be non-zero
- Parameters:
name (str) – The name of the variable
timeout (float | None, optional) – How long to wait for it to be non-zero. Defaults to None.
- Returns:
The value of the variable
- Return type:
int
- activate() dict[str, Allocation][source]¶
Activate the hook
- class memobj.hook.JmpHook(process: Process, *, special_deallocate: bool = True, delayed_close_allocator_seconds: float | None = 0.5)[source]¶
Bases:
HookInitializes an instance of the specified class with provided parameters.
- Parameters:
- PATTERN: ClassVar[Pattern[bytes] | bytes | None] = None¶
- MODULE: ClassVar[str | None] = None¶
- activate() dict[str, Allocation][source]¶
Activate the hook
- memobj.hook.create_capture_hook(pattern: Pattern[bytes] | bytes, module: str, bitness: Literal[32, 64], *, register_captures: list[RegisterCaptureSettings]) type[JmpHook][source]¶
Create a capture hook class
- Parameters:
pattern (regex.Pattern[bytes] | bytes) – Pattern to hook at
module (str) – Module to search in
bitness (int) – What bitness of hook to create
register_captures (list[RegisterCaptureSettings]) – Registers to capture
- Returns:
The created capture hook
- Return type:
type[JmpHook]