Skip to content

Commit

Permalink
fix: (?) WinApi 299 errors (#136)
Browse files Browse the repository at this point in the history
`pymem` is sometimes throwing this error when you're just standing
still. There's a [proposed
fix](srounet/Pymem#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.
  • Loading branch information
jmctune authored Oct 19, 2023
1 parent d5747d6 commit 9423fcd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/common/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion app/pymem/pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9423fcd

Please sign in to comment.