diff --git a/PInvoke/DbgHelp/DbgHelp.Sym.cs b/PInvoke/DbgHelp/DbgHelp.Sym.cs new file mode 100644 index 00000000..9072fc58 --- /dev/null +++ b/PInvoke/DbgHelp/DbgHelp.Sym.cs @@ -0,0 +1,102 @@ +using System; +using System.Runtime.InteropServices; +using System.Text; +using static Vanara.PInvoke.Kernel32; + +namespace Vanara.PInvoke +{ + /// Items from the DbgHelp.dll + public static partial class DbgHelp + { + /* + SymEnumerateSymbols64 +SymEnumerateSymbolsProc64 +SymEnumLines +SymEnumLinesProc +SymEnumProcesses +SymEnumProcessesProc +SymEnumSourceFiles +SymEnumSourceFilesProc +SymEnumSourceFileTokens +PENUMSOURCEFILETOKENSCALLBACK +SymEnumSourceLines +SymEnumSymbols +SymEnumSymbolsEx +SymEnumSymbolsForAddr +SymEnumSymbolsProc +SymEnumTypes +SymEnumTypesByName +SymFindDebugInfoFile +SymFindExecutableImage +SymFindFileInPath +SymFindFileInPathProc +SymFromAddr +SymFromIndex +SymFromInlineContext +SymFromName +SymFromToken +SymFunctionTableAccess64 +SymFunctionTableAccess64AccessRoutines +SymGetExtendedOption +SymGetFileLineOffsets64 +SymGetHomeDirectory +SymGetLineFromAddr64 +SymGetLineFromInlineContext +SymGetLineFromName64 +SymGetLineNext64 +SymGetLinePrev64 +SymGetModuleBase64 +SymGetModuleInfo64 +SymGetOmaps +SymGetOptions +SymGetScope +SymGetSearchPath +SymGetSourceFile +SymGetSourceFileChecksum +SymGetSourceFileFromToken +SymGetSourceFileToken +SymGetSourceVarFromToken +SymGetSymbolFile +SymGetSymFromAddr64 +SymGetSymFromName64 +SymGetSymNext64 +SymGetSymPrev64 +SymGetTypeFromName +SymGetTypeInfo +SymGetTypeInfoEx +SymInitialize +SymLoadModule64 +SymLoadModuleEx +SymMatchFileName +SymMatchString +SymNext +SymPrev +SymQueryInlineTrace +SymRefreshModuleList +SymRegisterCallback64 +SymRegisterCallbackProc64 +SymRegisterFunctionEntryCallback64 +SymRegisterFunctionEntryCallbackProc64 +SymSearch +SymSetContext +SymSetExtendedOption +SymSetHomeDirectory +SymSetOptions +SymSetParentWindow +SymSetScopeFromAddr +SymSetScopeFromIndex +SymSetScopeFromInlineContext +SymSetSearchPath +SymSrvDeltaName +SymSrvGetFileIndexes +SymSrvGetFileIndexInfo +SymSrvGetFileIndexString +SymSrvGetSupplement +SymSrvIsStore +SymSrvStoreFile +SymSrvStoreSupplement +SymUnDName64 +SymUnloadModule64 + */ + } +} \ No newline at end of file diff --git a/PInvoke/DbgHelp/DbgHelp.cs b/PInvoke/DbgHelp/DbgHelp.cs index baa71ff1..d5ded4d3 100644 --- a/PInvoke/DbgHelp/DbgHelp.cs +++ b/PInvoke/DbgHelp/DbgHelp.cs @@ -1,5 +1,7 @@ using System; +using System.Collections.Generic; using System.Runtime.InteropServices; +using System.Security.Cryptography.X509Certificates; using System.Text; using static Vanara.PInvoke.Kernel32; @@ -64,10 +66,45 @@ namespace Vanara.PInvoke // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nc-dbghelp-penumloaded_modules_callback PENUMLOADED_MODULES_CALLBACK // PenumloadedModulesCallback; BOOL PenumloadedModulesCallback( PCSTR ModuleName, ULONG ModuleBase, ULONG ModuleSize, PVOID // UserContext ) {...} - [UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet = CharSet.Auto)] + [UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet = CharSet.Ansi)] [PInvokeData("dbghelp.h", MSDNShortId = "NC:dbghelp.PENUMLOADED_MODULES_CALLBACK")] [return: MarshalAs(UnmanagedType.Bool)] - public delegate bool PENUMLOADED_MODULES_CALLBACK([MarshalAs(UnmanagedType.LPTStr)] string ModuleName, [In] IntPtr ModuleBase, [In] IntPtr ModuleSize, [In, Optional] IntPtr UserContext); + public delegate bool PENUMLOADED_MODULES_CALLBACK([MarshalAs(UnmanagedType.LPStr)] string ModuleName, [In] uint ModuleBase, [In] uint ModuleSize, [In, Optional] IntPtr UserContext); + + /// + /// An application-defined callback function used with the EnumerateLoadedModules64 function. + /// + /// The PENUMLOADED_MODULES_CALLBACK64 and PENUMLOADED_MODULES_CALLBACKW64 types define a pointer to this callback + /// function. EnumerateLoadedModulesProc64 is a placeholder for the application-defined function name. + /// + /// + /// The name of the enumerated module. + /// + /// The base address of the module. Note that it is possible for this address to become invalid (for example, the module may be + /// unloaded). Use exception handling when accessing the address or passing the address to another function to prevent an access + /// violation from occurring. + /// + /// The size of the module, in bytes. + /// Optional user-defined data. This value is passed from EnumerateLoadedModules64. + /// + /// To continue enumeration, the callback function must return TRUE. + /// To stop enumeration, the callback function must return FALSE. + /// + /// + /// + /// This callback function supersedes the PENUMLOADED_MODULES_CALLBACK callback function. PENUMLOADED_MODULES_CALLBACK is defined as + /// follows in DbgHelp.h. + /// + /// + /// #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64) #define PENUMLOADED_MODULES_CALLBACK PENUMLOADED_MODULES_CALLBACK64 #else typedef BOOL (CALLBACK *PENUMLOADED_MODULES_CALLBACK)( __in PCSTR ModuleName, __in ULONG ModuleBase, __in ULONG ModuleSize, __in_opt PVOID UserContext ); #endif + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nc-dbghelp-penumloaded_modules_callbackw64 + // PENUMLOADED_MODULES_CALLBACKW64 PenumloadedModulesCallbackw64; BOOL PenumloadedModulesCallbackw64( PCWSTR ModuleName, DWORD64 ModuleBase, ULONG ModuleSize, PVOID UserContext ) {...} + [PInvokeData("dbghelp.h", MSDNShortId = "NC:dbghelp.PENUMLOADED_MODULES_CALLBACKW64")] + [UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet = CharSet.Unicode)] + [return: MarshalAs(UnmanagedType.Bool)] + public delegate bool PENUMLOADED_MODULES_CALLBACKW64([MarshalAs(UnmanagedType.LPWStr)] string ModuleName, ulong ModuleBase, uint ModuleSize, [In, Optional] IntPtr UserContext); /// /// @@ -178,6 +215,250 @@ namespace Vanara.PInvoke [PInvokeData("dbghelp.h", MSDNShortId = "NC:dbghelp.PFUNCTION_TABLE_ACCESS_ROUTINE64")] public delegate IntPtr PFUNCTION_TABLE_ACCESS_ROUTINE64(HPROCESS ahProcess, ulong AddrBase); + /// + /// + /// An application-defined callback function used with the StackWalk64 function. It is called when StackWalk64 needs a module + /// base address for a given virtual address. + /// + /// + /// The PGET_MODULE_BASE_ROUTINE64 type defines a pointer to this callback function. GetModuleBaseProc64 is a + /// placeholder for the application-defined function name. + /// + /// + /// A handle to the process for which the stack trace is generated. + /// An address within the module image to be located. + /// The function returns the base address of the module. + /// + /// + /// This callback function supersedes the PGET_MODULE_BASE_ROUTINE callback function. PGET_MODULE_BASE_ROUTINE is defined as follows + /// in DbgHelp.h. + /// + /// + /// #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64) #define PGET_MODULE_BASE_ROUTINE PGET_MODULE_BASE_ROUTINE64 #else typedef DWORD (__stdcall *PGET_MODULE_BASE_ROUTINE)( __in HANDLE hProcess, __in DWORD Address ); #endif + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nc-dbghelp-pget_module_base_routine PGET_MODULE_BASE_ROUTINE + // PgetModuleBaseRoutine; DWORD PgetModuleBaseRoutine( HANDLE hProcess, DWORD Address ) {...} + [UnmanagedFunctionPointer(CallingConvention.Winapi)] + [PInvokeData("dbghelp.h", MSDNShortId = "NC:dbghelp.PGET_MODULE_BASE_ROUTINE")] + public delegate uint PGET_MODULE_BASE_ROUTINE(HPROCESS hProcess, uint Address); + + /// + /// + /// An application-defined callback function used with the StackWalk64 function. It is called when StackWalk64 needs a module + /// base address for a given virtual address. + /// + /// + /// The PGET_MODULE_BASE_ROUTINE64 type defines a pointer to this callback function. GetModuleBaseProc64 is a + /// placeholder for the application-defined function name. + /// + /// + /// A handle to the process for which the stack trace is generated. + /// An address within the module image to be located. + /// The function returns the base address of the module. + /// + /// + /// This callback function supersedes the PGET_MODULE_BASE_ROUTINE callback function. PGET_MODULE_BASE_ROUTINE is defined as follows + /// in DbgHelp.h. + /// + /// + /// #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64) #define PGET_MODULE_BASE_ROUTINE PGET_MODULE_BASE_ROUTINE64 #else typedef DWORD (__stdcall *PGET_MODULE_BASE_ROUTINE)( __in HANDLE hProcess, __in DWORD Address ); #endif + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nc-dbghelp-pget_module_base_routine64 PGET_MODULE_BASE_ROUTINE64 + // PgetModuleBaseRoutine64; DWORD64 PgetModuleBaseRoutine64( HANDLE hProcess, DWORD64 Address ) {...} + [UnmanagedFunctionPointer(CallingConvention.Winapi)] + [PInvokeData("dbghelp.h", MSDNShortId = "NC:dbghelp.PGET_MODULE_BASE_ROUTINE64")] + public delegate ulong PGET_MODULE_BASE_ROUTINE64(HPROCESS hProcess, ulong Address); + + /// + /// + /// An application-defined callback function used with the StackWalk64 function. It is called when StackWalk64 needs to read + /// memory from the address space of the process. + /// + /// + /// The PREAD_PROCESS_MEMORY_ROUTINE64 type defines a pointer to this callback function. ReadProcessMemoryProc64 is a + /// placeholder for the application-defined function name. + /// + /// + /// A handle to the process for which the stack trace is generated. + /// The base address of the memory to be read. + /// A pointer to a buffer that receives the memory to be read. + /// The size of the memory to be read, in bytes. + /// A pointer to a variable that receives the number of bytes actually read. + /// + /// If the function succeeds, the return value should be TRUE. If the function fails, the return value should be FALSE. + /// + /// + /// In many cases, this function can best service the callback with a corresponding call to ReadProcessMemory. + /// + /// This function should read as much of the requested memory as possible. The StackWalk64 function handles the case where only part + /// of the requested memory is read. + /// + /// + /// This callback function supersedes the PREAD_PROCESS_MEMORY_ROUTINE callback function. PREAD_PROCESS_MEMORY_ROUTINE is defined as + /// follows in Dbghelp.h. + /// + /// + /// #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64) #define PREAD_PROCESS_MEMORY_ROUTINE PREAD_PROCESS_MEMORY_ROUTINE64 #else typedef BOOL (__stdcall *PREAD_PROCESS_MEMORY_ROUTINE)( __in HANDLE hProcess, __in DWORD lpBaseAddress, __out_bcount(nSize) PVOID lpBuffer, __in DWORD nSize, __out PDWORD lpNumberOfBytesRead ); #endif + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nc-dbghelp-pread_process_memory_routine PREAD_PROCESS_MEMORY_ROUTINE + // PreadProcessMemoryRoutine; BOOL PreadProcessMemoryRoutine( HANDLE hProcess, DWORD lpBaseAddress, PVOID lpBuffer, DWORD nSize, + // PDWORD lpNumberOfBytesRead ) {...} + [UnmanagedFunctionPointer(CallingConvention.Winapi)] + [PInvokeData("dbghelp.h", MSDNShortId = "NC:dbghelp.PREAD_PROCESS_MEMORY_ROUTINE")] + [return: MarshalAs(UnmanagedType.Bool)] + public delegate bool PREAD_PROCESS_MEMORY_ROUTINE(HPROCESS hProcess, uint lpBaseAddress, [Out] IntPtr lpBuffer, uint nSize, out uint lpNumberOfBytesRead); + + /// + /// + /// An application-defined callback function used with the StackWalk64 function. It is called when StackWalk64 needs to read + /// memory from the address space of the process. + /// + /// + /// The PREAD_PROCESS_MEMORY_ROUTINE64 type defines a pointer to this callback function. ReadProcessMemoryProc64 is a + /// placeholder for the application-defined function name. + /// + /// + /// A handle to the process for which the stack trace is generated. + /// The base address of the memory to be read. + /// A pointer to a buffer that receives the memory to be read. + /// The size of the memory to be read, in bytes. + /// A pointer to a variable that receives the number of bytes actually read. + /// + /// If the function succeeds, the return value should be TRUE. If the function fails, the return value should be FALSE. + /// + /// + /// In many cases, this function can best service the callback with a corresponding call to ReadProcessMemory. + /// + /// This function should read as much of the requested memory as possible. The StackWalk64 function handles the case where only part + /// of the requested memory is read. + /// + /// + /// This callback function supersedes the PREAD_PROCESS_MEMORY_ROUTINE callback function. PREAD_PROCESS_MEMORY_ROUTINE is defined as + /// follows in Dbghelp.h. + /// + /// + /// #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64) #define PREAD_PROCESS_MEMORY_ROUTINE PREAD_PROCESS_MEMORY_ROUTINE64 #else typedef BOOL (__stdcall *PREAD_PROCESS_MEMORY_ROUTINE)( __in HANDLE hProcess, __in DWORD lpBaseAddress, __out_bcount(nSize) PVOID lpBuffer, __in DWORD nSize, __out PDWORD lpNumberOfBytesRead ); #endif + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nc-dbghelp-pread_process_memory_routine PREAD_PROCESS_MEMORY_ROUTINE + // PreadProcessMemoryRoutine; BOOL PreadProcessMemoryRoutine( HANDLE hProcess, DWORD lpBaseAddress, PVOID lpBuffer, DWORD nSize, + // PDWORD lpNumberOfBytesRead ) {...} + [UnmanagedFunctionPointer(CallingConvention.Winapi)] + [PInvokeData("dbghelp.h", MSDNShortId = "NC:dbghelp.PREAD_PROCESS_MEMORY_ROUTINE")] + [return: MarshalAs(UnmanagedType.Bool)] + public delegate bool PREAD_PROCESS_MEMORY_ROUTINE64(HPROCESS hProcess, ulong lpBaseAddress, [Out] IntPtr lpBuffer, uint nSize, out uint lpNumberOfBytesRead); + + /// + /// + /// An application-defined callback function used with the SymEnumerateModules64 function. It is called once for each enumerated + /// module, and receives the module information. + /// + /// + /// The PSYM_ENUMMODULES_CALLBACK64 and PSYM_ENUMMODULES_CALLBACKW64 types define a pointer to this callback function. + /// SymEnumerateModulesProc64 is a placeholder for the application-defined function name. + /// + /// + /// The name of the module. + /// The base address where the module is loaded into memory. + /// + /// The user-defined value specified in SymEnumerateModules64, or NULL. Typically, this parameter is used by an application + /// to pass a pointer to a data structure that lets the callback function establish some type of context. + /// + /// + /// If the return value is TRUE, the enumeration will continue. + /// If the return value is FALSE, the enumeration will stop. + /// + /// + /// + /// The calling application is called once per module until all modules are enumerated, or until the enumeration callback function + /// returns FALSE. + /// + /// + /// This callback function supersedes the PSYM_ENUMMODULES_CALLBACK callback function. PSYM_ENUMMODULES_CALLBACK is defined as + /// follows in DbgHelp.h. + /// + /// + /// #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64) #define PSYM_ENUMMODULES_CALLBACK PSYM_ENUMMODULES_CALLBACK64 #else typedef BOOL (CALLBACK *PSYM_ENUMMODULES_CALLBACK)( __in PCSTR ModuleName, __in ULONG BaseOfDll, __in_opt PVOID UserContext ); #endif + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nc-dbghelp-psym_enummodules_callback PSYM_ENUMMODULES_CALLBACK + // PsymEnummodulesCallback; BOOL PsymEnummodulesCallback( PCSTR ModuleName, ULONG BaseOfDll, PVOID UserContext ) {...} + [UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet = CharSet.Ansi)] + [PInvokeData("dbghelp.h", MSDNShortId = "NC:dbghelp.PSYM_ENUMMODULES_CALLBACK")] + [return: MarshalAs(UnmanagedType.Bool)] + public delegate bool PSYM_ENUMMODULES_CALLBACK([MarshalAs(UnmanagedType.LPStr)] string ModuleName, uint BaseOfDll, [In, Optional] IntPtr UserContext); + + /// + /// + /// An application-defined callback function used with the SymEnumerateModules64 function. It is called once for each enumerated + /// module, and receives the module information. + /// + /// + /// The PSYM_ENUMMODULES_CALLBACK64 and PSYM_ENUMMODULES_CALLBACKW64 types define a pointer to this callback function. + /// SymEnumerateModulesProc64 is a placeholder for the application-defined function name. + /// + /// + /// The name of the module. + /// The base address where the module is loaded into memory. + /// + /// The user-defined value specified in SymEnumerateModules64, or NULL. Typically, this parameter is used by an application + /// to pass a pointer to a data structure that lets the callback function establish some type of context. + /// + /// + /// If the return value is TRUE, the enumeration will continue. + /// If the return value is FALSE, the enumeration will stop. + /// + /// + /// + /// The calling application is called once per module until all modules are enumerated, or until the enumeration callback function + /// returns FALSE. + /// + /// + /// This callback function supersedes the PSYM_ENUMMODULES_CALLBACK callback function. PSYM_ENUMMODULES_CALLBACK is defined as + /// follows in DbgHelp.h. + /// + /// + /// #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64) #define PSYM_ENUMMODULES_CALLBACK PSYM_ENUMMODULES_CALLBACK64 #else typedef BOOL (CALLBACK *PSYM_ENUMMODULES_CALLBACK)( __in PCSTR ModuleName, __in ULONG BaseOfDll, __in_opt PVOID UserContext ); #endif + /// + /// + // https://docs.microsoft.com/id-id/windows/win32/api/dbghelp/nc-dbghelp-psym_enummodules_callback64 PSYM_ENUMMODULES_CALLBACK64 + // PsymEnummodulesCallback64; BOOL PsymEnummodulesCallback64( PCSTR ModuleName, DWORD64 BaseOfDll, PVOID UserContext ) {...} + [UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet = CharSet.Auto)] + [PInvokeData("dbghelp.h", MSDNShortId = "NC:dbghelp.PSYM_ENUMMODULES_CALLBACK64")] + [return: MarshalAs(UnmanagedType.Bool)] + public delegate bool PSYM_ENUMMODULES_CALLBACK64([MarshalAs(UnmanagedType.LPTStr)] string ModuleName, ulong BaseOfDll, [In, Optional] IntPtr UserContext); + + /// + /// + /// An application-defined callback function used with the StackWalk64 function. It provides address translation for 16-bit addresses. + /// + /// + /// The PTRANSLATE_ADDRESS_ROUTINE64 type defines a pointer to this callback function. TranslateAddressProc64 is a + /// placeholder for the application-defined function name. + /// + /// + /// A handle to the process for which the stack trace is generated. + /// A handle to the thread for which the stack trace is generated. + /// An address to be translated. + /// The function returns the translated address. + /// + /// + /// This callback function supersedes the PTRANSLATE_ADDRESS_ROUTINE callback function. PTRANSLATE_ADDRESS_ROUTINE is defined as + /// follows in Dbghelp.h. + /// + /// + /// #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64) #define PTRANSLATE_ADDRESS_ROUTINE PTRANSLATE_ADDRESS_ROUTINE64 #else typedef DWORD (__stdcall *PTRANSLATE_ADDRESS_ROUTINE)( __in HANDLE hProcess, __in HANDLE hThread, __out LPADDRESS lpaddr ); #endif + /// + /// + // https://docs.microsoft.com/vi-vn/windows/win32/api/dbghelp/nc-dbghelp-ptranslate_address_routine64 PTRANSLATE_ADDRESS_ROUTINE64 + // PtranslateAddressRoutine64; DWORD64 PtranslateAddressRoutine64( HANDLE hProcess, HANDLE hThread, LPADDRESS64 lpaddr ) {...} + [UnmanagedFunctionPointer(CallingConvention.Winapi)] + [PInvokeData("dbghelp.h", MSDNShortId = "NC:dbghelp.PTRANSLATE_ADDRESS_ROUTINE64")] + public delegate ulong PTRANSLATE_ADDRESS_ROUTINE64(HPROCESS hProcess, HTHREAD hThread, in ADDRESS64 lpaddr); + /// The addressing mode. [PInvokeData("dbghelp.h", MSDNShortId = "NS:dbghelp._tagADDRESS64")] public enum ADDRESS_MODE @@ -933,6 +1214,41 @@ namespace Vanara.PInvoke ModuleWriteCodeSegs = 0x0040, } + /// Indicates the result of the comparison. + [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.SymCompareInlineTrace")] + public enum SYM_INLINE_COMP + { + /// An error occurred. + SYM_INLINE_COMP_ERROR = 0, + + /// The inline contexts are identical. + SYM_INLINE_COMP_IDENTICAL = 1, + + /// The inline trace is a step-in of an inline function. + SYM_INLINE_COMP_STEPIN = 2, + + /// The inline trace is a step-out of an inline function. + SYM_INLINE_COMP_STEPOUT = 3, + + /// The inline trace is a step-over of an inline function. + SYM_INLINE_COMP_STEPOVER = 4, + + /// The inline contexts are different. + SYM_INLINE_COMP_DIFFERENT = 5, + } + + /// Flags for . + [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.StackWalkEx")] + [Flags] + public enum SYM_STKWALK + { + /// + SYM_STKWALK_DEFAULT = 0x00000000, + + /// + SYM_STKWALK_FORCE_FRAMEPTR = 0x00000001 + } + /// Identifies the type of thread information that will be written to the minidump file by the MiniDumpWriteDump function. // https://docs.microsoft.com/en-us/windows/win32/api/minidumpapiset/ne-minidumpapiset-thread_write_flags typedef enum // _THREAD_WRITE_FLAGS { ThreadWriteThread, ThreadWriteStack, ThreadWriteContext, ThreadWriteBackingStore, @@ -973,6 +1289,63 @@ namespace Vanara.PInvoke ThreadWriteThreadInfo, } + /// The options for how the decorated name is undecorated. + [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.UnDecorateSymbolName")] + [Flags] + public enum UNDNAME : uint + { + /// Undecorate 32-bit decorated names. + UNDNAME_32_BIT_DECODE = 0x0800, + + /// Enable full undecoration. + UNDNAME_COMPLETE = 0x0000, + + /// Undecorate only the name for primary declaration. Returns [scope::]name. Does expand template parameters. + UNDNAME_NAME_ONLY = 0x1000, + + /// Disable expansion of access specifiers for members. + UNDNAME_NO_ACCESS_SPECIFIERS = 0x0080, + + /// Disable expansion of the declaration language specifier. + UNDNAME_NO_ALLOCATION_LANGUAGE = 0x0010, + + /// Disable expansion of the declaration model. + UNDNAME_NO_ALLOCATION_MODEL = 0x0008, + + /// Do not undecorate function arguments. + UNDNAME_NO_ARGUMENTS = 0x2000, + + /// Disable expansion of CodeView modifiers on the this type for primary declaration. + UNDNAME_NO_CV_THISTYPE = 0x0040, + + /// Disable expansion of return types for primary declarations. + UNDNAME_NO_FUNCTION_RETURNS = 0x0004, + + /// Remove leading underscores from Microsoft keywords. + UNDNAME_NO_LEADING_UNDERSCORES = 0x0001, + + /// Disable expansion of the static or virtual attribute of members. + UNDNAME_NO_MEMBER_TYPE = 0x0200, + + /// Disable expansion of Microsoft keywords. + UNDNAME_NO_MS_KEYWORDS = 0x0002, + + /// Disable expansion of Microsoft keywords on the this type for primary declaration. + UNDNAME_NO_MS_THISTYPE = 0x0020, + + /// Disable expansion of the Microsoft model for user-defined type returns. + UNDNAME_NO_RETURN_UDT_MODEL = 0x0400, + + /// Do not undecorate special names, such as vtable, vcall, vector, metatype, and so on. + UNDNAME_NO_SPECIAL_SYMS = 0x4000, + + /// Disable all modifiers on the this type. + UNDNAME_NO_THISTYPE = 0x0060, + + /// Disable expansion of throw-signatures for functions and pointers to functions. + UNDNAME_NO_THROW_SIGNATURES = 0x0100, + } + /// Enumerates all occurrences of the specified file in the specified directory tree. /// A handle to a process. This handle must have been previously passed to the SymInitialize function. /// The path where the function should begin searching for the file. @@ -1009,7 +1382,25 @@ namespace Vanara.PInvoke [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.EnumDirTree")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool EnumDirTree([Optional] HPROCESS hProcess, [MarshalAs(UnmanagedType.LPTStr)] string RootPath, [MarshalAs(UnmanagedType.LPTStr)] string InputPathName, - [MarshalAs(UnmanagedType.LPTStr)] StringBuilder OutputPathBuffer, [Optional] PENUMDIRTREE_CALLBACK cb, [In, Optional] IntPtr data); + [Optional, MarshalAs(UnmanagedType.LPTStr)] StringBuilder OutputPathBuffer, [Optional] PENUMDIRTREE_CALLBACK cb, [In, Optional] IntPtr data); + + /// Enumerates all occurrences of the specified file in the specified directory tree. + /// A handle to a process. This handle must have been previously passed to the SymInitialize function. + /// The path where the function should begin searching for the file. + /// The name of the file to be found. You can specify a partial path. + /// A list of files matching the . + public static IList EnumDirTree(HPROCESS hProcess, string RootPath, string InputPathName) + { + var paths = new List(); + EnumDirTree(hProcess, RootPath, InputPathName, null, Callback); + return paths; + + bool Callback(string FilePath, IntPtr CallerData) + { + paths.Add(FilePath); + return false; + } + } /// Enumerates the loaded modules for the specified process. /// A handle to the process whose modules will be enumerated. @@ -1042,11 +1433,62 @@ namespace Vanara.PInvoke /// // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-enumerateloadedmodules BOOL IMAGEAPI // EnumerateLoadedModules( HANDLE hProcess, PENUMLOADED_MODULES_CALLBACK EnumLoadedModulesCallback, PVOID UserContext ); - [DllImport(Lib_DbgHelp, SetLastError = true, CharSet = CharSet.Auto)] + [DllImport(Lib_DbgHelp, SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true)] [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.EnumerateLoadedModules")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool EnumerateLoadedModules(HPROCESS hProcess, PENUMLOADED_MODULES_CALLBACK EnumLoadedModulesCallback, [In, Optional] IntPtr UserContext); + /// Enumerates the loaded modules for the specified process. + /// A handle to the process whose modules will be enumerated. + /// An application-defined callback function. For more information, see EnumerateLoadedModulesProc64. + /// Optional user-defined data. This value is passed to the callback function. + /// + /// If the function succeeds, the return value is TRUE. + /// If the function fails, the return value is FALSE. To retrieve extended error information, call GetLastError. + /// + /// + /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more than one thread to this function. + /// To call the Unicode version of this function, EnumerateLoadedModulesW64, define DBGHELP_TRANSLATE_TCHAR. EnumerateLoadedModulesW64 is defined as follows in DbgHelp.h. + /// BOOL IMAGEAPI EnumerateLoadedModulesW64( __in HANDLE hProcess, __in PENUMLOADED_MODULES_CALLBACKW64 EnumLoadedModulesCallback, __in PVOID UserContext ); #ifdef DBGHELP_TRANSLATE_TCHAR #define EnumerateLoadedModules64 EnumerateLoadedModulesW64 #endif + /// This function supersedes the EnumerateLoadedModules function. For more information, see Updated Platform Support. EnumerateLoadedModules is defined as follows in DbgHelp.h. + /// #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64) #define EnumerateLoadedModules EnumerateLoadedModules64 #else BOOL IMAGEAPI EnumerateLoadedModules( __in HANDLE hProcess, __in PENUMLOADED_MODULES_CALLBACK EnumLoadedModulesCallback, __in_opt PVOID UserContext ); #endif + /// + // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-enumerateloadedmodules64 + // BOOL IMAGEAPI EnumerateLoadedModules64( HANDLE hProcess, PENUMLOADED_MODULES_CALLBACK64 EnumLoadedModulesCallback, PVOID UserContext ); + [DllImport(Lib_DbgHelp, SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "EnumerateLoadedModulesW64")] + [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.EnumerateLoadedModules64")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool EnumerateLoadedModules64(HPROCESS hProcess, PENUMLOADED_MODULES_CALLBACKW64 EnumLoadedModulesCallback, [In, Optional] IntPtr UserContext); + + /// + /// Enumerates the loaded modules for the specified process. This overload will call the 32 or 64-bit version of the function based + /// on the calling process. + /// + /// A handle to the process whose modules will be enumerated. + /// A list of all loaded module names, base addresses, and sizes. + [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.EnumerateLoadedModules")] + public static IList<(string ModuleName, IntPtr ModuleBase, uint ModuleSize)> EnumerateLoadedModules(HPROCESS hProcess) + { + var mods = new List<(string, IntPtr, uint)>(); + if (Vanara.InteropServices.LibHelper.Is64BitProcess) + EnumerateLoadedModules64(hProcess, Callback64); + else + EnumerateLoadedModules(hProcess, Callback); + return mods; + + bool Callback(string ModuleName, uint ModuleBase, uint ModuleSize, IntPtr UserContext) + { + mods.Add((ModuleName, new IntPtr(unchecked((int)ModuleBase)), ModuleSize)); + return true; + } + + bool Callback64(string ModuleName, ulong ModuleBase, uint ModuleSize, IntPtr UserContext) + { + mods.Add((ModuleName, new IntPtr(unchecked((long)ModuleBase)), ModuleSize)); + return true; + } + } + /// Enumerates the loaded modules for the specified process. /// A handle to the process whose modules will be enumerated. /// An application-defined callback function. For more information, see EnumerateLoadedModulesProc64. @@ -1065,10 +1507,27 @@ namespace Vanara.PInvoke /// // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-enumerateloadedmodulesexw BOOL IMAGEAPI // EnumerateLoadedModulesExW( HANDLE hProcess, PENUMLOADED_MODULES_CALLBACKW64 EnumLoadedModulesCallback, PVOID UserContext ); - [DllImport(Lib_DbgHelp, SetLastError = true, CharSet = CharSet.Auto)] + [DllImport(Lib_DbgHelp, SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "EnumerateLoadedModulesExW")] [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.EnumerateLoadedModulesExW")] [return: MarshalAs(UnmanagedType.Bool)] - public static extern bool EnumerateLoadedModulesEx(HPROCESS hProcess, PENUMLOADED_MODULES_CALLBACK EnumLoadedModulesCallback, [In, Optional] IntPtr UserContext); + public static extern bool EnumerateLoadedModulesEx(HPROCESS hProcess, PENUMLOADED_MODULES_CALLBACKW64 EnumLoadedModulesCallback, [In, Optional] IntPtr UserContext); + + /// Enumerates the loaded modules for the specified process. + /// A handle to the process whose modules will be enumerated. + /// A list of all loaded module names, base addresses, and sizes. + [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.EnumerateLoadedModulesExW")] + public static IList<(string ModuleName, IntPtr ModuleBase, uint ModuleSize)> EnumerateLoadedModulesEx(HPROCESS hProcess) + { + var mods = new List<(string, IntPtr, uint)>(); + EnumerateLoadedModulesEx(hProcess, Callback); + return mods; + + bool Callback(string ModuleName, ulong ModuleBase, uint ModuleSize, IntPtr UserContext) + { + mods.Add((ModuleName, new IntPtr(unchecked((long)ModuleBase)), ModuleSize)); + return true; + } + } /// /// Locates a debug (.dbg) file. @@ -1102,7 +1561,8 @@ namespace Vanara.PInvoke // FileName, PCSTR SymbolPath, PSTR DebugFilePath ); [DllImport(Lib_DbgHelp, SetLastError = true, ExactSpelling = true)] [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.FindDebugInfoFile")] - public static extern SafeHFILE FindDebugInfoFile([MarshalAs(UnmanagedType.LPStr)] string FileName, [MarshalAs(UnmanagedType.LPStr)] string SymbolPath, [Out, MarshalAs(UnmanagedType.LPStr)] StringBuilder DebugFilePath); + public static extern SafeHFILE FindDebugInfoFile([MarshalAs(UnmanagedType.LPStr)] string FileName, [MarshalAs(UnmanagedType.LPStr)] string SymbolPath, + [Out, MarshalAs(UnmanagedType.LPStr)] StringBuilder DebugFilePath); /// Locates the specified debug (.dbg) file. /// The name of the .dbg file to locate. You can use a partial path. @@ -1235,6 +1695,69 @@ namespace Vanara.PInvoke public static extern SafeHFILE FindExecutableImageEx([MarshalAs(UnmanagedType.LPTStr)] string FileName, [MarshalAs(UnmanagedType.LPTStr)] string SymbolPath, [Out, MarshalAs(UnmanagedType.LPTStr)] StringBuilder ImageFilePath, [Optional] PFIND_EXE_FILE_CALLBACK Callback, [In, Optional] IntPtr CallerData); + /// Locates the specified executable file. + /// The name of the symbol file to be located. This parameter can be a partial path. + /// + /// The paths where symbol files are located. To retrieve the symbol path, use the function. + /// + /// + /// + /// An application-defined callback function that verifies whether the correct executable file was found, or whether the function + /// should continue its search. + /// + /// This parameter can be . + /// + /// The full path of the executable file. + /// + /// + /// The FindExecutableImageEx function is provided so executable files can be found in several different directories by using + /// a single function call. If the parameter contains multiple paths, the function searches each + /// specified directory tree for the executable file. When the file is found, the search stops. Thus, be sure to specify + /// with the paths in the correct order. + /// + /// + public static string FindExecutableImageEx(string FileName, string[] SymbolPaths, Func verifyFoundFile = null) + { + var sb = new StringBuilder(261); + if (verifyFoundFile is null) + return FindExecutableImage(FileName, string.Join(";", SymbolPaths), sb).IsInvalid ? null : sb.ToString(); + else + return FindExecutableImageEx(FileName, string.Join(";", SymbolPaths), sb, Callback).IsInvalid ? null : sb.ToString(); + + bool Callback(HFILE FileHandle, string FileName, IntPtr CallerData) => verifyFoundFile(FileName); + } + + /// Gets the last symbol load error. + /// The last symbol load error. + // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-getsymloaderror DWORD IMAGEAPI GetSymLoadError(); + [DllImport(Lib_DbgHelp, SetLastError = false, ExactSpelling = true)] + [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.GetSymLoadError")] + public static extern uint GetSymLoadError(); + + /// Retrieves the time stamp of a loaded image. + /// The base address of an image that is mapped into memory by a call to the MapViewOfFile function. + /// + /// If the function succeeds, the return value is the time stamp from the image. + /// If the function fails, the return value is zero. To retrieve extended error information, call GetLastError. + /// + /// + /// + /// The time stamp for an image is initially set by the linker, but it can be modified by operations such as rebasing. The value is + /// represented in the number of seconds elapsed since midnight (00:00:00), January 1, 1970, Universal Coordinated Time, according + /// to the system clock. The time stamp can be printed using the C run-time (CRT) function ctime. + /// + /// + /// All DbgHelp Functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will + /// likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more + /// than one thread to this function. + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-gettimestampforloadedlibrary DWORD IMAGEAPI + // GetTimestampForLoadedLibrary( HMODULE Module ); + [DllImport(Lib_DbgHelp, SetLastError = true, ExactSpelling = true)] + [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.GetTimestampForLoadedLibrary")] + public static extern uint GetTimestampForLoadedLibrary(HINSTANCE Module); + /// /// Obtains access to image-specific data. /// @@ -1336,134 +1859,14 @@ namespace Vanara.PInvoke public static extern IntPtr ImageDirectoryEntryToData(IntPtr Base, [MarshalAs(UnmanagedType.U1)] bool MappedAsImage, IMAGE_DIRECTORY_ENTRY DirectoryEntry, out uint Size); /// - /// Locates a relative virtual address (RVA) within the image header of a file that is mapped as a file and returns the virtual - /// address of the corresponding byte in the file. + /// Locates a directory entry within the image header and returns the address of the data for the directory entry. This function + /// returns the section header for the data located, if one exists. /// - /// - /// A pointer to an IMAGE_NT_HEADERS structure. This structure can be obtained by calling the ImageNtHeader function. - /// - /// The base address of an image that is mapped into memory through a call to the MapViewOfFile function. - /// The relative virtual address to be located. - /// - /// A pointer to an IMAGE_SECTION_HEADER structure that specifies the last RVA section. This is an optional parameter. When - /// specified, it points to a variable that contains the last section value used for the specified image to translate an RVA to a VA. - /// - /// - /// If the function succeeds, the return value is the virtual address in the mapped file. - /// If the function fails, the return value is NULL. To retrieve extended error information, call GetLastError. - /// - /// - /// - /// The ImageRvaToVa function locates an RVA within the image header of a file that is mapped as a file and returns the - /// virtual address of the corresponding byte in the file. - /// - /// - /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will - /// likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more - /// than one thread to this function. - /// - /// - // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-imagervatova PVOID IMAGEAPI ImageRvaToVa( PIMAGE_NT_HEADERS - // NtHeaders, PVOID Base, ULONG Rva, OUT PIMAGE_SECTION_HEADER *LastRvaSection ); - [DllImport(Lib_DbgHelp, SetLastError = true, ExactSpelling = true)] - [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.ImageRvaToVa")] - public static extern IntPtr ImageRvaToVa(in IMAGE_NT_HEADERS NtHeaders, IntPtr Base, uint Rva, out IntPtr LastRvaSection); - - /// - /// Locates a relative virtual address (RVA) within the image header of a file that is mapped as a file and returns the virtual - /// address of the corresponding byte in the file. - /// - /// - /// A pointer to an IMAGE_NT_HEADERS structure. This structure can be obtained by calling the ImageNtHeader function. - /// - /// The base address of an image that is mapped into memory through a call to the MapViewOfFile function. - /// The relative virtual address to be located. - /// - /// A pointer to an IMAGE_SECTION_HEADER structure that specifies the last RVA section. This is an optional parameter. When - /// specified, it points to a variable that contains the last section value used for the specified image to translate an RVA to a VA. - /// - /// - /// If the function succeeds, the return value is the virtual address in the mapped file. - /// If the function fails, the return value is NULL. To retrieve extended error information, call GetLastError. - /// - /// - /// - /// The ImageRvaToVa function locates an RVA within the image header of a file that is mapped as a file and returns the - /// virtual address of the corresponding byte in the file. - /// - /// - /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will - /// likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more - /// than one thread to this function. - /// - /// - // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-imagervatova PVOID IMAGEAPI ImageRvaToVa( PIMAGE_NT_HEADERS - // NtHeaders, PVOID Base, ULONG Rva, OUT PIMAGE_SECTION_HEADER *LastRvaSection ); - [DllImport(Lib_DbgHelp, SetLastError = true, ExactSpelling = true)] - [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.ImageRvaToVa")] - public static extern IntPtr ImageRvaToVa(IntPtr NtHeaders, IntPtr Base, uint Rva, out IntPtr LastRvaSection); - - /// - /// An application-defined callback function used with the StackWalk64 function. It is called when StackWalk64 needs a module base address for a given virtual address. - /// The PGET_MODULE_BASE_ROUTINE64 type defines a pointer to this callback function. GetModuleBaseProc64 is a placeholder for the application-defined function name. - /// - /// A handle to the process for which the stack trace is generated. - /// An address within the module image to be located. - /// The function returns the base address of the module. - /// - /// This callback function supersedes the PGET_MODULE_BASE_ROUTINE callback function. PGET_MODULE_BASE_ROUTINE is defined as follows in DbgHelp.h. - /// #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64) #define PGET_MODULE_BASE_ROUTINE PGET_MODULE_BASE_ROUTINE64 #else typedef DWORD (__stdcall *PGET_MODULE_BASE_ROUTINE)( __in HANDLE hProcess, __in DWORD Address ); #endif - /// - // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nc-dbghelp-pget_module_base_routine64 - // PGET_MODULE_BASE_ROUTINE64 PgetModuleBaseRoutine64; DWORD64 PgetModuleBaseRoutine64( HANDLE hProcess, DWORD64 Address ) {...} - [UnmanagedFunctionPointer(CallingConvention.Winapi)] - [PInvokeData("dbghelp.h", MSDNShortId = "NC:dbghelp.PGET_MODULE_BASE_ROUTINE64")] - public delegate ulong PGET_MODULE_BASE_ROUTINE64(HPROCESS hProcess, ulong Address); - - /// - /// An application-defined callback function used with the StackWalk64 function. It is called when StackWalk64 needs a module base address for a given virtual address. - /// The PGET_MODULE_BASE_ROUTINE64 type defines a pointer to this callback function. GetModuleBaseProc64 is a placeholder for the application-defined function name. - /// - /// A handle to the process for which the stack trace is generated. - /// An address within the module image to be located. - /// The function returns the base address of the module. - /// - /// This callback function supersedes the PGET_MODULE_BASE_ROUTINE callback function. PGET_MODULE_BASE_ROUTINE is defined as follows in DbgHelp.h. - /// #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64) #define PGET_MODULE_BASE_ROUTINE PGET_MODULE_BASE_ROUTINE64 #else typedef DWORD (__stdcall *PGET_MODULE_BASE_ROUTINE)( __in HANDLE hProcess, __in DWORD Address ); #endif - /// - // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nc-dbghelp-pget_module_base_routine - // PGET_MODULE_BASE_ROUTINE PgetModuleBaseRoutine; DWORD PgetModuleBaseRoutine( HANDLE hProcess, DWORD Address ) {...} - [UnmanagedFunctionPointer(CallingConvention.Winapi)] - [PInvokeData("dbghelp.h", MSDNShortId = "NC:dbghelp.PGET_MODULE_BASE_ROUTINE")] - public delegate uint PGET_MODULE_BASE_ROUTINE(HPROCESS hProcess, uint Address); - - /// Gets the last symbol load error. - /// The last symbol load error. - // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-getsymloaderror - // DWORD IMAGEAPI GetSymLoadError(); - [DllImport(Lib_DbgHelp, SetLastError = false, ExactSpelling = true)] - [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.GetSymLoadError")] - public static extern uint GetSymLoadError(); - - /// Retrieves the time stamp of a loaded image. - /// The base address of an image that is mapped into memory by a call to the MapViewOfFile function. - /// - /// If the function succeeds, the return value is the time stamp from the image. - /// If the function fails, the return value is zero. To retrieve extended error information, call GetLastError. - /// - /// - /// The time stamp for an image is initially set by the linker, but it can be modified by operations such as rebasing. The value is represented in the number of seconds elapsed since midnight (00:00:00), January 1, 1970, Universal Coordinated Time, according to the system clock. The time stamp can be printed using the C run-time (CRT) function ctime. - /// All DbgHelp Functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more than one thread to this function. - /// - // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-gettimestampforloadedlibrary - // DWORD IMAGEAPI GetTimestampForLoadedLibrary( HMODULE Module ); - [DllImport(Lib_DbgHelp, SetLastError = true, ExactSpelling = true)] - [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.GetTimestampForLoadedLibrary")] - public static extern uint GetTimestampForLoadedLibrary(HINSTANCE Module); - - /// Locates a directory entry within the image header and returns the address of the data for the directory entry. This function returns the section header for the data located, if one exists. /// The base address of the image or data file. - /// If the flag is TRUE, the file is mapped by the system as an image. If this flag is FALSE, the file is mapped as a data file by the MapViewOfFile function. + /// + /// If the flag is TRUE, the file is mapped by the system as an image. If this flag is FALSE, the file is mapped as a + /// data file by the MapViewOfFile function. + /// /// /// The directory entry to be located. The value must be one of the following values. /// @@ -1534,14 +1937,21 @@ namespace Vanara.PInvoke /// /// /// A pointer to a variable that receives the size of the data for the directory entry that is located. - /// A pointer to an IMAGE_SECTION_HEADER structure that receives the data. If the section header does not exist, this parameter is NULL. + /// + /// A pointer to an IMAGE_SECTION_HEADER structure that receives the data. If the section header does not exist, this parameter is NULL. + /// /// /// If the function succeeds, the return value is a pointer to the data for the directory entry. /// If the function fails, the return value is NULL. To retrieve extended error information, call GetLastError. - /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more than one thread to this function. + /// + /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will + /// likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more + /// than one thread to this function. + /// /// - // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-imagedirectoryentrytodataex - // PVOID IMAGEAPI ImageDirectoryEntryToDataEx( PVOID Base, BOOLEAN MappedAsImage, USHORT DirectoryEntry, PULONG Size, PIMAGE_SECTION_HEADER *FoundHeader ); + // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-imagedirectoryentrytodataex PVOID IMAGEAPI + // ImageDirectoryEntryToDataEx( PVOID Base, BOOLEAN MappedAsImage, USHORT DirectoryEntry, PULONG Size, PIMAGE_SECTION_HEADER + // *FoundHeader ); [DllImport(Lib_DbgHelp, SetLastError = true, ExactSpelling = true)] [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.ImageDirectoryEntryToDataEx")] public static extern IntPtr ImageDirectoryEntryToDataEx(IntPtr Base, [MarshalAs(UnmanagedType.U1)] bool MappedAsImage, IMAGE_DIRECTORY_ENTRY DirectoryEntry, out uint Size, out IntPtr FoundHeader); @@ -1552,11 +1962,18 @@ namespace Vanara.PInvoke /// /// The return value is a pointer to an API_VERSION structure. /// - /// Use the information in the API_VERSION structure to determine whether the version of the library installed on the system is compatible with the version of the library used by the application. Although the library functions are backward compatible, functions introduced in one version are obviously not available in earlier versions. - /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more than one thread to this function. + /// + /// Use the information in the API_VERSION structure to determine whether the version of the library installed on the system is + /// compatible with the version of the library used by the application. Although the library functions are backward compatible, + /// functions introduced in one version are obviously not available in earlier versions. + /// + /// + /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will + /// likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more + /// than one thread to this function. + /// /// - // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-imagehlpapiversion - // LPAPI_VERSION IMAGEAPI ImagehlpApiVersion(); + // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-imagehlpapiversion LPAPI_VERSION IMAGEAPI ImagehlpApiVersion(); [DllImport(Lib_DbgHelp, SetLastError = false, ExactSpelling = true)] [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.ImagehlpApiVersion")] public static extern IntPtr ImagehlpApiVersion(); @@ -1565,11 +1982,21 @@ namespace Vanara.PInvoke /// A pointer to an API_VERSION structure that contains valid version information for your application. /// The return value is a pointer to an API_VERSION structure. /// - /// Use the ImagehlpApiVersionEx function to indicate the version of the library with which the application was built. The library uses this information to ensure compatibility. For example, consider walking through kernel-mode callback stack frames (User and GDI exist in kernel mode). If you call ImagehlpApiVersionEx to set the Revision member to version 4 or later, the StackWalk64 function will continue through a callback stack frame. Otherwise, if you set Revision to a version earlier than 4, StackWalk64 will stop at the kernel transition. - /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more than one thread to this function. + /// + /// Use the ImagehlpApiVersionEx function to indicate the version of the library with which the application was built. The + /// library uses this information to ensure compatibility. For example, consider walking through kernel-mode callback stack frames + /// (User and GDI exist in kernel mode). If you call ImagehlpApiVersionEx to set the Revision member to version 4 or + /// later, the StackWalk64 function will continue through a callback stack frame. Otherwise, if you set Revision to a version + /// earlier than 4, StackWalk64 will stop at the kernel transition. + /// + /// + /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will + /// likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more + /// than one thread to this function. + /// /// - // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-imagehlpapiversionex - // LPAPI_VERSION IMAGEAPI ImagehlpApiVersionEx( LPAPI_VERSION AppVersion ); + // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-imagehlpapiversionex LPAPI_VERSION IMAGEAPI + // ImagehlpApiVersionEx( LPAPI_VERSION AppVersion ); [DllImport(Lib_DbgHelp, SetLastError = false, ExactSpelling = true)] [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.ImagehlpApiVersionEx")] public static extern IntPtr ImagehlpApiVersionEx(in API_VERSION AppVersion); @@ -1580,56 +2007,155 @@ namespace Vanara.PInvoke /// If the function succeeds, the return value is a pointer to an IMAGE_NT_HEADERS structure. /// If the function fails, the return value is NULL. To retrieve extended error information, call GetLastError. /// - /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more than one thread to this function. - // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-imagentheader - // PIMAGE_NT_HEADERS IMAGEAPI ImageNtHeader( PVOID Base ); + /// + /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will + /// likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more + /// than one thread to this function. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-imagentheader PIMAGE_NT_HEADERS IMAGEAPI ImageNtHeader( + // PVOID Base ); [DllImport(Lib_DbgHelp, SetLastError = true, ExactSpelling = true)] [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.ImageNtHeader")] public static extern IntPtr ImageNtHeader(IntPtr Base); - /// Locates a relative virtual address (RVA) within the image header of a file that is mapped as a file and returns a pointer to the section table entry for that RVA. - /// A pointer to an IMAGE_NT_HEADERS structure. This structure can be obtained by calling the ImageNtHeader function. + /// + /// Locates a relative virtual address (RVA) within the image header of a file that is mapped as a file and returns a pointer to the + /// section table entry for that RVA. + /// + /// + /// A pointer to an IMAGE_NT_HEADERS structure. This structure can be obtained by calling the ImageNtHeader function. + /// /// This parameter is reserved. /// The relative virtual address to be located. /// /// If the function succeeds, the return value is a pointer to an IMAGE_SECTION_HEADER structure. /// If the function fails, the return value is NULL. To retrieve extended error information, call GetLastError. /// - /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more than one thread to this function. - // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-imagervatosection - // PIMAGE_SECTION_HEADER IMAGEAPI ImageRvaToSection( PIMAGE_NT_HEADERS NtHeaders, PVOID Base, ULONG Rva ); + /// + /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will + /// likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more + /// than one thread to this function. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-imagervatosection PIMAGE_SECTION_HEADER IMAGEAPI + // ImageRvaToSection( PIMAGE_NT_HEADERS NtHeaders, PVOID Base, ULONG Rva ); [DllImport(Lib_DbgHelp, SetLastError = true, ExactSpelling = true)] [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.ImageRvaToSection")] public static extern IntPtr ImageRvaToSection(in IMAGE_NT_HEADERS NtHeaders, IntPtr Base, uint Rva); - /// Locates a relative virtual address (RVA) within the image header of a file that is mapped as a file and returns a pointer to the section table entry for that RVA. - /// A pointer to an IMAGE_NT_HEADERS structure. This structure can be obtained by calling the ImageNtHeader function. + /// + /// Locates a relative virtual address (RVA) within the image header of a file that is mapped as a file and returns a pointer to the + /// section table entry for that RVA. + /// + /// + /// A pointer to an IMAGE_NT_HEADERS structure. This structure can be obtained by calling the ImageNtHeader function. + /// /// This parameter is reserved. /// The relative virtual address to be located. /// /// If the function succeeds, the return value is a pointer to an IMAGE_SECTION_HEADER structure. /// If the function fails, the return value is NULL. To retrieve extended error information, call GetLastError. /// - /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more than one thread to this function. - // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-imagervatosection - // PIMAGE_SECTION_HEADER IMAGEAPI ImageRvaToSection( PIMAGE_NT_HEADERS NtHeaders, PVOID Base, ULONG Rva ); + /// + /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will + /// likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more + /// than one thread to this function. + /// + // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-imagervatosection PIMAGE_SECTION_HEADER IMAGEAPI + // ImageRvaToSection( PIMAGE_NT_HEADERS NtHeaders, PVOID Base, ULONG Rva ); [DllImport(Lib_DbgHelp, SetLastError = true, ExactSpelling = true)] [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.ImageRvaToSection")] public static extern IntPtr ImageRvaToSection([In] IntPtr NtHeaders, IntPtr Base, uint Rva); + /// + /// Locates a relative virtual address (RVA) within the image header of a file that is mapped as a file and returns the virtual + /// address of the corresponding byte in the file. + /// + /// + /// A pointer to an IMAGE_NT_HEADERS structure. This structure can be obtained by calling the ImageNtHeader function. + /// + /// The base address of an image that is mapped into memory through a call to the MapViewOfFile function. + /// The relative virtual address to be located. + /// + /// A pointer to an IMAGE_SECTION_HEADER structure that specifies the last RVA section. This is an optional parameter. When + /// specified, it points to a variable that contains the last section value used for the specified image to translate an RVA to a VA. + /// + /// + /// If the function succeeds, the return value is the virtual address in the mapped file. + /// If the function fails, the return value is NULL. To retrieve extended error information, call GetLastError. + /// + /// + /// + /// The ImageRvaToVa function locates an RVA within the image header of a file that is mapped as a file and returns the + /// virtual address of the corresponding byte in the file. + /// + /// + /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will + /// likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more + /// than one thread to this function. + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-imagervatova PVOID IMAGEAPI ImageRvaToVa( PIMAGE_NT_HEADERS + // NtHeaders, PVOID Base, ULONG Rva, OUT PIMAGE_SECTION_HEADER *LastRvaSection ); + [DllImport(Lib_DbgHelp, SetLastError = true, ExactSpelling = true)] + [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.ImageRvaToVa")] + public static extern IntPtr ImageRvaToVa(in IMAGE_NT_HEADERS NtHeaders, IntPtr Base, uint Rva, out IntPtr LastRvaSection); + + /// + /// Locates a relative virtual address (RVA) within the image header of a file that is mapped as a file and returns the virtual + /// address of the corresponding byte in the file. + /// + /// + /// A pointer to an IMAGE_NT_HEADERS structure. This structure can be obtained by calling the ImageNtHeader function. + /// + /// The base address of an image that is mapped into memory through a call to the MapViewOfFile function. + /// The relative virtual address to be located. + /// + /// A pointer to an IMAGE_SECTION_HEADER structure that specifies the last RVA section. This is an optional parameter. When + /// specified, it points to a variable that contains the last section value used for the specified image to translate an RVA to a VA. + /// + /// + /// If the function succeeds, the return value is the virtual address in the mapped file. + /// If the function fails, the return value is NULL. To retrieve extended error information, call GetLastError. + /// + /// + /// + /// The ImageRvaToVa function locates an RVA within the image header of a file that is mapped as a file and returns the + /// virtual address of the corresponding byte in the file. + /// + /// + /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will + /// likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more + /// than one thread to this function. + /// + /// + // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-imagervatova PVOID IMAGEAPI ImageRvaToVa( PIMAGE_NT_HEADERS + // NtHeaders, PVOID Base, ULONG Rva, OUT PIMAGE_SECTION_HEADER *LastRvaSection ); + [DllImport(Lib_DbgHelp, SetLastError = true, ExactSpelling = true)] + [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.ImageRvaToVa")] + public static extern IntPtr ImageRvaToVa(IntPtr NtHeaders, IntPtr Base, uint Rva, out IntPtr LastRvaSection); + /// Creates all the directories in the specified path, beginning with the root. - /// A valid path name. If the final component of the path is a directory, not a file name, the string must end with a backslash () character. + /// + /// A valid path name. If the final component of the path is a directory, not a file name, the string must end with a backslash () character. + /// /// /// If the function succeeds, the return value is TRUE. /// If the function fails, the return value is FALSE. To retrieve extended error information, call GetLastError. /// /// - /// Each directory specified is created, if it does not already exist. If only some of the directories are created, the function will return FALSE. + /// + /// Each directory specified is created, if it does not already exist. If only some of the directories are created, the function + /// will return FALSE. + /// /// This function does not support Unicode strings. To specify a Unicode path, use the SHCreateDirectoryEx function. - /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more than one thread to this function. + /// + /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will + /// likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more + /// than one thread to this function. + /// /// - // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-makesuredirectorypathexists - // BOOL IMAGEAPI MakeSureDirectoryPathExists( PCSTR DirPath ); + // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-makesuredirectorypathexists BOOL IMAGEAPI + // MakeSureDirectoryPathExists( PCSTR DirPath ); [DllImport(Lib_DbgHelp, SetLastError = true, ExactSpelling = true)] [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.MakeSureDirectoryPathExists")] [return: MarshalAs(UnmanagedType.Bool)] @@ -1637,89 +2163,75 @@ namespace Vanara.PInvoke /// /// Obtains access to the debugging information for an image. - /// Note This function is provided only for backward compatibility. It does not return reliable information. New applications should use the SymGetModuleInfo64 and SymLoadModule64 functions. + /// + /// Note This function is provided only for backward compatibility. It does not return reliable information. New applications + /// should use the SymGetModuleInfo64 and SymLoadModule64 functions. + /// /// /// A handle to an open executable image or NULL. /// The name of an executable image file or NULL. - /// The path where symbol files are located. The path can be multiple paths separated by semicolons. To retrieve the symbol path, use the SymGetSearchPath function. + /// + /// The path where symbol files are located. The path can be multiple paths separated by semicolons. To retrieve the symbol path, + /// use the SymGetSearchPath function. + /// /// The base address for the image or zero. /// /// If the function succeeds, the return value is a pointer to an IMAGE_DEBUG_INFORMATION structure. /// If the function fails, the return value is NULL. To retrieve extended error information, call GetLastError. /// /// - /// The MapDebugInformation function is used to obtain access to an image's debugging information. The debugging information is extracted from the image or the symbol file and placed into the IMAGE_DEBUG_INFORMATION structure. This structure is allocated by the library and must be deallocated by using the UnmapDebugInformation function. The memory for the structure is not in the process's default heap, so attempts to free it with a memory deallocation routine will fail. - /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more than one thread to this function. + /// + /// The MapDebugInformation function is used to obtain access to an image's debugging information. The debugging information + /// is extracted from the image or the symbol file and placed into the IMAGE_DEBUG_INFORMATION structure. This structure is + /// allocated by the library and must be deallocated by using the UnmapDebugInformation function. The memory for the structure is + /// not in the process's default heap, so attempts to free it with a memory deallocation routine will fail. + /// + /// + /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will + /// likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more + /// than one thread to this function. + /// /// - // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-mapdebuginformation - // PIMAGE_DEBUG_INFORMATION IMAGEAPI MapDebugInformation( HANDLE FileHandle, PCSTR FileName, PCSTR SymbolPath, ULONG ImageBase ); + // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-mapdebuginformation PIMAGE_DEBUG_INFORMATION IMAGEAPI + // MapDebugInformation( HANDLE FileHandle, PCSTR FileName, PCSTR SymbolPath, ULONG ImageBase ); [DllImport(Lib_DbgHelp, SetLastError = true, ExactSpelling = true)] [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.MapDebugInformation")] public static extern IntPtr MapDebugInformation([Optional] HFILE FileHandle, [MarshalAs(UnmanagedType.LPStr)] string FileName, [Optional, MarshalAs(UnmanagedType.LPStr)] string SymbolPath, uint ImageBase); - /// - /// An application-defined callback function used with the StackWalk64 function. It is called when StackWalk64 needs to read memory from the address space of the process. - /// The PREAD_PROCESS_MEMORY_ROUTINE64 type defines a pointer to this callback function. ReadProcessMemoryProc64 is a placeholder for the application-defined function name. - /// - /// A handle to the process for which the stack trace is generated. - /// The base address of the memory to be read. - /// A pointer to a buffer that receives the memory to be read. - /// The size of the memory to be read, in bytes. - /// A pointer to a variable that receives the number of bytes actually read. - /// If the function succeeds, the return value should be TRUE. If the function fails, the return value should be FALSE. - /// - /// In many cases, this function can best service the callback with a corresponding call to ReadProcessMemory. - /// This function should read as much of the requested memory as possible. The StackWalk64 function handles the case where only part of the requested memory is read. - /// This callback function supersedes the PREAD_PROCESS_MEMORY_ROUTINE callback function. PREAD_PROCESS_MEMORY_ROUTINE is defined as follows in Dbghelp.h. - /// #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64) #define PREAD_PROCESS_MEMORY_ROUTINE PREAD_PROCESS_MEMORY_ROUTINE64 #else typedef BOOL (__stdcall *PREAD_PROCESS_MEMORY_ROUTINE)( __in HANDLE hProcess, __in DWORD lpBaseAddress, __out_bcount(nSize) PVOID lpBuffer, __in DWORD nSize, __out PDWORD lpNumberOfBytesRead ); #endif - /// - // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nc-dbghelp-pread_process_memory_routine - // PREAD_PROCESS_MEMORY_ROUTINE PreadProcessMemoryRoutine; BOOL PreadProcessMemoryRoutine( HANDLE hProcess, DWORD lpBaseAddress, PVOID lpBuffer, DWORD nSize, PDWORD lpNumberOfBytesRead ) {...} - [UnmanagedFunctionPointer(CallingConvention.Winapi)] - [PInvokeData("dbghelp.h", MSDNShortId = "NC:dbghelp.PREAD_PROCESS_MEMORY_ROUTINE")] - [return: MarshalAs(UnmanagedType.Bool)] - public delegate bool PREAD_PROCESS_MEMORY_ROUTINE(HPROCESS hProcess, uint lpBaseAddress, [Out] IntPtr lpBuffer, uint nSize, out uint lpNumberOfBytesRead); - - /// - /// An application-defined callback function used with the StackWalk64 function. It is called when StackWalk64 needs to read memory from the address space of the process. - /// The PREAD_PROCESS_MEMORY_ROUTINE64 type defines a pointer to this callback function. ReadProcessMemoryProc64 is a placeholder for the application-defined function name. - /// - /// A handle to the process for which the stack trace is generated. - /// The base address of the memory to be read. - /// A pointer to a buffer that receives the memory to be read. - /// The size of the memory to be read, in bytes. - /// A pointer to a variable that receives the number of bytes actually read. - /// If the function succeeds, the return value should be TRUE. If the function fails, the return value should be FALSE. - /// - /// In many cases, this function can best service the callback with a corresponding call to ReadProcessMemory. - /// This function should read as much of the requested memory as possible. The StackWalk64 function handles the case where only part of the requested memory is read. - /// This callback function supersedes the PREAD_PROCESS_MEMORY_ROUTINE callback function. PREAD_PROCESS_MEMORY_ROUTINE is defined as follows in Dbghelp.h. - /// #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64) #define PREAD_PROCESS_MEMORY_ROUTINE PREAD_PROCESS_MEMORY_ROUTINE64 #else typedef BOOL (__stdcall *PREAD_PROCESS_MEMORY_ROUTINE)( __in HANDLE hProcess, __in DWORD lpBaseAddress, __out_bcount(nSize) PVOID lpBuffer, __in DWORD nSize, __out PDWORD lpNumberOfBytesRead ); #endif - /// - // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nc-dbghelp-pread_process_memory_routine - // PREAD_PROCESS_MEMORY_ROUTINE PreadProcessMemoryRoutine; BOOL PreadProcessMemoryRoutine( HANDLE hProcess, DWORD lpBaseAddress, PVOID lpBuffer, DWORD nSize, PDWORD lpNumberOfBytesRead ) {...} - [UnmanagedFunctionPointer(CallingConvention.Winapi)] - [PInvokeData("dbghelp.h", MSDNShortId = "NC:dbghelp.PREAD_PROCESS_MEMORY_ROUTINE")] - [return: MarshalAs(UnmanagedType.Bool)] - public delegate bool PREAD_PROCESS_MEMORY_ROUTINE64(HPROCESS hProcess, ulong lpBaseAddress, [Out] IntPtr lpBuffer, uint nSize, out uint lpNumberOfBytesRead); - /// Searches a directory tree for a specified file. /// The path where the function should begin searching for the file. /// The file for which the function will search. You can use a partial path. - /// A pointer to a buffer that receives the full path to the file that is found. This string is not modified if the return value is FALSE. + /// + /// A pointer to a buffer that receives the full path to the file that is found. This string is not modified if the return value is FALSE. + /// /// /// If the function succeeds, the return value is TRUE. /// If the function fails, the return value is FALSE. To retrieve extended error information, call GetLastError. /// /// - /// The function searches for the file specified by the InputPathName parameter beginning at the path specified in the RootPath parameter. The maximum path depth that is allowed in the RootPath is 32 directories. When the function finds the file in the directory tree, it places the full path to the file in the buffer specified by the OutputPathBuffer parameter. The underlying file system specifies the order of the subdirectory search. - /// The search can be canceled if you register a SymRegisterCallbackProc64 callback function. For every directory searched, SearchTreeForFile calls this callback function with CBA_DEFERRED_SYMBOL_LOAD_CANCEL. If the callback function returns TRUE, SearchTreeForFile cancels the search. - /// This function triggers one CBA_DEFERRED_SYMBOL_LOAD_CANCEL event per directory searched. This allows the caller to cancel the search. - /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more than one thread to this function. + /// + /// The function searches for the file specified by the InputPathName parameter beginning at the path specified in the RootPath + /// parameter. The maximum path depth that is allowed in the RootPath is 32 directories. When the function finds the file in the + /// directory tree, it places the full path to the file in the buffer specified by the OutputPathBuffer parameter. The underlying + /// file system specifies the order of the subdirectory search. + /// + /// + /// The search can be canceled if you register a SymRegisterCallbackProc64 callback function. For every directory searched, + /// SearchTreeForFile calls this callback function with CBA_DEFERRED_SYMBOL_LOAD_CANCEL. If the callback function returns + /// TRUE, SearchTreeForFile cancels the search. + /// + /// + /// This function triggers one CBA_DEFERRED_SYMBOL_LOAD_CANCEL event per directory searched. This allows the caller to cancel the search. + /// + /// + /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will + /// likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more + /// than one thread to this function. + /// /// To call the Unicode version of this function, define DBGHELP_TRANSLATE_TCHAR. /// - // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-searchtreeforfile - // BOOL IMAGEAPI SearchTreeForFile( PCSTR RootPath, PCSTR InputPathName, PSTR OutputPathBuffer ); + // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-searchtreeforfile BOOL IMAGEAPI SearchTreeForFile( PCSTR + // RootPath, PCSTR InputPathName, PSTR OutputPathBuffer ); [DllImport(Lib_DbgHelp, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.SearchTreeForFile")] [return: MarshalAs(UnmanagedType.Bool)] @@ -1728,15 +2240,16 @@ namespace Vanara.PInvoke /// Sets a symbol load error. /// A symbol load error. /// This function does not return a value. - // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-setsymloaderror - // void IMAGEAPI SetSymLoadError( DWORD error ); + // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-setsymloaderror void IMAGEAPI SetSymLoadError( DWORD error ); [DllImport(Lib_DbgHelp, SetLastError = false, ExactSpelling = true)] [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.SetSymLoadError")] public static extern void SetSymLoadError(uint error); /// Obtains a stack trace. /// - /// The architecture type of the computer for which the stack trace is generated. This parameter can be one of the following values. + /// + /// The architecture type of the computer for which the stack trace is generated. This parameter can be one of the following values. + /// /// /// /// Value @@ -1756,25 +2269,61 @@ namespace Vanara.PInvoke /// /// /// - /// A handle to the process for which the stack trace is generated. If the caller supplies a valid callback pointer for the ReadMemoryRoutine parameter, then this value does not have to be a valid process handle. It can be a token that is unique and consistently the same for all calls to the StackWalk64 function. If the symbol handler is used with StackWalk64, use the same process handles for the calls to each function. - /// A handle to the thread for which the stack trace is generated. If the caller supplies a valid callback pointer for the ReadMemoryRoutine parameter, then this value does not have to be a valid thread handle. It can be a token that is unique and consistently the same for all calls to the StackWalk64 function. - /// A pointer to a STACKFRAME64 structure. This structure receives information for the next frame, if the function call succeeds. + /// + /// A handle to the process for which the stack trace is generated. If the caller supplies a valid callback pointer for the + /// ReadMemoryRoutine parameter, then this value does not have to be a valid process handle. It can be a token that is unique and + /// consistently the same for all calls to the StackWalk64 function. If the symbol handler is used with StackWalk64, + /// use the same process handles for the calls to each function. + /// + /// + /// A handle to the thread for which the stack trace is generated. If the caller supplies a valid callback pointer for the + /// ReadMemoryRoutine parameter, then this value does not have to be a valid thread handle. It can be a token that is unique and + /// consistently the same for all calls to the StackWalk64 function. + /// + /// + /// A pointer to a STACKFRAME64 structure. This structure receives information for the next frame, if the function call succeeds. + /// /// - /// A pointer to a CONTEXT structure. This parameter is required only when the MachineType parameter is not IMAGE_FILE_MACHINE_I386. However, it is recommended that this parameter contain a valid context record. This allows StackWalk64 to handle a greater variety of situations. + /// + /// A pointer to a CONTEXT structure. This parameter is required only when the MachineType parameter is not + /// IMAGE_FILE_MACHINE_I386. However, it is recommended that this parameter contain a valid context record. This allows + /// StackWalk64 to handle a greater variety of situations. + /// /// This context may be modified, so do not pass a context record that should not be modified. /// /// - /// A callback routine that provides memory read services. When the StackWalk64 function needs to read memory from the process's address space, the ReadProcessMemoryProc64 callback is used. - /// If this parameter is NULL, then the function uses a default routine. In this case, the hProcess parameter must be a valid process handle. - /// If this parameter is not NULL, the application should implement and register a symbol handler callback function that handles CBA_READ_MEMORY. + /// + /// A callback routine that provides memory read services. When the StackWalk64 function needs to read memory from the + /// process's address space, the ReadProcessMemoryProc64 callback is used. + /// + /// + /// If this parameter is NULL, then the function uses a default routine. In this case, the hProcess parameter must be a valid + /// process handle. + /// + /// + /// If this parameter is not NULL, the application should implement and register a symbol handler callback function that + /// handles CBA_READ_MEMORY. + /// /// /// - /// A callback routine that provides access to the run-time function table for the process. This parameter is required because the StackWalk64 function does not have access to the process's run-time function table. For more information, see FunctionTableAccessProc64. - /// The symbol handler provides functions that load and access the run-time table. If these functions are used, then SymFunctionTableAccess64 can be passed as a valid parameter. + /// + /// A callback routine that provides access to the run-time function table for the process. This parameter is required because the + /// StackWalk64 function does not have access to the process's run-time function table. For more information, see FunctionTableAccessProc64. + /// + /// + /// The symbol handler provides functions that load and access the run-time table. If these functions are used, then + /// SymFunctionTableAccess64 can be passed as a valid parameter. + /// /// /// - /// A callback routine that provides a module base for any given virtual address. This parameter is required. For more information, see GetModuleBaseProc64. - /// The symbol handler provides functions that load and maintain module information. If these functions are used, then SymGetModuleBase64 can be passed as a valid parameter. + /// + /// A callback routine that provides a module base for any given virtual address. This parameter is required. For more information, + /// see GetModuleBaseProc64. + /// + /// + /// The symbol handler provides functions that load and maintain module information. If these functions are used, then + /// SymGetModuleBase64 can be passed as a valid parameter. + /// /// /// /// A callback routine that provides address translation for 16-bit addresses. For more information, see TranslateAddressProc64. @@ -1782,17 +2331,38 @@ namespace Vanara.PInvoke /// /// /// If the function succeeds, the return value is TRUE. - /// If the function fails, the return value is FALSE. Note that StackWalk64 generally does not set the last error code. + /// + /// If the function fails, the return value is FALSE. Note that StackWalk64 generally does not set the last error code. + /// /// /// - /// The StackWalk64 function provides a portable method for obtaining a stack trace. Using the StackWalk64 function is recommended over writing your own function because of all the complexities associated with stack walking on platforms. In addition, there are compiler options that cause the stack to appear differently, depending on how the module is compiled. By using this function, your application has a portable stack trace that continues to work as the compiler and operating system change. - /// The first call to this function will fail if the AddrPC, AddrFrame, and AddrStack members of the STACKFRAME64 structure passed in the StackFrame parameter are not initialized. - /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more than one thread to this function. - /// This function supersedes the StackWalk function. For more information, see Updated Platform Support. StackWalk is defined as follows in DbgHelp.h. - /// #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64) #define StackWalk StackWalk64 #else BOOL IMAGEAPI StackWalk( DWORD MachineType, __in HANDLE hProcess, __in HANDLE hThread, __inout LPSTACKFRAME StackFrame, __inout PVOID ContextRecord, __in_opt PREAD_PROCESS_MEMORY_ROUTINE ReadMemoryRoutine, __in_opt PFUNCTION_TABLE_ACCESS_ROUTINE FunctionTableAccessRoutine, __in_opt PGET_MODULE_BASE_ROUTINE GetModuleBaseRoutine, __in_opt PTRANSLATE_ADDRESS_ROUTINE TranslateAddress ); #endif + /// + /// The StackWalk64 function provides a portable method for obtaining a stack trace. Using the StackWalk64 function is + /// recommended over writing your own function because of all the complexities associated with stack walking on platforms. In + /// addition, there are compiler options that cause the stack to appear differently, depending on how the module is compiled. By + /// using this function, your application has a portable stack trace that continues to work as the compiler and operating system change. + /// + /// + /// The first call to this function will fail if the AddrPC, AddrFrame, and AddrStack members of the + /// STACKFRAME64 structure passed in the StackFrame parameter are not initialized. + /// + /// + /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will + /// likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more + /// than one thread to this function. + /// + /// + /// This function supersedes the StackWalk function. For more information, see Updated Platform Support. StackWalk is + /// defined as follows in DbgHelp.h. + /// + /// + /// #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64) #define StackWalk StackWalk64 #else BOOL IMAGEAPI StackWalk( DWORD MachineType, __in HANDLE hProcess, __in HANDLE hThread, __inout LPSTACKFRAME StackFrame, __inout PVOID ContextRecord, __in_opt PREAD_PROCESS_MEMORY_ROUTINE ReadMemoryRoutine, __in_opt PFUNCTION_TABLE_ACCESS_ROUTINE FunctionTableAccessRoutine, __in_opt PGET_MODULE_BASE_ROUTINE GetModuleBaseRoutine, __in_opt PTRANSLATE_ADDRESS_ROUTINE TranslateAddress ); #endif + /// /// - // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-stackwalk64 - // BOOL IMAGEAPI StackWalk64( DWORD MachineType, HANDLE hProcess, HANDLE hThread, LPSTACKFRAME64 StackFrame, PVOID ContextRecord, PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine, PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine, PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine, PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress ); + // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-stackwalk64 BOOL IMAGEAPI StackWalk64( DWORD MachineType, + // HANDLE hProcess, HANDLE hThread, LPSTACKFRAME64 StackFrame, PVOID ContextRecord, PREAD_PROCESS_MEMORY_ROUTINE64 + // ReadMemoryRoutine, PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine, PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine, + // PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress ); [DllImport(Lib_DbgHelp, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.StackWalk64")] [return: MarshalAs(UnmanagedType.Bool)] @@ -1800,28 +2370,11 @@ namespace Vanara.PInvoke [Optional] PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine, [Optional] PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine, [Optional] PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine, [Optional] PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress); - /// - /// An application-defined callback function used with the StackWalk64 function. It provides address translation for 16-bit addresses. - /// The PTRANSLATE_ADDRESS_ROUTINE64 type defines a pointer to this callback function. TranslateAddressProc64 is a placeholder for the application-defined function name. - /// - /// A handle to the process for which the stack trace is generated. - /// A handle to the thread for which the stack trace is generated. - /// An address to be translated. - /// The function returns the translated address. - /// - /// This callback function supersedes the PTRANSLATE_ADDRESS_ROUTINE callback function. PTRANSLATE_ADDRESS_ROUTINE is defined as follows in Dbghelp.h. - /// #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64) #define PTRANSLATE_ADDRESS_ROUTINE PTRANSLATE_ADDRESS_ROUTINE64 #else typedef DWORD (__stdcall *PTRANSLATE_ADDRESS_ROUTINE)( __in HANDLE hProcess, __in HANDLE hThread, __out LPADDRESS lpaddr ); #endif - /// - // https://docs.microsoft.com/vi-vn/windows/win32/api/dbghelp/nc-dbghelp-ptranslate_address_routine64 - // PTRANSLATE_ADDRESS_ROUTINE64 PtranslateAddressRoutine64; DWORD64 PtranslateAddressRoutine64( HANDLE hProcess, HANDLE hThread, LPADDRESS64 lpaddr ) {...} - [UnmanagedFunctionPointer(CallingConvention.Winapi)] - [PInvokeData("dbghelp.h", MSDNShortId = "NC:dbghelp.PTRANSLATE_ADDRESS_ROUTINE64")] - public delegate ulong PTRANSLATE_ADDRESS_ROUTINE64(HPROCESS hProcess, HTHREAD hThread, in ADDRESS64 lpaddr); - - /// Obtains a stack trace. /// - /// The architecture type of the computer for which the stack trace is generated. This parameter can be one of the following values. + /// + /// The architecture type of the computer for which the stack trace is generated. This parameter can be one of the following values. + /// /// /// /// Value @@ -1841,25 +2394,61 @@ namespace Vanara.PInvoke /// /// /// - /// A handle to the process for which the stack trace is generated. If the caller supplies a valid callback pointer for the ReadMemoryRoutine parameter, then this value does not have to be a valid process handle. It can be a token that is unique and consistently the same for all calls to the StackWalkEx function. If the symbol handler is used with StackWalkEx, use the same process handles for the calls to each function. - /// A handle to the thread for which the stack trace is generated. If the caller supplies a valid callback pointer for the ReadMemoryRoutine parameter, then this value does not have to be a valid thread handle. It can be a token that is unique and consistently the same for all calls to the StackWalkEx function. - /// A pointer to a STACKFRAME_EX structure. This structure receives information for the next frame, if the function call succeeds. + /// + /// A handle to the process for which the stack trace is generated. If the caller supplies a valid callback pointer for the + /// ReadMemoryRoutine parameter, then this value does not have to be a valid process handle. It can be a token that is unique and + /// consistently the same for all calls to the StackWalkEx function. If the symbol handler is used with StackWalkEx, + /// use the same process handles for the calls to each function. + /// + /// + /// A handle to the thread for which the stack trace is generated. If the caller supplies a valid callback pointer for the + /// ReadMemoryRoutine parameter, then this value does not have to be a valid thread handle. It can be a token that is unique and + /// consistently the same for all calls to the StackWalkEx function. + /// + /// + /// A pointer to a STACKFRAME_EX structure. This structure receives information for the next frame, if the function call succeeds. + /// /// - /// A pointer to a CONTEXT structure. This parameter is required only when the MachineType parameter is not IMAGE_FILE_MACHINE_I386. However, it is recommended that this parameter contain a valid context record. This allows StackWalkEx to handle a greater variety of situations. + /// + /// A pointer to a CONTEXT structure. This parameter is required only when the MachineType parameter is not + /// IMAGE_FILE_MACHINE_I386. However, it is recommended that this parameter contain a valid context record. This allows + /// StackWalkEx to handle a greater variety of situations. + /// /// This context may be modified, so do not pass a context record that should not be modified. /// /// - /// A callback routine that provides memory read services. When the StackWalkEx function needs to read memory from the process's address space, the ReadProcessMemoryProc64 callback is used. - /// If this parameter is NULL, then the function uses a default routine. In this case, the hProcess parameter must be a valid process handle. - /// If this parameter is not NULL, the application should implement and register a symbol handler callback function that handles CBA_READ_MEMORY. + /// + /// A callback routine that provides memory read services. When the StackWalkEx function needs to read memory from the + /// process's address space, the ReadProcessMemoryProc64 callback is used. + /// + /// + /// If this parameter is NULL, then the function uses a default routine. In this case, the hProcess parameter must be a valid + /// process handle. + /// + /// + /// If this parameter is not NULL, the application should implement and register a symbol handler callback function that + /// handles CBA_READ_MEMORY. + /// /// /// - /// A callback routine that provides access to the run-time function table for the process. This parameter is required because the StackWalkEx function does not have access to the process's run-time function table. For more information, see FunctionTableAccessProc64. - /// The symbol handler provides functions that load and access the run-time table. If these functions are used, then SymFunctionTableAccess64 can be passed as a valid parameter. + /// + /// A callback routine that provides access to the run-time function table for the process. This parameter is required because the + /// StackWalkEx function does not have access to the process's run-time function table. For more information, see FunctionTableAccessProc64. + /// + /// + /// The symbol handler provides functions that load and access the run-time table. If these functions are used, then + /// SymFunctionTableAccess64 can be passed as a valid parameter. + /// /// /// - /// A callback routine that provides a module base for any given virtual address. This parameter is required. For more information, see GetModuleBaseProc64. - /// The symbol handler provides functions that load and maintain module information. If these functions are used, then SymGetModuleBase64 can be passed as a valid parameter. + /// + /// A callback routine that provides a module base for any given virtual address. This parameter is required. For more information, + /// see GetModuleBaseProc64. + /// + /// + /// The symbol handler provides functions that load and maintain module information. If these functions are used, then + /// SymGetModuleBase64 can be passed as a valid parameter. + /// /// /// /// A callback routine that provides address translation for 16-bit addresses. For more information, see TranslateAddressProc64. @@ -1872,15 +2461,31 @@ namespace Vanara.PInvoke /// /// /// If the function succeeds, the return value is TRUE. - /// If the function fails, the return value is FALSE. Note that StackWalkEx generally does not set the last error code. + /// + /// If the function fails, the return value is FALSE. Note that StackWalkEx generally does not set the last error code. + /// /// /// - /// The StackWalkEx function provides a portable method for obtaining a stack trace. Using the StackWalkEx function is recommended over writing your own function because of all the complexities associated with stack walking on platforms. In addition, there are compiler options that cause the stack to appear differently, depending on how the module is compiled. By using this function, your application has a portable stack trace that continues to work as the compiler and operating system change. - /// The first call to this function will fail if the AddrPC, AddrFrame, and AddrStack members of the STACKFRAME64 structure passed in the StackFrame parameter are not initialized. - /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more than one thread to this function. + /// + /// The StackWalkEx function provides a portable method for obtaining a stack trace. Using the StackWalkEx function is + /// recommended over writing your own function because of all the complexities associated with stack walking on platforms. In + /// addition, there are compiler options that cause the stack to appear differently, depending on how the module is compiled. By + /// using this function, your application has a portable stack trace that continues to work as the compiler and operating system change. + /// + /// + /// The first call to this function will fail if the AddrPC, AddrFrame, and AddrStack members of the + /// STACKFRAME64 structure passed in the StackFrame parameter are not initialized. + /// + /// + /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will + /// likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more + /// than one thread to this function. + /// /// - // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-stackwalkex - // BOOL IMAGEAPI StackWalkEx( DWORD MachineType, HANDLE hProcess, HANDLE hThread, LPSTACKFRAME_EX StackFrame, PVOID ContextRecord, PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine, PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine, PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine, PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress, DWORD Flags ); + // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-stackwalkex BOOL IMAGEAPI StackWalkEx( DWORD MachineType, + // HANDLE hProcess, HANDLE hThread, LPSTACKFRAME_EX StackFrame, PVOID ContextRecord, PREAD_PROCESS_MEMORY_ROUTINE64 + // ReadMemoryRoutine, PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine, PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine, + // PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress, DWORD Flags ); [DllImport(Lib_DbgHelp, SetLastError = false, ExactSpelling = true)] [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.StackWalkEx")] [return: MarshalAs(UnmanagedType.Bool)] @@ -1888,25 +2493,12 @@ namespace Vanara.PInvoke [Optional] PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine, [Optional] PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine, [Optional] PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine, [Optional] PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress, SYM_STKWALK Flags); - /// - /// Flags for . - /// - [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.StackWalkEx")] - [Flags] - public enum SYM_STKWALK - { - /// - SYM_STKWALK_DEFAULT = 0x00000000, - /// - SYM_STKWALK_FORCE_FRAMEPTR = 0x00000001 - } - /// Indicates whether the specified address is within an inline frame. /// A handle to a process. This handle must have been previously passed to the SymInitialize function. /// The address. /// Returns zero if the address is not within an inline frame. - // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-symaddrincludeinlinetrace - // DWORD IMAGEAPI SymAddrIncludeInlineTrace( HANDLE hProcess, DWORD64 Address ); + // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-symaddrincludeinlinetrace DWORD IMAGEAPI + // SymAddrIncludeInlineTrace( HANDLE hProcess, DWORD64 Address ); [DllImport(Lib_DbgHelp, SetLastError = false, ExactSpelling = true)] [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.SymAddrIncludeInlineTrace")] public static extern uint SymAddrIncludeInlineTrace(HPROCESS hProcess, ulong Address); @@ -1914,7 +2506,10 @@ namespace Vanara.PInvoke /// Adds the stream to the specified module for use by the Source Server. /// A handle to a process. This handle must have been previously passed to the SymInitialize function. /// The base address of the module. - /// A null-terminated string that contains the absolute or relative path to a file that contains the source indexing stream. Can be NULL if Buffer is not NULL. + /// + /// A null-terminated string that contains the absolute or relative path to a file that contains the source indexing stream. Can be + /// NULL if Buffer is not NULL. + /// /// A buffer that contains the source indexing stream. Can be NULL if StreamFile is not NULL. /// Size, in bytes, of the Buffer buffer. /// @@ -1922,11 +2517,19 @@ namespace Vanara.PInvoke /// If the function fails, the return value is FALSE. To retrieve extended error information, call GetLastError. /// /// - /// SymAddSourceStream adds a stream of data formatted for use by the source Server to a designated module. The caller can pass the stream either as a buffer in the Buffer parameter or a file in the StreamFile parameter. If both parameters are filled, then the function uses the Buffer parameter. If both parameters are NULL, then the function returns FALSE and the last-error code is set to ERROR_INVALID_PARAMETER. - /// It is important to note that SymAddSourceStream does not add the stream to any corresponding PDB in order to persist the data. This function is used by those programmatically implementing their own debuggers in scenarios in which a PDB is not available. + /// + /// SymAddSourceStream adds a stream of data formatted for use by the source Server to a designated module. The caller can + /// pass the stream either as a buffer in the Buffer parameter or a file in the StreamFile parameter. If both parameters are filled, + /// then the function uses the Buffer parameter. If both parameters are NULL, then the function returns FALSE and the + /// last-error code is set to ERROR_INVALID_PARAMETER. + /// + /// + /// It is important to note that SymAddSourceStream does not add the stream to any corresponding PDB in order to persist the + /// data. This function is used by those programmatically implementing their own debuggers in scenarios in which a PDB is not available. + /// /// - // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-symaddsourcestream - // BOOL IMAGEAPI SymAddSourceStream( HANDLE hProcess, ULONG64 Base, PCSTR StreamFile, PBYTE Buffer, size_t Size ); + // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-symaddsourcestream BOOL IMAGEAPI SymAddSourceStream( HANDLE + // hProcess, ULONG64 Base, PCSTR StreamFile, PBYTE Buffer, size_t Size ); [DllImport(Lib_DbgHelp, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.SymAddSourceStream")] [return: MarshalAs(UnmanagedType.Bool)] @@ -1944,11 +2547,15 @@ namespace Vanara.PInvoke /// If the function fails, the return value is FALSE. To retrieve extended error information, call GetLastError. /// /// - /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more than one thread to this function. + /// + /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will + /// likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more + /// than one thread to this function. + /// /// To call the Unicode version of this function, define DBGHELP_TRANSLATE_TCHAR. /// - // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-symaddsymbol - // BOOL IMAGEAPI SymAddSymbol( HANDLE hProcess, ULONG64 BaseOfDll, PCSTR Name, DWORD64 Address, DWORD Size, DWORD Flags ); + // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-symaddsymbol BOOL IMAGEAPI SymAddSymbol( HANDLE hProcess, + // ULONG64 BaseOfDll, PCSTR Name, DWORD64 Address, DWORD Size, DWORD Flags ); [DllImport(Lib_DbgHelp, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.SymAddSymbol")] [return: MarshalAs(UnmanagedType.Bool)] @@ -1961,13 +2568,19 @@ namespace Vanara.PInvoke /// If the function fails, the return value is FALSE. To retrieve extended error information, call GetLastError. /// /// - /// This function frees all resources associated with the process handle. Failure to call this function causes memory and resource leaks in the calling application - /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will likely result in unexpected behavior or memory corruption. To avoid this, call SymInitialize only when your process starts and SymCleanup only when your process ends. It is not necessary for each thread in the process to call these functions. + /// + /// This function frees all resources associated with the process handle. Failure to call this function causes memory and resource + /// leaks in the calling application + /// + /// + /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will + /// likely result in unexpected behavior or memory corruption. To avoid this, call SymInitialize only when your process starts and + /// SymCleanup only when your process ends. It is not necessary for each thread in the process to call these functions. + /// /// Examples /// For an example, see Terminating the Symbol Handler. /// - // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-symcleanup - // BOOL IMAGEAPI SymCleanup( HANDLE hProcess ); + // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-symcleanup BOOL IMAGEAPI SymCleanup( HANDLE hProcess ); [DllImport(Lib_DbgHelp, SetLastError = true, ExactSpelling = true)] [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.SymCleanup")] [return: MarshalAs(UnmanagedType.Bool)] @@ -2013,32 +2626,12 @@ namespace Vanara.PInvoke /// /// /// - // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-symcompareinlinetrace - // DWORD IMAGEAPI SymCompareInlineTrace( HANDLE hProcess, DWORD64 Address1, DWORD InlineContext1, DWORD64 RetAddress1, DWORD64 Address2, DWORD64 RetAddress2 ); + // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-symcompareinlinetrace DWORD IMAGEAPI SymCompareInlineTrace( + // HANDLE hProcess, DWORD64 Address1, DWORD InlineContext1, DWORD64 RetAddress1, DWORD64 Address2, DWORD64 RetAddress2 ); [DllImport(Lib_DbgHelp, SetLastError = false, ExactSpelling = true)] [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.SymCompareInlineTrace")] public static extern SYM_INLINE_COMP SymCompareInlineTrace(HPROCESS hProcess, ulong Address1, uint InlineContext1, ulong RetAddress1, ulong Address2, ulong RetAddress2); - /// - /// Indicates the result of the comparison. - /// - [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.SymCompareInlineTrace")] - public enum SYM_INLINE_COMP - { - /// An error occurred. - SYM_INLINE_COMP_ERROR = 0, - /// The inline contexts are identical. - SYM_INLINE_COMP_IDENTICAL = 1, - /// The inline trace is a step-in of an inline function. - SYM_INLINE_COMP_STEPIN = 2, - /// The inline trace is a step-out of an inline function. - SYM_INLINE_COMP_STEPOUT = 3, - /// The inline trace is a step-over of an inline function. - SYM_INLINE_COMP_STEPOVER = 4, - /// The inline contexts are different. - SYM_INLINE_COMP_DIFFERENT = 5, - } - /// Deletes a virtual symbol from the specified module. /// A handle to a process. This handle must have been previously passed to the SymInitialize function. /// The base address of the module. @@ -2050,229 +2643,296 @@ namespace Vanara.PInvoke /// If the function fails, the return value is FALSE. To retrieve extended error information, call GetLastError. /// /// - /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more than one thread to this function. + /// + /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will + /// likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more + /// than one thread to this function. + /// /// To call the Unicode version of this function, define DBGHELP_TRANSLATE_TCHAR. /// - // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-symdeletesymbol - // BOOL IMAGEAPI SymDeleteSymbol( HANDLE hProcess, ULONG64 BaseOfDll, PCSTR Name, DWORD64 Address, DWORD Flags ); - [DllImport(Lib.Dbghelp, SetLastError = true, CharSet = CharSet.Auto)] + // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-symdeletesymbol BOOL IMAGEAPI SymDeleteSymbol( HANDLE + // hProcess, ULONG64 BaseOfDll, PCSTR Name, DWORD64 Address, DWORD Flags ); + [DllImport(Lib_DbgHelp, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.SymDeleteSymbol")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SymDeleteSymbol(HPROCESS hProcess, ulong BaseOfDll, [MarshalAs(UnmanagedType.LPTStr)] string Name, ulong Address, uint Flags = 0); /// Enumerates all modules that have been loaded for the process by the SymLoadModule64 or SymLoadModuleEx function. /// A handle to the process that was originally passed to the SymInitialize function. - /// The enumeration callback function. This function is called once per module. For more information, see SymEnumerateModulesProc64. - /// A user-defined value or NULL. This value is simply passed to the callback function. Normally, this parameter is used by an application to pass a pointer to a data structure that lets the callback function establish some type of context. + /// + /// The enumeration callback function. This function is called once per module. For more information, see SymEnumerateModulesProc64. + /// + /// + /// A user-defined value or NULL. This value is simply passed to the callback function. Normally, this parameter is used by + /// an application to pass a pointer to a data structure that lets the callback function establish some type of context. + /// /// /// If the function succeeds, the return value is TRUE. /// If the function fails, the return value is FALSE. To retrieve extended error information, call GetLastError. /// /// - /// The SymEnumerateModules64 function enumerates all modules that have been loaded for the process by SymLoadModule64, even if the symbol loading is deferred. The enumeration callback function is called once for each module and is passed the module information. - /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more than one thread to this function. - /// To call the Unicode version of this function, define DBGHELP_TRANSLATE_TCHAR. SymEnumerateModulesW64 is defined as follows in Dbghelp.h. - /// BOOL IMAGEAPI SymEnumerateModulesW64( __in HANDLE hProcess, __in PSYM_ENUMMODULES_CALLBACKW64 EnumModulesCallback, __in_opt PVOID UserContext ); #ifdef DBGHELP_TRANSLATE_TCHAR #define SymEnumerateModules64 SymEnumerateModulesW64 #endif - /// This function supersedes the SymEnumerateModules function. For more information, see Updated Platform Support. SymEnumerateModules is defined as follows in Dbghelp.h. - /// #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64) #define SymEnumerateModules SymEnumerateModules64 #else BOOL IMAGEAPI SymEnumerateModules( __in HANDLE hProcess, __in PSYM_ENUMMODULES_CALLBACK EnumModulesCallback, __in_opt PVOID UserContext ); #endif + /// + /// The SymEnumerateModules64 function enumerates all modules that have been loaded for the process by SymLoadModule64, even + /// if the symbol loading is deferred. The enumeration callback function is called once for each module and is passed the module information. + /// + /// + /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will + /// likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more + /// than one thread to this function. + /// + /// + /// To call the Unicode version of this function, define DBGHELP_TRANSLATE_TCHAR. SymEnumerateModulesW64 is defined as + /// follows in Dbghelp.h. + /// + /// + /// BOOL IMAGEAPI SymEnumerateModulesW64( __in HANDLE hProcess, __in PSYM_ENUMMODULES_CALLBACKW64 EnumModulesCallback, __in_opt PVOID UserContext ); #ifdef DBGHELP_TRANSLATE_TCHAR #define SymEnumerateModules64 SymEnumerateModulesW64 #endif + /// + /// + /// This function supersedes the SymEnumerateModules function. For more information, see Updated Platform Support. + /// SymEnumerateModules is defined as follows in Dbghelp.h. + /// + /// + /// #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64) #define SymEnumerateModules SymEnumerateModules64 #else BOOL IMAGEAPI SymEnumerateModules( __in HANDLE hProcess, __in PSYM_ENUMMODULES_CALLBACK EnumModulesCallback, __in_opt PVOID UserContext ); #endif + /// /// Examples /// For an example, see Enumerating Symbol Modules. /// - // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-symenumeratemodules - // BOOL IMAGEAPI SymEnumerateModules( HANDLE hProcess, PSYM_ENUMMODULES_CALLBACK EnumModulesCallback, PVOID UserContext ); - [DllImport(Lib.Dbghelp, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Ansi)] + // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-symenumeratemodules BOOL IMAGEAPI SymEnumerateModules( + // HANDLE hProcess, PSYM_ENUMMODULES_CALLBACK EnumModulesCallback, PVOID UserContext ); + [DllImport(Lib_DbgHelp, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Ansi)] [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.SymEnumerateModules")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SymEnumerateModules(HPROCESS hProcess, PSYM_ENUMMODULES_CALLBACK EnumModulesCallback, [In, Optional] IntPtr UserContext); /// Enumerates all modules that have been loaded for the process by the SymLoadModule64 or SymLoadModuleEx function. /// A handle to the process that was originally passed to the SymInitialize function. - /// The enumeration callback function. This function is called once per module. For more information, see SymEnumerateModulesProc64. - /// A user-defined value or NULL. This value is simply passed to the callback function. Normally, this parameter is used by an application to pass a pointer to a data structure that lets the callback function establish some type of context. + /// + /// The enumeration callback function. This function is called once per module. For more information, see SymEnumerateModulesProc64. + /// + /// + /// A user-defined value or NULL. This value is simply passed to the callback function. Normally, this parameter is used by + /// an application to pass a pointer to a data structure that lets the callback function establish some type of context. + /// /// /// If the function succeeds, the return value is TRUE. /// If the function fails, the return value is FALSE. To retrieve extended error information, call GetLastError. /// /// - /// The SymEnumerateModules64 function enumerates all modules that have been loaded for the process by SymLoadModule64, even if the symbol loading is deferred. The enumeration callback function is called once for each module and is passed the module information. - /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more than one thread to this function. - /// To call the Unicode version of this function, define DBGHELP_TRANSLATE_TCHAR. SymEnumerateModulesW64 is defined as follows in Dbghelp.h. - /// BOOL IMAGEAPI SymEnumerateModulesW64( __in HANDLE hProcess, __in PSYM_ENUMMODULES_CALLBACKW64 EnumModulesCallback, __in_opt PVOID UserContext ); #ifdef DBGHELP_TRANSLATE_TCHAR #define SymEnumerateModules64 SymEnumerateModulesW64 #endif - /// This function supersedes the SymEnumerateModules function. For more information, see Updated Platform Support. SymEnumerateModules is defined as follows in Dbghelp.h. - /// #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64) #define SymEnumerateModules SymEnumerateModules64 #else BOOL IMAGEAPI SymEnumerateModules( __in HANDLE hProcess, __in PSYM_ENUMMODULES_CALLBACK EnumModulesCallback, __in_opt PVOID UserContext ); #endif + /// + /// The SymEnumerateModules64 function enumerates all modules that have been loaded for the process by SymLoadModule64, even + /// if the symbol loading is deferred. The enumeration callback function is called once for each module and is passed the module information. + /// + /// + /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will + /// likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more + /// than one thread to this function. + /// + /// + /// To call the Unicode version of this function, define DBGHELP_TRANSLATE_TCHAR. SymEnumerateModulesW64 is defined as + /// follows in Dbghelp.h. + /// + /// + /// BOOL IMAGEAPI SymEnumerateModulesW64( __in HANDLE hProcess, __in PSYM_ENUMMODULES_CALLBACKW64 EnumModulesCallback, __in_opt PVOID UserContext ); #ifdef DBGHELP_TRANSLATE_TCHAR #define SymEnumerateModules64 SymEnumerateModulesW64 #endif + /// + /// + /// This function supersedes the SymEnumerateModules function. For more information, see Updated Platform Support. + /// SymEnumerateModules is defined as follows in Dbghelp.h. + /// + /// + /// #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64) #define SymEnumerateModules SymEnumerateModules64 #else BOOL IMAGEAPI SymEnumerateModules( __in HANDLE hProcess, __in PSYM_ENUMMODULES_CALLBACK EnumModulesCallback, __in_opt PVOID UserContext ); #endif + /// /// Examples /// For an example, see Enumerating Symbol Modules. /// - // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-symenumeratemodules64 - // BOOL IMAGEAPI SymEnumerateModules64( HANDLE hProcess, PSYM_ENUMMODULES_CALLBACK64 EnumModulesCallback, PVOID UserContext ); - [DllImport(Lib.Dbghelp, SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true)] + // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-symenumeratemodules64 BOOL IMAGEAPI SymEnumerateModules64( + // HANDLE hProcess, PSYM_ENUMMODULES_CALLBACK64 EnumModulesCallback, PVOID UserContext ); + [DllImport(Lib_DbgHelp, SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true)] [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.SymEnumerateModules64")] - [return: MarshalAs(UnmanagedType.Bool)] + [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SymEnumerateModules64(HANDLE hProcess, PSYM_ENUMMODULES_CALLBACK64 EnumModulesCallback, [In, Optional] IntPtr UserContext); /// Enumerates all modules that have been loaded for the process by the SymLoadModule64 or SymLoadModuleEx function. /// A handle to the process that was originally passed to the SymInitialize function. - /// The enumeration callback function. This function is called once per module. For more information, see SymEnumerateModulesProc64. - /// A user-defined value or NULL. This value is simply passed to the callback function. Normally, this parameter is used by an application to pass a pointer to a data structure that lets the callback function establish some type of context. + /// + /// The enumeration callback function. This function is called once per module. For more information, see SymEnumerateModulesProc64. + /// + /// + /// A user-defined value or NULL. This value is simply passed to the callback function. Normally, this parameter is used by + /// an application to pass a pointer to a data structure that lets the callback function establish some type of context. + /// /// /// If the function succeeds, the return value is TRUE. /// If the function fails, the return value is FALSE. To retrieve extended error information, call GetLastError. /// /// - /// The SymEnumerateModules64 function enumerates all modules that have been loaded for the process by SymLoadModule64, even if the symbol loading is deferred. The enumeration callback function is called once for each module and is passed the module information. - /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more than one thread to this function. - /// To call the Unicode version of this function, define DBGHELP_TRANSLATE_TCHAR. SymEnumerateModulesW64 is defined as follows in Dbghelp.h. - /// BOOL IMAGEAPI SymEnumerateModulesW64( __in HANDLE hProcess, __in PSYM_ENUMMODULES_CALLBACKW64 EnumModulesCallback, __in_opt PVOID UserContext ); #ifdef DBGHELP_TRANSLATE_TCHAR #define SymEnumerateModules64 SymEnumerateModulesW64 #endif - /// This function supersedes the SymEnumerateModules function. For more information, see Updated Platform Support. SymEnumerateModules is defined as follows in Dbghelp.h. - /// #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64) #define SymEnumerateModules SymEnumerateModules64 #else BOOL IMAGEAPI SymEnumerateModules( __in HANDLE hProcess, __in PSYM_ENUMMODULES_CALLBACK EnumModulesCallback, __in_opt PVOID UserContext ); #endif + /// + /// The SymEnumerateModules64 function enumerates all modules that have been loaded for the process by SymLoadModule64, even + /// if the symbol loading is deferred. The enumeration callback function is called once for each module and is passed the module information. + /// + /// + /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will + /// likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more + /// than one thread to this function. + /// + /// + /// To call the Unicode version of this function, define DBGHELP_TRANSLATE_TCHAR. SymEnumerateModulesW64 is defined as + /// follows in Dbghelp.h. + /// + /// + /// BOOL IMAGEAPI SymEnumerateModulesW64( __in HANDLE hProcess, __in PSYM_ENUMMODULES_CALLBACKW64 EnumModulesCallback, __in_opt PVOID UserContext ); #ifdef DBGHELP_TRANSLATE_TCHAR #define SymEnumerateModules64 SymEnumerateModulesW64 #endif + /// + /// + /// This function supersedes the SymEnumerateModules function. For more information, see Updated Platform Support. + /// SymEnumerateModules is defined as follows in Dbghelp.h. + /// + /// + /// #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64) #define SymEnumerateModules SymEnumerateModules64 #else BOOL IMAGEAPI SymEnumerateModules( __in HANDLE hProcess, __in PSYM_ENUMMODULES_CALLBACK EnumModulesCallback, __in_opt PVOID UserContext ); #endif + /// /// Examples /// For an example, see Enumerating Symbol Modules. /// - // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-symenumeratemodulesw64 - // BOOL IMAGEAPI SymEnumerateModulesW64( HANDLE hProcess, PSYM_ENUMMODULES_CALLBACKW64 EnumModulesCallback, PVOID UserContext ); - [DllImport(Lib.Dbghelp, SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true)] + // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-symenumeratemodulesw64 BOOL IMAGEAPI + // SymEnumerateModulesW64( HANDLE hProcess, PSYM_ENUMMODULES_CALLBACKW64 EnumModulesCallback, PVOID UserContext ); + [DllImport(Lib_DbgHelp, SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true)] [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.SymEnumerateModulesW64")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SymEnumerateModulesW64(HANDLE hProcess, PSYM_ENUMMODULES_CALLBACK64 EnumModulesCallback, [In, Optional] IntPtr UserContext); - /// - /// An application-defined callback function used with the SymEnumerateModules64 function. It is called once for each enumerated module, and receives the module information. - /// The PSYM_ENUMMODULES_CALLBACK64 and PSYM_ENUMMODULES_CALLBACKW64 types define a pointer to this callback function. SymEnumerateModulesProc64 is a placeholder for the application-defined function name. - /// - /// The name of the module. - /// The base address where the module is loaded into memory. - /// The user-defined value specified in SymEnumerateModules64, or NULL. Typically, this parameter is used by an application to pass a pointer to a data structure that lets the callback function establish some type of context. + /// Undecorates the specified decorated C++ symbol name. + /// + /// The decorated C++ symbol name. This name can be identified by the first character of the name, which is always a question mark (?). + /// + /// A pointer to a string buffer that receives the undecorated name. + /// The size of the UnDecoratedName buffer, in characters. + /// + /// The options for how the decorated name is undecorated. This parameter can be zero or more of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// UNDNAME_32_BIT_DECODE 0x0800 + /// Undecorate 32-bit decorated names. + /// + /// + /// UNDNAME_COMPLETE 0x0000 + /// Enable full undecoration. + /// + /// + /// UNDNAME_NAME_ONLY 0x1000 + /// Undecorate only the name for primary declaration. Returns [scope::]name. Does expand template parameters. + /// + /// + /// UNDNAME_NO_ACCESS_SPECIFIERS 0x0080 + /// Disable expansion of access specifiers for members. + /// + /// + /// UNDNAME_NO_ALLOCATION_LANGUAGE 0x0010 + /// Disable expansion of the declaration language specifier. + /// + /// + /// UNDNAME_NO_ALLOCATION_MODEL 0x0008 + /// Disable expansion of the declaration model. + /// + /// + /// UNDNAME_NO_ARGUMENTS 0x2000 + /// Do not undecorate function arguments. + /// + /// + /// UNDNAME_NO_CV_THISTYPE 0x0040 + /// Disable expansion of CodeView modifiers on the this type for primary declaration. + /// + /// + /// UNDNAME_NO_FUNCTION_RETURNS 0x0004 + /// Disable expansion of return types for primary declarations. + /// + /// + /// UNDNAME_NO_LEADING_UNDERSCORES 0x0001 + /// Remove leading underscores from Microsoft keywords. + /// + /// + /// UNDNAME_NO_MEMBER_TYPE 0x0200 + /// Disable expansion of the static or virtual attribute of members. + /// + /// + /// UNDNAME_NO_MS_KEYWORDS 0x0002 + /// Disable expansion of Microsoft keywords. + /// + /// + /// UNDNAME_NO_MS_THISTYPE 0x0020 + /// Disable expansion of Microsoft keywords on the this type for primary declaration. + /// + /// + /// UNDNAME_NO_RETURN_UDT_MODEL 0x0400 + /// Disable expansion of the Microsoft model for user-defined type returns. + /// + /// + /// UNDNAME_NO_SPECIAL_SYMS 0x4000 + /// Do not undecorate special names, such as vtable, vcall, vector, metatype, and so on. + /// + /// + /// UNDNAME_NO_THISTYPE 0x0060 + /// Disable all modifiers on the this type. + /// + /// + /// UNDNAME_NO_THROW_SIGNATURES 0x0100 + /// Disable expansion of throw-signatures for functions and pointers to functions. + /// + /// + /// /// - /// If the return value is TRUE, the enumeration will continue. - /// If the return value is FALSE, the enumeration will stop. + /// + /// If the function succeeds, the return value is the number of characters in the UnDecoratedName buffer, not including the NULL terminator. + /// + /// If the function fails, the return value is zero. To retrieve extended error information, call GetLastError. + /// If the function fails and returns zero, the content of the UnDecoratedName buffer is undetermined. /// /// - /// The calling application is called once per module until all modules are enumerated, or until the enumeration callback function returns FALSE. - /// This callback function supersedes the PSYM_ENUMMODULES_CALLBACK callback function. PSYM_ENUMMODULES_CALLBACK is defined as follows in DbgHelp.h. - /// #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64) #define PSYM_ENUMMODULES_CALLBACK PSYM_ENUMMODULES_CALLBACK64 #else typedef BOOL (CALLBACK *PSYM_ENUMMODULES_CALLBACK)( __in PCSTR ModuleName, __in ULONG BaseOfDll, __in_opt PVOID UserContext ); #endif + /// To use undecorated symbols, call the SymSetOptions function with the SYMOPT_UNDNAME option. + /// + /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will + /// likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more + /// than one thread to this function. + /// + /// To call the Unicode version of this function, define DBGHELP_TRANSLATE_TCHAR. + /// Examples + /// For an example, see Retrieving Undecorated Symbol Names. /// - // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nc-dbghelp-psym_enummodules_callback - // PSYM_ENUMMODULES_CALLBACK PsymEnummodulesCallback; BOOL PsymEnummodulesCallback( PCSTR ModuleName, ULONG BaseOfDll, PVOID UserContext ) {...} - [UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet = CharSet.Ansi)] - [PInvokeData("dbghelp.h", MSDNShortId = "NC:dbghelp.PSYM_ENUMMODULES_CALLBACK")] - [return: MarshalAs(UnmanagedType.Bool)] - public delegate bool PSYM_ENUMMODULES_CALLBACK([MarshalAs(UnmanagedType.LPStr)] string ModuleName, uint BaseOfDll, [In, Optional] IntPtr UserContext); + // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-undecoratesymbolname DWORD IMAGEAPI UnDecorateSymbolName( + // PCSTR name, PSTR outputString, DWORD maxStringLength, DWORD flags ); + [DllImport(Lib_DbgHelp, SetLastError = true, CharSet = CharSet.Auto)] + [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.UnDecorateSymbolName")] + public static extern uint UnDecorateSymbolName([MarshalAs(UnmanagedType.LPTStr)] string name, [Out, MarshalAs(UnmanagedType.LPTStr)] StringBuilder outputString, + uint maxStringLength, UNDNAME flags); /// - /// An application-defined callback function used with the SymEnumerateModules64 function. It is called once for each enumerated module, and receives the module information. - /// The PSYM_ENUMMODULES_CALLBACK64 and PSYM_ENUMMODULES_CALLBACKW64 types define a pointer to this callback function. SymEnumerateModulesProc64 is a placeholder for the application-defined function name. + /// Deallocates the memory and resources allocated by a call to the MapDebugInformation function. + /// + /// Note This function is provided only for backward compatibility. New applications should use the SymUnloadModule64 function. + /// /// - /// The name of the module. - /// The base address where the module is loaded into memory. - /// The user-defined value specified in SymEnumerateModules64, or NULL. Typically, this parameter is used by an application to pass a pointer to a data structure that lets the callback function establish some type of context. + /// A pointer to an IMAGE_DEBUG_INFORMATION structure that is returned from a call to MapDebugInformation. /// - /// If the return value is TRUE, the enumeration will continue. - /// If the return value is FALSE, the enumeration will stop. + /// If the function succeeds, the return value is TRUE. + /// If the function fails, the return value is FALSE. To retrieve extended error information, call GetLastError. /// /// - /// The calling application is called once per module until all modules are enumerated, or until the enumeration callback function returns FALSE. - /// This callback function supersedes the PSYM_ENUMMODULES_CALLBACK callback function. PSYM_ENUMMODULES_CALLBACK is defined as follows in DbgHelp.h. - /// #if !defined(_IMAGEHLP_SOURCE_) && defined(_IMAGEHLP64) #define PSYM_ENUMMODULES_CALLBACK PSYM_ENUMMODULES_CALLBACK64 #else typedef BOOL (CALLBACK *PSYM_ENUMMODULES_CALLBACK)( __in PCSTR ModuleName, __in ULONG BaseOfDll, __in_opt PVOID UserContext ); #endif + /// + /// The UnmapDebugInformation function is the counterpart to the MapDebugInformation function and must be used to deallocate + /// the memory and resources allocated by a call to the MapDebugInformation function. + /// + /// + /// All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will + /// likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more + /// than one thread to this function. + /// /// - // https://docs.microsoft.com/id-id/windows/win32/api/dbghelp/nc-dbghelp-psym_enummodules_callback64 - // PSYM_ENUMMODULES_CALLBACK64 PsymEnummodulesCallback64; BOOL PsymEnummodulesCallback64( PCSTR ModuleName, DWORD64 BaseOfDll, PVOID UserContext ) {...} - [UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet = CharSet.Auto)] - [PInvokeData("dbghelp.h", MSDNShortId = "NC:dbghelp.PSYM_ENUMMODULES_CALLBACK64")] + // https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-unmapdebuginformation BOOL IMAGEAPI UnmapDebugInformation( + // PIMAGE_DEBUG_INFORMATION DebugInfo ); + [DllImport(Lib_DbgHelp, SetLastError = true, ExactSpelling = true)] + [PInvokeData("dbghelp.h", MSDNShortId = "NF:dbghelp.UnmapDebugInformation")] [return: MarshalAs(UnmanagedType.Bool)] - public delegate bool PSYM_ENUMMODULES_CALLBACK64([MarshalAs(UnmanagedType.LPTStr)] string ModuleName, ulong BaseOfDll, [In, Optional] IntPtr UserContext); - - /* - SymEnumerateSymbols64 -SymEnumerateSymbolsProc64 -SymEnumLines -SymEnumLinesProc -SymEnumProcesses -SymEnumProcessesProc -SymEnumSourceFiles -SymEnumSourceFilesProc -SymEnumSourceFileTokens -PENUMSOURCEFILETOKENSCALLBACK -SymEnumSourceLines -SymEnumSymbols -SymEnumSymbolsEx -SymEnumSymbolsForAddr -SymEnumSymbolsProc -SymEnumTypes -SymEnumTypesByName -SymFindDebugInfoFile -SymFindExecutableImage -SymFindFileInPath -SymFindFileInPathProc -SymFromAddr -SymFromIndex -SymFromInlineContext -SymFromName -SymFromToken -SymFunctionTableAccess64 -SymFunctionTableAccess64AccessRoutines -SymGetExtendedOption -SymGetFileLineOffsets64 -SymGetHomeDirectory -SymGetLineFromAddr64 -SymGetLineFromInlineContext -SymGetLineFromName64 -SymGetLineNext64 -SymGetLinePrev64 -SymGetModuleBase64 -SymGetModuleInfo64 -SymGetOmaps -SymGetOptions -SymGetScope -SymGetSearchPath -SymGetSourceFile -SymGetSourceFileChecksum -SymGetSourceFileFromToken -SymGetSourceFileToken -SymGetSourceVarFromToken -SymGetSymbolFile -SymGetSymFromAddr64 -SymGetSymFromName64 -SymGetSymNext64 -SymGetSymPrev64 -SymGetTypeFromName -SymGetTypeInfo -SymGetTypeInfoEx -SymInitialize -SymLoadModule64 -SymLoadModuleEx -SymMatchFileName -SymMatchString -SymNext -SymPrev -SymQueryInlineTrace -SymRefreshModuleList -SymRegisterCallback64 -SymRegisterCallbackProc64 -SymRegisterFunctionEntryCallback64 -SymRegisterFunctionEntryCallbackProc64 -SymSearch -SymSetContext -SymSetExtendedOption -SymSetHomeDirectory -SymSetOptions -SymSetParentWindow -SymSetScopeFromAddr -SymSetScopeFromIndex -SymSetScopeFromInlineContext -SymSetSearchPath -SymSrvDeltaName -SymSrvGetFileIndexes -SymSrvGetFileIndexInfo -SymSrvGetFileIndexString -SymSrvGetSupplement -SymSrvIsStore -SymSrvStoreFile -SymSrvStoreSupplement -SymUnDName64 -SymUnloadModule64 -TranslateAddressProc64 -UnDecorateSymbolName -UnmapDebugInformation - */ + public static extern bool UnmapDebugInformation(IntPtr DebugInfo); } } \ No newline at end of file diff --git a/UnitTests/PInvoke/DbgHelp/DbgHelp.csproj b/UnitTests/PInvoke/DbgHelp/DbgHelp.csproj index 67911b3c..6a65746a 100644 --- a/UnitTests/PInvoke/DbgHelp/DbgHelp.csproj +++ b/UnitTests/PInvoke/DbgHelp/DbgHelp.csproj @@ -7,7 +7,7 @@ {F2C94926-224F-43AB-B351-C20C9B2D8656} Library Properties - UnitTest.PInvoke.ImageHlp + UnitTest.PInvoke.DbgHelp v4.7.2 512 @@ -20,7 +20,7 @@ DEBUG;TRACE prompt 4 - x86 + x64 true diff --git a/UnitTests/PInvoke/DbgHelp/DbgHelpTests.cs b/UnitTests/PInvoke/DbgHelp/DbgHelpTests.cs index 95cf6d57..0cf00683 100644 --- a/UnitTests/PInvoke/DbgHelp/DbgHelpTests.cs +++ b/UnitTests/PInvoke/DbgHelp/DbgHelpTests.cs @@ -2,6 +2,7 @@ using NUnit.Framework.Internal; using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Runtime.InteropServices; using Vanara.Extensions; @@ -25,6 +26,39 @@ namespace Vanara.PInvoke.Tests { } + [Test] + public void EnumDirTreeTest() + { + var output = EnumDirTree(HPROCESS.NULL, Environment.GetFolderPath(Environment.SpecialFolder.Windows), imgName); + Assert.That(output, Is.Not.Empty); + TestContext.WriteLine($"Count: {output.Count}"); + output.WriteValues(); + } + + [Test] + public void EnumerateLoadedModulesTest() + { + var output = EnumerateLoadedModules(Process.GetCurrentProcess().Handle); + Assert.That(output, Is.Not.Empty); + TestContext.WriteLine($"Count: {output.Count}"); + output.WriteValues(); + } + + [Test] + public void EnumerateLoadedModulesExTest() + { + var output = EnumerateLoadedModulesEx(Process.GetCurrentProcess().Handle); + Assert.That(output, Is.Not.Empty); + TestContext.WriteLine($"Count: {output.Count}"); + output.WriteValues(); + } + + [Test] + public void FindExecutableImageExTest() + { + Assert.That(FindExecutableImageEx(imgName, new[] { Environment.GetFolderPath(Environment.SpecialFolder.System), TestCaseSources.TempDir }), ResultIs.Not.Value(null)); + } + [Test] public void GetImageConfigInformationTest() {