I am trying to call some function from Kernel32.dll in my Python script running on Linux. As Johannes Weiß pointed out How to call a dll from python on Linux? I load the kernel kernel32.dll.so library through ctypes.cdll.LoadLibrary () and it loads normally. I can see that kernel32 is loaded and even has a GetLastError () function inside. However, whenever I try to call the i function, you get segfault.
import ctypes kernel32 = ctypes.cdll.LoadLibrary('/usr/lib/i386-linux-gnu/wine/kernel32.dll.so') print kernel32
At first I thought about challenging the odds, but everything seems to be in order. I am finishing testing a simple GetLastError function without any parameters, but I still get a segmentation error.
My testing system is Ubuntu 12.10, Python 2.7.3 and wine-1.4.1 (all 32 bits)
UPD
I continue testing and find several functions that I can call through ctypes without segfault. For example, I can name the functions Beep () and GetCurrentThread (), many other functions still give me segfault. I created a small C application to test the kernel32.dll.so library without python, but I have almost the same results.
int main(int argc, char **argv) { void *lib_handle; #define LOAD_LIBRARY_AS_DATAFILE 0x00000002 long (*GetCurrentThread)(void); long (*beep)(long,long); void (*sleep)(long); long (*LoadLibraryExA)(char*, long, long); long x; char *error; lib_handle = dlopen("/usr/local/lib/wine/kernel32.dll.so", RTLD_LAZY); if (!lib_handle) { fprintf(stderr, "%s\n", dlerror()); exit(1); }
I tried to use various calling conventions for the Sleep () function, but also no luck. When I compare function declarations \ implementations in Wine sources, they are essentially the same
ads
HANDLE WINAPI GetCurrentThread(void) // http://source.winehq.org/source/dlls/kernel32/thread.c#L573 BOOL WINAPI Beep( DWORD dwFreq, DWORD dwDur ) // http://source.winehq.org/source/dlls/kernel32/console.c#L354 HMODULE WINAPI DECLSPEC_HOTPATCH LoadLibraryExA(LPCSTR libname, HANDLE hfile, DWORD flags) // http://source.winehq.org/source/dlls/kernel32/module.c#L928 VOID WINAPI DECLSPEC_HOTPATCH Sleep( DWORD timeout ) // http://source.winehq.org/source/dlls/kernel32/sync.c#L95 WINAPI is defined to be __stdcall
However, some of them work, and some do not. Since I can understand that these are sources for the kernel32.dll file, and the kernel32.dll.so file is some kind of proxy server that should provide access to kernel32.dll for linux code. I probably need to find the exact sources of the kernel32.dll.so file and take a look at the ads.
Is there any tool I can use to look inside the .so file and find out what features and conventions are used?