srounet / Pymem

A python library for windows, providing the needed functions to start working on your own with memory editing.
MIT License
303 stars 45 forks source link

Processes sometimes have same name. Should be able to specify PID. #85

Closed chrisjd20 closed 1 year ago

chrisjd20 commented 2 years ago

Users should be able to alternatively specify a process id number instead of name only. This would allow for more specificity in the event that two processes share the same name. Cause as it stands right now, the code at:

https://github.com/srounet/Pymem/blob/0ca7f667190eed6189ea141cf59de2c2225cf242/pymem/process.py#L285-L302

Returns only the first match. Which is a problem if we want to attach to the second matching process. Additionally, it also attaches if a process name merely contains only the word specified. For example, if I wanted to attach to bigbinary.exe but I had another process named reallybigbinary.exe, its possible for it to select reallybigbinary.exe when I really wanted to attach to bigbinary.exe.

This code specifically is what im referring to

if name in process.szExeFile.decode(locale.getpreferredencoding()).lower():

This is too forgiving in my opinion. Should be along the lines of:

if name.strip() == process.szExeFile.decode(locale.getpreferredencoding()).lower().strip():

Alternatively, if you want to make this more forgiving option an argument that can be passed so both options could be chosen.

chrisjd20 commented 2 years ago

Ok so it looks like that CAN be done using a process id by specifying:

PM = pymem.Pymem()
PM.open_process_from_id(process_id)
PM.check_wow64()