From 799be7d9316c7366f5b69536093dbd7e9747a15b Mon Sep 17 00:00:00 2001 From: BonePolk <87945722+BonePolk@users.noreply.github.com> Date: Sat, 1 Nov 2025 22:01:04 +0300 Subject: [PATCH 1/5] Optimize scan_memory_for_exact_value --- PyMemoryEditor/util/scan.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/PyMemoryEditor/util/scan.py b/PyMemoryEditor/util/scan.py index a62135a..082b898 100644 --- a/PyMemoryEditor/util/scan.py +++ b/PyMemoryEditor/util/scan.py @@ -19,29 +19,26 @@ def scan_memory_for_exact_value( """ Search for an exact value at the memory region. - This method uses an efficient searching algorithm. + This method uses an efficient searching algorithm. Default find function literally) """ - searcher = KMPSearch(target_value, target_value_size) + data = bytes(memory_region_data) last_index = 0 + found_index = data.find(target_value, 0) - for found_index in searcher.search(memory_region_data, memory_region_data_size): - - # Return the found index if user is searching for an exact value. + while found_index != -1: if comparison is ScanTypesEnum.EXACT_VALUE: yield found_index - continue - - # Return the interval between last_index and found_address, if user is searching for a different value. - for different_index in range(last_index, found_index): - yield different_index - last_index = found_index + 1 + elif comparison is ScanTypesEnum.NOT_EXACT_VALUE: + for different_index in range(last_index, found_index): + yield different_index + last_index = found_index + 1 + found_index = data.find(target_value, found_index+1) - # If user is searching for a different value, return the rest of the addresses that were not found. if comparison is ScanTypesEnum.NOT_EXACT_VALUE: for different_index in range(last_index, memory_region_data_size): yield different_index - - + + def scan_memory( memory_region_data: Sequence, memory_region_data_size: int, From 37bd439c2bdb1fe083c40e4a3d98bdd1037e91d4 Mon Sep 17 00:00:00 2001 From: Jean Loui Bernard <45553309+JeanExtreme002@users.noreply.github.com> Date: Sun, 28 Dec 2025 02:26:57 -0300 Subject: [PATCH 2/5] rollback line comments --- PyMemoryEditor/util/scan.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/PyMemoryEditor/util/scan.py b/PyMemoryEditor/util/scan.py index 082b898..b28a846 100644 --- a/PyMemoryEditor/util/scan.py +++ b/PyMemoryEditor/util/scan.py @@ -26,19 +26,23 @@ def scan_memory_for_exact_value( found_index = data.find(target_value, 0) while found_index != -1: + # Return the found index if user is searching for an exact value. if comparison is ScanTypesEnum.EXACT_VALUE: yield found_index + + # Return the interval between last_index and found_address, if user is searching for a different value. elif comparison is ScanTypesEnum.NOT_EXACT_VALUE: for different_index in range(last_index, found_index): yield different_index last_index = found_index + 1 found_index = data.find(target_value, found_index+1) + # If user is searching for a different value, return the rest of the addresses that were not found. if comparison is ScanTypesEnum.NOT_EXACT_VALUE: for different_index in range(last_index, memory_region_data_size): yield different_index - - + + def scan_memory( memory_region_data: Sequence, memory_region_data_size: int, From a66aaaf15f2b6e14bd722dab9758a791720a8c22 Mon Sep 17 00:00:00 2001 From: Jean Loui Bernard <45553309+JeanExtreme002@users.noreply.github.com> Date: Sun, 28 Dec 2025 02:28:36 -0300 Subject: [PATCH 3/5] improve function string doc --- PyMemoryEditor/util/scan.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PyMemoryEditor/util/scan.py b/PyMemoryEditor/util/scan.py index b28a846..0819071 100644 --- a/PyMemoryEditor/util/scan.py +++ b/PyMemoryEditor/util/scan.py @@ -19,7 +19,7 @@ def scan_memory_for_exact_value( """ Search for an exact value at the memory region. - This method uses an efficient searching algorithm. Default find function literally) + This method uses an efficient searching algorithm. """ data = bytes(memory_region_data) last_index = 0 From 656e4e56edeef6fabdbb79a4d2cf2fc0c5963aa3 Mon Sep 17 00:00:00 2001 From: bonepolk Date: Tue, 6 Jan 2026 01:52:53 +0300 Subject: [PATCH 4/5] fix permission error if write to other proccesses on linux --- PyMemoryEditor/linux/functions.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/PyMemoryEditor/linux/functions.py b/PyMemoryEditor/linux/functions.py index 93bbf4c..d1343f0 100644 --- a/PyMemoryEditor/linux/functions.py +++ b/PyMemoryEditor/linux/functions.py @@ -230,14 +230,16 @@ def write_process_memory( """ Write a value to a memory address. """ - if pytype not in [bool, int, float, str, bytes]: - raise ValueError("The type must be bool, int, float, str or bytes.") - data = get_c_type_of(pytype, bufflength) data.value = value.encode() if isinstance(value, str) else value - libc.process_vm_writev( - pid, (iovec * 1)(iovec(addressof(data), sizeof(data))), - 1, (iovec * 1)(iovec(address, sizeof(data))), 1, 0 - ) + mem = open(f"/proc/{pid}/mem", "rb+") + try: + mem.seek(address) + mem.write(data) + mem.close() + except (OSError, ValueError): + raise PermissionError(f"Can't access the memory of process {pid} at {hex(address)}") + return value + From d6c27d1adb1932c2f36824a7cef677de9e8b2ba6 Mon Sep 17 00:00:00 2001 From: bonepolk Date: Wed, 7 Jan 2026 04:09:42 +0300 Subject: [PATCH 5/5] closed process write fix --- PyMemoryEditor/linux/functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PyMemoryEditor/linux/functions.py b/PyMemoryEditor/linux/functions.py index d1343f0..a710dc0 100644 --- a/PyMemoryEditor/linux/functions.py +++ b/PyMemoryEditor/linux/functions.py @@ -233,8 +233,8 @@ def write_process_memory( data = get_c_type_of(pytype, bufflength) data.value = value.encode() if isinstance(value, str) else value - mem = open(f"/proc/{pid}/mem", "rb+") try: + mem = open(f"/proc/{pid}/mem", "rb+") mem.seek(address) mem.write(data) mem.close()