pyinjector icon indicating copy to clipboard operation
pyinjector copied to clipboard

Failure to inject on Mac

Open kmaork opened this issue 2 years ago • 9 comments

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.

kmaork avatar Jul 11 '23 21:07 kmaork

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 ?

icoco avatar Jul 14 '23 02:07 icoco

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

kmaork avatar Jul 14 '23 11:07 kmaork

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 ?

icoco avatar Jul 16 '23 14:07 icoco

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?

kmaork avatar Jul 18 '23 18:07 kmaork

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 avatar Jul 19 '23 03:07 icoco

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

icoco avatar Aug 21 '23 14:08 icoco

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!

itay-sho avatar Sep 20 '23 18:09 itay-sho

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

icoco avatar Feb 22 '24 03:02 icoco