64 #if !defined(DSO_WIN32)
73 static FARPROC GetProcAddressA(HMODULE hModule,LPCSTR lpProcName)
75 WCHAR lpProcNameW[64];
78 for (i=0;lpProcName[i] && i<64;i++)
79 lpProcNameW[i] = (WCHAR)lpProcName[i];
80 if (i==64)
return NULL;
83 return GetProcAddressW(hModule,lpProcNameW);
86 # undef GetProcAddress
87 # define GetProcAddress GetProcAddressA
89 static HINSTANCE LoadLibraryA(LPCSTR lpLibFileName)
92 size_t len_0=strlen(lpLibFileName)+1,i;
95 fnamw = (WCHAR *)_alloca (len_0*
sizeof(WCHAR));
97 fnamw = (WCHAR *)alloca (len_0*
sizeof(WCHAR));
101 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
105 #if defined(_WIN32_WCE) && _WIN32_WCE>=101
106 if (!MultiByteToWideChar(CP_ACP,0,lpLibFileName,len_0,fnamw,len_0))
108 for (i=0;i<len_0;i++) fnamw[i]=(WCHAR)lpLibFileName[i];
110 return LoadLibraryW(fnamw);
115 #define DSO_MAX_TRANSLATED_SIZE 256
117 static int win32_load(
DSO *dso);
118 static int win32_unload(
DSO *dso);
119 static void *win32_bind_var(
DSO *dso,
const char *symname);
122 static int win32_unbind_var(
DSO *dso,
char *symname,
void *symptr);
123 static int win32_unbind_func(
DSO *dso,
char *symname,
DSO_FUNC_TYPE symptr);
124 static int win32_init(
DSO *dso);
125 static int win32_finish(
DSO *dso);
126 static long win32_ctrl(
DSO *dso,
int cmd,
long larg,
void *parg);
128 static char *win32_name_converter(
DSO *dso,
const char *
filename);
129 static char *win32_merger(
DSO *dso,
const char *filespec1,
130 const char *filespec2);
131 static int win32_pathbyaddr(
void *addr,
char *path,
int sz);
132 static void *win32_globallookup(
const char *name);
134 static const char *openssl_strnchr(
const char *
string,
int c,
size_t len);
137 "OpenSSL 'win32' shared library method",
148 win32_name_converter,
158 return(&dso_meth_win32);
166 static int win32_load(
DSO *dso)
168 HINSTANCE
h = NULL, *
p = NULL;
177 h = LoadLibraryA(filename);
210 static int win32_unload(
DSO *dso)
241 static void *win32_bind_var(
DSO *dso,
const char *symname)
246 if((dso == NULL) || (symname == NULL))
262 sym = GetProcAddress(*ptr, symname);
277 if((dso == NULL) || (symname == NULL))
293 sym = GetProcAddress(*ptr, symname);
305 const char *node;
int nodelen;
306 const char *device;
int devicelen;
307 const char *predir;
int predirlen;
308 const char *dir;
int dirlen;
309 const char *
file;
int filelen;
312 static struct file_st *win32_splitter(
DSO *dso,
const char *filename,
313 int assume_last_is_dir)
315 struct file_st *result = NULL;
316 enum { IN_NODE, IN_DEVICE, IN_FILE } position;
335 memset(result, 0,
sizeof(
struct file_st));
336 position = IN_DEVICE;
338 if((filename[0] ==
'\\' && filename[1] ==
'\\')
339 || (filename[0] ==
'/' && filename[1] ==
'/'))
344 result->node = start;
353 if(position != IN_DEVICE)
361 result->device = start;
362 result->devicelen = (int)(filename - start);
369 if(position == IN_NODE)
371 result->nodelen = (int)(filename - start);
376 else if(position == IN_DEVICE)
381 result->dirlen = (int)(filename - start);
387 result->dirlen += (int)(filename - start);
392 if(position == IN_NODE)
394 result->nodelen = (int)(filename - start);
398 if(filename - start > 0)
400 if (assume_last_is_dir)
402 if (position == IN_DEVICE)
408 (int)(filename - start);
412 result->file = start;
414 (int)(filename - start);
426 if(!result->nodelen) result->node = NULL;
427 if(!result->devicelen) result->device = NULL;
428 if(!result->dirlen) result->dir = NULL;
429 if(!result->filelen) result->file = NULL;
434 static char *win32_joiner(
DSO *dso,
const struct file_st *file_split)
436 int len = 0, offset = 0;
448 len += 2 + file_split->nodelen;
449 if(file_split->predir || file_split->dir || file_split->file)
452 else if(file_split->device)
454 len += file_split->devicelen + 1;
456 len += file_split->predirlen;
457 if(file_split->predir && (file_split->dir || file_split->file))
461 len += file_split->dirlen;
462 if(file_split->dir && file_split->file)
466 len += file_split->filelen;
484 strcpy(&result[offset],
"\\\\"); offset += 2;
485 strncpy(&result[offset], file_split->node,
486 file_split->nodelen); offset += file_split->nodelen;
487 if(file_split->predir || file_split->dir || file_split->file)
489 result[offset] =
'\\'; offset++;
492 else if(file_split->device)
494 strncpy(&result[offset], file_split->device,
495 file_split->devicelen); offset += file_split->devicelen;
496 result[offset] =
':'; offset++;
498 start = file_split->predir;
499 while(file_split->predirlen > (start - file_split->predir))
501 const char *end = openssl_strnchr(start,
'/',
502 file_split->predirlen - (start - file_split->predir));
505 + file_split->predirlen
506 - (start - file_split->predir);
507 strncpy(&result[offset], start,
508 end - start); offset += (int)(end - start);
509 result[offset] =
'\\'; offset++;
514 if(file_split->predir && (file_split->dir || file_split->file))
516 result[offset] =
'\\'; offset++;
519 start = file_split->dir;
520 while(file_split->dirlen > (start - file_split->dir))
522 const char *end = openssl_strnchr(start,
'/',
523 file_split->dirlen - (start - file_split->dir));
527 - (start - file_split->dir);
528 strncpy(&result[offset], start,
529 end - start); offset += (int)(end - start);
530 result[offset] =
'\\'; offset++;
535 if(file_split->dir && file_split->file)
537 result[offset] =
'\\'; offset++;
540 strncpy(&result[offset], file_split->file,
541 file_split->filelen); offset += file_split->filelen;
542 result[offset] =
'\0';
546 static char *win32_merger(
DSO *dso,
const char *filespec1,
const char *filespec2)
549 struct file_st *filespec1_split = NULL;
550 struct file_st *filespec2_split = NULL;
552 if(!filespec1 && !filespec2)
567 strcpy(merged, filespec1);
578 strcpy(merged, filespec2);
582 filespec1_split = win32_splitter(dso, filespec1, 0);
583 if (!filespec1_split)
589 filespec2_split = win32_splitter(dso, filespec2, 1);
590 if (!filespec2_split)
599 if (!filespec1_split->node && !filespec1_split->device)
601 filespec1_split->node = filespec2_split->node;
602 filespec1_split->nodelen = filespec2_split->nodelen;
603 filespec1_split->device = filespec2_split->device;
604 filespec1_split->devicelen = filespec2_split->devicelen;
606 if (!filespec1_split->dir)
608 filespec1_split->dir = filespec2_split->dir;
609 filespec1_split->dirlen = filespec2_split->dirlen;
611 else if (filespec1_split->dir[0] !=
'\\'
612 && filespec1_split->dir[0] !=
'/')
614 filespec1_split->predir = filespec2_split->dir;
615 filespec1_split->predirlen = filespec2_split->dirlen;
617 if (!filespec1_split->file)
619 filespec1_split->file = filespec2_split->file;
620 filespec1_split->filelen = filespec2_split->filelen;
623 merged = win32_joiner(dso, filespec1_split);
630 static char *win32_name_converter(
DSO *dso,
const char *filename)
635 len = strlen(filename);
636 transform = ((strstr(filename,
"/") == NULL) &&
637 (strstr(filename,
"\\") == NULL) &&
638 (strstr(filename,
":") == NULL));
645 if(translated == NULL)
652 sprintf(translated,
"%s.dll", filename);
654 sprintf(translated,
"%s", filename);
658 static const char *openssl_strnchr(
const char *
string,
int c,
size_t len)
662 for (i = 0, p =
string; i < len && *
p; i++, p++)
672 # define DLLNAME "TOOLHELP.DLL"
674 # ifdef MODULEENTRY32
675 # undef MODULEENTRY32
677 # define DLLNAME "KERNEL32.DLL"
680 typedef HANDLE (WINAPI *CREATETOOLHELP32SNAPSHOT)(DWORD, DWORD);
681 typedef BOOL (WINAPI *CLOSETOOLHELP32SNAPSHOT)(HANDLE);
684 static int win32_pathbyaddr(
void *addr,
char *path,
int sz)
687 HANDLE hModuleSnap = INVALID_HANDLE_VALUE;
689 CREATETOOLHELP32SNAPSHOT create_snap;
690 CLOSETOOLHELP32SNAPSHOT close_snap;
691 MODULE32 module_first, module_next;
696 union { int(*
f)(
void*,
char*,int);
void *
p; }
t =
697 { win32_pathbyaddr };
701 dll = LoadLibrary(TEXT(DLLNAME));
708 create_snap = (CREATETOOLHELP32SNAPSHOT)
709 GetProcAddress(dll,
"CreateToolhelp32Snapshot");
710 if (create_snap == NULL)
718 close_snap = (CLOSETOOLHELP32SNAPSHOT)
719 GetProcAddress(dll,
"CloseToolhelp32Snapshot");
721 close_snap = (CLOSETOOLHELP32SNAPSHOT)CloseHandle;
723 module_first = (MODULE32)GetProcAddress(dll,
"Module32First");
724 module_next = (MODULE32)GetProcAddress(dll,
"Module32Next");
727 if( hModuleSnap == INVALID_HANDLE_VALUE )
734 me32.
dwSize =
sizeof(me32);
736 if(!(*module_first)(hModuleSnap,&me32))
738 (*close_snap)(hModuleSnap);
748 (*close_snap)(hModuleSnap);
751 # if _WIN32_WCE >= 101
752 return WideCharToMultiByte(CP_ACP,0,me32.
szExePath,-1,
756 if (sz <= 0)
return len+1;
757 if (len >= sz) len=sz-1;
765 if (sz <= 0)
return len+1;
766 if (len >= sz) len=sz-1;
772 }
while((*module_next)(hModuleSnap, &me32));
774 (*close_snap)(hModuleSnap);
779 static void *win32_globallookup(
const char *name)
782 HANDLE hModuleSnap = INVALID_HANDLE_VALUE;
784 CREATETOOLHELP32SNAPSHOT create_snap;
785 CLOSETOOLHELP32SNAPSHOT close_snap;
786 MODULE32 module_first, module_next;
789 dll = LoadLibrary(TEXT(DLLNAME));
796 create_snap = (CREATETOOLHELP32SNAPSHOT)
797 GetProcAddress(dll,
"CreateToolhelp32Snapshot");
798 if (create_snap == NULL)
806 close_snap = (CLOSETOOLHELP32SNAPSHOT)
807 GetProcAddress(dll,
"CloseToolhelp32Snapshot");
809 close_snap = (CLOSETOOLHELP32SNAPSHOT)CloseHandle;
811 module_first = (MODULE32)GetProcAddress(dll,
"Module32First");
812 module_next = (MODULE32)GetProcAddress(dll,
"Module32Next");
815 if( hModuleSnap == INVALID_HANDLE_VALUE )
822 me32.
dwSize =
sizeof(me32);
824 if (!(*module_first)(hModuleSnap,&me32))
826 (*close_snap)(hModuleSnap);
832 if ((ret = GetProcAddress(me32.
hModule,name)))
834 (*close_snap)(hModuleSnap);
838 }
while((*module_next)(hModuleSnap,&me32));
840 (*close_snap)(hModuleSnap);