//============================================================================ // getLineForAddress //============================================================================ public void getLineForAddress(uint pAddr, ref string filePath, ref int lineNum) { char[] ByteArray = new char[10000]; DbgHelp._IMAGEHLP_LINE64 lineinfo = new DbgHelp._IMAGEHLP_LINE64(); uint displacement = 0; bool result = true; unsafe { fixed(char *p = ByteArray) { IntPtr MyIntPtr = (IntPtr)p; lineinfo.SizeOfStruct = (uint)DbgHelp._IMAGEHLP_LINE64.getSize(); lineinfo.FileName = MyIntPtr; result = DbgHelp.SymGetLineFromAddr64(hProcess, (UInt64)pAddr, ref displacement, ref lineinfo); } } if (result) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append(ByteArray); filePath = sb.ToString(); lineNum = (int)lineinfo.LineNumber; } else { Int32 errCode = System.Runtime.InteropServices.Marshal.GetLastWin32Error(); filePath = "[unknown]"; lineNum = 0; } }
public bool lookupImmediate(UInt32 address, ref LookupInfo info) { info.mAddress = address; info.mLine = -1; info.mFilename = "?"; info.mSymbol = "?"; info.mFoundLine = false; info.mFoundSymbol = false; /////////////////////////////////////////////////// //lookup filename byte[] fName = new byte[1000]; uint displacement = 0; DbgHelp._IMAGEHLP_LINE64 lineinfo = new DbgHelp._IMAGEHLP_LINE64(); lineinfo.SizeOfStruct = (uint)DbgHelp._IMAGEHLP_LINE64.getSize(); unsafe { fixed(byte *pCst = fName) { //IntPtr ptr = new IntPtr() lineinfo.FileName = new IntPtr(pCst); info.mFoundLine = DbgHelp.SymGetLineFromAddr64(hProcess, (UInt64)address, ref displacement, ref lineinfo); } } if (!info.mFoundLine) { Int32 errCode = System.Runtime.InteropServices.Marshal.GetLastWin32Error(); return(false); } else { info.mLine = (int)lineinfo.LineNumber; info.mFilename = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(lineinfo.FileName); } /////////////////////////////////////////////////// //lookup symbol ulong pdwDisplacment = 0; DbgHelp.SYMBOL_INFO symbInfo = new DbgHelp.SYMBOL_INFO(); symbInfo.SizeOfStruct = (uint)DbgHelp.SYMBOL_INFO.getSize(); symbInfo.MaxNameLen = (int)DbgHelp.SYMBOL_INFO.getmaxCharSize(); info.mFoundSymbol = DbgHelp.SymFromAddr(hProcess, address, ref pdwDisplacment, ref symbInfo); if (!info.mFoundSymbol) { Int32 errCode = System.Runtime.InteropServices.Marshal.GetLastWin32Error(); return(false); } else { info.mSymbol = symbInfo.Name; info.mFoundSymbol = true; } return(true); }