1 /***********************************************************************\ 2 * imagehlp.d * 3 * * 4 * Windows API header module * 5 * * 6 * Translated from MinGW Windows headers * 7 * by Stewart Gordon * 8 * * 9 * Placed into public domain * 10 \***********************************************************************/ 11 module win32.imagehlp; 12 version(Windows): 13 14 /* Comment from MinGW 15 NOTE: This strictly does not belong in the Win32 API since it's 16 really part of Platform SDK. However, GDB needs it and we might 17 as well provide it here. 18 */ 19 20 private import win32.winbase, win32.windef; 21 22 // FIXME: check types of constants 23 24 const API_VERSION_NUMBER = 7; 25 26 const BIND_NO_BOUND_IMPORTS = 1; 27 const BIND_NO_UPDATE = 2; 28 const BIND_ALL_IMAGES = 4; 29 const BIND_CACHE_IMPORT_DLLS = 8; 30 31 enum { 32 CBA_DEFERRED_SYMBOL_LOAD_START = 1, 33 CBA_DEFERRED_SYMBOL_LOAD_COMPLETE, 34 CBA_DEFERRED_SYMBOL_LOAD_FAILURE, 35 CBA_SYMBOLS_UNLOADED, 36 CBA_DUPLICATE_SYMBOL 37 } 38 39 const CERT_PE_IMAGE_DIGEST_DEBUG_INFO = 1; 40 const CERT_PE_IMAGE_DIGEST_RESOURCES = 2; 41 const CERT_PE_IMAGE_DIGEST_ALL_IMPORT_INFO = 4; 42 const CERT_PE_IMAGE_DIGEST_NON_PE_INFO = 8; 43 44 const CERT_SECTION_TYPE_ANY = 255; 45 46 enum { 47 CHECKSUM_SUCCESS = 0, 48 CHECKSUM_OPEN_FAILURE, 49 CHECKSUM_MAP_FAILURE, 50 CHECKSUM_MAPVIEW_FAILURE, 51 CHECKSUM_UNICODE_FAILURE 52 } 53 54 const IMAGE_SEPARATION = 65536; 55 56 const SPLITSYM_REMOVE_PRIVATE = 1; 57 const SPLITSYM_EXTRACT_ALL = 2; 58 const SPLITSYM_SYMBOLPATH_IS_SRC = 4; 59 60 const SYMF_OMAP_GENERATED = 1; 61 const SYMF_OMAP_MODIFIED = 2; 62 63 const SYMOPT_CASE_INSENSITIVE = 1; 64 const SYMOPT_UNDNAME = 2; 65 const SYMOPT_DEFERRED_LOADS = 4; 66 const SYMOPT_NO_CPP = 8; 67 const SYMOPT_LOAD_LINES = 16; 68 const SYMOPT_OMAP_FIND_NEAREST = 32; 69 70 const UNDNAME_COMPLETE = 0; 71 const UNDNAME_NO_LEADING_UNDERSCORES = 1; 72 const UNDNAME_NO_MS_KEYWORDS = 2; 73 const UNDNAME_NO_FUNCTION_RETURNS = 4; 74 const UNDNAME_NO_ALLOCATION_MODEL = 8; 75 const UNDNAME_NO_ALLOCATION_LANGUAGE = 16; 76 const UNDNAME_NO_MS_THISTYPE = 32; 77 const UNDNAME_NO_CV_THISTYPE = 64; 78 const UNDNAME_NO_THISTYPE = 96; 79 const UNDNAME_NO_ACCESS_SPECIFIERS = 128; 80 const UNDNAME_NO_THROW_SIGNATURES = 256; 81 const UNDNAME_NO_MEMBER_TYPE = 512; 82 const UNDNAME_NO_RETURN_UDT_MODEL = 1024; 83 const UNDNAME_32_BIT_DECODE = 2048; 84 const UNDNAME_NAME_ONLY = 4096; 85 const UNDNAME_NO_ARGUMENTS = 8192; 86 const UNDNAME_NO_SPECIAL_SYMS = 16384; 87 88 enum IMAGEHLP_STATUS_REASON { 89 BindOutOfMemory, 90 BindRvaToVaFailed, 91 BindNoRoomInImage, 92 BindImportModuleFailed, 93 BindImportProcedureFailed, 94 BindImportModule, 95 BindImportProcedure, 96 BindForwarder, 97 BindForwarderNOT, 98 BindImageModified, 99 BindExpandFileHeaders, 100 BindImageComplete, 101 BindMismatchedSymbols, 102 BindSymbolsNotUpdated 103 } 104 105 struct LOADED_IMAGE { 106 LPSTR ModuleName; 107 HANDLE hFile; 108 PUCHAR MappedAddress; 109 PIMAGE_NT_HEADERS FileHeader; 110 PIMAGE_SECTION_HEADER LastRvaSection; 111 ULONG NumberOfSections; 112 PIMAGE_SECTION_HEADER Sections; 113 ULONG Characteristics; 114 BOOLEAN fSystemImage; 115 BOOLEAN fDOSImage; 116 LIST_ENTRY Links; 117 ULONG SizeOfImage; 118 } 119 alias LOADED_IMAGE* PLOADED_IMAGE; 120 121 struct IMAGE_DEBUG_INFORMATION { 122 LIST_ENTRY List; 123 DWORD Size; 124 PVOID MappedBase; 125 USHORT Machine; 126 USHORT Characteristics; 127 DWORD CheckSum; 128 DWORD ImageBase; 129 DWORD SizeOfImage; 130 DWORD NumberOfSections; 131 PIMAGE_SECTION_HEADER Sections; 132 DWORD ExportedNamesSize; 133 LPSTR ExportedNames; 134 DWORD NumberOfFunctionTableEntries; 135 PIMAGE_FUNCTION_ENTRY FunctionTableEntries; 136 DWORD LowestFunctionStartingAddress; 137 DWORD HighestFunctionEndingAddress; 138 DWORD NumberOfFpoTableEntries; 139 PFPO_DATA FpoTableEntries; 140 DWORD SizeOfCoffSymbols; 141 PIMAGE_COFF_SYMBOLS_HEADER CoffSymbols; 142 DWORD SizeOfCodeViewSymbols; 143 PVOID CodeViewSymbols; 144 LPSTR ImageFilePath; 145 LPSTR ImageFileName; 146 LPSTR DebugFilePath; 147 DWORD TimeDateStamp; 148 BOOL RomImage; 149 PIMAGE_DEBUG_DIRECTORY DebugDirectory; 150 DWORD NumberOfDebugDirectories; 151 DWORD[3] Reserved; 152 } 153 alias IMAGE_DEBUG_INFORMATION* PIMAGE_DEBUG_INFORMATION; 154 155 enum ADDRESS_MODE { 156 AddrMode1616, 157 AddrMode1632, 158 AddrModeReal, 159 AddrModeFlat 160 } 161 162 struct ADDRESS { 163 DWORD Offset; 164 WORD Segment; 165 ADDRESS_MODE Mode; 166 } 167 alias ADDRESS* LPADDRESS; 168 169 struct KDHELP { 170 DWORD Thread; 171 DWORD ThCallbackStack; 172 DWORD NextCallback; 173 DWORD FramePointer; 174 DWORD KiCallUserMode; 175 DWORD KeUserCallbackDispatcher; 176 DWORD SystemRangeStart; 177 } 178 alias KDHELP* PKDHELP; 179 180 struct STACKFRAME { 181 ADDRESS AddrPC; 182 ADDRESS AddrReturn; 183 ADDRESS AddrFrame; 184 ADDRESS AddrStack; 185 LPVOID FuncTableEntry; 186 DWORD[4] Params; 187 BOOL Far; 188 BOOL Virtual; 189 DWORD[3] Reserved; 190 KDHELP KdHelp; 191 } 192 alias STACKFRAME* LPSTACKFRAME; 193 194 struct API_VERSION { 195 USHORT MajorVersion; 196 USHORT MinorVersion; 197 USHORT Revision; 198 USHORT Reserved; 199 } 200 alias API_VERSION* LPAPI_VERSION; 201 202 enum SYM_TYPE { 203 SymNone, 204 SymCoff, 205 SymCv, 206 SymPdb, 207 SymExport, 208 SymDeferred, 209 SymSym 210 } 211 212 struct IMAGEHLP_SYMBOL { 213 DWORD SizeOfStruct; 214 DWORD Address; 215 DWORD Size; 216 DWORD Flags; 217 DWORD MaxNameLength; 218 CHAR[1] Name; 219 } 220 alias IMAGEHLP_SYMBOL* PIMAGEHLP_SYMBOL; 221 222 struct IMAGEHLP_MODULE { 223 DWORD SizeOfStruct; 224 DWORD BaseOfImage; 225 DWORD ImageSize; 226 DWORD TimeDateStamp; 227 DWORD CheckSum; 228 DWORD NumSyms; 229 SYM_TYPE SymType; 230 CHAR[32] ModuleName; 231 CHAR[256] ImageName; 232 CHAR[256] LoadedImageName; 233 } 234 alias IMAGEHLP_MODULE* PIMAGEHLP_MODULE; 235 236 struct IMAGEHLP_LINE { 237 DWORD SizeOfStruct; 238 DWORD Key; 239 DWORD LineNumber; 240 PCHAR FileName; 241 DWORD Address; 242 } 243 alias IMAGEHLP_LINE* PIMAGEHLP_LINE; 244 245 struct IMAGEHLP_DEFERRED_SYMBOL_LOAD { 246 DWORD SizeOfStruct; 247 DWORD BaseOfImage; 248 DWORD CheckSum; 249 DWORD TimeDateStamp; 250 CHAR[MAX_PATH] FileName; 251 BOOLEAN Reparse; 252 } 253 alias IMAGEHLP_DEFERRED_SYMBOL_LOAD* PIMAGEHLP_DEFERRED_SYMBOL_LOAD; 254 255 struct IMAGEHLP_DUPLICATE_SYMBOL { 256 DWORD SizeOfStruct; 257 DWORD NumberOfDups; 258 PIMAGEHLP_SYMBOL Symbol; 259 ULONG SelectedSymbol; 260 } 261 alias IMAGEHLP_DUPLICATE_SYMBOL* PIMAGEHLP_DUPLICATE_SYMBOL; 262 263 mixin DECLARE_HANDLE!("DIGEST_HANDLE"); 264 265 extern (Windows) { 266 alias BOOL function(IMAGEHLP_STATUS_REASON, LPSTR, LPSTR, ULONG, ULONG) 267 PIMAGEHLP_STATUS_ROUTINE; 268 alias BOOL function(HANDLE , LPCVOID, LPVOID, DWORD, LPDWORD) 269 PREAD_PROCESS_MEMORY_ROUTINE; 270 alias LPVOID function(HANDLE, DWORD) PFUNCTION_TABLE_ACCESS_ROUTINE; 271 alias DWORD function(HANDLE, DWORD) PGET_MODULE_BASE_ROUTINE; 272 alias DWORD function(HANDLE, HANDLE, LPADDRESS) 273 PTRANSLATE_ADDRESS_ROUTINE; 274 alias BOOL function(LPSTR, ULONG, PVOID) PSYM_ENUMMODULES_CALLBACK; 275 alias BOOL function(LPSTR, ULONG, ULONG, PVOID) PSYM_ENUMSYMBOLS_CALLBACK; 276 alias BOOL function(LPSTR, ULONG, ULONG, PVOID) 277 PENUMLOADED_MODULES_CALLBACK; 278 alias BOOL function(HANDLE, ULONG, PVOID, PVOID) 279 PSYMBOL_REGISTERED_CALLBACK; 280 alias BOOL function(DIGEST_HANDLE refdata, PBYTE pData, DWORD dwLength) 281 DIGEST_FUNCTION; 282 283 PIMAGE_NT_HEADERS CheckSumMappedFile(LPVOID, DWORD, LPDWORD, LPDWORD); 284 DWORD MapFileAndCheckSumA(LPSTR, LPDWORD, LPDWORD); 285 DWORD MapFileAndCheckSumW(PWSTR, LPDWORD, LPDWORD); 286 BOOL TouchFileTimes(HANDLE, LPSYSTEMTIME); 287 BOOL SplitSymbols(LPSTR, LPSTR, LPSTR, DWORD); 288 HANDLE FindDebugInfoFile(LPSTR, LPSTR, LPSTR); 289 HANDLE FindExecutableImage(LPSTR, LPSTR, LPSTR); 290 BOOL UpdateDebugInfoFile(LPSTR, LPSTR, LPSTR, PIMAGE_NT_HEADERS); 291 BOOL UpdateDebugInfoFileEx(LPSTR, LPSTR, LPSTR, PIMAGE_NT_HEADERS, DWORD); 292 BOOL BindImage(LPSTR, LPSTR, LPSTR); 293 BOOL BindImageEx(DWORD, LPSTR, LPSTR, LPSTR, PIMAGEHLP_STATUS_ROUTINE); 294 BOOL ReBaseImage(LPSTR, LPSTR, BOOL, BOOL, BOOL, ULONG, ULONG*, ULONG*, 295 ULONG*, ULONG*, ULONG); 296 PLOADED_IMAGE ImageLoad(LPSTR, LPSTR); 297 BOOL ImageUnload(PLOADED_IMAGE); 298 PIMAGE_NT_HEADERS ImageNtHeader(PVOID); 299 PVOID ImageDirectoryEntryToData(PVOID, BOOLEAN, USHORT, PULONG); 300 PIMAGE_SECTION_HEADER ImageRvaToSection(PIMAGE_NT_HEADERS, PVOID, ULONG); 301 PVOID ImageRvaToVa(PIMAGE_NT_HEADERS, PVOID, ULONG, 302 PIMAGE_SECTION_HEADER*); 303 BOOL MapAndLoad(LPSTR, LPSTR, PLOADED_IMAGE, BOOL, BOOL); 304 BOOL GetImageConfigInformation(PLOADED_IMAGE, 305 PIMAGE_LOAD_CONFIG_DIRECTORY); 306 DWORD GetImageUnusedHeaderBytes(PLOADED_IMAGE, LPDWORD); 307 BOOL SetImageConfigInformation(PLOADED_IMAGE, 308 PIMAGE_LOAD_CONFIG_DIRECTORY); 309 BOOL UnMapAndLoad(PLOADED_IMAGE); 310 PIMAGE_DEBUG_INFORMATION MapDebugInformation(HANDLE, LPSTR, LPSTR, DWORD); 311 BOOL UnmapDebugInformation(PIMAGE_DEBUG_INFORMATION); 312 HANDLE FindExecutableImage(LPSTR, LPSTR, LPSTR); 313 BOOL SearchTreeForFile(LPSTR, LPSTR, LPSTR); 314 BOOL MakeSureDirectoryPathExists(LPCSTR); 315 DWORD UnDecorateSymbolName(LPCSTR, LPSTR, DWORD, DWORD); 316 BOOL StackWalk(DWORD, HANDLE, HANDLE, LPSTACKFRAME, LPVOID, 317 PREAD_PROCESS_MEMORY_ROUTINE, PFUNCTION_TABLE_ACCESS_ROUTINE, 318 PGET_MODULE_BASE_ROUTINE, PTRANSLATE_ADDRESS_ROUTINE); 319 LPAPI_VERSION ImagehlpApiVersion(); 320 LPAPI_VERSION ImagehlpApiVersionEx(LPAPI_VERSION); 321 DWORD GetTimestampForLoadedLibrary(HMODULE); 322 BOOL RemovePrivateCvSymbolic(PCHAR, PCHAR*, ULONG*); 323 VOID RemoveRelocations(PCHAR); 324 DWORD SymSetOptions(DWORD); 325 DWORD SymGetOptions(); 326 BOOL SymCleanup(HANDLE); 327 BOOL SymEnumerateModules(HANDLE, PSYM_ENUMMODULES_CALLBACK, PVOID); 328 BOOL SymEnumerateSymbols(HANDLE, DWORD, PSYM_ENUMSYMBOLS_CALLBACK, PVOID); 329 BOOL EnumerateLoadedModules(HANDLE, PENUMLOADED_MODULES_CALLBACK, PVOID); 330 LPVOID SymFunctionTableAccess(HANDLE, DWORD); 331 BOOL SymGetModuleInfo(HANDLE, DWORD, PIMAGEHLP_MODULE); 332 DWORD SymGetModuleBase(HANDLE, DWORD); 333 BOOL SymGetSymFromAddr(HANDLE, DWORD, PDWORD, PIMAGEHLP_SYMBOL); 334 BOOL SymGetSymFromName(HANDLE, LPSTR, PIMAGEHLP_SYMBOL); 335 BOOL SymGetSymNext(HANDLE, PIMAGEHLP_SYMBOL); 336 BOOL SymGetSymPrev(HANDLE, PIMAGEHLP_SYMBOL); 337 BOOL SymGetLineFromAddr(HANDLE, DWORD, PDWORD, PIMAGEHLP_LINE); 338 BOOL SymGetLineFromName(HANDLE, LPSTR, LPSTR, DWORD, PLONG, 339 PIMAGEHLP_LINE); 340 BOOL SymGetLineNext(HANDLE, PIMAGEHLP_LINE); 341 BOOL SymGetLinePrev(HANDLE, PIMAGEHLP_LINE); 342 BOOL SymMatchFileName(LPSTR, LPSTR, LPSTR*, LPSTR*); 343 BOOL SymInitialize(HANDLE, LPSTR, BOOL); 344 BOOL SymGetSearchPath(HANDLE, LPSTR, DWORD); 345 BOOL SymSetSearchPath(HANDLE, LPSTR); 346 BOOL SymLoadModule(HANDLE, HANDLE, PSTR, PSTR, DWORD, DWORD); 347 BOOL SymUnloadModule(HANDLE, DWORD); 348 BOOL SymUnDName(PIMAGEHLP_SYMBOL, LPSTR, DWORD); 349 BOOL SymRegisterCallback(HANDLE, PSYMBOL_REGISTERED_CALLBACK, PVOID); 350 BOOL ImageGetDigestStream(HANDLE, DWORD, DIGEST_FUNCTION, DIGEST_HANDLE); 351 BOOL ImageAddCertificate(HANDLE, LPWIN_CERTIFICATE, PDWORD); 352 BOOL ImageRemoveCertificate(HANDLE, DWORD); 353 BOOL ImageEnumerateCertificates(HANDLE, WORD, PDWORD, PDWORD, DWORD); 354 BOOL ImageGetCertificateData(HANDLE, DWORD, LPWIN_CERTIFICATE, PDWORD); 355 BOOL ImageGetCertificateHeader(HANDLE, DWORD, LPWIN_CERTIFICATE); 356 BOOL CopyPdb(CHAR*, CHAR*, BOOL); 357 BOOL RemovePrivateCvSymbolicEx(PCHAR, ULONG, PCHAR*, ULONG*); 358 } 359 360 version (Unicode) { 361 alias MapFileAndCheckSumW MapFileAndCheckSum; 362 } else { 363 alias MapFileAndCheckSumA MapFileAndCheckSum; 364 }