kmaork/hypno

LoadLibrary in the target process failed: win32 error code 1114

Dobatymo opened this issue · 10 comments

Using Windows 7, Python 3.8.10, hypno 1.0.3, pyinjector 1.3.0

py -m hypno <pid> "import traceback; traceback.print_stack()"

Traceback (most recent call last):
  File "C:\Program Files\Python38\lib\site-packages\pyinjector\api.py", line 71, in attach
    yield injector
  File "C:\Program Files\Python38\lib\site-packages\pyinjector\api.py", line 94, in inject
    handle = injector.inject(encoded_library_path)
injector.InjectorException: ('injector_inject', -5, 'LoadLibrary in the target process failed: win32 error code 1114')

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Program Files\Python38\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\Python38\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Program Files\Python38\lib\site-packages\hypno\__main__.py", line 20, in <module>
    main()
  File "C:\Program Files\Python38\lib\site-packages\hypno\__main__.py", line 16, in main
    inject_py(parsed_args.pid, parsed_args.python_code)
  File "C:\Program Files\Python38\lib\site-packages\hypno\api.py", line 49, in inject_py
    inject(pid, str(temp.name))
  File "C:\Program Files\Python38\lib\site-packages\pyinjector\api.py", line 97, in inject
    return handle
  File "C:\Program Files\Python38\lib\contextlib.py", line 131, in __exit__
    self.gen.throw(type, value, traceback)
  File "C:\Program Files\Python38\lib\site-packages\pyinjector\api.py", line 77, in attach
    raise exception_cls(func_name, ret_val, error_str) from e
pyinjector.api.InjectorError: Injector failed with -5 calling injector_inject: LoadLibrary in the target process failed: win32 error code 1114

Thank you for the report! I don't think I've tested on windows 7. Was the traceback printed?

Actually only the first line is printed. Something simple like "print('asd\nasd')" is printed completely (but still shows the same error message).
I also tried running hypno from non-elevated and elevated prompts. Same result.
Let me know if I can do anything to help debug if you don't have access to a Win 7 machine.

Thank you! I think it might be related to the current method I use to unload the library on windows which is a bit hacky. The fix is probably not very hard, I hope to get to try it in the next week or so.

Hey @Dobatymo, could you please try it from my branch? You can use pip install git+https://github.com/kmaork/hypno.git@windows_fix

Hi @kmaork
The error message is gone. And I think the reason that "only the first line" is printed, is that print_stack() doesn't work as I expected.
Using

from time import sleep
from traceback import print_stack
def asd():
    while True:
        print_stack()
        sleep(100)
asd()

The result is

  File "hypno_test.py", line 7, in <module>
    asd()
  File "hypno_test.py", line 5, in asd
    print_stack()  # <<< and above from the test file
  File "<string>", line 1, in <module>  # <<< from the injection

It seems the injection doesn't happen at the site of the current code execution (which is probably expected, just not by me).

Thanks for the quick fix of the error message though.

Ok great! Thank you for helping me with debugging the issue :)

hypno uses PyRun_SimpleString which according to https://docs.python.org/3/c-api/veryhigh.html#c.PyRun_SimpleStringFlags

Executes the Python source code from command in the __main__ module

So the print_stack() makes sense.

Maybe add this info to the docs.

I released hypno==1.1.0 with the fix :) Btw for easier debugging (e.g. printing nice and accurate tracebacks) you can try using madbg

madbg doesn’t support windows does it?

Currently no :(