From 5a032da984b753744536af2b18506d65a02018c8 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Thu, 8 Apr 2021 19:49:19 -0700 Subject: [PATCH 1/5] try to reduce log spam --- mem_edit/abstract.py | 1 - mem_edit/linux.py | 5 ++--- mem_edit/windows.py | 7 +++---- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/mem_edit/abstract.py b/mem_edit/abstract.py index f2e6cd1..e086d4e 100644 --- a/mem_edit/abstract.py +++ b/mem_edit/abstract.py @@ -13,7 +13,6 @@ from . import utils from .utils import ctypes_buffer_t -logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) diff --git a/mem_edit/linux.py b/mem_edit/linux.py index 58460b8..18f3b8f 100644 --- a/mem_edit/linux.py +++ b/mem_edit/linux.py @@ -15,7 +15,6 @@ from .abstract import Process as AbstractProcess from .utils import ctypes_buffer_t, MemEditError -logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) @@ -94,14 +93,14 @@ class Process(AbstractProcess): def get_pid_by_name(target_name: str) -> Optional[int]: for pid in Process.list_available_pids(): try: - logger.info('Checking name for pid {}'.format(pid)) + logger.debug('Checking name for pid {}'.format(pid)) with open('/proc/{}/cmdline'.format(pid), 'rb') as cmdline: path = cmdline.read().decode().split('\x00')[0] except FileNotFoundError: continue name = os.path.basename(path) - logger.info('Name was "{}"'.format(name)) + logger.debug('Name was "{}"'.format(name)) if path is not None and name == target_name: return pid diff --git a/mem_edit/windows.py b/mem_edit/windows.py index e3bb013..b945058 100644 --- a/mem_edit/windows.py +++ b/mem_edit/windows.py @@ -14,7 +14,6 @@ from .abstract import Process as AbstractProcess from .utils import ctypes_buffer_t, MemEditError -logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) @@ -229,18 +228,18 @@ class Process(AbstractProcess): def get_pid_by_name(target_name: str) -> Optional[int]: for pid in Process.list_available_pids(): try: - logger.info('Checking name for pid {}'.format(pid)) + logger.debug('Checking name for pid {}'.format(pid)) with Process.open_process(pid) as process: path = process.get_path() name = os.path.basename(path) - logger.info('Name was "{}"'.format(name)) + logger.debug('Name was "{}"'.format(name)) if path is not None and name == target_name: return pid except ValueError: pass except MemEditError as err: - logger.info(repr(err)) + logger.debug(repr(err)) logger.info('Found no process with name {}'.format(target_name)) return None From c29be9f4293a70a51ff9dfafce7f5cff117bd4df Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Thu, 8 Apr 2021 19:49:55 -0700 Subject: [PATCH 2/5] strip newlines from version string --- mem_edit/VERSION.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mem_edit/VERSION.py b/mem_edit/VERSION.py index d15f477..aa70ad0 100644 --- a/mem_edit/VERSION.py +++ b/mem_edit/VERSION.py @@ -1,4 +1,4 @@ """ VERSION defintion. THIS FILE IS MANUALLY PARSED BY setup.py and REQUIRES A SPECIFIC FORMAT """ __version__ = ''' 0.5 -''' +'''.strip() From ef1a39152ccbe75e63f232f40a69448718a48abc Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Thu, 8 Apr 2021 19:50:22 -0700 Subject: [PATCH 3/5] bump version to v0.6 --- mem_edit/VERSION.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mem_edit/VERSION.py b/mem_edit/VERSION.py index aa70ad0..e4f476e 100644 --- a/mem_edit/VERSION.py +++ b/mem_edit/VERSION.py @@ -1,4 +1,4 @@ """ VERSION defintion. THIS FILE IS MANUALLY PARSED BY setup.py and REQUIRES A SPECIFIC FORMAT """ __version__ = ''' -0.5 +0.6 '''.strip() From f3154e443dc906b8bfe23c56a12dcf9b679f8f42 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Sun, 11 Jul 2021 17:25:00 -0700 Subject: [PATCH 4/5] update email --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 130ebf2..b5a234e 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ setup(name='mem_edit', long_description=long_description, long_description_content_type='text/markdown', author='Jan Petykiewicz', - author_email='anewusername@gmail.com', + author_email='jan@mpxd.net', url='https://mpxd.net/code/jan/mem_edit', keywords=[ 'memory', From 46e9456fd4ef46ee440102780067f26e58af61d8 Mon Sep 17 00:00:00 2001 From: xerool Date: Sat, 30 Apr 2022 22:37:17 -0500 Subject: [PATCH 5/5] linux: wait for process before detach, and send SIGCONT I had issues with the ptrace call failing because the process had not yet stopped from SIGSTOP. From this stackoverflow answer, it seems that you can use waitpid to wait until the process is actually stopped. In python, this is exposed as os.waitpid. https://stackoverflow.com/questions/20510300/ptrace-detach-fails-after-ptrace-cont-with-errno-esrch#20525326 Additionally, the process was left frozen. I send a SIGCONT to continue the process after the detach, so that it isn't left stopped. --- mem_edit/linux.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mem_edit/linux.py b/mem_edit/linux.py index 18f3b8f..aa25a49 100644 --- a/mem_edit/linux.py +++ b/mem_edit/linux.py @@ -58,7 +58,9 @@ class Process(AbstractProcess): def close(self): os.kill(self.pid, signal.SIGSTOP) + os.waitpid(self.pid, 0) ptrace(ptrace_commands['PTRACE_DETACH'], self.pid, 0, 0) + os.kill(self.pid, signal.SIGCONT) self.pid = None def write_memory(self, base_address: int, write_buffer: ctypes_buffer_t):