PythonMemoryModule icon indicating copy to clipboard operation
PythonMemoryModule copied to clipboard

Fails to import dlls which can't use TLS

Open rkbennett opened this issue 1 year ago • 11 comments

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.

rkbennett avatar Jun 20 '24 15:06 rkbennett

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?

naksyn avatar Jun 20 '24 18:06 naksyn

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

rkbennett avatar Jun 20 '24 18:06 rkbennett

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

rkbennett avatar Jun 20 '24 18:06 rkbennett

image

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

rkbennett avatar Jun 20 '24 19:06 rkbennett

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.

rkbennett avatar Jun 20 '24 20:06 rkbennett

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

naksyn avatar Jun 20 '24 20:06 naksyn

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

rkbennett avatar Jun 20 '24 20:06 rkbennett

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.

naksyn avatar Jun 20 '24 22:06 naksyn

How did you obtain that version of _rust.pyd?

rkbennett avatar Jun 21 '24 12:06 rkbennett

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.

naksyn avatar Jun 24 '24 07:06 naksyn

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

rkbennett avatar Jul 10 '24 21:07 rkbennett

How about this? DD.zip

DEBUG: execute 0
DEBUG: read 1
DEBUG: write 0
DEBUG: physaddr:0x826f000
DEBUG: Executing TLS.
DEBUG: no TLS address found
DEBUG: Starting new thread to execute PE
DEBUG: Checking for entry point.
DEBUG: Calling dll entrypoint 0x819588c with DLL_PROCESS_ATTACH

Then the script terminated.

Could you tell me if there exists any workaround? Thanks!

JiaPai12138 avatar Mar 19 '25 02:03 JiaPai12138