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