Skip to content

Commit

Permalink
removed duplicated docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanExtreme002 committed Dec 12, 2023
1 parent 6b2d968 commit d3eb7d3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 107 deletions.
4 changes: 2 additions & 2 deletions PyMemoryEditor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

"""
Multi-platform library developed with ctypes for reading, writing and
searching process memory, in a simple and friendly way with Python 3.
searching at process memory, in a simple and friendly way with Python 3.
The package supports Windows and Linux (32-bit and 64-bit).
"""

__author__ = "Jean Loui Bernard Silva de Jesus"
__version__ = "1.5.19"
__version__ = "1.5.20"


from .enums import ScanTypesEnum
Expand Down
64 changes: 11 additions & 53 deletions PyMemoryEditor/linux/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

class LinuxProcess(AbstractProcess):
"""
Class to open a Linux process for reading and writing memory.
Class to open a Linux process for reading, writing and searching at its memory.
"""

def __init__(
Expand All @@ -42,19 +42,13 @@ def __init__(
self.__closed = False

def close(self) -> bool:
"""
Close the process handle.
"""
# Check the documentation of this method in the AbstractProcess superclass for more information.
self.__closed = True
return True

def get_memory_regions(self) -> Generator[dict, None, None]:
"""
Generates dictionaries with the address, size and other
information of each memory region used by the process.
"""
# Check the documentation of this method in the AbstractProcess superclass for more information.
if self.__closed: raise ClosedProcess()

return get_memory_regions(self.pid)

def read_process_memory(
Expand All @@ -63,15 +57,8 @@ def read_process_memory(
pytype: Type[T],
bufflength: int
) -> T:
"""
Return a value from a memory address.
:param address: target memory address (ex: 0x006A9EC0).
:param pytype: type of the value to be received (bool, int, float, str or bytes).
:param bufflength: value size in bytes (1, 2, 4, 8).
"""
# Check the documentation of this method in the AbstractProcess superclass for more information.
if self.__closed: raise ClosedProcess()

return read_process_memory(self.pid, address, pytype, bufflength)

def search_by_addresses(
Expand All @@ -82,10 +69,8 @@ def search_by_addresses(
*,
raise_error: bool = False,
) -> Generator[Tuple[int, Optional[T]], None, None]:
"""
Search the whole memory space, accessible to the process,
for the provided list of addresses, returning their values.
"""

# Check the documentation of this method in the AbstractProcess superclass for more information.
if self.__closed: raise ClosedProcess()
return search_values_by_addresses(self.pid, pytype, bufflength, addresses, raise_error=raise_error)

Expand All @@ -99,17 +84,8 @@ def search_by_value(
progress_information: bool = False,
writeable_only: bool = False,
) -> Generator[Union[int, Tuple[int, dict]], None, None]:
"""
Search the whole memory space, accessible to the process,
for the provided value, returning the found addresses.
:param pytype: type of value to be queried (bool, int, float, str or bytes).
:param bufflength: value size in bytes (1, 2, 4, 8).
:param value: value to be queried (bool, int, float, str or bytes).
:param scan_type: the way to compare the values.
:param progress_information: if True, a dictionary with the progress information will be return.
:param writeable_only: if True, search only at writeable memory regions.
"""

# Check the documentation of this method in the AbstractProcess superclass for more information.
if self.__closed: raise ClosedProcess()

if scan_type in [ScanTypesEnum.VALUE_BETWEEN, ScanTypesEnum.NOT_VALUE_BETWEEN]:
Expand All @@ -128,18 +104,8 @@ def search_by_value_between(
progress_information: bool = False,
writeable_only: bool = False,
) -> Generator[Union[int, Tuple[int, dict]], None, None]:
"""
Search the whole memory space, accessible to the process,
for a value within the provided range, returning the found addresses.
:param pytype: type of value to be queried (bool, int, float, str or bytes).
:param bufflength: value size in bytes (1, 2, 4, 8).
:param start: minimum inclusive value to be queried (bool, int, float, str or bytes).
:param end: maximum inclusive value to be queried (bool, int, float, str or bytes).
:param not_between: if True, return only addresses of values that are NOT within the range.
:param progress_information: if True, a dictionary with the progress information will be return.
:param writeable_only: if True, search only at writeable memory regions.
"""

# Check the documentation of this method in the AbstractProcess superclass for more information.
if self.__closed: raise ClosedProcess()

scan_type = ScanTypesEnum.NOT_VALUE_BETWEEN if not_between else ScanTypesEnum.VALUE_BETWEEN
Expand All @@ -152,14 +118,6 @@ def write_process_memory(
bufflength: int,
value: Union[bool, int, float, str, bytes]
) -> T:
"""
Write a value to a memory address.
:param address: target memory address (ex: 0x006A9EC0).
:param pytype: type of value to be written into memory (bool, int, float, str or bytes).
:param bufflength: value size in bytes (1, 2, 4, 8).
:param value: value to be written (bool, int, float, str or bytes).
"""
# Check the documentation of this method in the AbstractProcess superclass for more information.
if self.__closed: raise ClosedProcess()

return write_process_memory(self.pid, address, pytype, bufflength, value)
62 changes: 11 additions & 51 deletions PyMemoryEditor/win32/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

class WindowsProcess(AbstractProcess):
"""
Class to open a Windows process for reading and writing memory.
Class to open a Windows process for reading, writing and searching at its memory.
"""

def __init__(
Expand Down Expand Up @@ -54,21 +54,15 @@ def __init__(
self.__process_handle = GetProcessHandle(self.__permission.value, False, self.pid)

def close(self) -> bool:
"""
Close the process handle.
"""
# Check the documentation of this method in the AbstractProcess superclass for more information.
if self.__closed: return True

self.__closed = CloseProcessHandle(self.__process_handle) != 0
return self.__closed

def get_memory_regions(self) -> Generator[dict, None, None]:
"""
Generates dictionaries with the address, size and other
information of each memory region used by the process.
"""
# Check the documentation of this method in the AbstractProcess superclass for more information.
if self.__closed: raise ClosedProcess()

return GetMemoryRegions(self.__process_handle)

def search_by_addresses(
Expand All @@ -79,10 +73,8 @@ def search_by_addresses(
*,
raise_error: bool = False,
) -> Generator[Tuple[int, Optional[T]], None, None]:
"""
Search the whole memory space, accessible to the process,
for the provided list of addresses, returning their values.
"""

# Check the documentation of this method in the AbstractProcess superclass for more information.
if self.__closed: raise ClosedProcess()

valid_permissions = [
Expand All @@ -104,17 +96,8 @@ def search_by_value(
progress_information: bool = False,
writeable_only: bool = False,
) -> Generator[Union[int, Tuple[int, dict]], None, None]:
"""
Search the whole memory space, accessible to the process,
for the provided value, returning the found addresses.
:param pytype: type of value to be queried (bool, int, float, str or bytes).
:param bufflength: value size in bytes (1, 2, 4, 8).
:param value: value to be queried (bool, int, float, str or bytes).
:param scan_type: the way to compare the values.
:param progress_information: if True, a dictionary with the progress information will be return.
:param writeable_only: if True, search only at writeable memory regions.
"""

# Check the documentation of this method in the AbstractProcess superclass for more information.
if self.__closed: raise ClosedProcess()

valid_permissions = [
Expand All @@ -140,18 +123,8 @@ def search_by_value_between(
progress_information: bool = False,
writeable_only: bool = False,
) -> Generator[Union[int, Tuple[int, dict]], None, None]:
"""
Search the whole memory space, accessible to the process,
for a value within the provided range, returning the found addresses.
:param pytype: type of value to be queried (bool, int, float, str or bytes).
:param bufflength: value size in bytes (1, 2, 4, 8).
:param start: minimum inclusive value to be queried (bool, int, float, str or bytes).
:param end: maximum inclusive value to be queried (bool, int, float, str or bytes).
:param not_between: if True, return only addresses of values that are NOT within the range.
:param progress_information: if True, a dictionary with the progress information will be return.
:param writeable_only: if True, search only at writeable memory regions.
"""

# Check the documentation of this method in the AbstractProcess superclass for more information.
if self.__closed: raise ClosedProcess()

valid_permissions = [
Expand All @@ -170,13 +143,7 @@ def read_process_memory(
pytype: Type[T],
bufflength: int
) -> T:
"""
Return a value from a memory address.
:param address: target memory address (ex: 0x006A9EC0).
:param pytype: type of the value to be received (bool, int, float, str or bytes).
:param bufflength: value size in bytes (1, 2, 4, 8).
"""
# Check the documentation of this method in the AbstractProcess superclass for more information.
if self.__closed: raise ClosedProcess()

valid_permissions = [
Expand All @@ -195,14 +162,7 @@ def write_process_memory(
bufflength: int,
value: Union[bool, int, float, str, bytes]
) -> T:
"""
Write a value to a memory address.
:param address: target memory address (ex: 0x006A9EC0).
:param pytype: type of value to be written into memory (bool, int, float, str or bytes).
:param bufflength: value size in bytes (1, 2, 4, 8).
:param value: value to be written (bool, int, float, str or bytes).
"""
# Check the documentation of this method in the AbstractProcess superclass for more information.
if self.__closed: raise ClosedProcess()

valid_permissions = [
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "PyMemoryEditor"
dynamic = ["version"]
description = "Multi-platform library developed with ctypes for reading, writing and searching process memory, in a simple and friendly way with Python 3."
description = "Multi-platform library developed with ctypes for reading, writing and searching at process memory, in a simple and friendly way with Python 3."
authors = [
{ name = "Jean Loui Bernard Silva de Jesus", email = "[email protected]" },
]
Expand Down

0 comments on commit d3eb7d3

Please sign in to comment.