2
0

dso_win32.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  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. len = strlen(filename);
  409. transform = ((strstr(filename, "/") == NULL) &&
  410. (strstr(filename, "\\") == NULL) &&
  411. (strstr(filename, ":") == NULL));
  412. if (transform)
  413. /* We will convert this to "%s.dll" */
  414. translated = OPENSSL_malloc(len + 5);
  415. else
  416. /* We will simply duplicate filename */
  417. translated = OPENSSL_malloc(len + 1);
  418. if (translated == NULL) {
  419. ERR_raise(ERR_LIB_DSO, DSO_R_NAME_TRANSLATION_FAILED);
  420. return NULL;
  421. }
  422. if (transform)
  423. sprintf(translated, "%s.dll", filename);
  424. else
  425. sprintf(translated, "%s", filename);
  426. return translated;
  427. }
  428. static const char *openssl_strnchr(const char *string, int c, size_t len)
  429. {
  430. size_t i;
  431. const char *p;
  432. for (i = 0, p = string; i < len && *p; i++, p++) {
  433. if (*p == c)
  434. return p;
  435. }
  436. return NULL;
  437. }
  438. # include <tlhelp32.h>
  439. # ifdef _WIN32_WCE
  440. # define DLLNAME "TOOLHELP.DLL"
  441. # else
  442. # ifdef MODULEENTRY32
  443. # undef MODULEENTRY32 /* unmask the ASCII version! */
  444. # endif
  445. # define DLLNAME "KERNEL32.DLL"
  446. # endif
  447. typedef HANDLE(WINAPI *CREATETOOLHELP32SNAPSHOT) (DWORD, DWORD);
  448. typedef BOOL(WINAPI *CLOSETOOLHELP32SNAPSHOT) (HANDLE);
  449. typedef BOOL(WINAPI *MODULE32) (HANDLE, MODULEENTRY32 *);
  450. static int win32_pathbyaddr(void *addr, char *path, int sz)
  451. {
  452. HMODULE dll;
  453. HANDLE hModuleSnap = INVALID_HANDLE_VALUE;
  454. MODULEENTRY32 me32;
  455. CREATETOOLHELP32SNAPSHOT create_snap;
  456. CLOSETOOLHELP32SNAPSHOT close_snap;
  457. MODULE32 module_first, module_next;
  458. if (addr == NULL) {
  459. union {
  460. int (*f) (void *, char *, int);
  461. void *p;
  462. } t = {
  463. win32_pathbyaddr
  464. };
  465. addr = t.p;
  466. }
  467. dll = LoadLibrary(TEXT(DLLNAME));
  468. if (dll == NULL) {
  469. ERR_raise(ERR_LIB_DSO, DSO_R_UNSUPPORTED);
  470. return -1;
  471. }
  472. create_snap = (CREATETOOLHELP32SNAPSHOT)
  473. GetProcAddress(dll, "CreateToolhelp32Snapshot");
  474. if (create_snap == NULL) {
  475. FreeLibrary(dll);
  476. ERR_raise(ERR_LIB_DSO, DSO_R_UNSUPPORTED);
  477. return -1;
  478. }
  479. /* We take the rest for granted... */
  480. # ifdef _WIN32_WCE
  481. close_snap = (CLOSETOOLHELP32SNAPSHOT)
  482. GetProcAddress(dll, "CloseToolhelp32Snapshot");
  483. # else
  484. close_snap = (CLOSETOOLHELP32SNAPSHOT) CloseHandle;
  485. # endif
  486. module_first = (MODULE32) GetProcAddress(dll, "Module32First");
  487. module_next = (MODULE32) GetProcAddress(dll, "Module32Next");
  488. /*
  489. * Take a snapshot of current process which includes
  490. * list of all involved modules.
  491. */
  492. hModuleSnap = (*create_snap) (TH32CS_SNAPMODULE, 0);
  493. if (hModuleSnap == INVALID_HANDLE_VALUE) {
  494. FreeLibrary(dll);
  495. ERR_raise(ERR_LIB_DSO, DSO_R_UNSUPPORTED);
  496. return -1;
  497. }
  498. me32.dwSize = sizeof(me32);
  499. if (!(*module_first) (hModuleSnap, &me32)) {
  500. (*close_snap) (hModuleSnap);
  501. FreeLibrary(dll);
  502. ERR_raise(ERR_LIB_DSO, DSO_R_FAILURE);
  503. return -1;
  504. }
  505. /* Enumerate the modules to find one which includes me. */
  506. do {
  507. if ((size_t) addr >= (size_t) me32.modBaseAddr &&
  508. (size_t) addr < (size_t) (me32.modBaseAddr + me32.modBaseSize)) {
  509. (*close_snap) (hModuleSnap);
  510. FreeLibrary(dll);
  511. # ifdef _WIN32_WCE
  512. # if _WIN32_WCE >= 101
  513. return WideCharToMultiByte(CP_ACP, 0, me32.szExePath, -1,
  514. path, sz, NULL, NULL);
  515. # else
  516. {
  517. int i, len = (int)wcslen(me32.szExePath);
  518. if (sz <= 0)
  519. return len + 1;
  520. if (len >= sz)
  521. len = sz - 1;
  522. for (i = 0; i < len; i++)
  523. path[i] = (char)me32.szExePath[i];
  524. path[len++] = '\0';
  525. return len;
  526. }
  527. # endif
  528. # else
  529. {
  530. int len = (int)strlen(me32.szExePath);
  531. if (sz <= 0)
  532. return len + 1;
  533. if (len >= sz)
  534. len = sz - 1;
  535. memcpy(path, me32.szExePath, len);
  536. path[len++] = '\0';
  537. return len;
  538. }
  539. # endif
  540. }
  541. } while ((*module_next) (hModuleSnap, &me32));
  542. (*close_snap) (hModuleSnap);
  543. FreeLibrary(dll);
  544. return 0;
  545. }
  546. static void *win32_globallookup(const char *name)
  547. {
  548. HMODULE dll;
  549. HANDLE hModuleSnap = INVALID_HANDLE_VALUE;
  550. MODULEENTRY32 me32;
  551. CREATETOOLHELP32SNAPSHOT create_snap;
  552. CLOSETOOLHELP32SNAPSHOT close_snap;
  553. MODULE32 module_first, module_next;
  554. union {
  555. void *p;
  556. FARPROC f;
  557. } ret = { NULL };
  558. dll = LoadLibrary(TEXT(DLLNAME));
  559. if (dll == NULL) {
  560. ERR_raise(ERR_LIB_DSO, DSO_R_UNSUPPORTED);
  561. return NULL;
  562. }
  563. create_snap = (CREATETOOLHELP32SNAPSHOT)
  564. GetProcAddress(dll, "CreateToolhelp32Snapshot");
  565. if (create_snap == NULL) {
  566. FreeLibrary(dll);
  567. ERR_raise(ERR_LIB_DSO, DSO_R_UNSUPPORTED);
  568. return NULL;
  569. }
  570. /* We take the rest for granted... */
  571. # ifdef _WIN32_WCE
  572. close_snap = (CLOSETOOLHELP32SNAPSHOT)
  573. GetProcAddress(dll, "CloseToolhelp32Snapshot");
  574. # else
  575. close_snap = (CLOSETOOLHELP32SNAPSHOT) CloseHandle;
  576. # endif
  577. module_first = (MODULE32) GetProcAddress(dll, "Module32First");
  578. module_next = (MODULE32) GetProcAddress(dll, "Module32Next");
  579. hModuleSnap = (*create_snap) (TH32CS_SNAPMODULE, 0);
  580. if (hModuleSnap == INVALID_HANDLE_VALUE) {
  581. FreeLibrary(dll);
  582. ERR_raise(ERR_LIB_DSO, DSO_R_UNSUPPORTED);
  583. return NULL;
  584. }
  585. me32.dwSize = sizeof(me32);
  586. if (!(*module_first) (hModuleSnap, &me32)) {
  587. (*close_snap) (hModuleSnap);
  588. FreeLibrary(dll);
  589. return NULL;
  590. }
  591. do {
  592. if ((ret.f = GetProcAddress(me32.hModule, name))) {
  593. (*close_snap) (hModuleSnap);
  594. FreeLibrary(dll);
  595. return ret.p;
  596. }
  597. } while ((*module_next) (hModuleSnap, &me32));
  598. (*close_snap) (hModuleSnap);
  599. FreeLibrary(dll);
  600. return NULL;
  601. }
  602. #endif /* DSO_WIN32 */