本文介绍了C#中按地址的符号信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我正在尝试从地址中获取符号信息,但出现错误87(0x57),但我不知道为什么,在这里我也找到了相同的问题,https://social.msdn.microsoft.com/Forums/zh-CN/bd3e1c89-83c7-41c3-9d5d-a41069da2555/retrieving-symbol-information-by-address-in-c?forum=netfxtoolsdev 但是答案对我不起作用,或者至少不清楚.这是我的代码:
静态IntPtr GetThreadStartAddress(int threadId) { var hThread = OpenThread(ThreadAccess.QueryInformation,false,threadId); 如果(hThread == IntPtr.Zero){ 抛出新的Win32Exception(); } var buf = Marshal.AllocHGlobal(IntPtr.Size); 尝试 { var result = NtQueryInformationThread(hThread,ThreadInfoClass.ThreadQuerySetWin32StartAddress,buf,IntPtr.Size,IntPtr.Zero); 如果(结果!= 0) 抛出新的Win32Exception(string.Format("NtQueryInformationThread失败; NTSTATUS = {0:X8}",结果))); IntPtr threadAddress = Marshal.ReadIntPtr(buf); 如果(DbgHelpNative.SymInitialize(IntPtr.Zero,null,false)) { int bufferSize = Marshal.SizeOf(typeof(DbgHelpNative.SYMBOL_INFO))+((2000-2)* 2); var buffer = Marshal.AllocHGlobal(bufferSize); DbgHelpNative.SYMBOL_INFO symbolInfo =新的DbgHelpNative.SYMBOL_INFO(); ulong位移= 0; Marshal.PtrToStructure(buffer,typeof(DbgHelpNative.SYMBOL_INFO)); symbolInfo.SizeOfStruct =(uint)元帅.SizeOf(typeof(DbgHelpNative.SYMBOL_INFO)); symbolInfo.MaxNameLen = 2000; 如果(DbgHelpNative.SymFromAddr(hThread,(ulong)threadAddress,置换,ref symbolInfo)) { MessageBox.Show(成功"); } 别的 { var错误= Marshal.GetLastWin32Error(); MessageBox.Show(error.ToString()); } } 返回threadAddress; } 最后 { CloseHandle(hThread); 元帅FreeHGlobal(buf); }
解决方案
这篇关于C#中按地址的符号信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!