srounet / Pymem

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

Python interpreter injection #118

Open Chassss opened 7 months ago

Chassss commented 7 months ago

Describe the bug Whenever injecting the python interpreter into any process theres a good 50/50 chance it'll crash the program, been dealing with this ever since 3.11 came out because i didnt wanna reinstall 3.10 specifically for pymem

Your Environment

  1. python version - happens in both 3.11.5 and 3.12.0
  2. os version - Windows 11 10.0.22621 Build 2261
  3. pymem version - 1.12.0 and 1.13.0 although version of pymem shouldnt matter

Expected behavior The python interpreter sucessfully injects without crashing the program

Traceback The only traceback that happens is

raise RuntimeError('Could not allocate memory for shellcode') RuntimeError: Could not allocate memory for shellcode

ctypes.getlasterror returns 5 (access denied) because the python interpreter crashed the program so its trying to write to a non existent process

theirs no traceback when injecting the python interpreter

StarrFox commented 5 months ago

I've done some debugging on this and was able to reproduce the crashes with 3.12 but not 3.11; from what I've gathered from debugging the process we're injecting into it seems that the global object allocator is not being set for some reason

it should be getting set by our initialize call which I've confirmed is being called

devvratmiglani commented 1 week ago

Is there any fix to this. I don't want to use any other lib for python as of now and injecting the interpreter seems to me as the only reason to use pymem.

It's because it's wayyy too good, but it doesn't work unfortunately.