{"library":"pymem","title":"Pymem","description":"Pymem is a Python library that simplifies direct memory access and manipulation in Windows processes. It provides functionalities to open processes, read and write various data types to memory, and search for patterns. Currently at version 1.14.0, its release cadence is infrequent, focusing on stability and compatibility with Windows system updates rather than rapid feature additions.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install pymem"],"cli":null},"imports":["from pymem import Pymem"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nimport time\nfrom pymem import Pymem, process\nfrom pymem.exception import PymemError\n\n# NOTE: Pymem is Windows-specific and often requires administrator privileges.\n# For this example, we'll try to find 'notepad.exe'.\n# Make sure Notepad is running before executing this code.\n\nprocess_name = \"notepad.exe\"\np = None\n\ntry:\n    # Find the process ID of notepad.exe\n    pid = process.get_pid_by_name(process_name)\n    print(f\"Found {process_name} with PID: {pid}\")\n\n    # Open the process\n    p = Pymem(process_name)\n    print(f\"Successfully opened process {process_name}.\")\n\n    # Example: Reading the base address (typically the module's base address)\n    # This is often used to calculate offsets to specific memory locations.\n    base_address = p.base_address\n    print(f\"Base address of {process_name}: {hex(base_address)}\")\n\n    # For a more meaningful example, one would typically search for a known pattern\n    # or address relative to the base address and then read/write data.\n    # As a simple demonstration, let's just confirm we can access some memory.\n    # Reading a few bytes from the base address itself (usually code):\n    try:\n        first_bytes = p.read_bytes(base_address, 8)\n        print(f\"First 8 bytes at base address: {first_bytes.hex()}\")\n    except PymemError as e:\n        print(f\"Could not read from base address (might be protected): {e}\")\n\nfinally:\n    if p:\n        p.close_process()\n        print(f\"Closed process handle for {process_name}.\")\n    else:\n        print(f\"Could not open process {process_name}. Ensure it's running and you have permissions.\")\n","lang":"python","description":"This quickstart demonstrates how to open a target process (notepad.exe), retrieve its Process ID (PID) and base memory address, and attempt to read a few bytes from it. It's crucial that the target process is running and the Python script has sufficient permissions (e.g., run as administrator) to interact with it.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}