forked from jan/mem_edit
		
	improve type annotations
This commit is contained in:
		
							parent
							
								
									fec96b92a7
								
							
						
					
					
						commit
						5f2b1a432e
					
				@ -1,8 +1,8 @@
 | 
				
			|||||||
"""
 | 
					"""
 | 
				
			||||||
Abstract class for cross-platform memory editing.
 | 
					Abstract class for cross-platform memory editing.
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
 | 
					from typing import Self
 | 
				
			||||||
from typing import Generator
 | 
					from collections.abc import Generator
 | 
				
			||||||
from abc import ABCMeta, abstractmethod
 | 
					from abc import ABCMeta, abstractmethod
 | 
				
			||||||
from contextlib import contextmanager
 | 
					from contextlib import contextmanager
 | 
				
			||||||
import copy
 | 
					import copy
 | 
				
			||||||
@ -346,7 +346,7 @@ class Process(metaclass=ABCMeta):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @classmethod
 | 
					    @classmethod
 | 
				
			||||||
    @contextmanager
 | 
					    @contextmanager
 | 
				
			||||||
    def open_process(cls, process_id: int) -> Generator['Process', None, None]:
 | 
					    def open_process(cls: type[Self], process_id: int) -> Generator[Self, None, None]:
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        Context manager which automatically closes the constructed Process:
 | 
					        Context manager which automatically closes the constructed Process:
 | 
				
			||||||
        ```
 | 
					        ```
 | 
				
			||||||
 | 
				
			|||||||
@ -11,16 +11,15 @@ Utility functions and types:
 | 
				
			|||||||
  Check if two buffers (ctypes objects) store equal values:
 | 
					  Check if two buffers (ctypes objects) store equal values:
 | 
				
			||||||
    ctypes_equal(a, b)
 | 
					    ctypes_equal(a, b)
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
from typing import Union
 | 
					 | 
				
			||||||
import ctypes
 | 
					import ctypes
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ctypes_buffer_t = Union[
 | 
					ctypes_buffer_t = (
 | 
				
			||||||
    ctypes._SimpleCData,
 | 
					    ctypes._SimpleCData
 | 
				
			||||||
    ctypes.Array,
 | 
					    | ctypes.Array
 | 
				
			||||||
    ctypes.Structure,
 | 
					    | ctypes.Structure
 | 
				
			||||||
    ctypes.Union,
 | 
					    | ctypes.Union
 | 
				
			||||||
    ]
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class MemEditError(Exception):
 | 
					class MemEditError(Exception):
 | 
				
			||||||
 | 
				
			|||||||
@ -92,7 +92,7 @@ class MEMORY_BASIC_INFORMATION64(ctypes.Structure):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
PTR_SIZE = ctypes.sizeof(ctypes.c_void_p)
 | 
					PTR_SIZE = ctypes.sizeof(ctypes.c_void_p)
 | 
				
			||||||
MEMORY_BASIC_INFORMATION: ctypes.Structure
 | 
					MEMORY_BASIC_INFORMATION: type[ctypes.Structure]
 | 
				
			||||||
if PTR_SIZE == 8:       # 64-bit python
 | 
					if PTR_SIZE == 8:       # 64-bit python
 | 
				
			||||||
    MEMORY_BASIC_INFORMATION = MEMORY_BASIC_INFORMATION64
 | 
					    MEMORY_BASIC_INFORMATION = MEMORY_BASIC_INFORMATION64
 | 
				
			||||||
elif PTR_SIZE == 4:     # 32-bit python
 | 
					elif PTR_SIZE == 4:     # 32-bit python
 | 
				
			||||||
@ -256,7 +256,7 @@ class Process(AbstractProcess):
 | 
				
			|||||||
        start = sys_info.lpMinimumApplicationAddress
 | 
					        start = sys_info.lpMinimumApplicationAddress
 | 
				
			||||||
        stop = sys_info.lpMaximumApplicationAddress
 | 
					        stop = sys_info.lpMaximumApplicationAddress
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        def get_mem_info(address):
 | 
					        def get_mem_info(address: int) -> MEMORY_BASIC_INFORMATION:
 | 
				
			||||||
            """
 | 
					            """
 | 
				
			||||||
            Query the memory region starting at or before 'address' to get its size/type/state/permissions.
 | 
					            Query the memory region starting at or before 'address' to get its size/type/state/permissions.
 | 
				
			||||||
            """
 | 
					            """
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user