1 //
2 // DelayImp.h
3 //
4 //  Copyright (c) Microsoft Corporation.  All rights reserved.
5 //
6 //  Define structures and prototypes necessary for delay loading of imports
7 //
8 #pragma once
9
10 #define _DELAY_IMP_VER  2
11
12 #if defined(__cplusplus)
13 #define ExternC extern "C"
14 #else
15 #define ExternC extern
16 #endif
17
18 typedef IMAGE_THUNK_DATA *                PImgThunkData;
19 typedef const IMAGE_THUNK_DATA *      PCImgThunkData;
20 typedef DWORD                                      RVA;
21
22 typedef struct ImgDelayDescr {
23       DWORD                  grAttrs;             // attributes
24       RVA                     rvaDLLName;        // RVA to dll name
25       RVA                     rvaHmod;             // RVA of module handle
26       RVA                     rvaIAT;               // RVA of the IAT
27       RVA                     rvaINT;               // RVA of the INT
28       RVA                     rvaBoundIAT;      // RVA of the optional bound IAT
29       RVA                     rvaUnloadIAT;     // RVA of optional copy of original IAT
30       DWORD                  dwTimeStamp;      // 0 if not bound,
31                                                             // O.W. date/time stamp of DLL bound to (Old BIND)
32       } ImgDelayDescr, * PImgDelayDescr;
33
34 typedef const ImgDelayDescr *     PCImgDelayDescr;
35
36 enum DLAttr {                               // Delay Load Attributes
37       dlattrRva = 0x1,                          // RVAs are used instead of pointers
38                                                             // Having this set indicates a VC7.0
39                                                             // and above delay load descriptor.
40       };
41
42 //
43 // Delay load import hook notifications
44 //
45 enum {
46       dliStartProcessing,                     // used to bypass or note helper only
47       dliNoteStartProcessing = dliStartProcessing,
48
49       dliNotePreLoadLibrary,                // called just before LoadLibrary, can
50                                                             //  override w/ new HMODULE return val
51       dliNotePreGetProcAddress,           // called just before GetProcAddress, can
52                                                             //  override w/ new FARPROC return value
53       dliFailLoadLib,                            // failed to load library, fix it by
54                                                             //  returning a valid HMODULE
55       dliFailGetProc,                            // failed to get proc address, fix it by
56                                                             //  returning a valid FARPROC
57       dliNoteEndProcessing,                  // called after all processing is done, no
58                                                             //  no bypass possible at this point except
59                                                             //  by longjmp()/throw()/RaiseException.
60       };
61
62 typedef struct DelayLoadProc {
63       BOOL                          fImportByName;
64       union {
65              LPCSTR                szProcName;
66              DWORD                  dwOrdinal;
67              };
68       } DelayLoadProc;
Lines 69 ... 78 are skipped.
79       } DelayLoadInfo, * PDelayLoadInfo;
80
81 typedef FARPROC (WINAPI *PfnDliHook)(
82       unsigned             dliNotify,
83       PDelayLoadInfo  pdli
84       );
85
86 //
87 // Unload support
88 //
89
90 // routine definition; takes a pointer to a name to unload
91 //
92 ExternC
93 BOOL WINAPI
94 __FUnloadDelayLoadedDLL2(LPCSTR szDll);
95
96 //
97 // Snap load support
98 //
99 ExternC
100 HRESULT WINAPI
101 __HrLoadAllImportsForDll(LPCSTR szDll);
102
103
104 //
105 // Exception information
106 //
107 #define FACILITY_VISUALCPP  ((LONG)0x6d)
108 #define VcppException(sev,err)  ((sev) | (FACILITY_VISUALCPP<<16) | err)
109
110 //
111 // Hook pointers
112 //
113
114 // The "notify hook" gets called for every call to the
115 // delay load helper.  This allows a user to hook every call and
116 // skip the delay load helper entirely.
117 //
118 // dliNotify == {
119 //  dliStartProcessing |
120 //  dliNotePreLoadLibrary  |
121 //  dliNotePreGetProc |
122 //  dliNoteEndProcessing}
123 //  on this call.
124 //
125 ExternC
126 PfnDliHook     __pfnDliNotifyHook2;
127
128 // This is the failure hook, dliNotify = {dliFailLoadLib|dliFailGetProc}
129 ExternC
130 PfnDliHook     __pfnDliFailureHook2;
131