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/3] 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/3] 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/3] 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