home *** CD-ROM | disk | FTP | other *** search
/ PC World Plus! (NZ) 2001 June / HDC50.iso / Runimage / Delphi50 / Source / Rtl / Win / IMAGEHLP.PAS < prev    next >
Pascal/Delphi Source File  |  1999-08-11  |  32KB  |  754 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Borland Delphi Run-time Library                 }
  5. {                            }
  6. {    Prototypes and constants required for the       }
  7. {       Win32 image help routines.                      }
  8. {                            }
  9. {       Copyright (c) 1985-1999, Microsoft Corporation  }
  10. {                                                       }
  11. {       Translator: Inprise Corporation                 }
  12. {                                                       }
  13. {*******************************************************}
  14.  
  15. unit Imagehlp;
  16.  
  17. interface
  18.  
  19. {$HPPEMIT '#include <imagehlp.h>'}
  20.  
  21. uses Windows;
  22.  
  23. {$Z4}
  24.  
  25. { Define checksum return codes. }
  26. const
  27.   {$EXTERNALSYM CHECKSUM_SUCCESS}
  28.   CHECKSUM_SUCCESS                = 0;
  29.   {$EXTERNALSYM CHECKSUM_OPEN_FAILURE}
  30.   CHECKSUM_OPEN_FAILURE           = 1;
  31.   {$EXTERNALSYM CHECKSUM_MAP_FAILURE}
  32.   CHECKSUM_MAP_FAILURE            = 2;
  33.   {$EXTERNALSYM CHECKSUM_MAPVIEW_FAILURE}
  34.   CHECKSUM_MAPVIEW_FAILURE        = 3;
  35.   {$EXTERNALSYM CHECKSUM_UNICODE_FAILURE}
  36.   CHECKSUM_UNICODE_FAILURE        = 4;
  37.  
  38. { Define Splitsym flags. }
  39.  
  40.   {$EXTERNALSYM SPLITSYM_REMOVE_PRIVATE}
  41.   SPLITSYM_REMOVE_PRIVATE         = $00000001;      { Remove CV types/symbols and Fixup debug }
  42. {  Used for creating .dbg files that ship }
  43. {  as part of the product. }
  44.  
  45.   {$EXTERNALSYM SPLITSYM_EXTRACT_ALL}
  46.   SPLITSYM_EXTRACT_ALL            = $00000002;      { Extract all debug info from image. }
  47. {  Normally, FPO is left in the image }
  48. {  to allow stack traces through the code. }
  49. {  Using this switch is similar to linking }
  50. {  with -debug:none except the .dbg file }
  51. {  exists... }
  52.  
  53. { Define checksum function prototypes. }
  54. {$EXTERNALSYM CheckSumMappedFile}
  55. function CheckSumMappedFile(BaseAddress: Pointer; FileLength: DWORD;
  56.   HeaderSum: PDWORD; CheckSum: PDWORD): PImageNtHeaders; stdcall;
  57.  
  58. {$EXTERNALSYM MapFileAndCheckSumA}
  59. function MapFileAndCheckSumA(Filename: PAnsiChar; var HeaderSum,
  60.   CheckSum: DWORD): DWORD; stdcall;
  61. {$EXTERNALSYM MapFileAndCheckSumW}
  62. function MapFileAndCheckSumW(Filename: PWideChar; var HeaderSum,
  63.   CheckSum: DWORD): DWORD; stdcall;
  64. {$EXTERNALSYM MapFileAndCheckSum}
  65. function MapFileAndCheckSum(Filename: PChar; var HeaderSum,
  66.   CheckSum: DWORD): DWORD; stdcall;
  67.  
  68.  
  69. {$EXTERNALSYM TouchFileTimes}
  70. function TouchFileTimes(FileHandle: THandle; const lpSystemTime: TSystemTime):
  71.   Bool; stdcall;
  72.  
  73. {$EXTERNALSYM SplitSymbols}
  74. function SplitSymbols(ImageName, SymbolsPath, SymbolFilePath: LPSTR;
  75.   Flags: DWORD): Bool; stdcall;
  76.  
  77. {$EXTERNALSYM FindDebugInfoFile}
  78. function FindDebugInfoFile(FileName, SymbolPath, DebugFilePath: LPSTR): THandle; stdcall;
  79.  
  80. {$EXTERNALSYM FindExecutableImage}
  81. function FindExecutableImage(FileName, SymbolPath, ImageFilePath: LPSTR): THandle; stdcall;
  82.  
  83. {$EXTERNALSYM UpdateDebugInfoFile}
  84. function UpdateDebugInfoFile(ImageFileName, SymbolPath, DebugFilePath: LPSTR;
  85.   NtHeaders: PImageNtHeaders): Bool; stdcall;
  86.  
  87. {$EXTERNALSYM UpdateDebugInfoFileEx}
  88. function UpdateDebugInfoFileEx(ImageFileName, SymbolPath, DebugFilePath: LPSTR;
  89.   NtHeaders: PImageNtHeaders; OldChecksum: DWORD): Bool; stdcall;
  90.  
  91. {$EXTERNALSYM BindImage}
  92. function BindImage(ImageName, DllPath, SymbolPath: LPSTR): Bool; stdcall;
  93.  
  94. type
  95.   {$EXTERNALSYM _IMAGEHLP_STATUS_REASON}
  96.   _IMAGEHLP_STATUS_REASON = (
  97.     BindOutOfMemory,
  98.     BindRvaToVaFailed,
  99.     BindNoRoomInImage,
  100.     BindImportModuleFailed,
  101.     BindImportProcedureFailed,
  102.     BindImportModule,
  103.     BindImportProcedure,
  104.     BindForwarder,
  105.     BindForwarderNOT,
  106.     BindImageModified,
  107.     BindExpandFileHeaders,
  108.     BindImageComplete,
  109.     BindMismatchedSymbols,
  110.     BindSymbolsNotUpdated
  111.   );
  112.   {$EXTERNALSYM IMAGEHLP_STATUS_REASON}
  113.   IMAGEHLP_STATUS_REASON = _IMAGEHLP_STATUS_REASON;
  114.   TImagehlpStatusReason = _IMAGEHLP_STATUS_REASON;
  115.  
  116. type
  117.   {$EXTERNALSYM PIMAGEHLP_STATUS_ROUTINE}
  118.   PIMAGEHLP_STATUS_ROUTINE = function(Reason: TImagehlpStatusReason;
  119.     ImageName, DllName: LPSTR; Va, Parameter: ULONG): Bool; stdcall;
  120.   TImagehlpStatusRoutine = PIMAGEHLP_STATUS_ROUTINE;
  121.  
  122. {$EXTERNALSYM BindImageEx}
  123. function BindImageEx(Flags: DWORD; ImageName, DllPath, SymbolPath: LPSTR;
  124.   var StatusRoutine: TImagehlpStatusReason): Bool; stdcall;
  125.  
  126. const
  127.   {$EXTERNALSYM BIND_NO_BOUND_IMPORTS}
  128.   BIND_NO_BOUND_IMPORTS     = $00000001;
  129.   {$EXTERNALSYM BIND_NO_UPDATE}
  130.   BIND_NO_UPDATE            = $00000002;
  131.   {$EXTERNALSYM BIND_ALL_IMAGES}
  132.   BIND_ALL_IMAGES           = $00000004;
  133.  
  134. {$EXTERNALSYM ReBaseImage}
  135. function ReBaseImage(CurrentImageName, SymbolPath: LPSTR; fReBase,
  136.   fRebaseSysfileOk, fGoingDown: Bool; CheckImageSize: ULONG;
  137.   var OldImageSize, OldImageBase, NewImageSize, NewImageBase: ULONG;
  138.   TimeStamp: ULONG): Bool; stdcall;
  139.  
  140. const
  141.   {$EXTERNALSYM IMAGE_SEPARATION}
  142.   IMAGE_SEPARATION     = 64 * 1024;
  143.  
  144. type
  145.   PloadedImage = ^LoadedImage;
  146.   {$EXTERNALSYM _LOADED_IMAGE}
  147.   _LOADED_IMAGE = record
  148.     ModuleName: LPSTR;
  149.     hFile: THandle;
  150.     MappedAddress: PChar;
  151.     FileHeader: PImageNtHeaders;
  152.     LastRvaSection: PImageSectionHeader;
  153.     NumberOfSections: ULONG;
  154.     Sections: PImageSectionHeader;
  155.     Characteristics: ULONG;
  156.     fSystemImage: ByteBool;
  157.     fDOSImage: ByteBool;
  158.     Links: TListEntry;
  159.     SizeOfImage: ULONG;
  160.   end;
  161.   {$EXTERNALSYM LOADED_IMAGE}
  162.   LOADED_IMAGE = _LOADED_IMAGE;
  163.   LoadedImage = _LOADED_IMAGE;
  164.  
  165.  
  166. {$EXTERNALSYM ImageLoad}
  167. function ImageLoad(DllName, DllPath: LPSTR): PLoadedImage; stdcall;
  168.  
  169. {$EXTERNALSYM ImageUnload}
  170. function ImageUnload(LoadedImage: PLoadedImage): Bool; stdcall;
  171.  
  172. {$EXTERNALSYM ImageNtHeader}
  173. function ImageNtHeader(Base: Pointer): PImageNtHeaders; stdcall;
  174.  
  175. {$EXTERNALSYM ImageDirectoryEntryToData}
  176. function ImageDirectoryEntryToData(Base: Pointer; MappedAsImage: ByteBool;
  177.   DirectoryEntry: Word; var Size: ULONG): Pointer; stdcall;
  178.  
  179. {$EXTERNALSYM ImageRvaToSection}
  180. function ImageRvaToSection(NtHeaders: PImageNtHeaders; Base: Pointer;
  181.   Rva: ULONG): PImageSectionHeader; stdcall;
  182.  
  183. {$EXTERNALSYM ImageRvaToVa}
  184. function ImageRvaToVa(NtHeaders: PImageNtHeaders; Base: Pointer;
  185.   Rva: ULONG; var LastRvaSection: PImageSectionHeader): Pointer; stdcall;
  186.  
  187. {$EXTERNALSYM MapAndLoad}
  188. function MapAndLoad(ImageName, DllPath: LPSTR; LoadedImage: PLoadedImage;
  189.   DotDll, ReadOnly: Bool): Bool; stdcall;
  190.  
  191. {$EXTERNALSYM GetImageConfigInformation}
  192. function GetImageConfigInformation(LoadedImage: PLoadedImage;
  193.   var ImageConfigInformation: TImageLoadConfigDirectory): Bool; stdcall;
  194.  
  195. {$EXTERNALSYM GetImageUnusedHeaderBytes}
  196. function GetImageUnusedHeaderBytes(LoadedImage: PLoadedImage;
  197.   var SizeUnusedHeaderBytes: DWORD): DWORD; stdcall;
  198.  
  199. {$EXTERNALSYM SetImageConfigInformation}
  200. function SetImageConfigInformation(LoadedImage: PLoadedImage;
  201.   const ImageConfigInformation: TImageLoadConfigDirectory): Bool; stdcall;
  202.  
  203. {$EXTERNALSYM UnMapAndLoad}
  204. function UnMapAndLoad(LoadedImage: PLoadedImage): Bool; stdcall;
  205.  
  206. type
  207.   PimageDebugInformation = ^TImageDebugInformation;
  208.   {$EXTERNALSYM _IMAGE_DEBUG_INFORMATION}
  209.   _IMAGE_DEBUG_INFORMATION = packed record
  210.     List: TListEntry;
  211.     Size: DWORD;
  212.     MappedBase: Pointer;
  213.     Machine: Word;
  214.     Characteristics: Word;
  215.     CheckSum: DWORD;
  216.     ImageBase: DWORD;
  217.     SizeOfImage: DWORD;
  218.     NumberOfSections: DWORD;
  219.     Sections: PImageSectionHeader;
  220.     ExportedNamesSize: DWORD;
  221.     ExportedNames: LPSTR;
  222.     NumberOfFunctionTableEntries: DWORD;
  223.     FunctionTableEntries: PImageFunctionEntry;
  224.     LowestFunctionStartingAddress: DWORD;
  225.     HighestFunctionEndingAddress: DWORD;
  226.     NumberOfFpoTableEntries: DWORD;
  227.     FpoTableEntries: PFpoData;
  228.     SizeOfCoffSymbols: DWORD;
  229.     CoffSymbols: PImageCOFFSymbolsHeader;
  230.     SizeOfCodeViewSymbols: DWORD;
  231.     CodeViewSymbols: Pointer;
  232.     ImageFilePath: LPSTR;
  233.     ImageFileName: LPSTR;
  234.     DebugFilePath: LPSTR;
  235.     TimeDateStamp: DWORD;
  236.     RomImage: Bool;
  237.     DebugDirectory: PImageDebugDirectory;
  238.     NumberOfDebugDirectories: DWORD;
  239.     Reserved: packed array[0..2] of DWORD;
  240.   end;
  241.   {$EXTERNALSYM IMAGE_DEBUG_INFORMATION}
  242.   IMAGE_DEBUG_INFORMATION = _IMAGE_DEBUG_INFORMATION;
  243.   TImageDebugInformation = _IMAGE_DEBUG_INFORMATION;
  244.  
  245. {$EXTERNALSYM MapDebugInformation}
  246. function MapDebugInformation(FileHandle: THandle; FileName, SymbolPath: LPSTR;
  247.   ImageBase: DWORD): PImageDebugInformation; stdcall;
  248.  
  249. {$EXTERNALSYM UnmapDebugInformation}
  250. function UnmapDebugInformation(DebugInfo: PImageDebugInformation): Bool; stdcall;
  251.  
  252. {$EXTERNALSYM SearchTreeForFile}
  253. function SearchTreeForFile(RootPath, InputPathName, OutputPathBuffer: LPSTR):
  254.   Bool; stdcall;
  255.  
  256. {$EXTERNALSYM MakeSureDirectoryPathExists}
  257. function MakeSureDirectoryPathExists(DirPath: LPCSTR): Bool; stdcall;
  258.  
  259. { UnDecorateSymbolName Flags }
  260. const
  261.   {$EXTERNALSYM UNDNAME_COMPLETE}
  262.   UNDNAME_COMPLETE                     = $0000;    { Enable full undecoration }
  263.   {$EXTERNALSYM UNDNAME_NO_LEADING_UNDERSCORES}
  264.   UNDNAME_NO_LEADING_UNDERSCORES       = $0001;    { Remove leading underscores from MS extended keywords }
  265.   {$EXTERNALSYM UNDNAME_NO_MS_KEYWORDS}
  266.   UNDNAME_NO_MS_KEYWORDS               = $0002;    { Disable expansion of MS extended keywords }
  267.   {$EXTERNALSYM UNDNAME_NO_FUNCTION_RETURNS}
  268.   UNDNAME_NO_FUNCTION_RETURNS          = $0004;    { Disable expansion of return type for primary declaration }
  269.   {$EXTERNALSYM UNDNAME_NO_ALLOCATION_MODEL}
  270.   UNDNAME_NO_ALLOCATION_MODEL          = $0008;    { Disable expansion of the declaration model }
  271.   {$EXTERNALSYM UNDNAME_NO_ALLOCATION_LANGUAGE}
  272.   UNDNAME_NO_ALLOCATION_LANGUAGE       = $0010;    { Disable expansion of the declaration language specifier }
  273.   {$EXTERNALSYM UNDNAME_NO_MS_THISTYPE}
  274.   UNDNAME_NO_MS_THISTYPE               = $0020;    { NYI Disable expansion of MS keywords on the 'this' type for primary declaration }
  275.   {$EXTERNALSYM UNDNAME_NO_CV_THISTYPE}
  276.   UNDNAME_NO_CV_THISTYPE               = $0040;    { NYI Disable expansion of CV modifiers on the 'this' type for primary declaration }
  277.   {$EXTERNALSYM UNDNAME_NO_THISTYPE}
  278.   UNDNAME_NO_THISTYPE                  = $0060;    { Disable all modifiers on the 'this' type }
  279.   {$EXTERNALSYM UNDNAME_NO_ACCESS_SPECIFIERS}
  280.   UNDNAME_NO_ACCESS_SPECIFIERS         = $0080;    { Disable expansion of access specifiers for members }
  281.   {$EXTERNALSYM UNDNAME_NO_THROW_SIGNATURES}
  282.   UNDNAME_NO_THROW_SIGNATURES          = $0100;    { Disable expansion of 'throw-signatures' for functions and pointers to functions }
  283.   {$EXTERNALSYM UNDNAME_NO_MEMBER_TYPE}
  284.   UNDNAME_NO_MEMBER_TYPE               = $0200;    { Disable expansion of 'static' or 'virtual'ness of members }
  285.   {$EXTERNALSYM UNDNAME_NO_RETURN_UDT_MODEL}
  286.   UNDNAME_NO_RETURN_UDT_MODEL          = $0400;    { Disable expansion of MS model for UDT returns }
  287.   {$EXTERNALSYM UNDNAME_32_BIT_DECODE}
  288.   UNDNAME_32_BIT_DECODE                = $0800;    { Undecorate 32-bit decorated names }
  289.   {$EXTERNALSYM UNDNAME_NAME_ONLY}
  290.   UNDNAME_NAME_ONLY                    = $1000;    { Crack only the name for primary declaration; }
  291. {  return just [scope::]name.  Does expand template params }
  292.   {$EXTERNALSYM UNDNAME_NO_ARGUMENTS}
  293.   UNDNAME_NO_ARGUMENTS                 = $2000;    { Don't undecorate arguments to function }
  294.   {$EXTERNALSYM UNDNAME_NO_SPECIAL_SYMS}
  295.   UNDNAME_NO_SPECIAL_SYMS              = $4000;    { Don't undecorate special names (v-table, vcall, vector xxx, metatype, etc) }
  296.  
  297. {$EXTERNALSYM UnDecorateSymbolName}
  298. function UnDecorateSymbolName(DecoratedName, UnDecoratedName: LPSTR;
  299.   UndecoratedLength, Flags: DWORD): DWORD; stdcall;
  300.  
  301.  
  302. { StackWalking API }
  303. type
  304.   {$EXTERNALSYM ADDRESS_MODE}
  305.   ADDRESS_MODE = (
  306.     AddrMode1616,
  307.     AddrMode1632,
  308.     AddrModeReal,
  309.     AddrModeFlat
  310.   );
  311.   TAddressMode = ADDRESS_MODE;
  312.  
  313.   PAddress = ^TAddress;
  314.   {$EXTERNALSYM _tagADDRESS}
  315.   _tagADDRESS = record
  316.     Offset: DWORD;
  317.     Segment: Word;
  318.     Mode: TAddressMode;
  319.   end;
  320.   {$EXTERNALSYM ADDRESS}
  321.   ADDRESS = _tagADDRESS;
  322.   TAddress = _tagADDRESS;
  323.  
  324. { This structure is included in the STACKFRAME structure, }
  325. { and is used to trace through usermode callbacks in a thread's }
  326. { kernel stack.  The values must be copied by the kernel debugger }
  327. { from the DBGKD_GET_VERSION and WAIT_STATE_CHANGE packets. }
  328.  
  329.   PKdHelp = ^TKdHelp;
  330.   {$EXTERNALSYM _KDHELP}
  331.   _KDHELP = packed record { address of kernel thread object, as provided }
  332.                           { in the WAIT_STATE_CHANGE packet. }
  333.     Thread: DWORD;
  334.     { offset in thread object to pointer to the current callback frame }
  335.     { in kernel stack. }
  336.     ThCallbackStack: DWORD;
  337.     { offsets to values in frame: }
  338.     { address of next callback frame }
  339.     NextCallback: DWORD;
  340.     { address of saved frame pointer (if applicable) }
  341.     FramePointer: DWORD;
  342.     { Address of the kernel function that calls out to user mode }
  343.     KiCallUserMode: DWORD;
  344.     { Address of the user mode dispatcher function }
  345.     KeUserCallbackDispatcher: DWORD;
  346.   end;
  347.   {$EXTERNALSYM KDHELP}
  348.   KDHELP = _KDHELP;
  349.   TKdHelp = _KDHELP;
  350.  
  351.   PStackFrame = ^TStackFrame;
  352.   {$EXTERNALSYM _tagSTACKFRAME}
  353.   _tagSTACKFRAME = packed record
  354.     AddrPC: TAddress;                  { program counter }
  355.     AddrReturn: TAddress;              { return address }
  356.     AddrFrame: TAddress;               { frame pointer }
  357.     AddrStack: TAddress;               { stack pointer }
  358.     FuncTableEntry: Pointer;          { pointer to pdata/fpo or NULL }
  359.     Params: packed array[0..3] of DWORD;{ possible arguments to the function }
  360.     _Far: Bool;                        { WOW far call }
  361.     _Virtual: Bool;                    { is this a virtual frame? }
  362.     Reserved: packed array[0..2] of DWORD;{ used internally by StackWalk api }
  363.     KdHelp: TKdHelp;
  364.   end;
  365.   {$EXTERNALSYM STACKFRAME}
  366.   STACKFRAME = _tagSTACKFRAME;
  367.   TStackFrame = _tagSTACKFRAME;
  368.  
  369. type
  370.   {$EXTERNALSYM PREAD_PROCESS_MEMORY_ROUTINE}
  371.   PREAD_PROCESS_MEMORY_ROUTINE = function(hProcess: THandle;
  372.     lpBaseAddress, lpBuffer: Pointer; nSize: DWORD;
  373.     var lpNumberOfBytesRead: DWORD): Bool; stdcall;
  374.   TReadProcessMemoryRoutine = PREAD_PROCESS_MEMORY_ROUTINE;
  375.  
  376.   {$EXTERNALSYM PFUNCTION_TABLE_ACCESS_ROUTINE}
  377.   PFUNCTION_TABLE_ACCESS_ROUTINE = function(hProcess: THandle;
  378.     AddrBase: DWORD): Pointer; stdcall;
  379.   TFunctionTableAccessRoutine = PFUNCTION_TABLE_ACCESS_ROUTINE;
  380.  
  381.   {$EXTERNALSYM PGET_MODULE_BASE_ROUTINE}
  382.   PGET_MODULE_BASE_ROUTINE = function(hProcess: THandle;
  383.     ReturnAddress: DWORD): DWORD; stdcall;
  384.   TGetModuleBaseRoutine = PGET_MODULE_BASE_ROUTINE;
  385.  
  386.   {$EXTERNALSYM PTRANSLATE_ADDRESS_ROUTINE}
  387.   PTRANSLATE_ADDRESS_ROUTINE = function(hProcess, hThread: THandle;
  388.     lpaddr: PAddress): DWORD; stdcall;
  389.   TTranslateAddressRoutine = PTRANSLATE_ADDRESS_ROUTINE;
  390.  
  391. {$EXTERNALSYM StackWalk}
  392. function StackWalk(MachineType: DWORD; hProcess, hThread: THandle;
  393.   StackFrame: PStackFrame; ContextRecord: Pointer;
  394.   ReadMemoryRoutine: TReadProcessMemoryRoutine;
  395.   FunctionTableAccessRoutine: TFunctionTableAccessRoutine;
  396.   GetModuleBaseRoutine: TGetModuleBaseRoutine;
  397.   TranslateAddress: TTranslateAddressRoutine): Bool; stdcall;
  398.  
  399. const
  400.   {$EXTERNALSYM API_VERSION_NUMBER}
  401.   API_VERSION_NUMBER     = 5;
  402.  
  403. type
  404.   PApiVersion = ^TApiVersion;
  405.   {$EXTERNALSYM API_VERSION}
  406.   API_VERSION = packed record
  407.     MajorVersion: Word;
  408.     MinorVersion: Word;
  409.     Revision: Word;
  410.     Reserved: Word;
  411.   end;
  412.   TApiVersion = API_VERSION;
  413.  
  414. {$EXTERNALSYM ImagehlpApiVersion}
  415. function ImagehlpApiVersion: PApiVersion; stdcall;
  416.  
  417. {$EXTERNALSYM ImagehlpApiVersionEx}
  418. function ImagehlpApiVersionEx(var AppVersion: TApiVersion): PApiVersion; stdcall;
  419.  
  420. {$EXTERNALSYM GetTimestampForLoadedLibrary}
  421. function GetTimestampForLoadedLibrary(Module: HMODULE): DWORD; stdcall;
  422.  
  423. {$EXTERNALSYM RemovePrivateCvSymbolic}
  424. function RemovePrivateCvSymbolic(DebugData: PChar; var NewDebugData: PChar;
  425.   var NewDebugSize: ULONG): Bool; stdcall;
  426.  
  427. {$EXTERNALSYM RemoveRelocations}
  428. procedure RemoveRelocations(ImageName: PChar); stdcall;
  429.  
  430.  
  431. { typedefs for function pointers }
  432. type
  433.   {$EXTERNALSYM PSYM_ENUMMODULES_CALLBACK}
  434.   PSYM_ENUMMODULES_CALLBACK = function(ModuleName: LPSTR; BaseOfDll: ULONG;
  435.     UserContext: Pointer): Bool; stdcall;
  436.   TSymEnummodulesCallback = PSYM_ENUMMODULES_CALLBACK;
  437.  
  438.   {$EXTERNALSYM PSYM_ENUMSYMBOLS_CALLBACK}
  439.   PSYM_ENUMSYMBOLS_CALLBACK = function(SymbolName: LPSTR; SymbolAddress,
  440.     SymbolSize: ULONG; UserContext: Pointer): Bool; stdcall;
  441.   TSymEnumsymbolsCallback = PSYM_ENUMSYMBOLS_CALLBACK;
  442.  
  443.   {$EXTERNALSYM PENUMLOADED_MODULES_CALLBACK}
  444.   PENUMLOADED_MODULES_CALLBACK = function(ModuleName: LPSTR; ModuleBase,
  445.     ModuleSize: ULONG; UserContext: Pointer): Bool; stdcall;
  446.   TEnumloadedModulesCallback = PENUMLOADED_MODULES_CALLBACK;
  447.  
  448.   {$EXTERNALSYM PSYMBOL_REGISTERED_CALLBACK}
  449.   PSYMBOL_REGISTERED_CALLBACK = function(hProcess: THandle; ActionCode: ULONG;
  450.     CallbackData, UserContext: Pointer): Bool; stdcall;
  451.   TSymbolRegisteredCallback = PSYMBOL_REGISTERED_CALLBACK;
  452.  
  453.  
  454. { symbol flags }
  455. const
  456.   {$EXTERNALSYM SYMF_OMAP_GENERATED}
  457.   SYMF_OMAP_GENERATED       = $00000001;
  458.   {$EXTERNALSYM SYMF_OMAP_MODIFIED}
  459.   SYMF_OMAP_MODIFIED        = $00000002;
  460.  
  461.  
  462. { symbol type enumeration }
  463. type
  464.   {$EXTERNALSYM SYM_TYPE}
  465.   SYM_TYPE = (
  466.     SymNone,
  467.     SymCoff,
  468.     SymCv,
  469.     SymPdb,
  470.     SymExport,
  471.     SymDeferred,
  472.     SymSym                  { .sym file }
  473.   );
  474.   TSymType = SYM_TYPE;
  475.  
  476. { symbol data structure }
  477.   PImagehlpSymbol = ^TImagehlpSymbol;
  478.   {$EXTERNALSYM _IMAGEHLP_SYMBOL}
  479.   _IMAGEHLP_SYMBOL = packed record
  480.     SizeOfStruct: DWORD;                                { set to sizeof(IMAGEHLP_SYMBOL) }
  481.     Address: DWORD;                                     { virtual address including dll base address }
  482.     Size: DWORD;                                        { estimated size of symbol, can be zero }
  483.     Flags: DWORD;                                       { info about the symbols, see the SYMF defines }
  484.     MaxNameLength: DWORD;                               { maximum size of symbol name in 'Name' }
  485.     Name: packed array[0..0] of Char;                   { symbol name (null terminated string) }
  486.   end;
  487.   {$EXTERNALSYM IMAGEHLP_SYMBOL}
  488.   IMAGEHLP_SYMBOL = _IMAGEHLP_SYMBOL;
  489.   TImagehlpSymbol = _IMAGEHLP_SYMBOL;
  490.  
  491.  
  492. { module data structure }
  493.   PImagehlpModule = ^TImagehlpModule;
  494.   {$EXTERNALSYM _IMAGEHLP_MODULE}
  495.   _IMAGEHLP_MODULE = record
  496.     SizeOfStruct: DWORD;                                { set to sizeof(IMAGEHLP_MODULE) }
  497.     BaseOfImage: DWORD;                                 { base load address of module }
  498.     ImageSize: DWORD;                                   { virtual size of the loaded module }
  499.     TimeDateStamp: DWORD;                               { date/time stamp from pe header }
  500.     CheckSum: DWORD;                                    { checksum from the pe header }
  501.     NumSyms: DWORD;                                     { number of symbols in the symbol table }
  502.     SymType: TSymType;                                  { type of symbols loaded }
  503.     ModuleName: packed array[0..31] of Char;            { module name }
  504.     ImageName: packed array[0..255] of Char;            { image name }
  505.     LoadedImageName: packed array[0..255] of Char;      { symbol file name }
  506.   end;
  507.   {$EXTERNALSYM IMAGEHLP_MODULE}
  508.   IMAGEHLP_MODULE = _IMAGEHLP_MODULE;
  509.   TImagehlpModule = _IMAGEHLP_MODULE;
  510.  
  511.  
  512. { data structures used for registered symbol callbacks }
  513. const
  514.   {$EXTERNALSYM CBA_DEFERRED_SYMBOL_LOAD_START}
  515.   CBA_DEFERRED_SYMBOL_LOAD_START              = $00000001;
  516.   {$EXTERNALSYM CBA_DEFERRED_SYMBOL_LOAD_COMPLETE}
  517.   CBA_DEFERRED_SYMBOL_LOAD_COMPLETE           = $00000002;
  518.   {$EXTERNALSYM CBA_DEFERRED_SYMBOL_LOAD_FAILURE}
  519.   CBA_DEFERRED_SYMBOL_LOAD_FAILURE            = $00000003;
  520.   {$EXTERNALSYM CBA_SYMBOLS_UNLOADED}
  521.   CBA_SYMBOLS_UNLOADED                        = $00000004;
  522.   {$EXTERNALSYM CBA_DUPLICATE_SYMBOL}
  523.   CBA_DUPLICATE_SYMBOL                        = $00000005;
  524.  
  525. type
  526.   PImagehlpDeferredSymbolLoad = ^TImagehlpDeferredSymbolLoad;
  527.   {$EXTERNALSYM _IMAGEHLP_DEFERRED_SYMBOL_LOAD}
  528.   _IMAGEHLP_DEFERRED_SYMBOL_LOAD = packed record
  529.     SizeOfStruct: DWORD;                                { set to sizeof(IMAGEHLP_DEFERRED_SYMBOL_LOAD) }
  530.     BaseOfImage: DWORD;                                 { base load address of module }
  531.     CheckSum: DWORD;                                    { checksum from the pe header }
  532.     TimeDateStamp: DWORD;                               { date/time stamp from pe header }
  533.     FileName: packed array[0..MAX_PATH-1] of Char;      { symbols file or image name }
  534.   end;
  535.   {$EXTERNALSYM IMAGEHLP_DEFERRED_SYMBOL_LOAD}
  536.   IMAGEHLP_DEFERRED_SYMBOL_LOAD = _IMAGEHLP_DEFERRED_SYMBOL_LOAD;
  537.   TImagehlpDeferredSymbolLoad = _IMAGEHLP_DEFERRED_SYMBOL_LOAD;
  538.  
  539.   PImagehlpDuplicateSymbol = ^TImagehlpDuplicateSymbol;
  540.   {$EXTERNALSYM _IMAGEHLP_DUPLICATE_SYMBOL}
  541.   _IMAGEHLP_DUPLICATE_SYMBOL = packed record
  542.     SizeOfStruct: DWORD;                                { set to sizeof(IMAGEHLP_DUPLICATE_SYMBOL) }
  543.     NumberOfDups: DWORD;                                { number of duplicates in the Symbol array }
  544.     Symbol: PImagehlpSymbol;                            { array of duplicate symbols }
  545.     SelectedSymbol: ULONG;                           { symbol selected (-1 to start) }
  546.   end;
  547.   {$EXTERNALSYM IMAGEHLP_DUPLICATE_SYMBOL}
  548.   IMAGEHLP_DUPLICATE_SYMBOL = _IMAGEHLP_DUPLICATE_SYMBOL;
  549.   TImagehlpDuplicateSymbol = _IMAGEHLP_DUPLICATE_SYMBOL;
  550.  
  551.  
  552.  
  553. { options that are set/returned by SymSetOptions() & SymGetOptions() }
  554. { these are used as a mask }
  555.  
  556. const
  557.   {$EXTERNALSYM SYMOPT_CASE_INSENSITIVE}
  558.   SYMOPT_CASE_INSENSITIVE      = $00000001;
  559.   {$EXTERNALSYM SYMOPT_UNDNAME}
  560.   SYMOPT_UNDNAME               = $00000002;
  561.   {$EXTERNALSYM SYMOPT_DEFERRED_LOADS}
  562.   SYMOPT_DEFERRED_LOADS        = $00000004;
  563.   {$EXTERNALSYM SYMOPT_NO_CPP}
  564.   SYMOPT_NO_CPP                = $00000008;
  565.  
  566.  
  567. {$EXTERNALSYM SymSetOptions}
  568. function SymSetOptions(SymOptions: DWORD): DWORD; stdcall;
  569.  
  570. {$EXTERNALSYM SymGetOptions}
  571. function SymGetOptions: DWORD; stdcall;
  572.  
  573. {$EXTERNALSYM SymCleanup}
  574. function SymCleanup(hProcess: THandle): Bool; stdcall;
  575.  
  576. {$EXTERNALSYM SymEnumerateModules}
  577. function SymEnumerateModules(hProcess: THandle;
  578.   EnumModulesCallback: TSymEnumModulesCallback; UserContext: Pointer): Bool; stdcall;
  579.  
  580. {$EXTERNALSYM SymEnumerateSymbols}
  581. function SymEnumerateSymbols(hProcess: THandle; BaseOfDll: DWORD;
  582.   EnumSymbolsCallback: TSymEnumSymbolsCallback; UserContext: Pointer): Bool; stdcall;
  583.  
  584. {$EXTERNALSYM EnumerateLoadedModules}
  585. function EnumerateLoadedModules(hProcess: THandle;
  586.   EnumLoadedModulesCallback: TEnumLoadedModulesCallback;
  587.   UserContext: Pointer): Bool; stdcall;
  588.  
  589. {$EXTERNALSYM SymFunctionTableAccess}
  590. function SymFunctionTableAccess(hProcess: THandle; AddrBase: DWORD): Pointer; stdcall;
  591.  
  592. {$EXTERNALSYM SymGetModuleInfo}
  593. function SymGetModuleInfo(hProcess: THandle; dwAddr: DWORD;
  594.   var ModuleInfo: TImagehlpModule): Bool; stdcall;
  595.  
  596. {$EXTERNALSYM SymGetModuleBase}
  597. function SymGetModuleBase(hProcess: THandle; dwAddr: DWORD): DWORD; stdcall;
  598.  
  599. {$EXTERNALSYM SymGetSymFromAddr}
  600. function SymGetSymFromAddr(hProcess: THandle; dwAddr: DWORD;
  601.   pdwDisplacement: PDWORD; var Symbol: TImagehlpSymbol): Bool; stdcall;
  602.  
  603. {$EXTERNALSYM SymGetSymFromName}
  604. function SymGetSymFromName(hProcess: THandle; Name: LPSTR;
  605.   var Symbol: TImagehlpSymbol): Bool; stdcall;
  606.  
  607. {$EXTERNALSYM SymGetSymNext}
  608. function SymGetSymNext(hProcess: THandle; var Symbol: TImagehlpSymbol): Bool; stdcall;
  609.  
  610. {$EXTERNALSYM SymGetSymPrev}
  611. function SymGetSymPrev(hProcess: THandle; var Symbol: TImagehlpSymbol): Bool; stdcall;
  612.  
  613. {$EXTERNALSYM SymInitialize}
  614. function SymInitialize(hProcess: THandle; UserSearchPath: LPSTR;
  615.   fInvadeProcess: Bool): Bool; stdcall;
  616.  
  617. {$EXTERNALSYM SymGetSearchPath}
  618. function SymGetSearchPath(hProcess: THandle; SearchPath: LPSTR;
  619.   SearchPathLength: DWORD): Bool; stdcall;
  620.  
  621. {$EXTERNALSYM SymSetSearchPath}
  622. function SymSetSearchPath(hProcess: THandle; SearchPath: LPSTR): Bool; stdcall;
  623.  
  624. {$EXTERNALSYM SymLoadModule}
  625. function SymLoadModule(hProcess: THandle; hFile: THandle; ImageName,
  626.   ModuleName: LPSTR; BaseOfDll, SizeOfDll: DWORD): Bool; stdcall;
  627.  
  628. {$EXTERNALSYM SymUnloadModule}
  629. function SymUnloadModule(hProcess: THandle; BaseOfDll: DWORD): Bool; stdcall;
  630.  
  631. {$EXTERNALSYM SymUnDName}
  632. function SymUnDName(sym: PImagehlpSymbol; UnDecName: LPSTR;
  633.   UnDecNameLength: DWORD): Bool; stdcall;
  634.  
  635. {$EXTERNALSYM SymRegisterCallback}
  636. function SymRegisterCallback(hProcess: THandle;
  637.   CallbackFunction: TSymbolRegisteredCallback; UserContext: Pointer): Bool; stdcall;
  638.  
  639. { Image Integrity API's }
  640.  
  641. const
  642.   {$EXTERNALSYM CERT_PE_IMAGE_DIGEST_DEBUG_INFO}
  643.   CERT_PE_IMAGE_DIGEST_DEBUG_INFO             = $01;
  644.   {$EXTERNALSYM CERT_PE_IMAGE_DIGEST_RESOURCES}
  645.   CERT_PE_IMAGE_DIGEST_RESOURCES              = $02;
  646.   {$EXTERNALSYM CERT_PE_IMAGE_DIGEST_ALL_IMPORT_INFO}
  647.   CERT_PE_IMAGE_DIGEST_ALL_IMPORT_INFO        = $04;
  648.  
  649.   {$EXTERNALSYM CERT_SECTION_TYPE_ANY}
  650.   CERT_SECTION_TYPE_ANY                       = $FF;      { Any Certificate type }
  651.  
  652. type
  653.   {$EXTERNALSYM DIGEST_HANDLE}
  654.   DIGEST_HANDLE = Pointer;
  655.   TDigestHandle = DIGEST_HANDLE;
  656.  
  657. type
  658.   {$EXTERNALSYM DIGEST_FUNCTION}
  659.   DIGEST_FUNCTION = function(refdata: TDigestHandle; pData: PByte;
  660.     dwLength: DWORD): Bool; stdcall;
  661.   TDigestFunction = DIGEST_FUNCTION;
  662.  
  663. {$EXTERNALSYM ImageGetDigestStream}
  664. function ImageGetDigestStream(FileHandle: THandle; DigestLevel: DWORD;
  665.   DigestFunction: TDigestFunction; DigestHandle: TDigestHandle): Bool; stdcall;
  666.  
  667. {$EXTERNALSYM ImageAddCertificate}
  668. function ImageAddCertificate(FileHandle: THandle;
  669.   var Certificate: PWinCertificate; var Index: DWORD): Bool; stdcall;
  670.  
  671. {$EXTERNALSYM ImageRemoveCertificate}
  672. function ImageRemoveCertificate(FileHandle: THandle; Index: DWORD): Bool; stdcall;
  673.  
  674. {$EXTERNALSYM ImageEnumerateCertificates}
  675. function ImageEnumerateCertificates(FileHandle: THandle; TypeFilter: Word;
  676.   CertificateCount, Indices, IndexCount: PDWORD): Bool; stdcall;
  677.  
  678. {$EXTERNALSYM ImageGetCertificateData}
  679. function ImageGetCertificateData(FileHandle: THandle; CertificateIndex: DWORD;
  680.   Certificate: PWinCertificate; var RequiredLength: DWORD): Bool; stdcall;
  681.  
  682. {$EXTERNALSYM ImageGetCertificateHeader}
  683. function ImageGetCertificateHeader(FileHandle: THandle; CertificateIndex: DWORD;
  684.   var Certificateheader: PWinCertificate): Bool; stdcall;
  685.  
  686. implementation
  687.  
  688. const
  689.   ImagehlpLib = 'IMAGEHLP.DLL';
  690.  
  691. function BindImage;                     external ImagehlpLib name 'BindImage';
  692. function BindImageEx;                   external ImagehlpLib name 'BindImageEx';
  693. function CheckSumMappedFile;            external ImagehlpLib name 'CheckSumMappedFile';
  694. function EnumerateLoadedModules;        external ImagehlpLib name 'EnumerateLoadedModules';
  695. function FindDebugInfoFile;             external ImagehlpLib name 'FindDebugInfoFile';
  696. function FindExecutableImage;           external ImagehlpLib name 'FindExecutableImage';
  697. function GetImageConfigInformation;     external ImagehlpLib name 'GetImageConfigInformation';
  698. function GetImageUnusedHeaderBytes;     external ImagehlpLib name 'GetImageUnusedHeaderBytes';
  699. function GetTimestampForLoadedLibrary;  external ImagehlpLib name 'GetTimestampForLoadedLibrary';
  700. function ImageAddCertificate;           external ImagehlpLib name 'ImageAddCertificate';
  701. function ImageDirectoryEntryToData;     external ImagehlpLib name 'ImageDirectoryEntryToData';
  702. function ImageEnumerateCertificates;    external ImagehlpLib name 'ImageEnumerateCertificates';
  703. function ImageGetCertificateData;       external ImagehlpLib name 'ImageGetCertificateData';
  704. function ImageGetCertificateHeader;     external ImagehlpLib name 'ImageGetCertificateHeader';
  705. function ImageGetDigestStream;          external ImagehlpLib name 'ImageGetDigestStream';
  706. function ImagehlpApiVersion;            external ImagehlpLib name 'ImagehlpApiVersion';
  707. function ImagehlpApiVersionEx;          external ImagehlpLib name 'ImagehlpApiVersionEx';
  708. function ImageLoad;                     external ImagehlpLib name 'ImageLoad';
  709. function ImageNtHeader;                 external ImagehlpLib name 'ImageNtHeader';
  710. function ImageRemoveCertificate;        external ImagehlpLib name 'ImageRemoveCertificate';
  711. function ImageRvaToSection;             external ImagehlpLib name 'ImageRvaToSection';
  712. function ImageRvaToVa;                  external ImagehlpLib name 'ImageRvaToVa';
  713. function ImageUnload;                   external ImagehlpLib name 'ImageUnload';
  714. function MakeSureDirectoryPathExists;   external ImagehlpLib name 'MakeSureDirectoryPathExists';
  715. function MapAndLoad;                    external ImagehlpLib name 'MapAndLoad';
  716. function MapDebugInformation;           external ImagehlpLib name 'MapDebugInformation';
  717. function MapFileAndCheckSumA;           external ImagehlpLib name 'MapFileAndCheckSumA';
  718. function MapFileAndCheckSumW;           external ImagehlpLib name 'MapFileAndCheckSumW';
  719. function MapFileAndCheckSum;           external ImagehlpLib name 'MapFileAndCheckSumA';
  720. function ReBaseImage;                   external ImagehlpLib name 'ReBaseImage';
  721. function RemovePrivateCvSymbolic;       external ImagehlpLib name 'RemovePrivateCvSymbolic';
  722. procedure RemoveRelocations;            external ImagehlpLib name 'RemoveRelocations';
  723. function SearchTreeForFile;             external ImagehlpLib name 'SearchTreeForFile';
  724. function SetImageConfigInformation;     external ImagehlpLib name 'SetImageConfigInformation';
  725. function SplitSymbols;                  external ImagehlpLib name 'SplitSymbols';
  726. function StackWalk;                     external ImagehlpLib name 'StackWalk';
  727. function SymCleanup;                    external ImagehlpLib name 'SymCleanup';
  728. function SymEnumerateModules;           external ImagehlpLib name 'SymEnumerateModules';
  729. function SymEnumerateSymbols;           external ImagehlpLib name 'SymEnumerateSymbols';
  730. function SymFunctionTableAccess;        external ImagehlpLib name 'SymFunctionTableAccess';
  731. function SymGetModuleBase;              external ImagehlpLib name 'SymGetModuleBase';
  732. function SymGetModuleInfo;              external ImagehlpLib name 'SymGetModuleInfo';
  733. function SymGetOptions;                 external ImagehlpLib name 'SymGetOptions';
  734. function SymGetSearchPath;              external ImagehlpLib name 'SymGetSearchPath';
  735. function SymGetSymFromAddr;             external ImagehlpLib name 'SymGetSymFromAddr';
  736. function SymGetSymFromName;             external ImagehlpLib name 'SymGetSymFromName';
  737. function SymGetSymNext;                 external ImagehlpLib name 'SymGetSymNext';
  738. function SymGetSymPrev;                 external ImagehlpLib name 'SymGetSymPrev';
  739. function SymInitialize;                 external ImagehlpLib name 'SymInitialize';
  740. function SymLoadModule;                 external ImagehlpLib name 'SymLoadModule';
  741. function SymRegisterCallback;           external ImagehlpLib name 'SymRegisterCallback';
  742. function SymSetOptions;                 external ImagehlpLib name 'SymSetOptions';
  743. function SymSetSearchPath;              external ImagehlpLib name 'SymSetSearchPath';
  744. function SymUnDName;                    external ImagehlpLib name 'SymUnDName';
  745. function SymUnloadModule;               external ImagehlpLib name 'SymUnloadModule';
  746. function TouchFileTimes;                external ImagehlpLib name 'TouchFileTimes';
  747. function UnDecorateSymbolName;          external ImagehlpLib name 'UnDecorateSymbolName';
  748. function UnMapAndLoad;                  external ImagehlpLib name 'UnMapAndLoad';
  749. function UnmapDebugInformation;         external ImagehlpLib name 'UnmapDebugInformation';
  750. function UpdateDebugInfoFile;           external ImagehlpLib name 'UpdateDebugInfoFile';
  751. function UpdateDebugInfoFileEx;         external ImagehlpLib name 'UpdateDebugInfoFileEx';
  752.  
  753. end.
  754.