kmaork / pyinjector

Inject shared libraries into running processes
MIT License
86 stars 16 forks source link

Failure to inject on Mac #26

Open kmaork opened 1 year ago

kmaork commented 1 year ago

You may get this when trying to inject on Mac: pyinjector.api.MacUnknownInjectorError: injector_attach returned -1: TASK_FOR_PID error : (os/kern) failure This should be resolved by rerunning as root. Please comment here if it doesn't solved the issue or if you need to be able to run without root. Please state how you installed pyinjector.

icoco commented 1 year ago

use hypno, also sudo pip install hypno success , run command bellow

sudo hypno 7004 "import os; print('Hello again from', os.getpid())"                            

but throw error bellows:

raise exception_cls(func.__name__, ret, libinjector.injector_error())
pyinjector.api.MacUnknownInjectorError: injector_attach returned -1: TASK_FOR_PID error : (os/kern) failure
Mac restricts injection for security reasons. Please report this error in the issue:
https://github.com/kmaork/pyinjector/issues/26

again, use Macbook Pro M1, it could support ?

kmaork commented 1 year ago

Hey @icoco, can you please try running again, and if it fails, run ps -fp <the pid> and post the output here?

icoco commented 1 year ago

try

sudo hypno 68523 "import os; print('Hello again from', os.getpid())"

throw

    raise exception_cls(func.__name__, ret, libinjector.injector_error())
pyinjector.api.MacUnknownInjectorError: injector_attach returned -1: TASK_FOR_PID error : (os/kern) failure

and ps -fp result bellows :

ps -fp 68523
  UID   PID  PPID   C STIME   TTY           TIME CMD
  501 68523 16847   0 10:42PM ??         0:00.07 /py/Inject/env/bin/Python /py/Inject/app/test.py

should do Disable System Integrity Protection Temporarily ?

kmaork commented 1 year ago

Thanks for checking. You can try temporarily disabling SIP, that would be helpful to make sure that it is indeed the root cause.

Also, how did you install python? Where did this /py/Inject/env/bin/Python come from?

icoco commented 1 year ago

it work under virtualenv, so '/py/Inject/env/bin/Python' accurate point to the inner python of xcode

` /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/Resources/Python.app/Contents/MacOS/Python /py/Inject/app/test.py

`

icoco commented 1 year ago

it works, cause different python was installed on the computer, thanks for your time !

itay-sho commented 1 year ago

it works, cause different python was installed on the computer, thanks for your time !

I think I experience the same problem with my M1 Mac, can you please elaborate more what was the problem and how to overcome it?

Thanks!

icoco commented 7 months ago

it works, cause different python was installed on the computer, thanks for your time !

I think I experience the same problem with my M1 Mac, can you please elaborate more what was the problem and how to overcome it?

Thanks! sorry reply later,

I think that cause use different Python environment, assume the computer installed two version python on different location, maybe : '/Library/Frameworks/Python.framework/Versions/3.11/Resources/Python.app/Contents/MacOS/Python' and '/opt/homebrew/lib/python3.9/',

the target python application which need be injected use first, but the while inject command 'sudo hypno {process_id} xxx' , it use another, then nothing can be injected

once I make it works on the same , in fact should use ''/opt/homebrew/lib/python3.9' , then it works as expectation

hope this is helpful