-
-
Notifications
You must be signed in to change notification settings - Fork 48
Description
Describe the bug
I encountered an issue with the package where the open function defined in your code conflicts with Python's built-in open function. Here is the relevant part of your code:
def open(process_id, debug=True, process_access=None):
"""Open a process given its process_id.
By default, the process is opened with full access and in debug mode.
https://msdn.microsoft.com/en-us/library/windows/desktop/ms684320%28v=vs.85%29.aspx
https://msdn.microsoft.com/en-us/library/windows/desktop/aa379588%28v=vs.85%29.aspx
Parameters
----------
process_id: int
The identifier of the process to be opened
debug: bool
If the process should be opened in debug mode
process_access: pymem.ressources.structure.PROCESS
Desired access level, defaulting to all access
Returns
-------
int
A handle to the opened process
"""
if not process_access:
process_access = pymem.ressources.structure.PROCESS.PROCESS_ALL_ACCESS.value
if debug:
set_debug_privilege('SeDebugPrivilege', True)
process_handle = pymem.ressources.kernel32.OpenProcess(process_access, False, process_id)
return process_handleWhen I try to use Python's built-in open function within my code, it triggers an AttributeError: enter because Python uses the open function defined in your package instead of its own. This is causing compatibility issues with file operations.
Your Environment
- Python 3.10.9
- 64-bit
- pymem==1.13.1
Expected behavior
Traceback
Here's an example of the code that will trigger this error:
import pymem
from pymem.process import *
with open('example.txt', 'r') as file:
content = file.read()Error:
AttributeError: __enter__
Stackoverflow explanation: https://stackoverflow.com/questions/53564755/python-error-attributeerror-enter
Additional context
This happens because the open function in pymem overrides the built-in open function. Renaming the open function in your package to something more specific (e.g., open_process) could resolve this conflict.