Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

805 lines
22 KiB

  1. #include <private.h>
  2. #include <globals.h>
  3. #include <delayimp.h>
  4. #ifdef BUILD_DBGHELP
  5. BOOL
  6. GetDllVersionInfo(
  7. HINSTANCE hinst,
  8. LPVOID *lpVersionInfo
  9. );
  10. #define FreeLib(hDll) \
  11. {if (hDll && hDll != INVALID_HANDLE_VALUE) FreeLibrary(hDll);}
  12. #endif // #ifdef BUILD_DBGHELP
  13. typedef struct
  14. {
  15. PCHAR Name;
  16. FARPROC Function;
  17. } FUNCPTRS;
  18. #if DBG
  19. void
  20. OutputDBString(
  21. CHAR *text
  22. );
  23. #endif
  24. #ifdef BUILD_IMAGEHLP
  25. BOOL IMAGEAPI FailEnumerateLoadedModules(
  26. IN HANDLE hProcess,
  27. IN PENUMLOADED_MODULES_CALLBACK EnumLoadedModulesCallback,
  28. IN PVOID UserContext
  29. )
  30. { return FALSE; }
  31. BOOL IMAGEAPI FailEnumerateLoadedModules64(
  32. IN HANDLE hProcess,
  33. IN PENUMLOADED_MODULES_CALLBACK64 EnumLoadedModulesCallback,
  34. IN PVOID UserContext
  35. )
  36. { return FALSE; }
  37. HANDLE IMAGEAPI FailFindDebugInfoFile (
  38. PSTR FileName,
  39. PSTR SymbolPath,
  40. PSTR DebugFilePath
  41. )
  42. {return NULL;}
  43. HANDLE IMAGEAPI FailFindDebugInfoFileEx (
  44. PSTR FileName,
  45. PSTR SymbolPath,
  46. PSTR DebugFilePath,
  47. PFIND_DEBUG_FILE_CALLBACK Callback,
  48. PVOID CallerData
  49. )
  50. { return NULL; }
  51. HANDLE IMAGEAPI FailFindExecutableImage(
  52. PSTR FileName,
  53. PSTR SymbolPath,
  54. PSTR ImageFilePath
  55. )
  56. { return NULL; }
  57. LPAPI_VERSION IMAGEAPI FailImagehlpApiVersion(
  58. VOID
  59. )
  60. { return NULL; }
  61. LPAPI_VERSION IMAGEAPI FailImagehlpApiVersionEx(
  62. LPAPI_VERSION AppVersion
  63. )
  64. { return NULL; }
  65. BOOL IMAGEAPI FailMakeSureDirectoryPathExists(
  66. PCSTR DirPath
  67. )
  68. { return FALSE; }
  69. #ifndef _WIN64
  70. PIMAGE_DEBUG_INFORMATION IMAGEAPI FailMapDebugInformation(
  71. HANDLE FileHandle,
  72. PSTR FileName,
  73. PSTR SymbolPath,
  74. DWORD ImageBase
  75. )
  76. { return NULL; }
  77. #endif
  78. BOOL IMAGEAPI FailSearchTreeForFile(
  79. PSTR RootPath,
  80. PSTR InputPathName,
  81. PSTR OutputPathBuffer
  82. )
  83. { return FALSE; }
  84. BOOL IMAGEAPI FailStackWalk(
  85. DWORD MachineType,
  86. HANDLE hProcess,
  87. HANDLE hThread,
  88. LPSTACKFRAME StackFrame,
  89. PVOID ContextRecord,
  90. PREAD_PROCESS_MEMORY_ROUTINE ReadMemoryRoutine,
  91. PFUNCTION_TABLE_ACCESS_ROUTINE FunctionTableAccessRoutine,
  92. PGET_MODULE_BASE_ROUTINE GetModuleBaseRoutine,
  93. PTRANSLATE_ADDRESS_ROUTINE TranslateAddress
  94. )
  95. { return FALSE; }
  96. BOOL IMAGEAPI FailStackWalk64(
  97. DWORD MachineType,
  98. HANDLE hProcess,
  99. HANDLE hThread,
  100. LPSTACKFRAME64 StackFrame,
  101. PVOID ContextRecord,
  102. PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine,
  103. PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine,
  104. PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine,
  105. PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress
  106. )
  107. { return FALSE; }
  108. BOOL IMAGEAPI FailSymCleanup(
  109. IN HANDLE hProcess
  110. )
  111. { return FALSE; }
  112. BOOL IMAGEAPI FailSymEnumerateModules(
  113. IN HANDLE hProcess,
  114. IN PSYM_ENUMMODULES_CALLBACK EnumModulesCallback,
  115. IN PVOID UserContext
  116. )
  117. { return FALSE; }
  118. BOOL IMAGEAPI FailSymEnumerateModules64(
  119. IN HANDLE hProcess,
  120. IN PSYM_ENUMMODULES_CALLBACK64 EnumModulesCallback,
  121. IN PVOID UserContext
  122. )
  123. { return FALSE; }
  124. BOOL IMAGEAPI FailSymEnumerateSymbols(
  125. IN HANDLE hProcess,
  126. IN DWORD BaseOfDll,
  127. IN PSYM_ENUMSYMBOLS_CALLBACK EnumSymbolsCallback,
  128. IN PVOID UserContext
  129. )
  130. { return FALSE; }
  131. BOOL IMAGEAPI FailSymEnumerateSymbolsW(
  132. IN HANDLE hProcess,
  133. IN DWORD BaseOfDll,
  134. IN PSYM_ENUMSYMBOLS_CALLBACKW EnumSymbolsCallback,
  135. IN PVOID UserContext
  136. )
  137. { return FALSE; }
  138. BOOL IMAGEAPI FailSymEnumerateSymbols64(
  139. IN HANDLE hProcess,
  140. IN DWORD64 BaseOfDll,
  141. IN PSYM_ENUMSYMBOLS_CALLBACK64 EnumSymbolsCallback,
  142. IN PVOID UserContext
  143. )
  144. { return FALSE; }
  145. BOOL IMAGEAPI FailSymEnumerateSymbolsW64(
  146. IN HANDLE hProcess,
  147. IN DWORD64 BaseOfDll,
  148. IN PSYM_ENUMSYMBOLS_CALLBACK64W EnumSymbolsCallback,
  149. IN PVOID UserContext
  150. )
  151. { return FALSE; }
  152. PVOID IMAGEAPI FailSymFunctionTableAccess(
  153. HANDLE hProcess,
  154. DWORD AddrBase
  155. )
  156. { return NULL; }
  157. PVOID IMAGEAPI FailSymFunctionTableAccess64(
  158. HANDLE hProcess,
  159. DWORD64 AddrBase
  160. )
  161. { return NULL; }
  162. BOOL IMAGEAPI FailSymGetLineFromAddr(
  163. IN HANDLE hProcess,
  164. IN DWORD dwAddr,
  165. OUT PDWORD pdwDisplacement,
  166. OUT PIMAGEHLP_LINE Line
  167. )
  168. { return FALSE; }
  169. BOOL IMAGEAPI FailSymGetLineFromAddr64(
  170. IN HANDLE hProcess,
  171. IN DWORD64 qwAddr,
  172. OUT PDWORD pdwDisplacement,
  173. OUT PIMAGEHLP_LINE64 Line
  174. )
  175. { return FALSE; }
  176. BOOL IMAGEAPI FailSymGetLineFromName(
  177. IN HANDLE hProcess,
  178. IN PSTR ModuleName,
  179. IN PSTR FileName,
  180. IN DWORD dwLineNumber,
  181. OUT PLONG plDisplacement,
  182. IN OUT PIMAGEHLP_LINE Line
  183. )
  184. { return FALSE; }
  185. BOOL IMAGEAPI FailSymGetLineFromName64(
  186. IN HANDLE hProcess,
  187. IN PSTR ModuleName,
  188. IN PSTR FileName,
  189. IN DWORD dwLineNumber,
  190. OUT PLONG plDisplacement,
  191. IN OUT PIMAGEHLP_LINE64 Line
  192. )
  193. { return FALSE; }
  194. BOOL IMAGEAPI FailSymGetLineNext(
  195. IN HANDLE hProcess,
  196. IN OUT PIMAGEHLP_LINE Line
  197. )
  198. { return FALSE; }
  199. BOOL IMAGEAPI FailSymGetLineNext64(
  200. IN HANDLE hProcess,
  201. IN OUT PIMAGEHLP_LINE64 Line
  202. )
  203. { return FALSE; }
  204. BOOL IMAGEAPI FailSymGetLinePrev(
  205. IN HANDLE hProcess,
  206. IN OUT PIMAGEHLP_LINE Line
  207. )
  208. { return FALSE; }
  209. BOOL IMAGEAPI FailSymGetLinePrev64(
  210. IN HANDLE hProcess,
  211. IN OUT PIMAGEHLP_LINE64 Line
  212. )
  213. { return FALSE; }
  214. DWORD IMAGEAPI FailSymGetModuleBase(
  215. IN HANDLE hProcess,
  216. IN DWORD dwAddr
  217. )
  218. { return 0; }
  219. DWORD64 IMAGEAPI FailSymGetModuleBase64(
  220. IN HANDLE hProcess,
  221. IN DWORD64 qwAddr
  222. )
  223. { return 0; }
  224. BOOL IMAGEAPI FailSymGetModuleInfo(
  225. IN HANDLE hProcess,
  226. IN DWORD dwAddr,
  227. OUT PIMAGEHLP_MODULE ModuleInfo
  228. )
  229. { return FALSE; }
  230. BOOL IMAGEAPI FailSymGetModuleInfoW(
  231. IN HANDLE hProcess,
  232. IN DWORD dwAddr,
  233. OUT PIMAGEHLP_MODULEW ModuleInfo
  234. )
  235. { return FALSE; }
  236. BOOL IMAGEAPI FailSymGetModuleInfo64(
  237. IN HANDLE hProcess,
  238. IN DWORD64 qwAddr,
  239. OUT PIMAGEHLP_MODULE64 ModuleInfo
  240. )
  241. { return FALSE; }
  242. BOOL IMAGEAPI FailSymGetModuleInfoW64(
  243. IN HANDLE hProcess,
  244. IN DWORD64 qwAddr,
  245. OUT PIMAGEHLP_MODULEW64 ModuleInfo
  246. )
  247. { return FALSE; }
  248. DWORD IMAGEAPI FailSymGetOptions(
  249. VOID
  250. )
  251. { return 0; }
  252. BOOL IMAGEAPI FailSymGetSearchPath(
  253. IN HANDLE hProcess,
  254. OUT PSTR SearchPath,
  255. IN DWORD SearchPathLength
  256. )
  257. { return FALSE; }
  258. BOOL IMAGEAPI FailSymGetSymFromAddr(
  259. IN HANDLE hProcess,
  260. IN DWORD dwAddr,
  261. OUT PDWORD pdwDisplacement,
  262. OUT PIMAGEHLP_SYMBOL Symbol
  263. )
  264. { return FALSE; }
  265. BOOL IMAGEAPI FailSymGetSymFromAddr64(
  266. IN HANDLE hProcess,
  267. IN DWORD64 qwAddr,
  268. OUT PDWORD64 pdwDisplacement,
  269. OUT PIMAGEHLP_SYMBOL64 Symbol
  270. )
  271. { return FALSE; }
  272. BOOL IMAGEAPI FailSymGetSymFromName(
  273. IN HANDLE hProcess,
  274. IN PSTR Name,
  275. OUT PIMAGEHLP_SYMBOL Symbol
  276. )
  277. { return FALSE; }
  278. BOOL IMAGEAPI FailSymGetSymFromName64(
  279. IN HANDLE hProcess,
  280. IN PSTR Name,
  281. OUT PIMAGEHLP_SYMBOL64 Symbol
  282. )
  283. { return FALSE; }
  284. BOOL IMAGEAPI FailSymGetSymNext(
  285. IN HANDLE hProcess,
  286. IN OUT PIMAGEHLP_SYMBOL Symbol
  287. )
  288. { return FALSE; }
  289. BOOL IMAGEAPI FailSymGetSymNext64(
  290. IN HANDLE hProcess,
  291. IN OUT PIMAGEHLP_SYMBOL64 Symbol
  292. )
  293. { return FALSE; }
  294. BOOL IMAGEAPI FailSymGetSymPrev(
  295. IN HANDLE hProcess,
  296. IN OUT PIMAGEHLP_SYMBOL Symbol
  297. )
  298. { return FALSE; }
  299. BOOL IMAGEAPI FailSymGetSymPrev64(
  300. IN HANDLE hProcess,
  301. IN OUT PIMAGEHLP_SYMBOL64 Symbol
  302. )
  303. { return FALSE; }
  304. BOOL
  305. IMAGEAPI
  306. FailSymGetTypeInfo(
  307. IN HANDLE hProcess,
  308. IN DWORD64 ModBase,
  309. IN ULONG TypeId,
  310. IN IMAGEHLP_SYMBOL_TYPE_INFO GetType,
  311. OUT PVOID pInfo
  312. )
  313. { return FALSE; }
  314. BOOL
  315. IMAGEAPI
  316. FailSymGetTypeFromName(
  317. IN HANDLE hProcess,
  318. IN ULONG64 BaseOfDll,
  319. IN LPSTR Name,
  320. OUT PSYMBOL_INFO Symbol
  321. )
  322. { return FALSE; }
  323. BOOL
  324. IMAGEAPI
  325. FailSymEnumTypes(
  326. IN HANDLE hProcess,
  327. IN ULONG64 BaseOfDll,
  328. IN PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback,
  329. IN PVOID UserContext
  330. )
  331. { return FALSE; }
  332. BOOL IMAGEAPI FailSymInitialize(
  333. IN HANDLE hProcess,
  334. IN PSTR UserSearchPath,
  335. IN BOOL fInvadeProcess
  336. )
  337. { return FALSE; }
  338. DWORD IMAGEAPI FailSymLoadModule(
  339. IN HANDLE hProcess,
  340. IN HANDLE hFile,
  341. IN PSTR ImageName,
  342. IN PSTR ModuleName,
  343. IN DWORD BaseOfDll,
  344. IN DWORD SizeOfDll
  345. )
  346. { return 0; }
  347. DWORD64 IMAGEAPI FailSymLoadModule64(
  348. IN HANDLE hProcess,
  349. IN HANDLE hFile,
  350. IN PSTR ImageName,
  351. IN PSTR ModuleName,
  352. IN DWORD64 BaseOfDll,
  353. IN DWORD SizeOfDll
  354. )
  355. { return 0; }
  356. BOOL IMAGEAPI FailSymMatchFileName(
  357. IN PSTR FileName,
  358. IN PSTR Match,
  359. OUT PSTR *FileNameStop,
  360. OUT PSTR *MatchStop
  361. )
  362. { return FALSE; }
  363. BOOL IMAGEAPI FailSymRegisterCallback(
  364. IN HANDLE hProcess,
  365. IN PSYMBOL_REGISTERED_CALLBACK CallbackFunction,
  366. IN PVOID UserContext
  367. )
  368. { return FALSE; }
  369. BOOL IMAGEAPI FailSymRegisterCallback64(
  370. IN HANDLE hProcess,
  371. IN PSYMBOL_REGISTERED_CALLBACK64 CallbackFunction,
  372. IN ULONG64 UserContext
  373. )
  374. { return FALSE; }
  375. BOOL IMAGEAPI FailSymRegisterFunctionEntryCallback(
  376. IN HANDLE hProcess,
  377. IN PSYMBOL_FUNCENTRY_CALLBACK CallbackFunction,
  378. IN PVOID UserContext
  379. )
  380. { return FALSE; }
  381. BOOL IMAGEAPI FailSymRegisterFunctionEntryCallback64(
  382. IN HANDLE hProcess,
  383. IN PSYMBOL_FUNCENTRY_CALLBACK64 CallbackFunction,
  384. IN ULONG64 UserContext
  385. )
  386. { return FALSE; }
  387. BOOL IMAGEAPI FailSymSetContext(
  388. HANDLE hProcess,
  389. PIMAGEHLP_STACK_FRAME StackFrame,
  390. PIMAGEHLP_CONTEXT Context
  391. )
  392. { return FALSE;}
  393. DWORD IMAGEAPI FailSymSetOptions(
  394. IN DWORD SymOptions
  395. )
  396. { return 0; }
  397. BOOL IMAGEAPI FailSymSetSearchPath(
  398. IN HANDLE hProcess,
  399. IN PSTR SearchPath
  400. )
  401. { return FALSE; }
  402. BOOL IMAGEAPI FailSymUnDName(
  403. IN PIMAGEHLP_SYMBOL sym, // Symbol to undecorate
  404. OUT PSTR UnDecName, // Buffer to store undecorated name in
  405. IN DWORD UnDecNameLength // Size of the buffer
  406. )
  407. { return FALSE; }
  408. BOOL IMAGEAPI FailSymUnDName64(
  409. IN PIMAGEHLP_SYMBOL64 sym, // Symbol to undecorate
  410. OUT PSTR UnDecName, // Buffer to store undecorated name in
  411. IN DWORD UnDecNameLength // Size of the buffer
  412. )
  413. { return FALSE; }
  414. BOOL IMAGEAPI FailSymUnloadModule(
  415. IN HANDLE hProcess,
  416. IN DWORD BaseOfDll
  417. )
  418. { return FALSE; }
  419. BOOL IMAGEAPI FailSymUnloadModule64(
  420. IN HANDLE hProcess,
  421. IN DWORD64 BaseOfDll
  422. )
  423. { return FALSE; }
  424. #ifndef _WIN64
  425. BOOL IMAGEAPI FailUnmapDebugInformation(
  426. PIMAGE_DEBUG_INFORMATION DebugInfo
  427. )
  428. { return FALSE; }
  429. #endif
  430. BOOL IMAGEAPI FailSymEnumSym(
  431. IN HANDLE hProcess,
  432. IN DWORD64 BaseOfDll,
  433. IN PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback,
  434. IN PVOID UserContext
  435. )
  436. { return FALSE; }
  437. BOOL IMAGEAPI FailSymFromAddr(
  438. IN HANDLE hProcess,
  439. IN DWORD64 dwAddr,
  440. OUT PDWORD pdwDisplacement,
  441. OUT PSYMBOL_INFO Symbol
  442. )
  443. { return FALSE; }
  444. BOOL IMAGEAPI FailSymFromName(
  445. IN HANDLE hProcess,
  446. IN PSTR Name,
  447. OUT PSYMBOL_INFO Symbol
  448. )
  449. { return FALSE; }
  450. FUNCPTRS DbgHelpFailPtrs[] = {
  451. {"EnumerateLoadedModules", (FARPROC)FailEnumerateLoadedModules},
  452. {"EnumerateLoadedModules64", (FARPROC)FailEnumerateLoadedModules64},
  453. {"FindDebugInfoFile", (FARPROC)FailFindDebugInfoFile},
  454. {"FindDebugInfoFileEx", (FARPROC)FailFindDebugInfoFileEx},
  455. {"FindExecutableImage", (FARPROC)FailFindExecutableImage},
  456. {"ImagehlpApiVersion", (FARPROC)FailImagehlpApiVersion},
  457. {"ImagehlpApiVersionEx", (FARPROC)FailImagehlpApiVersionEx},
  458. {"MakeSureDirectoryPathExists", (FARPROC)FailMakeSureDirectoryPathExists},
  459. #ifndef _WIN64
  460. {"MapDebugInformation", (FARPROC)FailMapDebugInformation},
  461. #endif
  462. {"SearchTreeForFile", (FARPROC)FailSearchTreeForFile},
  463. {"StackWalk", (FARPROC)FailStackWalk},
  464. {"StackWalk64", (FARPROC)FailStackWalk64},
  465. {"SymCleanup", (FARPROC)FailSymCleanup},
  466. {"SymEnumerateModules", (FARPROC)FailSymEnumerateModules},
  467. {"SymEnumerateModules64", (FARPROC)FailSymEnumerateModules64},
  468. {"SymEnumerateSymbols", (FARPROC)FailSymEnumerateSymbols},
  469. {"SymEnumerateSymbols64", (FARPROC)FailSymEnumerateSymbols64},
  470. {"SymEnumerateSymbolsW", (FARPROC)FailSymEnumerateSymbolsW},
  471. {"SymEnumerateSymbolsW64", (FARPROC)FailSymEnumerateSymbolsW64},
  472. {"SymEnumSym", (FARPROC)FailSymEnumSym},
  473. {"SymEnumTypes", (FARPROC)FailSymEnumTypes},
  474. {"SymFromAddr", (FARPROC)FailSymFromAddr},
  475. {"SymFromName", (FARPROC)FailSymFromName},
  476. {"SymFunctionTableAccess", (FARPROC)FailSymFunctionTableAccess},
  477. {"SymFunctionTableAccess64", (FARPROC)FailSymFunctionTableAccess64},
  478. {"SymGetLineFromAddr", (FARPROC)FailSymGetLineFromAddr},
  479. {"SymGetLineFromAddr64", (FARPROC)FailSymGetLineFromAddr64},
  480. {"SymGetLineFromName", (FARPROC)FailSymGetLineFromName},
  481. {"SymGetLineFromName64", (FARPROC)FailSymGetLineFromName64},
  482. {"SymGetLineNext", (FARPROC)FailSymGetLineNext},
  483. {"SymGetLineNext64", (FARPROC)FailSymGetLineNext64},
  484. {"SymGetLinePrev", (FARPROC)FailSymGetLinePrev},
  485. {"SymGetLinePrev64", (FARPROC)FailSymGetLinePrev64},
  486. {"SymGetModuleBase", (FARPROC)FailSymGetModuleBase},
  487. {"SymGetModuleBase64", (FARPROC)FailSymGetModuleBase64},
  488. {"SymGetModuleInfo", (FARPROC)FailSymGetModuleInfo},
  489. {"SymGetModuleInfo64", (FARPROC)FailSymGetModuleInfo64},
  490. {"SymGetModuleInfoW", (FARPROC)FailSymGetModuleInfoW},
  491. {"SymGetModuleInfoW64", (FARPROC)FailSymGetModuleInfoW64},
  492. {"SymGetOptions", (FARPROC)FailSymGetOptions},
  493. {"SymGetSearchPath", (FARPROC)FailSymGetSearchPath},
  494. {"SymGetSymFromAddr", (FARPROC)FailSymGetSymFromAddr},
  495. {"SymGetSymFromAddr64", (FARPROC)FailSymGetSymFromAddr64},
  496. {"SymGetSymFromName", (FARPROC)FailSymGetSymFromName},
  497. {"SymGetSymFromName64", (FARPROC)FailSymGetSymFromName64},
  498. {"SymGetSymNext", (FARPROC)FailSymGetSymNext},
  499. {"SymGetSymNext64", (FARPROC)FailSymGetSymNext64},
  500. {"SymGetSymPrev", (FARPROC)FailSymGetSymPrev},
  501. {"SymGetSymPrev64", (FARPROC)FailSymGetSymPrev64},
  502. {"SymGetTypeFromName", (FARPROC)FailSymGetTypeFromName},
  503. {"SymGetTypeInfo", (FARPROC)FailSymGetTypeInfo},
  504. {"SymInitialize", (FARPROC)FailSymInitialize},
  505. {"SymLoadModule", (FARPROC)FailSymLoadModule},
  506. {"SymLoadModule64", (FARPROC)FailSymLoadModule64},
  507. {"SymMatchFileName", (FARPROC)FailSymMatchFileName},
  508. {"SymRegisterCallback", (FARPROC)FailSymRegisterCallback},
  509. {"SymRegisterCallback64", (FARPROC)FailSymRegisterCallback64},
  510. {"SymRegisterFunctionEntryCallback", (FARPROC)FailSymRegisterFunctionEntryCallback},
  511. {"SymRegisterFunctionEntryCallback64", (FARPROC)FailSymRegisterFunctionEntryCallback64},
  512. {"SymSetContext", (FARPROC)FailSymSetContext},
  513. {"SymSetOptions", (FARPROC)FailSymSetOptions},
  514. {"SymSetSearchPath", (FARPROC)FailSymSetSearchPath},
  515. {"SymUnDName", (FARPROC)FailSymUnDName},
  516. {"SymUnDName64", (FARPROC)FailSymUnDName64},
  517. {"SymUnloadModule", (FARPROC)FailSymUnloadModule},
  518. {"SymUnloadModule64", (FARPROC)FailSymUnloadModule64},
  519. #ifndef _WIN64
  520. {"UnmapDebugInformation", (FARPROC)FailUnmapDebugInformation},
  521. #endif
  522. {NULL, NULL}
  523. };
  524. #endif // BUILD_IMAGEHLP
  525. #ifdef BUILD_IMAGEHLP
  526. FUNCPTRS *FailFunctions[2] = {NULL, DbgHelpFailPtrs}; // {MsDbiFailPtrs, DbgHelpFailPtrs};
  527. HINSTANCE hDelayLoadDll[2];
  528. #else
  529. FUNCPTRS *FailFunctions[1] = {MsDbiFailPtrs};
  530. HINSTANCE hDelayLoadDll[1];
  531. #endif
  532. FARPROC
  533. FindFailureProc(
  534. UINT Index,
  535. const char *szProcName
  536. )
  537. {
  538. FUNCPTRS *fp = FailFunctions[Index];
  539. UINT x = 0;
  540. while (fp[x].Name) {
  541. if (!lstrcmpi(fp[x].Name, szProcName)) {
  542. return fp[x].Function;
  543. }
  544. x++;
  545. }
  546. return NULL;
  547. }
  548. /*
  549. * this function exists to prevent us from calling msvcrt!splitpath
  550. */
  551. VOID
  552. ParsePath(
  553. CHAR *fullpath,
  554. CHAR *path,
  555. CHAR *file
  556. )
  557. {
  558. CHAR *c;
  559. CHAR sz[_MAX_PATH];
  560. assert(fullpath);
  561. if (path)
  562. *path = 0;
  563. if (file)
  564. *file = 0;
  565. lstrcpy(sz, fullpath);
  566. for (c = sz + lstrlen(sz); c > sz; c--) {
  567. if (*c == '\\') {
  568. c++;
  569. if (file)
  570. lstrcpy(file, c);
  571. *c = 0;
  572. if (path)
  573. lstrcpy(path, sz);
  574. return;
  575. }
  576. }
  577. if (file)
  578. lstrcpy(file, fullpath);
  579. }
  580. FARPROC
  581. WINAPI
  582. ImagehlpDelayLoadHook (
  583. UINT unReason,
  584. PDelayLoadInfo pDelayInfo
  585. )
  586. {
  587. FARPROC ReturnValue = NULL;
  588. if (dliStartProcessing == unReason)
  589. {
  590. DWORD iDll = 0;
  591. #ifdef BUILD_IMAGEHLP
  592. if (!lstrcmpi(pDelayInfo->szDll, "dbghelp.dll")) {
  593. iDll = 2;
  594. }
  595. #endif
  596. if (iDll) {
  597. iDll--;
  598. // If the dll isn't loaded and isn't inproc already, attempt to load
  599. // from the same dir as imagehlp lives...
  600. if (!hDelayLoadDll[iDll] &&
  601. !(hDelayLoadDll[iDll] = GetModuleHandle(pDelayInfo->szDll)) &&
  602. g.hinst)
  603. {
  604. CHAR szImageName[_MAX_PATH];
  605. CHAR szPath[_MAX_DIR];
  606. CHAR szDll[_MAX_PATH];
  607. // Only load if dbghelp/msdbi are in the same dir as imagehlp
  608. GetModuleFileName(g.hinst, szImageName, sizeof(szImageName));
  609. ParsePath(szImageName, szPath, szDll);
  610. lstrcpy(szImageName, szPath);
  611. lstrcat(szImageName, pDelayInfo->szDll);
  612. hDelayLoadDll[iDll] = LoadLibrary(szImageName);
  613. if (!hDelayLoadDll[iDll]) {
  614. hDelayLoadDll[iDll] = (HINSTANCE)INVALID_HANDLE_VALUE;
  615. }
  616. }
  617. if (INVALID_HANDLE_VALUE != hDelayLoadDll[iDll] && g.hinst) {
  618. ReturnValue = GetProcAddress(hDelayLoadDll[iDll], pDelayInfo->dlp.szProcName);
  619. }
  620. if (!ReturnValue) {
  621. ReturnValue = FindFailureProc(iDll, pDelayInfo->dlp.szProcName);
  622. }
  623. #if DBG
  624. if (!ReturnValue) {
  625. OutputDBString("BogusDelayLoad function encountered...\n");
  626. }
  627. } else {
  628. OutputDBString("BogusDelayLoad function encountered...\n");
  629. #endif
  630. }
  631. }
  632. if (ReturnValue && g.hinst) {
  633. *pDelayInfo->ppfn = ReturnValue;
  634. }
  635. return ReturnValue;
  636. }
  637. #ifdef BUILD_DBGHELP
  638. typedef struct tagVERHEAD {
  639. WORD wTotLen;
  640. WORD wValLen;
  641. WORD wType; /* always 0 */
  642. WCHAR szKey[(sizeof("VS_VERSION_INFO")+3)&~03];
  643. VS_FIXEDFILEINFO vsf;
  644. } VERHEAD ;
  645. BOOL
  646. GetDllVersionInfo(
  647. HINSTANCE hinst,
  648. LPVOID *lpVersionInfo
  649. )
  650. {
  651. VS_FIXEDFILEINFO *pvsFFI = NULL;
  652. HRSRC hVerRes;
  653. VERHEAD *pVerHead;
  654. BOOL rc = FALSE;
  655. assert(lpVersionInfo && hinst);
  656. *lpVersionInfo = NULL;
  657. hVerRes = FindResource(hinst, MAKEINTRESOURCE(VS_VERSION_INFO), VS_FILE_INFO);
  658. if (hVerRes == NULL)
  659. goto Cleanup;
  660. pVerHead = (VERHEAD*)LoadResource(hinst, hVerRes);
  661. if (pVerHead == NULL)
  662. goto Cleanup;
  663. *lpVersionInfo = MemAlloc(pVerHead->wTotLen + pVerHead->wTotLen/2);
  664. if (*lpVersionInfo == NULL)
  665. goto Cleanup;
  666. memcpy(*lpVersionInfo, (PVOID)pVerHead, pVerHead->wTotLen);
  667. rc = TRUE;
  668. Cleanup:
  669. if (*lpVersionInfo && rc == FALSE)
  670. MemFree(*lpVersionInfo);
  671. return rc;
  672. }
  673. #endif // #ifdef BUILD_DBGHELP
  674. PfnDliHook __pfnDliNotifyHook = ImagehlpDelayLoadHook;
  675. PfnDliHook __pfnDliFailureHook = NULL;
  676. #if DBG
  677. void
  678. OutputDBString(
  679. CHAR *text
  680. )
  681. {
  682. CHAR sz[256];
  683. sprintf(sz, "%s: %s", MOD_FILENAME, text);
  684. OutputDebugString(sz);
  685. }
  686. #endif