pleiszenburg / zugbruecke

Calling routines in Windows DLLs from Python scripts running under Linux, MacOS or BSD
https://zugbruecke.readthedocs.io/en/latest/
GNU Lesser General Public License v2.1
108 stars 11 forks source link

OSError : [Errno 8] Bad EXE format for %1 #79

Open iwTao opened 2 years ago

iwTao commented 2 years ago

hello,i have a DLL file needed load by zurbruecke in Ubuntu, but when i loading file use zugbruecke.windll.LoadLibrary, python will report [Errno 8] Bad EXE format for %1to me. What should I do for this Error?

s-m-e commented 2 years ago

Can you configure the log_level to its maximum of 10 and post the complete output?

iwTao commented 2 years ago

There is the log

(1639896579.08/877d3127) UNIX o: [session-client] STARTING (STAGE 1) ...
(1639896579.09/877d3127) UNIX o: [session-client] Configured Wine-Python version is 3.5.3 for win32.
(1639896579.09/877d3127) UNIX o: [session-client] Log socket port: 39819.
(1639896579.09/877d3127) UNIX o: [session-client] STARTED (STAGE 1).
(1639896579.09/877d3127) UNIX o: [session-client] STARTING (STAGE 2) ...
(1639896579.09/877d3127) UNIX o: [interpreter] STARTING ...
(1639896579.09/877d3127) UNIX o: [interpreter] Command: wine /root/.zugbruecke/win32-python3.5.3/python.exe /usr/local/lib/python3.6/site-packages/zugbruecke/_server_.py --id 877d3127 --port_socket_wine 57203 --port_socket_unix 39819 --log_level 10 --log_write 1
(1639896579.09/877d3127) UNIX o: [interpreter] Started with PID 5251.
(1639896579.18/877d3127) UNIX o: [interpreter] Logging threads started.
(1639896579.18/877d3127) UNIX o: [interpreter] STARTED.
(1639896579.18/877d3127) UNIX o: [session-client] Waiting for session-server to be up ...
(1639896579.34/877d3127) WINE o: [session-server] STARTING ...
(1639896579.34/877d3127) WINE o: [mp-server] STARTING ...
(1639896579.34/877d3127) WINE o: [mp-server] Log attached.
(1639896579.34/877d3127) WINE o: [mp-server] STARTED.
(1639896579.34/877d3127) WINE o: [session-server] ctypes server is listening on port 57203.
(1639896579.34/877d3127) WINE o: [session-server] STARTED.
(1639896579.35/877d3127) WINE o: [session-server] Serve forever ...
(1639896579.36/877d3127) UNIX o: [session-client] ... session server is up (after 0.17 seconds).
(1639896579.36/877d3127) UNIX o: [session-client] STARTED (STAGE 2).
(1639896579.36/877d3127) UNIX o: [session-client] Attaching to DLL file "/home/klipper-us/uwc400/UWC4000.dll" with calling convention "windll" ...
(1639896579.36/877d3127) WINE o: [session-server] Attaching to DLL file "/home/klipper-us/uwc400/UWC4000.dll" with calling convention "windll" ...
(1639896579.36/877d3127) WINE o: [session-server] ... failed!
(1639896579.36/877d3127) UNIX o: [session-client] ... failed!
s-m-e commented 2 years ago

Thanks.

It could be a DLL that uses a different "calling convention". Try cdll instead of windll (although this error should not show at the time of attaching to the DLL but only a little later).

Or, most likely, it could be a 32 bit vs 64 bit issue. zugbruecke runs Wine in 32 bit mode by default. You can configure zugbruecke to run in 64 bit mode, assuming that you are dealing with a 64 bit DLL file.

Last but not least, I'd suspect that there is some issue with UWC4000.dll itself. It could simply be a broken/corrupted file.

jayhop commented 2 years ago

Hi @s-m-e. I have a similar issue. Using cdll instead of windll results in the following error:

import zugbruecke
dll_path = './test.dll'
isolib = zugbruecke.cdll.LoadLibrary(dll_path)
OSError: ./test.dll: invalid ELF header

Your other suggestion leads to the same error

import zugbruecke

zugbruecke.session({"log_level": 10, "arch": 'win64'})
dll_path = './test.dll'
isolib = zugbruecke.windll.LoadLibrary(dll_path)
(1648216507.31/bd1b8f2d) UNIX o: [session-client] STARTING (STAGE 1) ...
(1648216507.31/bd1b8f2d) UNIX o: [session-client] Configured Wine-Python version is 3.5.3 for win64.
(1648216507.31/bd1b8f2d) UNIX o: [session-client] Log socket port: 51263.
(1648216507.31/bd1b8f2d) UNIX o: [session-client] STARTED (STAGE 1).
OSError: [Errno 8] Bad EXE format for %1
(1648216514.82/bd1b8f2d) UNIX o: [session-client] TERMINATING ...
(1648216514.82/bd1b8f2d) UNIX o: [session-client] TERMINATED.

System information

s-m-e commented 2 years ago

@jayhop Interesting. Would you be able to share a reproducible example, i.e. code and the DLL, with me - so I can have a closer look at it directly?

jayhop commented 2 years ago

Unfortunately, I can't due to copyright issues. I'll try to create and post another example later this week or next.

s-m-e commented 2 years ago

@jayhop and @iwTao If your examples can be discussed under NDA perhaps feel free to reach out. I am still looking for a reliable way to reproduce this bug.

jayhop commented 1 year ago

@s-m-e Sorry for my late reply! I've added you to a private repo. I hope you can reproduce this bug.

s-m-e commented 1 year ago

@jayhop Thanks! Will look into it.

s-m-e commented 1 year ago

@jayhop Did a lot of cleanup, repaired CI etc and will release v0.1.0 today. I'll use this to bisect your issue.

jayhop commented 1 year ago

@jayhop Did a lot of cleanup, repaired CI etc and will release v0.1.0 today. I'll use this to bisect your issue.

Thanks for the update :pray:.

s-m-e commented 1 year ago

@jayhop Findings so far: zugbruecke wont attach to your DLL file. However, it's not zugbruecke itself, it is ctypes underneath that does not want to. zugbruecke (on Linux) correctly reports what ctypes (on Wine) complains about. I have started a Windows version of Python on top of Wine directly, effectively eliminating zugbruecke from the equation - same result. It is worth noting that (C)Python changed its FFI (foreign function interface) implementation between versions 3.7 and 3.8. In other words, the mechanism that ctypes depends on changed between those two versions. Interestingly, both throw different exceptions, but ultimately, both do not want to attach to your DLL. I have one last thing on my list, testing this on an actual Windows system, but I suspect that your DLL is somehow broken or uses some non-standard interface mechanism.

jayhop commented 1 year ago

@s-m-e that's suprising. Is it possible that the library VCRUNTIME140_APP.dll is missing in wine? Since my DLL depends on that.