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.

126 lines
3.9 KiB

  1. //
  2. // DelayImp.c
  3. //
  4. // define structures and prototypes necessary for delay loading of imports
  5. //
  6. #include "windows.h"
  7. typedef IMAGE_THUNK_DATA * PImgThunkData;
  8. typedef const IMAGE_THUNK_DATA * PCImgThunkData;
  9. typedef DWORD RVA;
  10. typedef struct ImgDelayDescrV2 {
  11. DWORD grAttrs; // attributes
  12. RVA rvaDLLName; // RVA to dll name
  13. RVA rvaHmod; // RVA of module handle
  14. RVA rvaIAT; // RVA of the IAT
  15. RVA rvaINT; // RVA of the INT
  16. RVA rvaBoundIAT; // RVA of the optional bound IAT
  17. RVA rvaUnloadIAT; // RVA of optional copy of original IAT
  18. DWORD dwTimeStamp; // 0 if not bound,
  19. // O.W. date/time stamp of DLL bound to (Old BIND)
  20. } ImgDelayDescrV2, * PImgDelayDescrV2;
  21. typedef ImgDelayDescrV2 ImgDelayDescr;
  22. typedef PImgDelayDescrV2 PImgDelayDescr;
  23. typedef const ImgDelayDescr * PCImgDelayDescr;
  24. enum DLAttr { // Delay Load Attributes
  25. dlattrRva = 0x1, // RVAs are used instead of pointers
  26. };
  27. //
  28. // Delay load import hook notifications
  29. //
  30. enum {
  31. dliStartProcessing, // used to bypass or note helper only
  32. dliNotePreLoadLibrary, // called just before LoadLibrary, can
  33. // override w/ new HMODULE return val
  34. dliNotePreGetProcAddress, // called just before GetProcAddress, can
  35. // override w/ new FARPROC return value
  36. dliFailLoadLib, // failed to load library, fix it by
  37. // returning a valid HMODULE
  38. dliFailGetProc, // failed to get proc address, fix it by
  39. // returning a valid FARPROC
  40. dliNoteEndProcessing, // called after all processing is done, no
  41. // no bypass possible at this point except
  42. // by longjmp()/throw()/RaiseException.
  43. };
  44. typedef struct DelayLoadProc {
  45. BOOL fImportByName;
  46. union {
  47. LPCSTR szProcName;
  48. DWORD dwOrdinal;
  49. };
  50. } DelayLoadProc;
  51. typedef struct DelayLoadInfo {
  52. DWORD cb; // size of structure
  53. PCImgDelayDescr pidd; // raw form of data (everything is there)
  54. FARPROC * ppfn; // points to address of function to load
  55. LPCSTR szDll; // name of dll
  56. DelayLoadProc dlp; // name or ordinal of procedure
  57. HMODULE hmodCur; // the hInstance of the library we have loaded
  58. FARPROC pfnCur; // the actual function that will be called
  59. DWORD dwLastError;// error received (if an error notification)
  60. } DelayLoadInfo, * PDelayLoadInfo;
  61. typedef FARPROC (WINAPI *PfnDliHook)(
  62. unsigned dliNotify,
  63. PDelayLoadInfo pdli
  64. );
  65. IMAGE_DOS_HEADER __ImageBase;
  66. //
  67. // Unload support
  68. //
  69. BOOL
  70. WINAPI
  71. __FUnloadDelayLoadedDLL2 (
  72. LPCSTR szDll
  73. )
  74. {
  75. return FALSE;
  76. }
  77. // structure definitions for the list of unload records
  78. typedef struct UnloadInfo * PUnloadInfo;
  79. typedef struct UnloadInfo {
  80. PUnloadInfo puiNext;
  81. PCImgDelayDescr pidd;
  82. } UnloadInfo;
  83. // the default delay load helper places the unloadinfo records in the list
  84. // headed by the following pointer.
  85. PUnloadInfo __puiHead;
  86. //
  87. // Hook pointers
  88. //
  89. // The "notify hook" gets called for every call to the
  90. // delay load helper. This allows a user to hook every call and
  91. // skip the delay load helper entirely.
  92. //
  93. // dliNotify == {
  94. // dliStartProcessing |
  95. // dliPreLoadLibrary |
  96. // dliPreGetProc |
  97. // dliNoteEndProcessing}
  98. // on this call.
  99. //
  100. PfnDliHook __pfnDliNotifyHook;
  101. PfnDliHook __pfnDliNotifyHook2;
  102. PfnDliHook __pfnDliFailureHook;
  103. PfnDliHook __pfnDliFailureHook2;