naksyn / PythonMemoryModule

pure-python implementation of MemoryModule technique to load dll and unmanaged exe entirely from memory
Apache License 2.0
297 stars 46 forks source link

Fails to import dlls which can't use TLS #7

Open rkbennett opened 5 months ago

rkbennett commented 5 months ago

Specifically, cryptography.hazmat.bindings._rust.pyd does not allow for TLS, but pythonmemorymodule forces use of TLS, not sure what the solution would be here, but it isn't compatible.

naksyn commented 5 months ago

Hi, I was able to load _rust.pyd calling PyInit__rust using PythonMemoryModule. immagine

The pyd has a TLS callback and it looks like it's correctly executed: immagine

Can you elaborate on the issue you are facing?

rkbennett commented 5 months ago

I'm using python 3.11 and the pyd you get when you pip install OpenSSL with dependencies

rkbennett commented 5 months ago

I'll try to get a screenshot when I get back to my desk

rkbennett commented 5 months ago

image

This is what I'm seeing when I try to do the dll = pythonmemorymodule.MemoryModule(data=buf debug=True)

rkbennett commented 5 months ago

I've also tried importing it directly with _memimporter and it throws a different error

image

This one led me to do some searching and it appeared as though _rust wasn't meant to support TLS.

naksyn commented 5 months ago

I was able to load _rust.pyd using Python 3.10.8 and pythonmemorymodule_wininet in the Pyramid dev branch. Give it a try and let me know if that goes through also for you

rkbennett commented 5 months ago

I downloaded the pythonmemorymodule_wininet.zip file, extracted it and then imported it and tried again on python3.10.11 and still get the same error.

image

image

naksyn commented 5 months ago

I confirm that with version 3.10.10 and 3.10.8 you can successfully load the _rust.pyd contained in this archive

immagine

I don't know the nuances of _rust.pyd files compiled for other python versions. I usually stick with versions 3.10.x because that's what I tested the most.

rkbennett commented 5 months ago

How did you obtain that version of _rust.pyd?

naksyn commented 4 months ago

it's a freezed dependency for paramiko from late 2022. Check the about.py file, It's the cryptography package version 37.0.4, you can download it directly from PyPi.

rkbennett commented 4 months ago

Awesome, I'll take a look at that and give it a try