xref: /reactos/sdk/include/psdk/imagehlp.h (revision f5f6ea29)
1 /*
2 	imagehlp.h - Include file for IMAGEHLP.DLL APIs
3 
4 	Written by Mumit Khan <khan@nanotech.wisc.edu>
5 
6 	This file is part of a free library for the Win32 API.
7 
8 	NOTE: This strictly does not belong in the Win32 API since it's
9 	really part of Platform SDK. However,GDB needs it and we might
10 	as well provide it here.
11 
12 	This library is distributed in the hope that it will be useful,
13 	but WITHOUT ANY WARRANTY; without even the implied warranty of
14 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 
16 */
17 
18 #ifndef _IMAGEHLP_H
19 #define _IMAGEHLP_H
20 
21 #ifdef _WIN64
22 #ifndef _IMAGEHLP64
23 #define _IMAGEHLP64
24 #endif
25 #endif
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 #include <wintrust.h>
32 
33 #define API_VERSION_NUMBER 7
34 #define BIND_NO_BOUND_IMPORTS 0x00000001
35 #define BIND_NO_UPDATE 0x00000002
36 #define BIND_ALL_IMAGES 0x00000004
37 #define BIND_CACHE_IMPORT_DLLS 0x00000008
38 #define CBA_DEFERRED_SYMBOL_LOAD_START 1
39 #define CBA_DEFERRED_SYMBOL_LOAD_COMPLETE 2
40 #define CBA_DEFERRED_SYMBOL_LOAD_FAILURE 3
41 #define CBA_SYMBOLS_UNLOADED 4
42 #define CBA_DUPLICATE_SYMBOL 5
43 #define CERT_PE_IMAGE_DIGEST_DEBUG_INFO 1
44 #define CERT_PE_IMAGE_DIGEST_RESOURCES 2
45 #define CERT_PE_IMAGE_DIGEST_ALL_IMPORT_INFO 4
46 #define CERT_PE_IMAGE_DIGEST_NON_PE_INFO 8
47 #define CERT_SECTION_TYPE_ANY 255
48 #define CHECKSUM_SUCCESS	0
49 #define CHECKSUM_OPEN_FAILURE	1
50 #define CHECKSUM_MAP_FAILURE	2
51 #define CHECKSUM_MAPVIEW_FAILURE	3
52 #define CHECKSUM_UNICODE_FAILURE	4
53 #define IMAGE_SEPARATION	65536
54 #define SPLITSYM_REMOVE_PRIVATE	1
55 #define SPLITSYM_EXTRACT_ALL	2
56 #define SPLITSYM_SYMBOLPATH_IS_SRC	4
57 #define SYMF_OMAP_GENERATED	1
58 #define SYMF_OMAP_MODIFIED	2
59 #define SYMOPT_CASE_INSENSITIVE	1
60 #define SYMOPT_UNDNAME	2
61 #define SYMOPT_DEFERRED_LOADS	4
62 #define SYMOPT_NO_CPP	8
63 #define SYMOPT_LOAD_LINES	16
64 #define SYMOPT_OMAP_FIND_NEAREST	32
65 #define UNDNAME_COMPLETE	0
66 #define UNDNAME_NO_LEADING_UNDERSCORES	1
67 #define UNDNAME_NO_MS_KEYWORDS	2
68 #define UNDNAME_NO_FUNCTION_RETURNS	4
69 #define UNDNAME_NO_ALLOCATION_MODEL	8
70 #define UNDNAME_NO_ALLOCATION_LANGUAGE	16
71 #define UNDNAME_NO_MS_THISTYPE	32
72 #define UNDNAME_NO_CV_THISTYPE	64
73 #define UNDNAME_NO_THISTYPE	96
74 #define UNDNAME_NO_ACCESS_SPECIFIERS	128
75 #define UNDNAME_NO_THROW_SIGNATURES	256
76 #define UNDNAME_NO_MEMBER_TYPE	512
77 #define UNDNAME_NO_RETURN_UDT_MODEL	1024
78 #define UNDNAME_32_BIT_DECODE	2048
79 #define UNDNAME_NAME_ONLY	4096
80 #define UNDNAME_NO_ARGUMENTS	8192
81 #define UNDNAME_NO_SPECIAL_SYMS	16384
82 
83 #ifdef _IMAGEHLP_SOURCE_
84     #define IMAGEAPI __stdcall
85     #define DBHLP_DEPRECIATED
86 #else
87     #define IMAGEAPI DECLSPEC_IMPORT __stdcall
88     #if (_MSC_VER >= 1300) && !defined(MIDL_PASS)
89         #define DBHLP_DEPRECIATED __declspec(deprecated)
90     #else
91         #define DBHLP_DEPRECIATED
92     #endif
93 #endif
94 
95 #define DBHLPAPI IMAGEAPI
96 
97 #ifndef RC_INVOKED
98 
99 typedef enum _IMAGEHLP_STATUS_REASON {
100 	BindOutOfMemory,
101 	BindRvaToVaFailed,
102 	BindNoRoomInImage,
103 	BindImportModuleFailed,
104 	BindImportProcedureFailed,
105 	BindImportModule,
106 	BindImportProcedure,
107 	BindForwarder,
108 	BindForwarderNOT,
109 	BindImageModified,
110 	BindExpandFileHeaders,
111 	BindImageComplete,
112 	BindMismatchedSymbols,
113 	BindSymbolsNotUpdated
114 } IMAGEHLP_STATUS_REASON;
115 typedef BOOL(WINAPI*PIMAGEHLP_STATUS_ROUTINE)(IMAGEHLP_STATUS_REASON,PCSTR,PCSTR,ULONG_PTR,ULONG_PTR);
116 typedef struct _LOADED_IMAGE {
117 	PSTR ModuleName;
118 	HANDLE hFile;
119 	PUCHAR MappedAddress;
120 #ifdef _IMAGEHLP64
121     PIMAGE_NT_HEADERS64 FileHeader;
122 #else
123     PIMAGE_NT_HEADERS32 FileHeader;
124 #endif
125 	PIMAGE_SECTION_HEADER LastRvaSection;
126 	ULONG NumberOfSections;
127 	PIMAGE_SECTION_HEADER Sections;
128 	ULONG Characteristics;
129 	BOOLEAN fSystemImage;
130 	BOOLEAN fDOSImage;
131     BOOLEAN fReadOnly;
132     UCHAR Version;
133 	LIST_ENTRY Links;
134 	ULONG SizeOfImage;
135 } LOADED_IMAGE,*PLOADED_IMAGE;
136 typedef struct _IMAGE_DEBUG_INFORMATION {
137 	LIST_ENTRY List;
138 	DWORD Size;
139 	PVOID MappedBase;
140 	USHORT Machine;
141 	USHORT Characteristics;
142 	DWORD CheckSum;
143 	DWORD ImageBase;
144 	DWORD SizeOfImage;
145 	DWORD NumberOfSections;
146 	PIMAGE_SECTION_HEADER Sections;
147 	DWORD ExportedNamesSize;
148 	LPSTR ExportedNames;
149 	DWORD NumberOfFunctionTableEntries;
150 	PIMAGE_FUNCTION_ENTRY FunctionTableEntries;
151 	DWORD LowestFunctionStartingAddress;
152 	DWORD HighestFunctionEndingAddress;
153 	DWORD NumberOfFpoTableEntries;
154 	PFPO_DATA FpoTableEntries;
155 	DWORD SizeOfCoffSymbols;
156 	PIMAGE_COFF_SYMBOLS_HEADER CoffSymbols;
157 	DWORD SizeOfCodeViewSymbols;
158 	PVOID CodeViewSymbols;
159 	LPSTR ImageFilePath;
160 	LPSTR ImageFileName;
161 	LPSTR DebugFilePath;
162 	DWORD TimeDateStamp;
163 	BOOL RomImage;
164 	PIMAGE_DEBUG_DIRECTORY DebugDirectory;
165 	DWORD NumberOfDebugDirectories;
166 	DWORD Reserved[3];
167 } IMAGE_DEBUG_INFORMATION,*PIMAGE_DEBUG_INFORMATION;
168 typedef enum {
169 	AddrMode1616,
170 	AddrMode1632,
171 	AddrModeReal,
172 	AddrModeFlat
173 } ADDRESS_MODE;
174 typedef struct _tagADDRESS {
175 	DWORD Offset;
176 	WORD Segment;
177 	ADDRESS_MODE Mode;
178 } ADDRESS,*LPADDRESS;
179 typedef struct _KDHELP {
180 	DWORD Thread;
181 	DWORD ThCallbackStack;
182 	DWORD NextCallback;
183 	DWORD FramePointer;
184 	DWORD KiCallUserMode;
185 	DWORD KeUserCallbackDispatcher;
186 	DWORD SystemRangeStart;
187 } KDHELP,*PKDHELP;
188 typedef struct _tagSTACKFRAME {
189 	ADDRESS AddrPC;
190 	ADDRESS AddrReturn;
191 	ADDRESS AddrFrame;
192 	ADDRESS AddrStack;
193 	LPVOID FuncTableEntry;
194 	DWORD Params[4];
195 	BOOL Far;
196 	BOOL Virtual;
197 	DWORD Reserved[3];
198 	KDHELP KdHelp;
199 } STACKFRAME,*LPSTACKFRAME;
200 typedef BOOL(WINAPI*PREAD_PROCESS_MEMORY_ROUTINE)(HANDLE ,LPCVOID,LPVOID,DWORD,LPDWORD);
201 typedef LPVOID(WINAPI*PFUNCTION_TABLE_ACCESS_ROUTINE)(HANDLE,DWORD);
202 typedef DWORD(WINAPI*PGET_MODULE_BASE_ROUTINE)(HANDLE,DWORD);
203 typedef DWORD(WINAPI*PTRANSLATE_ADDRESS_ROUTINE)(HANDLE,HANDLE,LPADDRESS);
204 typedef struct API_VERSION {
205 	USHORT MajorVersion;
206 	USHORT MinorVersion;
207 	USHORT Revision;
208 	USHORT Reserved;
209 } API_VERSION,*LPAPI_VERSION;
210 typedef BOOL(CALLBACK*PSYM_ENUMMODULES_CALLBACK)(LPSTR,ULONG,PVOID);
211 typedef BOOL(CALLBACK*PSYM_ENUMSYMBOLS_CALLBACK)(LPSTR,ULONG,ULONG,PVOID);
212 typedef BOOL(CALLBACK*PENUMLOADED_MODULES_CALLBACK)(LPSTR,ULONG,ULONG,PVOID);
213 typedef BOOL(CALLBACK*PSYMBOL_REGISTERED_CALLBACK)(HANDLE,ULONG,PVOID,PVOID);
214 typedef enum {
215 	SymNone,
216 	SymCoff,
217 	SymCv,
218 	SymPdb,
219 	SymExport,
220 	SymDeferred,
221 	SymSym
222 } SYM_TYPE;
223 #ifdef _NO_CVCONST_H
224 enum SymTagEnum
225 {
226     SymTagNull,
227     SymTagExe,
228     SymTagCompiland,
229     SymTagCompilandDetails,
230     SymTagCompilandEnv,
231     SymTagFunction,
232     SymTagBlock,
233     SymTagData,
234     SymTagAnnotation,
235     SymTagLabel,
236     SymTagPublicSymbol,
237     SymTagUDT,
238     SymTagEnum,
239     SymTagFunctionType,
240     SymTagPointerType,
241     SymTagArrayType,
242     SymTagBaseType,
243     SymTagTypedef,
244     SymTagBaseClass,
245     SymTagFriend,
246     SymTagFunctionArgType,
247     SymTagFuncDebugStart,
248     SymTagFuncDebugEnd,
249     SymTagUsingNamespace,
250     SymTagVTableShape,
251     SymTagVTable,
252     SymTagCustom,
253     SymTagThunk,
254     SymTagCustomType,
255     SymTagManagedType,
256     SymTagDimension,
257     SymTagCallSite,
258     SymTagInlineSite,
259     SymTagBaseInterface,
260     SymTagVectorType,
261     SymTagMatrixType,
262     SymTagHLSLType,
263     SymTagCaller,
264     SymTagCallee,
265     SymTagExport,
266     SymTagHeapAllocationSite,
267     SymTagCoffGroup,
268     SymTagMax
269 };
270 #endif // _NO_CVCONST_H
271 typedef struct _IMAGEHLP_SYMBOL {
272 	DWORD SizeOfStruct;
273 	DWORD Address;
274 	DWORD Size;
275 	DWORD Flags;
276 	DWORD MaxNameLength;
277 	CHAR Name[1];
278 } IMAGEHLP_SYMBOL,*PIMAGEHLP_SYMBOL;
279 typedef struct _IMAGEHLP_MODULE {
280 	DWORD SizeOfStruct;
281 	DWORD BaseOfImage;
282 	DWORD ImageSize;
283 	DWORD TimeDateStamp;
284 	DWORD CheckSum;
285 	DWORD NumSyms;
286 	SYM_TYPE SymType;
287 	CHAR ModuleName[32];
288 	CHAR ImageName[256];
289 	CHAR LoadedImageName[256];
290 } IMAGEHLP_MODULE,*PIMAGEHLP_MODULE;
291 typedef struct _IMAGEHLP_LINE {
292 	DWORD SizeOfStruct;
293 	DWORD Key;
294 	DWORD LineNumber;
295 	PCHAR FileName;
296 	DWORD Address;
297 } IMAGEHLP_LINE,*PIMAGEHLP_LINE;
298 typedef struct _IMAGEHLP_DEFERRED_SYMBOL_LOAD {
299 	DWORD SizeOfStruct;
300 	DWORD BaseOfImage;
301 	DWORD CheckSum;
302 	DWORD TimeDateStamp;
303 	CHAR FileName[MAX_PATH];
304 	BOOLEAN Reparse;
305 	HANDLE hFile;
306 } IMAGEHLP_DEFERRED_SYMBOL_LOAD,*PIMAGEHLP_DEFERRED_SYMBOL_LOAD;
307 typedef struct _IMAGEHLP_DUPLICATE_SYMBOL {
308 	DWORD SizeOfStruct;
309 	DWORD NumberOfDups;
310 	PIMAGEHLP_SYMBOL Symbol;
311 	ULONG SelectedSymbol;
312 } IMAGEHLP_DUPLICATE_SYMBOL,*PIMAGEHLP_DUPLICATE_SYMBOL;
313 typedef PVOID DIGEST_HANDLE;
314 typedef BOOL(WINAPI*DIGEST_FUNCTION)(DIGEST_HANDLE refdata,PBYTE pData,DWORD dwLength);
315 
316 PIMAGE_NT_HEADERS IMAGEAPI CheckSumMappedFile(LPVOID,DWORD,LPDWORD,LPDWORD);
317 DWORD IMAGEAPI MapFileAndCheckSumA(PCSTR,LPDWORD,LPDWORD);
318 DWORD IMAGEAPI MapFileAndCheckSumW(PCWSTR,LPDWORD,LPDWORD);
319 BOOL IMAGEAPI TouchFileTimes(HANDLE,LPSYSTEMTIME);
320 BOOL IMAGEAPI SplitSymbols(PSTR,PCSTR,PSTR,DWORD);
321 HANDLE IMAGEAPI FindDebugInfoFile(PCSTR,PCSTR,PSTR);
322 HANDLE IMAGEAPI FindExecutableImage(PCSTR,PCSTR,PSTR);
323 BOOL IMAGEAPI UpdateDebugInfoFile(PCSTR,PCSTR,PSTR,PIMAGE_NT_HEADERS32);
324 BOOL IMAGEAPI UpdateDebugInfoFileEx(PCSTR,PCSTR,PSTR,PIMAGE_NT_HEADERS32,DWORD);
325 BOOL IMAGEAPI BindImage(IN PCSTR,IN PCSTR,IN PCSTR);
326 BOOL IMAGEAPI BindImageEx(IN DWORD,IN LPCSTR,IN LPCSTR,IN LPCSTR,IN PIMAGEHLP_STATUS_ROUTINE);
327 BOOL IMAGEAPI ReBaseImage(IN PCSTR,IN PCSTR,IN BOOL, IN BOOL,IN BOOL, IN ULONG, OUT ULONG*, OUT ULONG_PTR*, OUT ULONG*, IN OUT ULONG_PTR*, IN ULONG);
328 
329 PLOADED_IMAGE IMAGEAPI ImageLoad(PCSTR,PCSTR);
330 BOOL IMAGEAPI ImageUnload(PLOADED_IMAGE);
331 PIMAGE_NT_HEADERS IMAGEAPI ImageNtHeader(IN PVOID);
332 PVOID IMAGEAPI ImageDirectoryEntryToData(IN PVOID,IN BOOLEAN,IN USHORT,OUT PULONG);
333 PVOID IMAGEAPI ImageDirectoryEntryToDataEx(IN PVOID Base, IN BOOLEAN MappedAsImage, IN USHORT DirectoryEntry, OUT PULONG Size, OUT PIMAGE_SECTION_HEADER *FoundSection OPTIONAL);
334 PVOID IMAGEAPI ImageDirectoryEntryToData32(PVOID Base, BOOLEAN MappedAsImage, USHORT DirectoryEntry, PULONG Size, PIMAGE_SECTION_HEADER *FoundHeader OPTIONAL, PIMAGE_FILE_HEADER FileHeader, PIMAGE_OPTIONAL_HEADER OptionalHeader);
335 PIMAGE_SECTION_HEADER IMAGEAPI ImageRvaToSection(IN PIMAGE_NT_HEADERS,IN PVOID,IN ULONG);
336 PVOID IMAGEAPI ImageRvaToVa(IN PIMAGE_NT_HEADERS,IN PVOID,IN ULONG,IN OUT PIMAGE_SECTION_HEADER*);
337 BOOL IMAGEAPI MapAndLoad(PCSTR,PCSTR,PLOADED_IMAGE,BOOL,BOOL);
338 BOOL IMAGEAPI GetImageConfigInformation(PLOADED_IMAGE,PIMAGE_LOAD_CONFIG_DIRECTORY);
339 DWORD IMAGEAPI GetImageUnusedHeaderBytes(PLOADED_IMAGE,LPDWORD);
340 BOOL IMAGEAPI SetImageConfigInformation(PLOADED_IMAGE,PIMAGE_LOAD_CONFIG_DIRECTORY);
341 BOOL IMAGEAPI UnMapAndLoad(PLOADED_IMAGE);
342 PIMAGE_DEBUG_INFORMATION IMAGEAPI MapDebugInformation(HANDLE,PCSTR,PCSTR,DWORD);
343 BOOL IMAGEAPI UnmapDebugInformation(PIMAGE_DEBUG_INFORMATION);
344 BOOL IMAGEAPI SearchTreeForFile(PCSTR,PCSTR,PSTR);
345 BOOL IMAGEAPI MakeSureDirectoryPathExists(LPCSTR);
346 DWORD IMAGEAPI WINAPI UnDecorateSymbolName(LPCSTR,LPSTR,DWORD,DWORD);
347 BOOL
348 IMAGEAPI
349 StackWalk(DWORD,HANDLE,HANDLE,LPSTACKFRAME,LPVOID,PREAD_PROCESS_MEMORY_ROUTINE,PFUNCTION_TABLE_ACCESS_ROUTINE,PGET_MODULE_BASE_ROUTINE,PTRANSLATE_ADDRESS_ROUTINE);
350 LPAPI_VERSION IMAGEAPI ImagehlpApiVersion(VOID);
351 LPAPI_VERSION IMAGEAPI ImagehlpApiVersionEx(LPAPI_VERSION);
352 DWORD IMAGEAPI GetTimestampForLoadedLibrary(HMODULE);
353 BOOL IMAGEAPI RemovePrivateCvSymbolic(PCHAR,PCHAR*,ULONG*);
354 VOID IMAGEAPI RemoveRelocations(PCHAR);
355 DWORD IMAGEAPI SymSetOptions(IN DWORD);
356 DWORD IMAGEAPI SymGetOptions(VOID);
357 BOOL IMAGEAPI SymCleanup(IN HANDLE);
358 BOOL IMAGEAPI SymEnumerateModules(IN HANDLE,IN PSYM_ENUMMODULES_CALLBACK,IN PVOID);
359 BOOL IMAGEAPI SymEnumerateSymbols(IN HANDLE,IN DWORD,IN PSYM_ENUMSYMBOLS_CALLBACK,IN PVOID);
360 BOOL IMAGEAPI EnumerateLoadedModules(IN HANDLE,IN PENUMLOADED_MODULES_CALLBACK,IN PVOID);
361 LPVOID IMAGEAPI SymFunctionTableAccess(HANDLE,DWORD);
362 BOOL IMAGEAPI SymGetModuleInfo(IN HANDLE,IN DWORD,OUT PIMAGEHLP_MODULE);
363 DWORD IMAGEAPI SymGetModuleBase(IN HANDLE,IN DWORD);
364 BOOL IMAGEAPI SymGetSymFromAddr(IN HANDLE,IN DWORD,OUT PDWORD,OUT PIMAGEHLP_SYMBOL);
365 BOOL IMAGEAPI SymGetSymFromName(IN HANDLE,IN LPSTR,OUT PIMAGEHLP_SYMBOL);
366 BOOL IMAGEAPI SymGetSymNext(IN HANDLE,IN OUT PIMAGEHLP_SYMBOL);
367 BOOL IMAGEAPI SymGetSymPrev(IN HANDLE,IN OUT PIMAGEHLP_SYMBOL);
368 BOOL IMAGEAPI SymGetLineFromAddr(IN HANDLE,IN DWORD,OUT PDWORD,OUT PIMAGEHLP_LINE);
369 BOOL IMAGEAPI SymGetLineFromName(IN HANDLE,IN LPSTR,IN LPSTR,IN DWORD,OUT PLONG,IN OUT PIMAGEHLP_LINE);
370 BOOL IMAGEAPI SymGetLineNext(IN HANDLE,IN OUT PIMAGEHLP_LINE);
371 BOOL IMAGEAPI SymGetLinePrev(IN HANDLE,IN OUT PIMAGEHLP_LINE);
372 BOOL IMAGEAPI SymMatchFileName(IN LPSTR,IN LPSTR,OUT LPSTR*,OUT LPSTR*);
373 BOOL IMAGEAPI SymInitialize(IN HANDLE,IN LPSTR,IN BOOL);
374 BOOL IMAGEAPI SymGetSearchPath(IN HANDLE,OUT LPSTR,IN DWORD);
375 BOOL IMAGEAPI SymSetSearchPath(IN HANDLE,IN LPSTR);
376 DWORD IMAGEAPI SymLoadModule(IN HANDLE,IN HANDLE,IN PSTR,IN PSTR,IN DWORD,IN DWORD);
377 BOOL IMAGEAPI SymUnloadModule(IN HANDLE,IN DWORD);
378 BOOL IMAGEAPI SymUnDName(IN PIMAGEHLP_SYMBOL,OUT LPSTR,IN DWORD);
379 BOOL IMAGEAPI SymRegisterCallback(IN HANDLE,IN PSYMBOL_REGISTERED_CALLBACK,IN PVOID);
380 BOOL IMAGEAPI ImageGetDigestStream(IN HANDLE,IN DWORD,IN DIGEST_FUNCTION,IN DIGEST_HANDLE);
381 BOOL IMAGEAPI ImageAddCertificate(IN HANDLE,IN LPWIN_CERTIFICATE,OUT PDWORD);
382 BOOL IMAGEAPI ImageRemoveCertificate(IN HANDLE,IN DWORD);
383 BOOL IMAGEAPI ImageEnumerateCertificates(IN HANDLE,IN WORD,OUT PDWORD,IN OUT PDWORD OPTIONAL,IN OUT DWORD OPTIONAL);
384 BOOL IMAGEAPI ImageGetCertificateData(IN HANDLE,IN DWORD,OUT LPWIN_CERTIFICATE,IN OUT PDWORD);
385 BOOL IMAGEAPI ImageGetCertificateHeader(IN HANDLE,IN DWORD,IN OUT LPWIN_CERTIFICATE);
386 BOOL IMAGEAPI CopyPdb(CHAR const*,CHAR const*,BOOL);
387 BOOL IMAGEAPI RemovePrivateCvSymbolicEx(PCHAR,ULONG,PCHAR*,ULONG*);
388 
389 #endif /* RC_INVOKED */
390 
391 #ifdef UNICODE
392 #define MapFileAndCheckSum MapFileAndCheckSumW
393 #else
394 #define MapFileAndCheckSum MapFileAndCheckSumA
395 #endif
396 
397 #ifdef __cplusplus
398 }
399 #endif
400 
401 #endif /* _IMAGEHLP_H */
402 
403