Skip to content

Commit

Permalink
refactored code, fixed bugs and searching methods return guaranteed o…
Browse files Browse the repository at this point in the history
…rdered addresses
  • Loading branch information
JeanExtreme002 committed Nov 19, 2023
1 parent 8d533c9 commit 9e40a88
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 159 deletions.
2 changes: 1 addition & 1 deletion PyMemoryEditor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"""

__author__ = "Jean Loui Bernard Silva de Jesus"
__version__ = "1.5.9"
__version__ = "1.5.10"


from .enums import ScanTypesEnum
Expand Down
15 changes: 9 additions & 6 deletions PyMemoryEditor/linux/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from typing import Dict, Generator, Optional, Sequence, Tuple, Type, TypeVar, Union

from ..enums import ScanTypesEnum
from ..util import convert_from_bytearray, get_c_type_of, scan_memory, scan_memory_for_exact_value
from ..util import convert_from_byte_array, get_c_type_of, scan_memory, scan_memory_for_exact_value
from .ptrace import libc
from .types import MEMORY_BASIC_INFORMATION, iovec

Expand Down Expand Up @@ -102,7 +102,7 @@ def search_addresses_by_value(

checked_memory_size = 0
memory_total = 0
regions = list()
memory_regions = list()

# Get the memory regions, computing the total amount of memory to be scanned.
for region in get_memory_regions(pid):
Expand All @@ -114,10 +114,13 @@ def search_addresses_by_value(
if writeable_only and not b"w" in region["struct"].Privileges: continue

memory_total += region["size"]
regions.append(region)
memory_regions.append(region)

# Sort the list to return ordered addresses.
memory_regions.sort(key=lambda region: region["address"])

# Check each memory region used by the process.
for region in regions:
for region in memory_regions:
address, size = region["address"], region["size"]
region_data = (ctypes.c_byte * size)()

Expand Down Expand Up @@ -177,7 +180,7 @@ def search_values_by_addresses(

# Walk by each memory region.
for region in memory_regions:
if address_index >= len(addresses): continue
if address_index >= len(addresses): break

target_address = addresses[address_index]

Expand All @@ -201,7 +204,7 @@ def search_values_by_addresses(
try:
data = region_data[offset: offset + bufflength]
data = (ctypes.c_byte * bufflength)(*data)
yield target_address, convert_from_bytearray(data, pytype, bufflength)
yield target_address, convert_from_byte_array(data, pytype, bufflength)

except Exception as error:
if raise_error: raise error
Expand Down
9 changes: 6 additions & 3 deletions PyMemoryEditor/sample/application.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-

from .main_application_window import ApplicationWindow
from .open_process_window import OpenProcessWindow

Expand All @@ -6,9 +8,10 @@ def main(*args, **kwargs):
open_process_window = OpenProcessWindow()
process = open_process_window.get_process()

if process:
ApplicationWindow(process)
process.close()
if not process: return

try: ApplicationWindow(process)
finally: process.close()


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit 9e40a88

Please sign in to comment.