Open RyanHope opened 1 week ago
Which branch are you using?
I'm on the main branch, I didn't notice the branches for specific versions. I will go test 3.10 branch, however, I ideally need to use this on 3.8.
I don't currently have one compiled for 3.8, if you put in a request for adding it I can try to put one together when I get back from out of town, but that'll be a couple weeks.
Well to be honest, I think I tested this project before I found your other. Loading a python module from mem (compiled or source) is my ultimate goal here so I think I should focus my efforts testing pythonmemimporter and od_import.
That's fair, just keep in mind stuff can get finicky, for instance Crypto and Crtyptodome have nonstandard pyds so I had to hook them in od_import. Feel free to close if you feel the issue has been resolved
Would you be able to test importing one of your cython pyds with this to see if it works, just for a comparison to pythonmemimporter
On my todo list for today.
Tested on 3.11
import sys
import importlib
import importlib.util
import py3memimporter
# from pythonmemimporter import _memimporter
# _memimporter = _memimporter()
class memory_importer(object):
def find_module(self, module, path=None):
if module == "helloworld":
return self
def load_module(self, name):
pass
def _get_module_content(file):
return open(f'D:\\temp\\{file}.cp311-win_amd64.pyd', "rb").read()
sys.meta_path.insert(0, memory_importer())
fullname = "helloworld"
fpath = "/some/fake/path/here"
spec = importlib.util.find_spec(fullname, fpath)
initname = f"PyInit_{fullname}"
mod = _memimporter.import_module(fullname, fpath, initname, _get_module_content, spec)
sys.modules[fullname] = mod
exec(f"{fullname} = sys.modules['{fullname}']")
print(helloworld.hello_world())
> python.exe .\test5.py
Traceback (most recent call last):
File "test5.py", line 25, in <module>
mod = _memimporter.import_module(fullname, fpath, initname, _get_module_content, spec)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: MemoryLoadLibrary failed loading /some/fake/path/here: The specified module could not be found. (126)
I try importing this module and after sitting for a few moments, python closes with no output.