Skip to content

Commit 979d18e

Browse files
authored
optimize scan_memory_for_exact_value (#18)
1 parent 893e63a commit 979d18e

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

PyMemoryEditor/util/scan.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,21 @@ def scan_memory_for_exact_value(
2121
2222
This method uses an efficient searching algorithm.
2323
"""
24-
searcher = KMPSearch(target_value, target_value_size)
24+
data = bytes(memory_region_data)
2525
last_index = 0
26+
found_index = data.find(target_value, 0)
2627

27-
for found_index in searcher.search(memory_region_data, memory_region_data_size):
28-
28+
while found_index != -1:
2929
# Return the found index if user is searching for an exact value.
3030
if comparison is ScanTypesEnum.EXACT_VALUE:
3131
yield found_index
32-
continue
3332

3433
# Return the interval between last_index and found_address, if user is searching for a different value.
35-
for different_index in range(last_index, found_index):
36-
yield different_index
37-
last_index = found_index + 1
34+
elif comparison is ScanTypesEnum.NOT_EXACT_VALUE:
35+
for different_index in range(last_index, found_index):
36+
yield different_index
37+
last_index = found_index + 1
38+
found_index = data.find(target_value, found_index+1)
3839

3940
# If user is searching for a different value, return the rest of the addresses that were not found.
4041
if comparison is ScanTypesEnum.NOT_EXACT_VALUE:

0 commit comments

Comments
 (0)