### Install Pymem Source: https://github.com/srounet/pymem/blob/master/README.md Install the Pymem library using pip. Use the `[speed]` option for performance enhancements. ```sh pip install pymem ``` ```sh pip install pymem[speed] ``` -------------------------------- ### Install Pymem Source: https://github.com/srounet/pymem/blob/master/docs/source/installation.md Install the Pymem package using pip within an activated virtual environment. ```bash $ pip install pymem ``` -------------------------------- ### Install Pymem with Speed Package Source: https://github.com/srounet/pymem/blob/master/docs/source/installation.md Install Pymem along with the optional 'regex' package for faster memory scans by adding '[speed]' to the pip install command. ```bash $ pip install pymem[speed] ``` -------------------------------- ### Install Pymem in Editable Mode Source: https://github.com/srounet/pymem/blob/master/docs/source/contributing.md Install Pymem and its development dependencies in editable mode. This allows changes to be reflected immediately without reinstallation. ```bash $ pip install -e . ``` -------------------------------- ### Clone Pymem Repository Source: https://github.com/srounet/pymem/blob/master/docs/source/contributing.md Clone the main Pymem repository locally to start development. Navigate into the cloned directory. ```bash $ git clone https://github.com/srounet/pymem $ cd pymem ``` -------------------------------- ### start_thread Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Creates a new thread within the current debugged process. It takes the starting address and optional parameters for the thread. ```APIDOC ## start_thread(address, params=None) ### Description Create a new thread within the current debugged process. ### Parameters #### Path Parameters - **address** (int) - Required - An address from where the thread starts - **params** (int) - Optional - An optional address with thread parameters ### Returns - **int** - The new thread identifier ``` -------------------------------- ### pymem.process.get_luid Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Gets the LUID for the SeCreateSymbolicLinkPrivilege. ```APIDOC ## pymem.process.get_luid(name) ### Description Get the LUID for the SeCreateSymbolicLinkPrivilege ``` -------------------------------- ### Inject Python Interpreter and Shellcode into Process Source: https://github.com/srounet/pymem/blob/master/PYPI-README.md This example demonstrates injecting a Python interpreter and custom shellcode into a target process (notepad.exe). The shellcode writes 'pymem_injection' to a specified file. Ensure necessary modules like 'subprocess' and 'os' are imported. ```python from pymem import Pymem notepad = subprocess.Popen(['notepad.exe']) pm = pymem.Pymem('notepad.exe') pm.inject_python_interpreter() filepath = os.path.join(os.path.abspath('.'), 'pymem_injection.txt') filepath = filepath.replace("\", "\\\\") shellcode = """ f = open("{}", "w+") f.write("pymem_injection") f.close() """.format(filepath) pm.inject_python_shellcode(shellcode) notepad.kill() ``` -------------------------------- ### Run Test Coverage Report Source: https://github.com/srounet/pymem/blob/master/docs/source/contributing.md Install test requirements, then run pytest with coverage enabled to generate a report indicating lines without test coverage. ```bash $ pip install -r requirements-test.txt $ python -m pytest --cov=pymem ``` -------------------------------- ### Get Process Entry by Name Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Finds a process by its name, with options for exact matching and case sensitivity. Defaults to partial, case-insensitive matching. ```python process_entry = pymem.process.process_from_name('notepad.exe') ``` -------------------------------- ### process_base Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Retrieves the base module information for the current process. This is useful for obtaining the starting address of the process's main module. ```APIDOC ## process_base ### Description Lookup process base Module. ### Raises * **TypeError** – process_id is not an integer * [**ProcessError**](#pymem.exception.ProcessError) – Could not find process first module address ### Returns Base module information ### Return type [MODULEINFO](#pymem.ressources.structure.MODULEINFO) ``` -------------------------------- ### Get Process Entry by ID Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Retrieves the process entry information for a given process ID. This function opens the process and returns its details. ```python process_entry = pymem.process.process_from_id(process_id) ``` -------------------------------- ### Get Module from Process Handle Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Retrieve a module loaded by a given process using its handle and module name. Requires the process handle and the name of the module. ```python >>> d3d9 = module_from_name(process_handle, 'd3d9') ``` -------------------------------- ### Scan Byte Pattern in Memory Page Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Searches for a byte pattern within a specific memory page starting from a given address. Handles wildcards in the pattern. Returns the found address or a list of addresses if return_multiple is True. If no match is found or permissions are insufficient, it may return None or an empty list. ```python >>> pm = pymem.Pymem("Notepad.exe") >>> address_reference = 0x7ABC00001 # Here the "." means that the byte can be any byte; a "wildcard" # also note that this pattern may be outdated >>> bytes_pattern = b".\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00" \ ... b"\x00\x00\x00\x00\x00\x00..\x00\x00..\x00\x00\x64\x04" >>> character_count_address = pymem.pattern.scan_pattern_page(pm.process_handle, address_reference, bytes_pattern) ``` -------------------------------- ### pymem.pattern.scan_pattern_page Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Searches a byte pattern within a specified memory page starting from a given address. It can return multiple occurrences or stop at the first match. Memory protection can be checked to avoid scanning restricted regions. ```APIDOC ## pymem.pattern.scan_pattern_page(handle, address, pattern, *, return_multiple=False, check_memory_protection=True) ### Description Search a byte pattern given a memory location. Will query memory location information and search over until it reaches the length of the memory page. If nothing is found the function returns the next page location. ### Parameters * **handle** (*int*) – Handle to an open object * **address** (*int*) – An address to search from * **pattern** (*bytes*) – A regex byte pattern to search for * **return_multiple** (*bool*) – If multiple results should be returned instead of stopping on the first * **check_memory_protection** (*bool*) – Don’t scan a region if its protection prohibits it. ### Returns next_region, found address found address may be None if one was not found, or we didn’t have permission to scan the region if return_multiple is True found address will instead be a list of found addresses or an empty list if no results ### Return type tuple ### Example ```pycon >>> pm = pymem.Pymem("Notepad.exe") >>> address_reference = 0x7ABC00001 # Here the "." means that the byte can be any byte; a "wildcard" also note that this pattern may be outdated >>> bytes_pattern = b".\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00..\x00\x00..\x00\x00d\x04" >>> character_count_address = pymem.pattern.scan_pattern_page(pm.process_handle, address_reference, bytes_pattern) ``` ``` -------------------------------- ### Build Documentation with Sphinx Source: https://github.com/srounet/pymem/blob/master/docs/source/contributing.md Navigate to the docs source directory, clean previous builds, and build the HTML documentation using Sphinx. ```bash $ cd docs/source $ make clean $ make html ``` -------------------------------- ### Create a Python Virtual Environment Source: https://github.com/srounet/pymem/blob/master/docs/source/installation.md Commands to create a new project directory and initialize a Python virtual environment named 'venv'. ```bash $ mkdir myproject $ cd myproject $ python3 -m venv venv ``` ```bat $ py -3 -m venv venv ``` -------------------------------- ### Minimal Pymem Application Source: https://github.com/srounet/pymem/blob/master/docs/source/quickstart.md This snippet shows how to initialize Pymem, allocate memory, write an integer, read it back, and free the memory within a target process. Ensure the target process is running before execution. ```python from pymem import Pymem pm = Pymem('notepad.exe') print('Process id: %s' % pm.process_id) address = pm.allocate(10) print('Allocated address: %s' % address) pm.write_int(address, 1337) value = pm.read_int(address) print('Allocated value: %s' % value) pm.free(address) ``` -------------------------------- ### Create and Activate Virtual Environment Source: https://github.com/srounet/pymem/blob/master/docs/source/contributing.md Create a Python virtual environment named 'env' and activate it. This isolates project dependencies. ```bash $ python3 -m venv env $ . env/bin/activate ``` ```bash > env\Scripts\activate ``` -------------------------------- ### Pymem Class Initialization Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Initializes the Pymem class, optionally opening a process by name or ID. ```APIDOC ## Pymem Class ### Description Initializes the Pymem class. If process_name is given, it will open the process and retrieve a handle over it. ### Parameters * **process_name** (str | int | None) - The name or process id of the process to be opened. * **exact_match** (bool) - Defaults to False. Specifies if the full name match or just part of it is expected. * **ignore_case** (bool) - Defaults to True. Specifies whether to ignore process name case. ``` -------------------------------- ### Running the Pymem Application Source: https://github.com/srounet/pymem/blob/master/docs/source/quickstart.md This shows the command to execute a Python script that uses Pymem and the expected output, including process ID, allocated address, and the read value. ```sh $ python hello.py Process id: 2345 Allocated address: 123456789 Allocated value: 1337 ``` -------------------------------- ### Run Basic Test Suite Source: https://github.com/srounet/pymem/blob/master/docs/source/contributing.md Execute the basic test suite using pytest. This runs tests for the current environment. ```bash $ python -m pytest ``` -------------------------------- ### Activate Python Virtual Environment Source: https://github.com/srounet/pymem/blob/master/docs/source/installation.md Commands to activate the created virtual environment. The shell prompt will change to indicate activation. ```bash $ . venv/bin/activate ``` ```bat > venv\Scripts\activate ``` -------------------------------- ### pymem.process.open Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Opens a process given its process ID. ```APIDOC ## pymem.process.open(process_id, debug=True, process_access=None) ### Description Open a process given its process_id. By default, the process is opened with full access and in debug mode. ### Parameters #### Path Parameters - **process_id** (int) - Required - The identifier of the process to be opened - **debug** (bool) - Optional - If the process should be opened in debug mode (defaults to True) - **process_access** (PROCESS) - Optional - Desired access level, defaulting to all access ### Returns - **int** - A handle to the opened process ``` -------------------------------- ### pymem.process.inject_dll_from_path Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Injects a DLL into an opened process using the Unicode version of LoadLibrary (LoadLibraryW). ```APIDOC ## pymem.process.inject_dll_from_path(handle: int, filepath: str) ### Description Inject a dll into opened process. Use Unicode version of LoadLibrary (LoadLibraryW) ### Parameters * **handle** (*int*) – Handle to an open object * **filepath** (*str*) – Dll to be injected filepath ### Returns The address of injected dll ### Return type DWORD ``` -------------------------------- ### pymem.process.process_from_name Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Opens a process given its name. ```APIDOC ## pymem.process.process_from_name(name: str, exact_match: bool = False, ignore_case: bool = True) ### Description Open a process given its name. ### Parameters #### Path Parameters - **name** (str) - Required - The name of the process to be opened - **exact_match** (bool) - Optional - Defaults to False, is the full name match or just part of it expected? - **ignore_case** (bool) - Optional - Default to True, should ignore process name case? ### Returns - **ProcessEntry32** - The process entry of the opened process ``` -------------------------------- ### pymem.process.list_processes Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Lists all running processes on the system. ```APIDOC ## pymem.process.list_processes() ### Description List all processes. ### Returns - **list[ProcessEntry32]** - A list of open process entries ``` -------------------------------- ### open_process_from_name Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Opens a process by its name and stores the handle. ```APIDOC ## open_process_from_name ### Description Open process given its name and stores the handle into process_handle. ### Parameters * **process_name** (str) - The name of the process to be opened. * **exact_match** (bool) - Defaults to False. Specifies if the full name match or just part of it is expected. * **ignore_case** (bool) - Defaults to True. Specifies whether to ignore process name case. ### Raises * **TypeError** - If process name is not valid or search parameters are of the wrong type. * [**ProcessNotFound**](#pymem.exception.ProcessNotFound) - If the process name is not found. * [**CouldNotOpenProcess**](#pymem.exception.CouldNotOpenProcess) - If the process cannot be opened. ``` -------------------------------- ### pymem.process.open_main_thread Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Opens a handle to the first created thread of a given process. ```APIDOC ## pymem.process.open_main_thread(process_id) ### Description List given process threads and return a handle to first created one. ### Parameters #### Path Parameters - **process_id** (int) - Required - The identifier of the process ### Returns - **int** - A handle to the main thread ``` -------------------------------- ### check_wow64 Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Checks if the target process is running under WoW64 (Windows 32-bit on Windows 64-bit). ```APIDOC ## check_wow64 ### Description Check if a process is running under WoW64. ``` -------------------------------- ### Create Branch for Feature Source: https://github.com/srounet/pymem/blob/master/docs/source/contributing.md Fetch the latest changes from origin and create a new branch for a feature addition or change, branching from the 'master' branch. ```bash $ git fetch origin $ git checkout -b your-branch-name origin/master ``` -------------------------------- ### allocate Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Allocates a specified amount of memory into the currently opened process. ```APIDOC ## allocate ### Description Allocate memory into the current opened process. ### Parameters * **size** (int) - The size of the region of memory to allocate, in bytes. ### Raises * [**ProcessError**](#pymem.exception.ProcessError) - If there is no process opened. * **TypeError** - If size is not an integer. ### Returns The base address of the allocated memory region in the current process. ### Return type int ``` -------------------------------- ### Open Process by ID Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Opens a process given its process ID. By default, the process is opened with full access and in debug mode. Ensure you have the necessary permissions. ```python process_handle = pymem.process.open(process_id) ``` -------------------------------- ### pymem.process.is_wow64 Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Determines if a process is running under WOW64 emulation. ```APIDOC ## pymem.process.is_wow64(handle) ### Description Determines whether the specified process is running under WOW64 (emulation). ### Parameters #### Path Parameters - **handle** (int) - Required - Handle of the process to check wow64 status of ### Returns - **bool** - If the process is running under wow64 ``` -------------------------------- ### pymem.process.inject_dll_from_ansi Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md (Deprecated) Injects a DLL into an opened process using the ANSI version of LoadLibrary (LoadLibraryA). Use `inject_dll_from_path` instead. ```APIDOC ## pymem.process.inject_dll_from_ansi(handle: int, filepath: bytes) ### Description (Deprecated) This function is deprecated. Use inject_dll_from_path instead. Inject a dll into opened process. Use ANSI version of LoadLibrary (LoadLibraryA) ### Parameters * **handle** (*int*) – Handle to an open object * **filepath** (*bytes*) – Dll to be injected filepath ### Returns The address of injected dll ### Return type DWORD ``` -------------------------------- ### List Loaded Modules in a Process Source: https://github.com/srounet/pymem/blob/master/docs/source/tutorials/listing_process_modules.md Hook into a specified process and iterate through its loaded modules, printing the name of each module. Requires the target process to be running. ```python import pymem pm = pymem.Pymem('python.exe') modules = list(pm.list_modules()) for module in modules: print(module.name) ``` -------------------------------- ### Create Branch for Bug Fix Source: https://github.com/srounet/pymem/blob/master/docs/source/contributing.md Fetch the latest changes from origin and create a new branch for a bug fix or documentation update, branching from the latest '.x' release. ```bash $ git fetch origin $ git checkout -b your-branch-name origin/1.1.x ``` -------------------------------- ### pymem.process.process_from_id Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Opens a process given its process ID. ```APIDOC ## pymem.process.process_from_id(process_id) ### Description Open a process given its id. ### Parameters #### Path Parameters - **process_id** (int) - Required - The identifier of the process to be opened ### Returns - **ProcessEntry32** - The process entry of the opened process ``` -------------------------------- ### Configure Git User Information Source: https://github.com/srounet/pymem/blob/master/docs/source/contributing.md Set your global Git username and email address. This is necessary for committing changes. ```bash $ git config --global user.name 'your name' $ git config --global user.email 'your email' ``` -------------------------------- ### open_process_from_id Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Opens a process using its unique process identifier and stores the handle. ```APIDOC ## open_process_from_id ### Description Open process given its ID and stores the handle into self.process_handle. ### Parameters * **process_id** (int) - The unique process identifier. ### Raises * **TypeError** - If process identifier is not an integer. * [**CouldNotOpenProcess**](#pymem.exception.CouldNotOpenProcess) - If the process cannot be opened. ``` -------------------------------- ### Inject DLL into Process (Unicode) Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Injects a DLL into an opened process using the Unicode version of LoadLibraryW. This is the recommended method for DLL injection. ```python pymem.process.inject_dll_from_path(handle: int, filepath: str) ``` -------------------------------- ### CS:GO Trigger Bot with Python Source: https://github.com/srounet/pymem/blob/master/docs/source/examples/csgo_trigger_bot.md This Python script implements a trigger bot for CS:GO. It requires the 'keyboard' and 'pymem' libraries. Ensure the game is running and the script is executed with appropriate permissions. Use at your own risk, as it may violate game terms of service. ```python import keyboard import pymem import pymem.process import time from win32gui import GetWindowText, GetForegroundWindow dwEntityList = (0x4D4B104) dwForceAttack = (0x317C6EC) dwLocalPlayer = (0xD36B94) m_fFlags = (0x104) m_iCrosshairId = (0xB3D4) m_iTeamNum = (0xF4) trigger_key = "shift" def main(): print("Sapphire has launched.") pm = pymem.Pymem("csgo.exe") client = pymem.process.module_from_name(pm.process_handle, "client.dll").lpBaseOfDll while True: if not keyboard.is_pressed(trigger_key): time.sleep(0.1) if not GetWindowText(GetForegroundWindow()) == "Counter-Strike: Global Offensive": continue if keyboard.is_pressed(trigger_key): player = pm.read_int(client + dwLocalPlayer) entity_id = pm.read_int(player + m_iCrosshairId) entity = pm.read_int(client + dwEntityList + (entity_id - 1) * 0x10) entity_team = pm.read_int(entity + m_iTeamNum) player_team = pm.read_int(player + m_iTeamNum) if entity_id > 0 and entity_id <= 64 and player_team != entity_team: pm.write_int(client + dwForceAttack, 6) time.sleep(0.006) if __name__ == '__main__': main() ``` -------------------------------- ### pymem.process.inject_dll Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md (Deprecated) Injects a DLL into an opened process using the ANSI version of LoadLibrary (LoadLibraryA). Use `inject_dll_from_path` instead. ```APIDOC ## pymem.process.inject_dll(handle: int, filepath: bytes) ### Description (Deprecated) This function is deprecated. Use inject_dll_from_path instead. Inject a dll into opened process. Use ANSI version of LoadLibrary (LoadLibraryA) ### Parameters * **handle** (*int*) – Handle to an open object * **filepath** (*bytes*) – Dll to be injected filepath ### Returns The address of injected dll ### Return type DWORD ``` -------------------------------- ### list_modules Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Retrieves a list of all modules loaded into the target process. ```APIDOC ## list_modules ### Description List a process loaded modules. ### Returns A list of MODULEINFO objects representing the loaded modules. ### Return type list([MODULEINFO](#pymem.ressources.structure.MODULEINFO)) ``` -------------------------------- ### pymem.process.open_thread Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Opens an existing thread object. ```APIDOC ## pymem.process.open_thread(thread_id, thread_access=None) ### Description Opens an existing thread object. ### Parameters #### Path Parameters - **thread_id** (int) - Required - The identifier of the thread to be opened - **thread_access** (int) - Optional - Desired access level, defaulting to all access ### Returns - **int** - A handle to the opened thread ``` -------------------------------- ### CS:GO External Glow ESP Implementation Source: https://github.com/srounet/pymem/blob/master/docs/source/examples/csgo_glow_esp.md This Python script uses PyMem to attach to 'csgo.exe' and modify entity glow properties. It iterates through players, setting their glow color based on their team (Terrorist or Counter-Terrorist). Ensure 'client.dll' is correctly mapped and offsets are up-to-date for functionality. ```python import pymem import pymem.process dwEntityList = (0x4D4B104) dwGlowObjectManager = (0x5292F20) m_iGlowIndex = (0xA428) m_iTeamNum = (0xF4) def main(): print("Diamond has launched.") pm = pymem.Pymem("csgo.exe") client = pymem.process.module_from_name(pm.process_handle, "client.dll").lpBaseOfDll while True: glow_manager = pm.read_int(client + dwGlowObjectManager) for i in range(1, 32): # Entities 1-32 are reserved for players. entity = pm.read_int(client + dwEntityList + i * 0x10) if entity: entity_team_id = pm.read_int(entity + m_iTeamNum) entity_glow = pm.read_int(entity + m_iGlowIndex) if entity_team_id == 2: # Terrorist pm.write_float(glow_manager + entity_glow * 0x38 + 0x4, float(1)) # R pm.write_float(glow_manager + entity_glow * 0x38 + 0x8, float(0)) # G pm.write_float(glow_manager + entity_glow * 0x38 + 0xC, float(0)) # B pm.write_float(glow_manager + entity_glow * 0x38 + 0x10, float(1)) # Alpha pm.write_int(glow_manager + entity_glow * 0x38 + 0x24, 1) # Enable glow elif entity_team_id == 3: # Counter-terrorist pm.write_float(glow_manager + entity_glow * 0x38 + 0x4, float(0)) # R pm.write_float(glow_manager + entity_glow * 0x38 + 0x8, float(0)) # G pm.write_float(glow_manager + entity_glow * 0x38 + 0xC, float(1)) # B pm.write_float(glow_manager + entity_glow * 0x38 + 0x10, float(1)) # Alpha pm.write_int(glow_manager + entity_glow * 0x38 + 0x24, 1) # Enable glow if __name__ == '__main__': main() ``` -------------------------------- ### pymem.process.module_from_name Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Retrieves a module loaded by a given process. ```APIDOC ## pymem.process.module_from_name(process_handle, module_name) ### Description Retrieve a module loaded by given process. ### Parameters #### Path Parameters - **process_handle** (int) - Required - Handle to the process to get the module from - **module_name** (str) - Required - Name of the module to get ### Returns - **MODULEINFO** - The retrieved module ### Examples ```pycon >>> d3d9 = module_from_name(process_handle, 'd3d9') ``` ``` -------------------------------- ### Integer Methods Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Common methods available for integer types, including ratio conversion, bit manipulation, and byte conversions. ```APIDOC ## Integer Methods ### as_integer_ratio() Return integer ratio. Return a pair of integers, whose ratio is exactly equal to the original int and with a positive denominator. ```pycon >>> (10).as_integer_ratio() (10, 1) >>> (-10).as_integer_ratio() (-10, 1) >>> (0).as_integer_ratio() (0, 1) ``` ### bit_count() Number of ones in the binary representation of the absolute value of self. Also known as the population count. ```pycon >>> bin(13) '0b1101' >>> (13).bit_count() 3 ``` ### bit_length() Number of bits necessary to represent self in binary. ```pycon >>> bin(37) '0b100101' >>> (37).bit_length() 6 ``` ### conjugate() Returns self, the complex conjugate of any int. ### denominator the denominator of a rational number in lowest terms ### from_bytes(byteorder, *, signed=False) Return the integer represented by the given array of bytes. Parameters: - **byteorder** (str) - The byte order used to represent the integer. Can be 'big' or 'little'. - **signed** (bool) - Indicates whether two’s complement is used to represent the integer. Defaults to False. ### imag the imaginary part of a complex number ### numerator the numerator of a rational number in lowest terms ### real the real part of a complex number ### to_bytes(length, byteorder, *, signed=False) Return an array of bytes representing an integer. Parameters: - **length** (int) - Length of bytes object to use. - **byteorder** (str) - The byte order used to represent the integer. Can be 'big' or 'little'. - **signed** (bool) - Determines whether two’s complement is used to represent the integer. Defaults to False. ``` -------------------------------- ### Inject DLL into Process (Deprecated) Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Injects a DLL into an opened process. This function is deprecated and `inject_dll_from_path` should be used instead. ```python pymem.process.inject_dll(handle: int, filepath: bytes) ``` -------------------------------- ### pymem.memory.read_ushort Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Reads a 2-byte unsigned short integer from a specified memory address in a process. Requires PROCESS_VM_OPERATION access rights. ```APIDOC ## pymem.memory.read_ushort(handle, address) ### Description Reads 2 byte from an area of memory in a specified process. The entire area to be read must be accessible or the operation fails. ### Parameters * **handle** (*int*) – The handle to a process. The function allocates memory within the virtual space of this process. The handle must have the PROCESS_VM_OPERATION access right. * **address** (*int*) – An address of the region of memory to be read. ### Raises * **TypeError** – If address is not a valid integer * [**WinAPIError**](#pymem.exception.WinAPIError) – If ReadProcessMemory failed ### Returns The raw value read as an int ### Return type int ``` -------------------------------- ### MODULEINFO Structure Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Contains information about a loaded module, including its base address, size, and entry point. ```APIDOC ### *class* MODULEINFO(handle) Contains the module load address, size, and entry point. #### lpBaseOfDll #### SizeOfImage #### EntryPoint [https://msdn.microsoft.com/en-us/library/windows/desktop/ms684229(v=vs.85).aspx](https://msdn.microsoft.com/en-us/library/windows/desktop/ms684229(v=vs.85).aspx) ``` -------------------------------- ### Inject DLL into Process (ANSI - Deprecated) Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Injects a DLL into an opened process using the ANSI version of LoadLibraryA. This function is deprecated and `inject_dll_from_path` should be used instead. ```python pymem.process.inject_dll_from_ansi(handle: int, filepath: bytes) ``` -------------------------------- ### inject_python_interpreter Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Injects a Python interpreter into the target process and initializes it. ```APIDOC ## inject_python_interpreter ### Description Inject python interpreter into target process and call Py_InitializeEx. ### Parameters * **initsigs** (int) - Optional argument for Py_InitializeEx, defaults to 1. ``` -------------------------------- ### Thread Class Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Provides basic thread information. ```APIDOC ## pymem.thread.Thread ### Description Provides basic thread information such as TEB. ### Class `pymem.thread.Thread(process_handle, th_entry_32)` ### Parameters * **process_handle** (*int*) – A handle to an opened process * **th_entry_32** ([*ThreadEntry32*](#pymem.ressources.structure.ThreadEntry32)) – Target thread’s entry object ``` -------------------------------- ### pattern_scan_all Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Scans the entire address space of a process for a given byte pattern. ```APIDOC ## pattern_scan_all(handle, pattern, *, return_multiple=False, check_memory_protection=True) ### Description Scan the entire address space for a given regex pattern. ### Parameters #### Path Parameters - **handle** (int) - Required - Handle to an open process - **pattern** (bytes) - Required - A regex bytes pattern to search for #### Query Parameters - **return_multiple** (bool) - Optional - If multiple results should be returned - **check_memory_protection** (bool) - Optional - Don't scan a region if its protection prohibits it. ### Returns Memory address of given pattern, or None if one was not found or a list of found addresses in return_multiple is True ### Return type int, list, optional ``` -------------------------------- ### pymem.memory.virtual_query Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Retrieves information about a range of pages within the virtual address space of a specified process. Requires PROCESS_VM_OPERATION access rights. ```APIDOC ## pymem.memory.virtual_query(handle, address) ### Description Retrieves information about a range of pages within the virtual address space of a specified process. ### Parameters * **handle** (*int*) – The handle to a process. The function allocates memory within the virtual address space of this process. The handle must have the PROCESS_VM_OPERATION access right. * **address** (*int*) – An address of the region of to be read. ### Returns A memory basic information object ### Return type MEMORY_BASIC_INFORMATION ``` -------------------------------- ### is_64_bit Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Checks if the target process is a 64-bit process. ```APIDOC ## is_64_bit (property) ### Description Returns True if the process is 64 bit, False otherwise. ### Returns True if the process is 64-bit, False otherwise. ### Return type bool ``` -------------------------------- ### pymem.process.is_64_bit Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Determines whether the specified process is 64-bit. ```APIDOC ## pymem.process.is_64_bit(handle) ### Description Determines whether the specified process is 64 bit. ### Parameters #### Path Parameters - **handle** (int) - Required - Handle of the process to check 64 bit status of ### Returns - **bool** - If the process is 64 bit ``` -------------------------------- ### pymem.memory.write_ushort Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Writes a 2-byte unsigned short integer to a specified memory address in a target process. The entire memory region must be accessible for the operation to succeed. ```APIDOC ## pymem.memory.write_ushort(handle, address, value) ### Description Writes 2 bytes to an area of memory in a specified process. The entire area to be written to must be accessible or the operation fails. ### Parameters #### Path Parameters - **handle** (int) - Required - The handle to a process. The function allocates memory within the virtual address space of this process. The handle must have the PROCESS_VM_OPERATION access right. - **address** (int) - Required - An address of the region of memory to be written. - **value** (int) - Required - A buffer that contains data to be written ### Raises - TypeError: If address is not a valid integer - WinAPIError: if WriteProcessMemory failed ### Returns A boolean indicating a successful write. ### Return type bool ``` -------------------------------- ### Push Commits to Fork Source: https://github.com/srounet/pymem/blob/master/docs/source/contributing.md Push your local commits to your fork on GitHub. This prepares your changes for a pull request. ```bash $ git push --set-upstream fork your-branch-name ``` -------------------------------- ### pattern_scan_all Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Scans the entire address space of the process for a given byte pattern (regex). ```APIDOC ## pattern_scan_all ### Description Scan the entire address space of this process for a regex pattern. ### Parameters * **pattern** (bytes) - The regex pattern to search for. * **return_multiple** (bool) - Defaults to False. If True, returns all occurrences; otherwise, returns the first. ### Returns The memory address of the first occurrence of the pattern, or a list of addresses if `return_multiple` is True. Returns None if the pattern is not found. ### Return type int | list | None ``` -------------------------------- ### pymem.process.get_python_dll Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Finds the path of a Python DLL given its version, using the current process as a placeholder. ```APIDOC ## pymem.process.get_python_dll(version) ### Description Given a python dll version will find its path using the current process as a placeholder ### Parameters * **version** (*str*) – A string representation of python version as a dll (python38.dll) ### Returns The full path of dll ### Return type str ``` -------------------------------- ### Display System PATH in PowerShell Source: https://github.com/srounet/pymem/blob/master/docs/source/installation.md Use this command in PowerShell to view your current system PATH environment variable. ```powershell $env:PATH ``` -------------------------------- ### CS:GO Auto Bunny Hopper Script Source: https://github.com/srounet/pymem/blob/master/docs/source/examples/csgo_bunny.md This script requires the 'keyboard', 'pymem', and 'win32gui' libraries. It continuously checks if the CS:GO window is active and if the spacebar is pressed. If both conditions are met, it attempts to simulate a jump by writing to the game's memory. Use with caution as it may violate game terms of service. ```python import keyboard import pymem import pymem.process import time from win32gui import GetWindowText, GetForegroundWindow dwForceJump = (0x51F4D88) dwLocalPlayer = (0xD36B94) m_fFlags = (0x104) def main(): print("Ruby has launched.") pm = pymem.Pymem("csgo.exe") client = pymem.process.module_from_name(pm.process_handle, "client.dll").lpBaseOfDll while True: if not GetWindowText(GetForegroundWindow()) == "Counter-Strike: Global Offensive": continue if keyboard.is_pressed("space"): force_jump = client + dwForceJump player = pm.read_int(client + dwLocalPlayer) if player: on_ground = pm.read_int(player + m_fFlags) if on_ground and on_ground == 257: pm.write_int(force_jump, 5) time.sleep(0.08) pm.write_int(force_jump, 4) time.sleep(0.002) if __name__ == '__main__': main() ``` -------------------------------- ### main_thread Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Retrieves information about the main thread of the process. ```APIDOC ## main_thread (property) ### Description Retrieve ThreadEntry32 of the main thread given its creation time. ### Raises * [**ProcessError**](#pymem.exception.ProcessError) - If there is no process opened or the process thread could not be listed. ### Returns Information about the process's main thread. ### Return type [Thread](#pymem.thread.Thread) ``` -------------------------------- ### write_ushort Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Writes an unsigned short integer value to the specified memory address in the current process. ```APIDOC ## write_ushort(address, value) ### Description Write value to the given address into the current opened process. ### Parameters #### Path Parameters - **address** (int) - Required - An address of the region of memory to be written. - **value** (int) - Required - the value to be written ### Raises - **ProcessError** - If there is no opened process - **MemoryWriteError** - If WriteProcessMemory failed - **TypeError** - If address is not a valid integer ``` -------------------------------- ### PROCESS Flags Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Constants representing access rights and flags for process manipulation. ```APIDOC ## PROCESS Flags ### Description Constants representing access rights and flags for process manipulation. ### Flags - **DELETE** (65536): Required to delete the object. - **PROCESS_ALL_ACCESS** (2035711): All possible access rights for a process object. - **PROCESS_CREATE_PROCESS** (128): Required to create a process. - **PROCESS_CREATE_THREAD** (2): Required to create a thread. - **PROCESS_DUP_HANDLE** (64): PROCESS_DUP_HANDLE. - **PROCESS_SET_INFORMATION** (512): Required to set certain information about a process, such as its priority class (see SetPriorityClass). - **PROCESS_SET_QUOTA** (256): Required to set memory limits using SetProcessWorkingSetSize. - **PROCESS_SUSPEND_RESUME** (2048): Required to suspend or resume a process. - **PROCESS_TERMINATE** (1): Required to terminate a process using TerminateProcess. - **PROCESS_VM_OPERATION** (8): Required to perform an operation on the address space of a process (see VirtualProtectEx and WriteProcessMemory). - **PROCESS_VM_READ** (16): Required to read memory in a process using ReadProcessMemory. - **PROCESS_VM_WRITE** (32): Required to write to memory in a process using WriteProcessMemory. - **READ_CONTROL** (131072): Required to read information in the security descriptor for the object, not including the information in the SACL. To read or write the SACL, you must request the ACCESS_SYSTEM_SECURITY access right. For more information see SACL Access Right. - **STANDARD_RIGHTS_REQUIRED** (983040): Combines DELETE, READ_CONTROL, WRITE_DAC, and WRITE_OWNER access. - **SYNCHRONIZE** (1048576): Required to wait for the process to terminate using the wait functions. - **WRITE_DAC** (262144): Required to modify the DACL in the security descriptor for the object. - **WRITE_OWNER** (524288): Required to change the owner in the security descriptor for the object. ``` -------------------------------- ### Inject Python Interpreter and Shellcode Source: https://github.com/srounet/pymem/blob/master/docs/source/tutorials/inject_python_interpreter.md Injects a Python interpreter into the 'notepad.exe' process and then executes Python shellcode to write to a file. Ensure the target process is running before execution. ```python from pymem import Pymem import os import subprocess notepad = subprocess.Popen(['notepad.exe']) pm = Pymem('notepad.exe') pm.inject_python_interpreter() filepath = os.path.join(os.path.abspath('.'), 'pymem_injection.txt') filepath = filepath.replace("\", "\\") shellcode = """ f = open("{}", "w+") f.write("pymem_injection") f.close() """.format(filepath) pm.inject_python_shellcode(shellcode) notepad.kill() ``` -------------------------------- ### pymem.process.base_module Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Retrieves the base module of a given process. ```APIDOC ## pymem.process.base_module(handle) ### Description Returns process base module ### Parameters * **handle** (*int*) – A valid handle to an open object ### Returns The base module of the process ### Return type [MODULEINFO](#pymem.ressources.structure.MODULEINFO) ``` -------------------------------- ### Integer Methods Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Methods available for integer manipulation, including ratio, bitwise operations, and byte conversions. ```APIDOC ## Integer Methods ### Description Methods available for integer manipulation, including ratio, bitwise operations, and byte conversions. ### Methods - **as_integer_ratio()** Return integer ratio. Return a pair of integers, whose ratio is exactly equal to the original int and with a positive denominator. ```pycon >>> (10).as_integer_ratio() (10, 1) >>> (-10).as_integer_ratio() (-10, 1) >>> (0).as_integer_ratio() (0, 1) ``` - **bit_count()** Number of ones in the binary representation of the absolute value of self. Also known as the population count. ```pycon >>> bin(13) '0b1101' >>> (13).bit_count() 3 ``` - **bit_length()** Number of bits necessary to represent self in binary. ```pycon >>> bin(37) '0b100101' >>> (37).bit_length() 6 ``` - **conjugate()** Returns self, the complex conjugate of any int. - **from_bytes(byteorder, ", ", signed=False)** Return the integer represented by the given array of bytes. Parameters: - **byteorder**: The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use `sys.byteorder` as the byte order value. - **signed**: Indicates whether two’s complement is used to represent the integer. - **to_bytes(length, byteorder, ", ", signed=False)** Return an array of bytes representing an integer. Parameters: - **length**: Length of bytes object to use. An OverflowError is raised if the integer is not representable with the given number of bytes. - **byteorder**: The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use `sys.byteorder` as the byte order value. - **signed**: Determines whether two’s complement is used to represent the integer. If signed is False and a negative integer is given, an OverflowError is raised. ``` -------------------------------- ### pymem.memory.write_short Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Writes a 2-byte integer value (short) to a specified memory address in a target process. The entire memory region must be accessible. ```APIDOC ## pymem.memory.write_short(handle, address, value) ### Description Writes a 2-byte integer value (short) to an area of memory in a specified process. The entire area to be written to must be accessible or the operation fails. ### Parameters #### Path Parameters - **handle** (int) - The handle to a process. The function allocates memory within the virtual address space of this process. The handle must have the PROCESS_VM_OPERATION access right. - **address** (int) - An address of the region of memory to be written. - **value** (int) - A buffer that contains data to be written ### Raises - TypeError: If address is not a valid integer - WinAPIError: if WriteProcessMemory failed ### Returns A boolean indicating a successful write. ### Return type bool ``` -------------------------------- ### Open Main Thread Handle Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Retrieves a handle to the first created thread of a given process. Useful for targeting the primary thread of execution. ```python main_thread_handle = pymem.process.open_main_thread(process_id) ``` -------------------------------- ### pymem.process.enum_process_module Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Lists and retrieves the base names of the specified loaded modules within a process. ```APIDOC ## pymem.process.enum_process_module(handle) ### Description List and retrieves the base names of the specified loaded module within a process [https://msdn.microsoft.com/en-us/library/windows/desktop/ms682633(v=vs.85).aspx](https://msdn.microsoft.com/en-us/library/windows/desktop/ms682633(v=vs.85).aspx) [https://msdn.microsoft.com/en-us/library/windows/desktop/ms683196(v=vs.85).aspx](https://msdn.microsoft.com/en-us/library/windows/desktop/ms683196(v=vs.85).aspx) ### Parameters * **handle** (*int*) – Handle of the process to enum the modules of ### Returns The process’s modules ### Return type list[[MODULEINFO](#pymem.ressources.structure.MODULEINFO)] ``` -------------------------------- ### write_short Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Writes a short integer value to the specified memory address in the current process. ```APIDOC ## write_short(address, value) ### Description Write value to the given address into the current opened process. ### Parameters #### Path Parameters - **address** (int) - Required - An address of the region of memory to be written. - **value** (int) - Required - the value to be written ### Raises - **ProcessError** - If there is no opened process - **MemoryWriteError** - If WriteProcessMemory failed - **TypeError** - If address is not a valid integer ``` -------------------------------- ### Add Fork Remote Source: https://github.com/srounet/pymem/blob/master/docs/source/contributing.md Add your GitHub fork as a remote repository. Replace {username} with your GitHub username. This allows you to push your work to your fork. ```bash git remote add fork https://github.com/{username}/pymem ``` -------------------------------- ### pymem.process.get_process_token Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Retrieves the current process token. ```APIDOC ## pymem.process.get_process_token() ### Description Get the current process token ``` -------------------------------- ### Module Information Structure Source: https://github.com/srounet/pymem/blob/master/docs/source/api.md Structure to hold information about a loaded module, including its base address, size, and entry point. ```python class MODULEINFO(handle) Contains the module load address, size, and entry point. #### lpBaseOfDll #### SizeOfImage #### EntryPoint ```