Skip to content

Commit 2226a1e

Browse files
committed
add Hook.wait_variable_non_zero
1 parent 3a76215 commit 2226a1e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

memobj/hook.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from iced_x86._iced_x86_py import Register as RegisterType
1919

2020
from memobj.allocation import Allocation, Allocator
21+
from memobj.utils import wait_for_value
2122

2223
if TYPE_CHECKING:
2324
from memobj.process import Process
@@ -165,6 +166,20 @@ def get_variable(self, name: str) -> Allocation:
165166
except KeyError:
166167
raise ValueError(f"Variable {name} has not been allocated")
167168

169+
def wait_variable_non_zero(self, name: str, *, timeout: float | None = None) -> int:
170+
"""Waits for a variable to be non-zero
171+
172+
Args:
173+
name (str): The name of the variable
174+
timeout (float | None, optional): How long to wait for it to be non-zero. Defaults to None.
175+
176+
Returns:
177+
int: The value of the variable
178+
"""
179+
allocation = self.get_variable(name)
180+
value, _ = wait_for_value(lambda: allocation.read_typed(self.process.pointer_type), 0, inverse=True, timeout=timeout)
181+
return value
182+
168183
def activate(self) -> dict[str, Allocation]:
169184
"""Activate the hook"""
170185
if self.active:

0 commit comments

Comments
 (0)