STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
delayimp.h
Go to the documentation of this file.
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)
33 
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
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 {
64  union {
65  LPCSTR szProcName;
67  };
68  } DelayLoadProc;
69 
70 typedef struct DelayLoadInfo {
71  DWORD cb; // size of structure
72  PCImgDelayDescr pidd; // raw form of data (everything is there)
73  FARPROC * ppfn; // points to address of function to load
74  LPCSTR szDll; // name of dll
75  DelayLoadProc dlp; // name or ordinal of procedure
76  HMODULE hmodCur; // the hInstance of the library we have loaded
77  FARPROC pfnCur; // the actual function that will be called
78  DWORD dwLastError;// error received (if an error notification)
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) now defined in winerror.h
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 // Prior to Visual Studio 2015 Update 3, these hooks were non-const. They were
126 // made const to improve security (global, writable function pointers are bad).
127 // If for backwards compatibility you require the hooks to be writable, define
128 // the macro DELAYIMP_INSECURE_WRITABLE_HOOKS prior to including this header and
129 // provide your own non-const definition of the hooks.
130 ExternC
131 #ifndef DELAYIMP_INSECURE_WRITABLE_HOOKS
132 const
133 #endif
135 
136 // This is the failure hook, dliNotify = {dliFailLoadLib|dliFailGetProc}
137 ExternC
138 #ifndef DELAYIMP_INSECURE_WRITABLE_HOOKS
139 const
140 #endif
Definition: delayimp.h:70
RVA rvaUnloadIAT
Definition: delayimp.h:29
FARPROC pfnCur
Definition: delayimp.h:77
const ImgDelayDescr * PCImgDelayDescr
Definition: delayimp.h:34
Definition: delayimp.h:53
struct DelayLoadProc DelayLoadProc
Definition: delayimp.h:47
Definition: delayimp.h:46
Definition: delayimp.h:57
Definition: delayimp.h:49
RVA rvaHmod
Definition: delayimp.h:25
Definition: delayimp.h:37
BOOL fImportByName
Definition: delayimp.h:63
RVA rvaDLLName
Definition: delayimp.h:24
RVA rvaIAT
Definition: delayimp.h:26
IMAGE_THUNK_DATA * PImgThunkData
Definition: delayimp.h:18
Definition: delayimp.h:62
DWORD dwTimeStamp
Definition: delayimp.h:30
LPCSTR szProcName
Definition: delayimp.h:65
ExternC HRESULT WINAPI __HrLoadAllImportsForDll(LPCSTR szDll)
Definition: delayhlp.cpp:444
DelayLoadProc dlp
Definition: delayimp.h:75
DWORD dwLastError
Definition: delayimp.h:78
struct ImgDelayDescr * PImgDelayDescr
HMODULE hmodCur
Definition: delayimp.h:76
struct DelayLoadInfo DelayLoadInfo
DWORD grAttrs
Definition: delayimp.h:23
FARPROC(WINAPI * PfnDliHook)(unsigned dliNotify, PDelayLoadInfo pdli)
Definition: delayimp.h:81
DWORD RVA
Definition: delayimp.h:20
ExternC const PfnDliHook __pfnDliNotifyHook2
Definition: delayimp.h:134
PCImgDelayDescr pidd
Definition: delayimp.h:72
unsigned long DWORD
Definition: concrt.h:63
DLAttr
Definition: delayimp.h:36
DWORD cb
Definition: delayimp.h:71
LPCSTR szDll
Definition: delayimp.h:74
struct DelayLoadInfo * PDelayLoadInfo
Definition: delayimp.h:55
DWORD dwOrdinal
Definition: delayimp.h:66
ExternC const PfnDliHook __pfnDliFailureHook2
Definition: delayimp.h:141
Definition: delayimp.h:22
const IMAGE_THUNK_DATA * PCImgThunkData
Definition: delayimp.h:19
FARPROC * ppfn
Definition: delayimp.h:73
#define ExternC
Definition: delayimp.h:15
ExternC BOOL WINAPI __FUnloadDelayLoadedDLL2(LPCSTR szDll)
Definition: delayhlp.cpp:414
RVA rvaBoundIAT
Definition: delayimp.h:28
struct ImgDelayDescr ImgDelayDescr
Definition: delayimp.h:51
RVA rvaINT
Definition: delayimp.h:27