Compare commits

..

5 commits

Author SHA1 Message Date
xerool
46e9456fd4 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.
2022-04-30 22:37:17 -05:00
f3154e443d update email 2021-07-11 17:25:00 -07:00
ef1a39152c bump version to v0.6 2021-04-08 19:50:22 -07:00
c29be9f429 strip newlines from version string 2021-04-08 19:49:55 -07:00
5a032da984 try to reduce log spam 2021-04-08 19:49:19 -07:00
5 changed files with 10 additions and 11 deletions

View file

@ -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()

View file

@ -13,7 +13,6 @@ from . import utils
from .utils import ctypes_buffer_t
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

View file

@ -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__)
@ -59,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):
@ -94,14 +95,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

View file

@ -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

View file

@ -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',