// returns a message from the event static string GetMessageFromDebugEvent(CorProcess corProcess, OUTPUT_DEBUG_STRING_INFO eventOds) { bool isUnicode = eventOds.fUnicode != 0; byte[] buffer = new byte[isUnicode?eventOds.nDebugStringLenght * 2:eventOds.nDebugStringLenght]; int bytesRead = corProcess.ReadMemory(eventOds.lpDebugStringData.ToInt64(), buffer); Debug.Assert(buffer.Length == bytesRead); System.Text.StringBuilder sb = new System.Text.StringBuilder(); for (int i = 0; i < buffer.Length; i++) { int val; if (isUnicode) { val = (int)buffer[i] + ((int)buffer[i + 1] << 8); i++; } else { val = buffer[i]; } sb.Append((char)val); } return(sb.ToString()); }
// returns a message from the event static string GetMessageFromDebugEvent(CorProcess corProcess, OUTPUT_DEBUG_STRING_INFO eventOds) { bool isUnicode = eventOds.fUnicode!=0; byte[] buffer = new byte[isUnicode?eventOds.nDebugStringLenght*2:eventOds.nDebugStringLenght]; int bytesRead = corProcess.ReadMemory(eventOds.lpDebugStringData.ToInt64(),buffer); Debug.Assert(buffer.Length==bytesRead); System.Text.StringBuilder sb = new System.Text.StringBuilder(); for(int i=0;i<buffer.Length;i++) { int val; if(isUnicode) { val =(int)buffer[i]+((int)buffer[i+1]<<8); i++; } else val = buffer[i]; sb.Append((char)val); } return sb.ToString(); }
/// <summary> /// Given a LoadModule debug event (and the process), get the ImageName /// </summary> /// <param name="corProcess"> The CorProcess where this image is loaded.</param> /// <param name="eventLoadDll"> The LOAD_DLL_DEBUG_INFO event.</param> /// <returns> The image name or null if it couldn't be determined from the event</returns> private static string GetImageNameFromDebugEvent(CorProcess corProcess, LOAD_DLL_DEBUG_INFO eventLoadDll) { string moduleName; bool bUnicode = eventLoadDll.fUnicode != 0; if (eventLoadDll.lpImageName == IntPtr.Zero) { return(null); } else { byte[] buffer = new byte[4]; int bytesRead = corProcess.ReadMemory(eventLoadDll.lpImageName.ToInt64(), buffer); Debug.Assert(bytesRead == buffer.Length); IntPtr newptr = new IntPtr((int)buffer[0] + ((int)buffer[1] << 8) + ((int)buffer[2] << 16) + ((int)buffer[3] << 24)); if (newptr == IntPtr.Zero) { return(null); } else { System.Text.StringBuilder sb = new System.Text.StringBuilder(); if (bUnicode) { buffer = new byte[2]; } else { buffer = new byte[1]; } do { bytesRead = corProcess.ReadMemory(newptr.ToInt64(), buffer); Debug.Assert(bytesRead == buffer.Length); if (bytesRead < buffer.Length) { break; } int b; if (bUnicode) { b = (int)buffer[0] + ((int)buffer[1] << 8); } else { b = (int)buffer[0]; } if (b == 0) { break; } sb.Append((char)b); newptr = new IntPtr(newptr.ToInt32() + 2); }while(true); moduleName = sb.ToString(); } } return(moduleName); }
/// <summary> /// Given a LoadModule debug event (and the process), get the ImageName /// </summary> /// <param name="corProcess"> The CorProcess where this image is loaded.</param> /// <param name="eventLoadDll"> The LOAD_DLL_DEBUG_INFO event.</param> /// <returns> The image name or null if it couldn't be determined from the event</returns> private static string GetImageNameFromDebugEvent(CorProcess corProcess, LOAD_DLL_DEBUG_INFO eventLoadDll) { string moduleName; bool bUnicode = eventLoadDll.fUnicode!=0; if(eventLoadDll.lpImageName == IntPtr.Zero) { return null; } else { byte[] buffer = new byte[4]; int bytesRead = corProcess.ReadMemory(eventLoadDll.lpImageName.ToInt64(),buffer); Debug.Assert(bytesRead==buffer.Length); IntPtr newptr=new IntPtr((int)buffer[0]+((int)buffer[1]<<8)+((int)buffer[2]<<16)+((int)buffer[3]<<24)); if(newptr == IntPtr.Zero) { return null; } else { System.Text.StringBuilder sb = new System.Text.StringBuilder(); if(bUnicode) buffer = new byte[2]; else buffer = new byte[1]; do { bytesRead = corProcess.ReadMemory(newptr.ToInt64(),buffer); Debug.Assert(bytesRead==buffer.Length); if(bytesRead<buffer.Length) break; int b; if(bUnicode) b=(int)buffer[0]+((int)buffer[1]<<8); else b=(int)buffer[0]; if(b==0) break; sb.Append((char)b); newptr=new IntPtr(newptr.ToInt32()+2); } while(true); moduleName = sb.ToString(); } } return moduleName; }