From 9423fcd99fa8c3780c6a718424c9837d177f6ef7 Mon Sep 17 00:00:00 2001 From: Joey <17505625+jmctune@users.noreply.github.com> Date: Thu, 19 Oct 2023 18:21:05 -0500 Subject: [PATCH] fix: (?) WinApi 299 errors (#136) `pymem` is sometimes throwing this error when you're just standing still. There's a [proposed fix](https://github.com/srounet/Pymem/pull/112) upstream that might resolve these. It looks like this issue started (at least for clarity) when I forked over some changes that were made to how bytes were read. --- app/common/memory.py | 1 + app/pymem/pattern.py | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/common/memory.py b/app/common/memory.py index 5c9ea6e..08654f5 100644 --- a/app/common/memory.py +++ b/app/common/memory.py @@ -97,6 +97,7 @@ def pattern_scan(self, pattern: bytes, return_multiple=False, use_regex=False, m ) except pymem.exception.WinAPIError as e: if e.error_code == 299: # impartial read, just return none. + log.debug("WinAPI Error 299") return None else: from common.process import is_dqx_process_running diff --git a/app/pymem/pattern.py b/app/pymem/pattern.py index ffba990..aa9f72b 100644 --- a/app/pymem/pattern.py +++ b/app/pymem/pattern.py @@ -49,7 +49,12 @@ def scan_pattern_page(handle, address, pattern, *, all_protections=True, use_reg if mbi.state != pymem.ressources.structure.MEMORY_STATE.MEM_COMMIT or mbi.protect not in allowed_protections: return next_region, None - page_bytes = pymem.memory.read_bytes(handle, address, mbi.RegionSize) + try: + page_bytes = pymem.memory.read_bytes(handle, address, mbi.RegionSize) + except pymem.exception.WinAPIError as e: + if e.error_code == 299: # hiding an issue where memory changes between query and read + return next_region, None + raise pymem.exception.MemoryReadError(address, mbi.RegionSize, e.error_code) if not return_multiple: found = None