我试图使用pyinjector创建一个dll注入器,它以.py的形式运行,但是当我使用pyinstaller将它打包成一个.exe时,我得到了这个错误。
Traceback (most recent call last):
File "loader.py", line 3, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "pyinjector\__init__.py", line 1, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "pyinjector\pyinjector.py", line 6, in <module>
AttributeError: 'NoneType' object has no attribute 'origin'
[4540] Failed to execute script loader
导入模块中的相关代码 pyinjector
:
import os
from importlib.util import find_spec
from ctypes import CDLL, Structure, POINTER, c_int32, byref, c_char_p
from typing import AnyStr, Callable, Any, Mapping, Type, Optional
libinjector_path = find_spec('.libinjector', __package__).origin
libinjector = CDLL(libinjector_path)
injector_t = type('injector_t', (Structure,), {})
injector_pointer_t = POINTER(injector_t)
pid_t = c_int32
最后是我使用的代码。
import psutil
from pyinjector import inject
# Iterate over all running process
pid = False
for proc in psutil.process_iter():
try:
# Get process name & pid from process object.
if proc.name() == "notepad.exe":
print("notepad detected, grabbing PID.")
pid = proc.pid
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
pass
if not pid:
print("notepad.exe not running.")
else:
print("Injecting.")
inject(pid, "extension.dll")
我用于生成exe的pyinstaller命令是:
pyinstaller --onefile --debug=all --add-binary extension.dll;. loader.py
尽管需要注意的是,我尝试了各种各样的标志,但都导致了相同的错误。
这是pyinstaller开发版本5.0和python 3.7.9
暂无答案!
目前还没有任何答案,快来回答吧!