dso_win32.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. /*
  2. * Copyright 2000-2022 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include "internal/e_os.h"
  10. #include "dso_local.h"
  11. #if defined(DSO_WIN32)
  12. # ifdef _WIN32_WCE
  13. # if _WIN32_WCE < 300
  14. static FARPROC GetProcAddressA(HMODULE hModule, LPCSTR lpProcName)
  15. {
  16. WCHAR lpProcNameW[64];
  17. int i;
  18. for (i = 0; lpProcName[i] && i < 64; i++)
  19. lpProcNameW[i] = (WCHAR)lpProcName[i];
  20. if (i == 64)
  21. return NULL;
  22. lpProcNameW[i] = 0;
  23. return GetProcAddressW(hModule, lpProcNameW);
  24. }
  25. # endif
  26. # undef GetProcAddress
  27. # define GetProcAddress GetProcAddressA
  28. static HINSTANCE LoadLibraryA(LPCSTR lpLibFileName)
  29. {
  30. WCHAR *fnamw;
  31. size_t len_0 = strlen(lpLibFileName) + 1, i;
  32. # ifdef _MSC_VER
  33. fnamw = (WCHAR *)_alloca(len_0 * sizeof(WCHAR));
  34. # else
  35. fnamw = (WCHAR *)alloca(len_0 * sizeof(WCHAR));
  36. # endif
  37. if (fnamw == NULL) {
  38. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  39. return NULL;
  40. }
  41. # if defined(_WIN32_WCE) && _WIN32_WCE>=101
  42. if (!MultiByteToWideChar(CP_ACP, 0, lpLibFileName, len_0, fnamw, len_0))
  43. # endif
  44. for (i = 0; i < len_0; i++)
  45. fnamw[i] = (WCHAR)lpLibFileName[i];
  46. return LoadLibraryW(fnamw);
  47. }
  48. # endif
  49. /* Part of the hack in "win32_load" ... */
  50. # define DSO_MAX_TRANSLATED_SIZE 256
  51. static int win32_load(DSO *dso);
  52. static int win32_unload(DSO *dso);
  53. static DSO_FUNC_TYPE win32_bind_func(DSO *dso, const char *symname);
  54. static char *win32_name_converter(DSO *dso, const char *filename);
  55. static char *win32_merger(DSO *dso, const char *filespec1,
  56. const char *filespec2);
  57. static int win32_pathbyaddr(void *addr, char *path, int sz);
  58. static void *win32_globallookup(const char *name);
  59. static const char *openssl_strnchr(const char *string, int c, size_t len);
  60. static DSO_METHOD dso_meth_win32 = {
  61. "OpenSSL 'win32' shared library method",
  62. win32_load,
  63. win32_unload,
  64. win32_bind_func,
  65. NULL, /* ctrl */
  66. win32_name_converter,
  67. win32_merger,
  68. NULL, /* init */
  69. NULL, /* finish */
  70. win32_pathbyaddr, /* pathbyaddr */
  71. win32_globallookup
  72. };
  73. DSO_METHOD *DSO_METHOD_openssl(void)
  74. {
  75. return &dso_meth_win32;
  76. }
  77. /*
  78. * For this DSO_METHOD, our meth_data STACK will contain; (i) a pointer to
  79. * the handle (HINSTANCE) returned from LoadLibrary(), and copied.
  80. */
  81. static int win32_load(DSO *dso)
  82. {
  83. HINSTANCE h = NULL, *p = NULL;
  84. /* See applicable comments from dso_dl.c */
  85. char *filename = DSO_convert_filename(dso, NULL);
  86. if (filename == NULL) {
  87. ERR_raise(ERR_LIB_DSO, DSO_R_NO_FILENAME);
  88. goto err;
  89. }
  90. h = LoadLibraryA(filename);
  91. if (h == NULL) {
  92. ERR_raise_data(ERR_LIB_DSO, DSO_R_LOAD_FAILED,
  93. "filename(%s)", filename);
  94. goto err;
  95. }
  96. p = OPENSSL_malloc(sizeof(*p));
  97. if (p == NULL)
  98. goto err;
  99. *p = h;
  100. if (!sk_void_push(dso->meth_data, p)) {
  101. ERR_raise(ERR_LIB_DSO, DSO_R_STACK_ERROR);
  102. goto err;
  103. }
  104. /* Success */
  105. dso->loaded_filename = filename;
  106. return 1;
  107. err:
  108. /* Cleanup ! */
  109. OPENSSL_free(filename);
  110. OPENSSL_free(p);
  111. if (h != NULL)
  112. FreeLibrary(h);
  113. return 0;
  114. }
  115. static int win32_unload(DSO *dso)
  116. {
  117. HINSTANCE *p;
  118. if (dso == NULL) {
  119. ERR_raise(ERR_LIB_DSO, ERR_R_PASSED_NULL_PARAMETER);
  120. return 0;
  121. }
  122. if (sk_void_num(dso->meth_data) < 1)
  123. return 1;
  124. p = sk_void_pop(dso->meth_data);
  125. if (p == NULL) {
  126. ERR_raise(ERR_LIB_DSO, DSO_R_NULL_HANDLE);
  127. return 0;
  128. }
  129. if (!FreeLibrary(*p)) {
  130. ERR_raise(ERR_LIB_DSO, DSO_R_UNLOAD_FAILED);
  131. /*
  132. * We should push the value back onto the stack in case of a retry.
  133. */
  134. sk_void_push(dso->meth_data, p);
  135. return 0;
  136. }
  137. /* Cleanup */
  138. OPENSSL_free(p);
  139. return 1;
  140. }
  141. static DSO_FUNC_TYPE win32_bind_func(DSO *dso, const char *symname)
  142. {
  143. HINSTANCE *ptr;
  144. union {
  145. void *p;
  146. FARPROC f;
  147. } sym;
  148. if ((dso == NULL) || (symname == NULL)) {
  149. ERR_raise(ERR_LIB_DSO, ERR_R_PASSED_NULL_PARAMETER);
  150. return NULL;
  151. }
  152. if (sk_void_num(dso->meth_data) < 1) {
  153. ERR_raise(ERR_LIB_DSO, DSO_R_STACK_ERROR);
  154. return NULL;
  155. }
  156. ptr = sk_void_value(dso->meth_data, sk_void_num(dso->meth_data) - 1);
  157. if (ptr == NULL) {
  158. ERR_raise(ERR_LIB_DSO, DSO_R_NULL_HANDLE);
  159. return NULL;
  160. }
  161. sym.f = GetProcAddress(*ptr, symname);
  162. if (sym.p == NULL) {
  163. ERR_raise_data(ERR_LIB_DSO, DSO_R_SYM_FAILURE, "symname(%s)", symname);
  164. return NULL;
  165. }
  166. return (DSO_FUNC_TYPE)sym.f;
  167. }
  168. struct file_st {
  169. const char *node;
  170. int nodelen;
  171. const char *device;
  172. int devicelen;
  173. const char *predir;
  174. int predirlen;
  175. const char *dir;
  176. int dirlen;
  177. const char *file;
  178. int filelen;
  179. };
  180. static struct file_st *win32_splitter(DSO *dso, const char *filename,
  181. int assume_last_is_dir)
  182. {
  183. struct file_st *result = NULL;
  184. enum { IN_NODE, IN_DEVICE, IN_FILE } position;
  185. const char *start = filename;
  186. char last;
  187. if (!filename) {
  188. ERR_raise(ERR_LIB_DSO, DSO_R_NO_FILENAME);
  189. return NULL;
  190. }
  191. result = OPENSSL_zalloc(sizeof(*result));
  192. if (result == NULL)
  193. return NULL;
  194. position = IN_DEVICE;
  195. if ((filename[0] == '\\' && filename[1] == '\\')
  196. || (filename[0] == '/' && filename[1] == '/')) {
  197. position = IN_NODE;
  198. filename += 2;
  199. start = filename;
  200. result->node = start;
  201. }
  202. do {
  203. last = filename[0];
  204. switch (last) {
  205. case ':':
  206. if (position != IN_DEVICE) {
  207. ERR_raise(ERR_LIB_DSO, DSO_R_INCORRECT_FILE_SYNTAX);
  208. OPENSSL_free(result);
  209. return NULL;
  210. }
  211. result->device = start;
  212. result->devicelen = (int)(filename - start);
  213. position = IN_FILE;
  214. start = ++filename;
  215. result->dir = start;
  216. break;
  217. case '\\':
  218. case '/':
  219. if (position == IN_NODE) {
  220. result->nodelen = (int)(filename - start);
  221. position = IN_FILE;
  222. start = ++filename;
  223. result->dir = start;
  224. } else if (position == IN_DEVICE) {
  225. position = IN_FILE;
  226. filename++;
  227. result->dir = start;
  228. result->dirlen = (int)(filename - start);
  229. start = filename;
  230. } else {
  231. filename++;
  232. result->dirlen += (int)(filename - start);
  233. start = filename;
  234. }
  235. break;
  236. case '\0':
  237. if (position == IN_NODE) {
  238. result->nodelen = (int)(filename - start);
  239. } else {
  240. if (filename - start > 0) {
  241. if (assume_last_is_dir) {
  242. if (position == IN_DEVICE) {
  243. result->dir = start;
  244. result->dirlen = 0;
  245. }
  246. result->dirlen += (int)(filename - start);
  247. } else {
  248. result->file = start;
  249. result->filelen = (int)(filename - start);
  250. }
  251. }
  252. }
  253. break;
  254. default:
  255. filename++;
  256. break;
  257. }
  258. }
  259. while (last);
  260. if (!result->nodelen)
  261. result->node = NULL;
  262. if (!result->devicelen)
  263. result->device = NULL;
  264. if (!result->dirlen)
  265. result->dir = NULL;
  266. if (!result->filelen)
  267. result->file = NULL;
  268. return result;
  269. }
  270. static char *win32_joiner(DSO *dso, const struct file_st *file_split)
  271. {
  272. int len = 0, offset = 0;
  273. char *result = NULL;
  274. const char *start;
  275. if (!file_split) {
  276. ERR_raise(ERR_LIB_DSO, ERR_R_PASSED_NULL_PARAMETER);
  277. return NULL;
  278. }
  279. if (file_split->node) {
  280. len += 2 + file_split->nodelen; /* 2 for starting \\ */
  281. if (file_split->predir || file_split->dir || file_split->file)
  282. len++; /* 1 for ending \ */
  283. } else if (file_split->device) {
  284. len += file_split->devicelen + 1; /* 1 for ending : */
  285. }
  286. len += file_split->predirlen;
  287. if (file_split->predir && (file_split->dir || file_split->file)) {
  288. len++; /* 1 for ending \ */
  289. }
  290. len += file_split->dirlen;
  291. if (file_split->dir && file_split->file) {
  292. len++; /* 1 for ending \ */
  293. }
  294. len += file_split->filelen;
  295. if (!len) {
  296. ERR_raise(ERR_LIB_DSO, DSO_R_EMPTY_FILE_STRUCTURE);
  297. return NULL;
  298. }
  299. result = OPENSSL_malloc(len + 1);
  300. if (result == NULL)
  301. return NULL;
  302. if (file_split->node) {
  303. strcpy(&result[offset], "\\\\");
  304. offset += 2;
  305. strncpy(&result[offset], file_split->node, file_split->nodelen);
  306. offset += file_split->nodelen;
  307. if (file_split->predir || file_split->dir || file_split->file) {
  308. result[offset] = '\\';
  309. offset++;
  310. }
  311. } else if (file_split->device) {
  312. strncpy(&result[offset], file_split->device, file_split->devicelen);
  313. offset += file_split->devicelen;
  314. result[offset] = ':';
  315. offset++;
  316. }
  317. start = file_split->predir;
  318. while (file_split->predirlen > (start - file_split->predir)) {
  319. const char *end = openssl_strnchr(start, '/',
  320. file_split->predirlen - (start -
  321. file_split->predir));
  322. if (!end)
  323. end = start
  324. + file_split->predirlen - (start - file_split->predir);
  325. strncpy(&result[offset], start, end - start);
  326. offset += (int)(end - start);
  327. result[offset] = '\\';
  328. offset++;
  329. start = end + 1;
  330. }
  331. start = file_split->dir;
  332. while (file_split->dirlen > (start - file_split->dir)) {
  333. const char *end = openssl_strnchr(start, '/',
  334. file_split->dirlen - (start -
  335. file_split->dir));
  336. if (!end)
  337. end = start + file_split->dirlen - (start - file_split->dir);
  338. strncpy(&result[offset], start, end - start);
  339. offset += (int)(end - start);
  340. result[offset] = '\\';
  341. offset++;
  342. start = end + 1;
  343. }
  344. strncpy(&result[offset], file_split->file, file_split->filelen);
  345. offset += file_split->filelen;
  346. result[offset] = '\0';
  347. return result;
  348. }
  349. static char *win32_merger(DSO *dso, const char *filespec1,
  350. const char *filespec2)
  351. {
  352. char *merged = NULL;
  353. struct file_st *filespec1_split = NULL;
  354. struct file_st *filespec2_split = NULL;
  355. if (!filespec1 && !filespec2) {
  356. ERR_raise(ERR_LIB_DSO, ERR_R_PASSED_NULL_PARAMETER);
  357. return NULL;
  358. }
  359. if (!filespec2) {
  360. merged = OPENSSL_strdup(filespec1);
  361. if (merged == NULL)
  362. return NULL;
  363. } else if (!filespec1) {
  364. merged = OPENSSL_strdup(filespec2);
  365. if (merged == NULL)
  366. return NULL;
  367. } else {
  368. filespec1_split = win32_splitter(dso, filespec1, 0);
  369. if (!filespec1_split) {
  370. ERR_raise(ERR_LIB_DSO, ERR_R_DSO_LIB);
  371. return NULL;
  372. }
  373. filespec2_split = win32_splitter(dso, filespec2, 1);
  374. if (!filespec2_split) {
  375. ERR_raise(ERR_LIB_DSO, ERR_R_DSO_LIB);
  376. OPENSSL_free(filespec1_split);
  377. return NULL;
  378. }
  379. /* Fill in into filespec1_split */
  380. if (!filespec1_split->node && !filespec1_split->device) {
  381. filespec1_split->node = filespec2_split->node;
  382. filespec1_split->nodelen = filespec2_split->nodelen;
  383. filespec1_split->device = filespec2_split->device;
  384. filespec1_split->devicelen = filespec2_split->devicelen;
  385. }
  386. if (!filespec1_split->dir) {
  387. filespec1_split->dir = filespec2_split->dir;
  388. filespec1_split->dirlen = filespec2_split->dirlen;
  389. } else if (filespec1_split->dir[0] != '\\'
  390. && filespec1_split->dir[0] != '/') {
  391. filespec1_split->predir = filespec2_split->dir;
  392. filespec1_split->predirlen = filespec2_split->dirlen;
  393. }
  394. if (!filespec1_split->file) {
  395. filespec1_split->file = filespec2_split->file;
  396. filespec1_split->filelen = filespec2_split->filelen;
  397. }
  398. merged = win32_joiner(dso, filespec1_split);
  399. }
  400. OPENSSL_free(filespec1_split);
  401. OPENSSL_free(filespec2_split);
  402. return merged;
  403. }
  404. static char *win32_name_converter(DSO *dso, const char *filename)
  405. {
  406. char *translated;
  407. int len, transform;
  408. transform = ((strstr(filename, "/") == NULL) &&
  409. (strstr(filename, "\\") == NULL) &&
  410. (strstr(filename, ":") == NULL));
  411. /* If transform != 0, then we convert to %s.dll, else just dupe filename */
  412. len = strlen(filename) + 1;
  413. if (transform)
  414. len += strlen(".dll");
  415. translated = OPENSSL_malloc(len);
  416. if (translated == NULL) {
  417. ERR_raise(ERR_LIB_DSO, DSO_R_NAME_TRANSLATION_FAILED);
  418. return NULL;
  419. }
  420. BIO_snprintf(translated, len, "%s%s", filename, transform ? ".dll" : "");
  421. return translated;
  422. }
  423. static const char *openssl_strnchr(const char *string, int c, size_t len)
  424. {
  425. size_t i;
  426. const char *p;
  427. for (i = 0, p = string; i < len && *p; i++, p++) {
  428. if (*p == c)
  429. return p;
  430. }
  431. return NULL;
  432. }
  433. # include <tlhelp32.h>
  434. # ifdef _WIN32_WCE
  435. # define DLLNAME "TOOLHELP.DLL"
  436. # else
  437. # ifdef MODULEENTRY32
  438. # undef MODULEENTRY32 /* unmask the ASCII version! */
  439. # endif
  440. # define DLLNAME "KERNEL32.DLL"
  441. # endif
  442. typedef HANDLE(WINAPI *CREATETOOLHELP32SNAPSHOT) (DWORD, DWORD);
  443. typedef BOOL(WINAPI *CLOSETOOLHELP32SNAPSHOT) (HANDLE);
  444. typedef BOOL(WINAPI *MODULE32) (HANDLE, MODULEENTRY32 *);
  445. static int win32_pathbyaddr(void *addr, char *path, int sz)
  446. {
  447. HMODULE dll;
  448. HANDLE hModuleSnap = INVALID_HANDLE_VALUE;
  449. MODULEENTRY32 me32;
  450. CREATETOOLHELP32SNAPSHOT create_snap;
  451. CLOSETOOLHELP32SNAPSHOT close_snap;
  452. MODULE32 module_first, module_next;
  453. if (addr == NULL) {
  454. union {
  455. int (*f) (void *, char *, int);
  456. void *p;
  457. } t = {
  458. win32_pathbyaddr
  459. };
  460. addr = t.p;
  461. }
  462. dll = LoadLibrary(TEXT(DLLNAME));
  463. if (dll == NULL) {
  464. ERR_raise(ERR_LIB_DSO, DSO_R_UNSUPPORTED);
  465. return -1;
  466. }
  467. create_snap = (CREATETOOLHELP32SNAPSHOT)
  468. GetProcAddress(dll, "CreateToolhelp32Snapshot");
  469. if (create_snap == NULL) {
  470. FreeLibrary(dll);
  471. ERR_raise(ERR_LIB_DSO, DSO_R_UNSUPPORTED);
  472. return -1;
  473. }
  474. /* We take the rest for granted... */
  475. # ifdef _WIN32_WCE
  476. close_snap = (CLOSETOOLHELP32SNAPSHOT)
  477. GetProcAddress(dll, "CloseToolhelp32Snapshot");
  478. # else
  479. close_snap = (CLOSETOOLHELP32SNAPSHOT) CloseHandle;
  480. # endif
  481. module_first = (MODULE32) GetProcAddress(dll, "Module32First");
  482. module_next = (MODULE32) GetProcAddress(dll, "Module32Next");
  483. /*
  484. * Take a snapshot of current process which includes
  485. * list of all involved modules.
  486. */
  487. hModuleSnap = (*create_snap) (TH32CS_SNAPMODULE, 0);
  488. if (hModuleSnap == INVALID_HANDLE_VALUE) {
  489. FreeLibrary(dll);
  490. ERR_raise(ERR_LIB_DSO, DSO_R_UNSUPPORTED);
  491. return -1;
  492. }
  493. me32.dwSize = sizeof(me32);
  494. if (!(*module_first) (hModuleSnap, &me32)) {
  495. (*close_snap) (hModuleSnap);
  496. FreeLibrary(dll);
  497. ERR_raise(ERR_LIB_DSO, DSO_R_FAILURE);
  498. return -1;
  499. }
  500. /* Enumerate the modules to find one which includes me. */
  501. do {
  502. if ((size_t) addr >= (size_t) me32.modBaseAddr &&
  503. (size_t) addr < (size_t) (me32.modBaseAddr + me32.modBaseSize)) {
  504. (*close_snap) (hModuleSnap);
  505. FreeLibrary(dll);
  506. # ifdef _WIN32_WCE
  507. # if _WIN32_WCE >= 101
  508. return WideCharToMultiByte(CP_ACP, 0, me32.szExePath, -1,
  509. path, sz, NULL, NULL);
  510. # else
  511. {
  512. int i, len = (int)wcslen(me32.szExePath);
  513. if (sz <= 0)
  514. return len + 1;
  515. if (len >= sz)
  516. len = sz - 1;
  517. for (i = 0; i < len; i++)
  518. path[i] = (char)me32.szExePath[i];
  519. path[len++] = '\0';
  520. return len;
  521. }
  522. # endif
  523. # else
  524. {
  525. int len = (int)strlen(me32.szExePath);
  526. if (sz <= 0)
  527. return len + 1;
  528. if (len >= sz)
  529. len = sz - 1;
  530. memcpy(path, me32.szExePath, len);
  531. path[len++] = '\0';
  532. return len;
  533. }
  534. # endif
  535. }
  536. } while ((*module_next) (hModuleSnap, &me32));
  537. (*close_snap) (hModuleSnap);
  538. FreeLibrary(dll);
  539. return 0;
  540. }
  541. static void *win32_globallookup(const char *name)
  542. {
  543. HMODULE dll;
  544. HANDLE hModuleSnap = INVALID_HANDLE_VALUE;
  545. MODULEENTRY32 me32;
  546. CREATETOOLHELP32SNAPSHOT create_snap;
  547. CLOSETOOLHELP32SNAPSHOT close_snap;
  548. MODULE32 module_first, module_next;
  549. union {
  550. void *p;
  551. FARPROC f;
  552. } ret = { NULL };
  553. dll = LoadLibrary(TEXT(DLLNAME));
  554. if (dll == NULL) {
  555. ERR_raise(ERR_LIB_DSO, DSO_R_UNSUPPORTED);
  556. return NULL;
  557. }
  558. create_snap = (CREATETOOLHELP32SNAPSHOT)
  559. GetProcAddress(dll, "CreateToolhelp32Snapshot");
  560. if (create_snap == NULL) {
  561. FreeLibrary(dll);
  562. ERR_raise(ERR_LIB_DSO, DSO_R_UNSUPPORTED);
  563. return NULL;
  564. }
  565. /* We take the rest for granted... */
  566. # ifdef _WIN32_WCE
  567. close_snap = (CLOSETOOLHELP32SNAPSHOT)
  568. GetProcAddress(dll, "CloseToolhelp32Snapshot");
  569. # else
  570. close_snap = (CLOSETOOLHELP32SNAPSHOT) CloseHandle;
  571. # endif
  572. module_first = (MODULE32) GetProcAddress(dll, "Module32First");
  573. module_next = (MODULE32) GetProcAddress(dll, "Module32Next");
  574. hModuleSnap = (*create_snap) (TH32CS_SNAPMODULE, 0);
  575. if (hModuleSnap == INVALID_HANDLE_VALUE) {
  576. FreeLibrary(dll);
  577. ERR_raise(ERR_LIB_DSO, DSO_R_UNSUPPORTED);
  578. return NULL;
  579. }
  580. me32.dwSize = sizeof(me32);
  581. if (!(*module_first) (hModuleSnap, &me32)) {
  582. (*close_snap) (hModuleSnap);
  583. FreeLibrary(dll);
  584. return NULL;
  585. }
  586. do {
  587. if ((ret.f = GetProcAddress(me32.hModule, name))) {
  588. (*close_snap) (hModuleSnap);
  589. FreeLibrary(dll);
  590. return ret.p;
  591. }
  592. } while ((*module_next) (hModuleSnap, &me32));
  593. (*close_snap) (hModuleSnap);
  594. FreeLibrary(dll);
  595. return NULL;
  596. }
  597. #endif /* DSO_WIN32 */