Pyinstaller build not running, AttributeError: 'NoneType' object has no attribute 'origin'

Viewed 326

I'm trying to make a dll injector using pyinjector, it works running it as a .py, but when I use pyinstaller to package it all into an .exe I get this error.

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

The relevant code from the imported module 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

and finally the code I'm using.

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")

The pyinstaller command I am using to build the exe is:

pyinstaller --onefile --debug=all --add-binary extension.dll;. loader.py

Though it is important to note I've tried a variety of flags all leading to the same error.

This is pyinstaller dev version 5.0, and python 3.7.9

0 Answers
Related