/// <summary> /// Callback is called when a new process is created so we can log it and decide to block it. /// </summary> /// <param name="createProc"></param> /// <returns></returns> public static UInt32 ProcessMonitorCallback(ref COMM_CREATE_PROC createProc) { try { string imageFileName = new string(createProc.ImageFileNameBuf, 0, createProc.ImageFileNameLength / 2); string cmdLine = new string(createProc.CommandLineBuf, 0, createProc.CommandLineLength / 2); Log.Info("New process: {0}", imageFileName); Log.Info(" Cmd line: {0}", new string(createProc.CommandLineBuf)); long ExecutableId; Decision decision = Arbiter.DecideOnProcess(imageFileName, out ExecutableId); PROCESS_INFO processInfo = new PROCESS_INFO(createProc); Database.LogProcessEvent(processInfo, ExecutableId, Database.ProcessState.Started); CommunicateProcessDecision(decision, ref createProc, imageFileName); } catch (Exception e) { Log.Exception(e, "Exception in ProcessMonitorCallback"); } return(0); }
/// <summary> /// Gets a description of the process. /// </summary> public int GetInfo(enum_PROCESS_INFO_FIELDS fields, PROCESS_INFO[] pProcessInfo) { DLog.Debug(DContext.VSDebuggerComCall, "IDebugProcess2.GetInfo {0}", fields); var foundFields = (enum_PROCESS_INFO_FIELDS)0; var info = new PROCESS_INFO(); if ((fields & enum_PROCESS_INFO_FIELDS.PIF_FILE_NAME) != 0) { info.bstrFileName = apkPath; foundFields |= enum_PROCESS_INFO_FIELDS.PIF_FILE_NAME; } if ((fields & enum_PROCESS_INFO_FIELDS.PIF_BASE_NAME) != 0) { info.bstrBaseName = Path.GetFileName(apkPath); foundFields |= enum_PROCESS_INFO_FIELDS.PIF_BASE_NAME; } if ((fields & enum_PROCESS_INFO_FIELDS.PIF_TITLE) != 0) { info.bstrTitle = Path.GetFileName(apkPath); foundFields |= enum_PROCESS_INFO_FIELDS.PIF_TITLE; } if ((fields & enum_PROCESS_INFO_FIELDS.PIF_PROCESS_ID) != 0) { var arr = new AD_PROCESS_ID[0]; GetPhysicalProcessId(arr); info.ProcessId = arr[0]; foundFields |= enum_PROCESS_INFO_FIELDS.PIF_PROCESS_ID; } if ((fields & enum_PROCESS_INFO_FIELDS.PIF_SESSION_ID) != 0) { info.dwSessionId = 1; foundFields |= enum_PROCESS_INFO_FIELDS.PIF_SESSION_ID; } if ((fields & enum_PROCESS_INFO_FIELDS.PIF_ATTACHED_SESSION_NAME) != 0) { info.bstrAttachedSessionName = "<deprecated>"; foundFields |= enum_PROCESS_INFO_FIELDS.PIF_ATTACHED_SESSION_NAME; } if ((fields & enum_PROCESS_INFO_FIELDS.PIF_CREATION_TIME) != 0) { var fileTime = DateTime.Now.ToFileTime(); info.CreationTime.dwLowDateTime = (uint)(fileTime & 0xFFFFFFFF); info.CreationTime.dwHighDateTime = (uint)(fileTime >> 32); foundFields |= enum_PROCESS_INFO_FIELDS.PIF_CREATION_TIME; } if ((fields & enum_PROCESS_INFO_FIELDS.PIF_FLAGS) != 0) { pProcessInfo[0].Flags = GetProcessStatus(); foundFields |= enum_PROCESS_INFO_FIELDS.PIF_FLAGS; } pProcessInfo[0].Fields = foundFields; return(VSConstants.S_OK); }
public int GetInfo(enum_PROCESS_INFO_FIELDS Fields, PROCESS_INFO[] pProcessInfo) { // The various string fields should match the strings returned by GetName - keep them in sync when making any changes here. var pi = new PROCESS_INFO(); pi.Fields = Fields; pi.bstrFileName = _exe; pi.bstrBaseName = BaseName; pi.bstrTitle = Title; pi.ProcessId.dwProcessId = (uint)_pid; pProcessInfo[0] = pi; return 0; }
int IDebugProcess2.GetInfo(enum_PROCESS_INFO_FIELDS Fields, PROCESS_INFO[] pProcessInfo) { pProcessInfo[0] = new PROCESS_INFO(); pProcessInfo[0].Fields = Fields; pProcessInfo[0].bstrFileName = "test.lua"; pProcessInfo[0].bstrBaseName = "base"; pProcessInfo[0].bstrTitle = "title"; pProcessInfo[0].dwSessionId = 1; pProcessInfo[0].Flags = enum_PROCESS_INFO_FLAGS.PIFLAG_PROCESS_RUNNING; return(VSConstants.S_OK); }
public int GetInfo(enum_PROCESS_INFO_FIELDS fields, PROCESS_INFO[] pProcessInfo) { Log.Debug("Process: GetInfo"); if ((fields & enum_PROCESS_INFO_FIELDS.PIF_FILE_NAME) != 0) { pProcessInfo[0].bstrFileName = Node.FileName; pProcessInfo[0].Flags = enum_PROCESS_INFO_FLAGS.PIFLAG_DEBUGGER_ATTACHED | enum_PROCESS_INFO_FLAGS.PIFLAG_PROCESS_RUNNING; pProcessInfo[0].Fields = enum_PROCESS_INFO_FIELDS.PIF_FILE_NAME | enum_PROCESS_INFO_FIELDS.PIF_FLAGS; } return VSConstants.S_OK; }
public int GetInfo(enum_PROCESS_INFO_FIELDS Fields, PROCESS_INFO[] pProcessInfo) { // The various string fields should match the strings returned by GetName - keep them in sync when making any changes here. var pi = new PROCESS_INFO(); pi.Fields = Fields; pi.bstrFileName = this._exe; pi.bstrBaseName = this.BaseName; pi.bstrTitle = this.Title; pi.ProcessId.dwProcessId = (uint)this._id; pProcessInfo[0] = pi; return(VSConstants.S_OK); }
public int GetInfo(enum_PROCESS_INFO_FIELDS Fields, PROCESS_INFO[] pProcessInfo) { // The various string fields should match the strings returned by GetName - keep them in sync when making any changes here. var pi = new PROCESS_INFO { Fields = Fields, bstrFileName = Name, bstrBaseName = Name, bstrTitle = "", ProcessId = { dwProcessId = ProcessId } }; pProcessInfo[0] = pi; return(VSConstants.S_OK); }
public List <PROCESS_INFO> GetProcessesList() { List <PROCESS_INFO> lst_ret = new List <PROCESS_INFO>(); foreach (Process proc in Process.GetProcesses()) { PROCESS_INFO pi = new PROCESS_INFO(); pi.m_pid = proc.Id; pi.m_process_name = proc.ProcessName; lst_ret.Add(pi); } return(lst_ret); }
public int GetInfo(enum_PROCESS_INFO_FIELDS Fields, PROCESS_INFO[] pProcessInfo) { // The various string fields should match the strings returned by GetName - keep them in sync when making any changes here. var pi = new PROCESS_INFO { Fields = Fields, bstrFileName = _exe, bstrBaseName = BaseName, bstrTitle = Title }; pi.ProcessId.dwProcessId = (uint)_pid; pProcessInfo[0] = pi; return(0); }
public int GetInfo(enum_PROCESS_INFO_FIELDS fields, PROCESS_INFO[] pProcessInfo) { if ((fields & enum_PROCESS_INFO_FIELDS.PIF_FILE_NAME) != 0) { pProcessInfo[0].bstrFileName = GetFileName(); pProcessInfo[0].Fields |= enum_PROCESS_INFO_FIELDS.PIF_FILE_NAME; } if ((fields & enum_PROCESS_INFO_FIELDS.PIF_BASE_NAME) != 0) { pProcessInfo[0].bstrBaseName = GetBaseName(); pProcessInfo[0].Fields |= enum_PROCESS_INFO_FIELDS.PIF_BASE_NAME; } if ((fields & enum_PROCESS_INFO_FIELDS.PIF_TITLE) != 0) { string title = GetTitle(); if (title != null) { pProcessInfo[0].bstrTitle = title; pProcessInfo[0].Fields |= enum_PROCESS_INFO_FIELDS.PIF_TITLE; } } if ((fields & enum_PROCESS_INFO_FIELDS.PIF_PROCESS_ID) != 0) { GetADProcessId(out pProcessInfo[0].ProcessId); pProcessInfo[0].Fields |= enum_PROCESS_INFO_FIELDS.PIF_PROCESS_ID; } if ((fields & enum_PROCESS_INFO_FIELDS.PIF_FLAGS) != 0) { pProcessInfo[0].Flags = 0; if (!_isSameUser || !this.HasRealCommandLine) { pProcessInfo[0].Flags |= enum_PROCESS_INFO_FLAGS.PIFLAG_SYSTEM_PROCESS; } pProcessInfo[0].Fields |= enum_PROCESS_INFO_FIELDS.PIF_FLAGS; } return HR.S_OK; }
/// <summary> /// Run when this service is first started. Most useful for at install, or anything that starts before us on boot. /// Check the currently executing processes and records info about them and also checks them against our rules to note /// anything that should not have been running already (TODO Need to alert about that) /// </summary> public void AnalyzeRunningProcesses() { foreach (Process process in Process.GetProcesses()) { try { Log.Info("Process: {0} ID: {1}", process.ProcessName, process.Id); string fileName = process.Modules[0].FileName; Log.Info("File name: {0}", fileName); long ExecutableId; if (Arbiter.DecideOnProcess(fileName, out ExecutableId) == Decision.DENY) { Log.Warn("*** This file should not be running: {0}", fileName); // File running that should not be. // TODO Alert and/or Kill this process } PROCESS_INFO processInfo = new PROCESS_INFO(process); Database.LogProcessEvent(processInfo, ExecutableId, Database.ProcessState.Exists); } catch (Exception e) { if (process.Id == 0 || process.Id == 4) { // "System" (4) and "idle" (0) processes cannot have their modules enumerated, // so ignore them } else if (process.HasExited) { // no-op, just an exception because the process already exited } else { Log.Exception(e, "Exception reading process: {0}", process.ProcessName); } } } }
int Microsoft.VisualStudio.Debugger.Interop.IDebugProcess2.GetInfo(uint Fields, PROCESS_INFO[] pProcessInfo) { Process process = null; PROCESS_INFO pi = new PROCESS_INFO(); pi.Fields = Fields; if (this.m_port == null) { return Utility.COM_HResults.E_FAIL; } if (this.m_port.IsLocalPort) { try { process = Process.GetProcessById((int)this.m_pid); } catch // Emulator has exited! { return Utility.COM_HResults.E_FAIL; } } if ((Fields & (uint) PROCESS_INFO_FIELDS.PIF_ATTACHED_SESSION_NAME) != 0) { pi.bstrAttachedSessionName = null; } if ((Fields & (uint) PROCESS_INFO_FIELDS.PIF_BASE_NAME) != 0) { //We aren't connected to the CLR yet. This information (it appears in the Processes window) //is probably better than nothing. if (process != null) { pi.bstrBaseName = process.ProcessName; } else { pi.bstrBaseName = m_portDefinition.DisplayName; } } if ((Fields & (uint) PROCESS_INFO_FIELDS.PIF_CREATION_TIME) != 0) { pi.CreationTime.dwHighDateTime = 0; pi.CreationTime.dwLowDateTime = 0; } if ((Fields & (uint) PROCESS_INFO_FIELDS.PIF_FILE_NAME) != 0) { if (process != null) { pi.bstrFileName = process.ProcessName; } else { pi.bstrFileName = m_portDefinition.DisplayName; } } if ((Fields & (uint) PROCESS_INFO_FIELDS.PIF_FLAGS) != 0) { if(m_fExecutionPaused) pi.Flags = (uint) PROCESS_INFO_FLAGS.PIFLAG_PROCESS_STOPPED; else pi.Flags = (uint) PROCESS_INFO_FLAGS.PIFLAG_PROCESS_RUNNING; } if ((Fields & (uint) PROCESS_INFO_FIELDS.PIF_PROCESS_ID) != 0) { pi.ProcessId = PhysicalProcessId; } if ((Fields & (uint) PROCESS_INFO_FIELDS.PIF_SESSION_ID) != 0) { //Can/should we enable debugging across sessions? Can we access other user's //debug pipe? pi.dwSessionId = 0; } if ((Fields & (uint) PROCESS_INFO_FIELDS.PIF_TITLE) != 0) { if (process != null) { pi.bstrTitle = process.MainWindowTitle; } else { pi.bstrTitle = "<Unknown>"; } } if (process != null) { process.Dispose(); process = null; } pProcessInfo[0] = pi; return Utility.COM_HResults.S_OK; }
/// <summary> /// Gets a description of the process. /// </summary> /// <param name="Fields">A combination of values from the PROCESS_INFO_FIELDS enumeration that specifies which fields of the pProcessInfo parameter are to be filled in.</param> /// <param name="pProcessInfo">A PROCESS_INFO structure that is filled in with a description of the process.</param> /// <returns>If successful, returns S_OK; otherwise, returns an error code.</returns> public virtual int GetInfo( enum_PROCESS_INFO_FIELDS Fields, PROCESS_INFO[] pProcessInfo ) { Logger.Debug( string.Empty ); return VSConstants.E_NOTIMPL; }
public int GetInfo(enum_PROCESS_INFO_FIELDS Fields, PROCESS_INFO[] pProcessInfo) { DebugHelper.TraceEnteringMethod(); throw new NotImplementedException(); }
public int Event(IDebugEngine2 engine, IDebugProcess2 process, IDebugProgram2 program, IDebugThread2 thread, IDebugEvent2 debugEvent, ref Guid riidEvent, uint attributes) { if (process == null) return VSConstants.S_OK; string processName; if (process.GetName((uint) enum_GETNAME_TYPE.GN_FILENAME, out processName) != VSConstants.S_OK) return VSConstants.S_OK; if (processName.EndsWith("vshost.exe")) return VSConstants.S_OK; var shortName = Path.GetFileName(processName); if (debugEvent is IDebugProcessCreateEvent2) { Log.Instance.SetStatus("[attaching...] {0}", shortName); Storage.Instance.SubscribeProcess(processName); } if (debugEvent is IDebugProcessDestroyEvent2) { Log.Instance.SetStatus("[detached] {0}", shortName); Log.Instance.AppendLine("[detached] {0}", shortName); } if (debugEvent is IDebugLoadCompleteEvent2) { if (program != null) { string engineName; Guid engineId; if (program.GetEngineInfo(out engineName, out engineId) == VSConstants.S_OK) { var fields = new PROCESS_INFO[1]; if (process.GetInfo((uint)enum_PROCESS_INFO_FIELDS.PIF_PROCESS_ID, fields) != VSConstants.S_OK) return VSConstants.S_OK; Storage.Instance.SubscribeEngine(processName, engineId); AttachCenter.Instance.Freeze(); Log.Instance.SetStatus("[attached] {0}", shortName); Log.Instance.AppendLine("[attached] {0} ({1}) / {2}", shortName, fields[0].ProcessId.dwProcessId, engineName); } } } return VSConstants.S_OK; }
public int GetInfo(enum_PROCESS_INFO_FIELDS Fields, PROCESS_INFO[] pProcessInfo) { return VSConstants.S_OK; }
/// <summary> /// Gets a description of the process. /// </summary> public int GetInfo(enum_PROCESS_INFO_FIELDS fields, PROCESS_INFO[] pProcessInfo) { DLog.Debug(DContext.VSDebuggerComCall, "IDebugProcess2.GetInfo {0}", fields); var foundFields = (enum_PROCESS_INFO_FIELDS)0; var info = new PROCESS_INFO(); if ((fields & enum_PROCESS_INFO_FIELDS.PIF_FILE_NAME) != 0) { info.bstrFileName = apkPath; foundFields |= enum_PROCESS_INFO_FIELDS.PIF_FILE_NAME; } if ((fields & enum_PROCESS_INFO_FIELDS.PIF_BASE_NAME) != 0) { info.bstrBaseName = Path.GetFileName(apkPath); foundFields |= enum_PROCESS_INFO_FIELDS.PIF_BASE_NAME; } if ((fields & enum_PROCESS_INFO_FIELDS.PIF_TITLE) != 0) { info.bstrTitle = Path.GetFileName(apkPath); foundFields |= enum_PROCESS_INFO_FIELDS.PIF_TITLE; } if ((fields & enum_PROCESS_INFO_FIELDS.PIF_PROCESS_ID) != 0) { var arr = new AD_PROCESS_ID[0]; GetPhysicalProcessId(arr); info.ProcessId = arr[0]; foundFields |= enum_PROCESS_INFO_FIELDS.PIF_PROCESS_ID; } if ((fields & enum_PROCESS_INFO_FIELDS.PIF_SESSION_ID) != 0) { info.dwSessionId = 1; foundFields |= enum_PROCESS_INFO_FIELDS.PIF_SESSION_ID; } if ((fields & enum_PROCESS_INFO_FIELDS.PIF_ATTACHED_SESSION_NAME) != 0) { info.bstrAttachedSessionName = "<deprecated>"; foundFields |= enum_PROCESS_INFO_FIELDS.PIF_ATTACHED_SESSION_NAME; } if ((fields & enum_PROCESS_INFO_FIELDS.PIF_CREATION_TIME) != 0) { var fileTime = DateTime.Now.ToFileTime(); info.CreationTime.dwLowDateTime = (uint) (fileTime & 0xFFFFFFFF); info.CreationTime.dwHighDateTime = (uint) (fileTime >> 32); foundFields |= enum_PROCESS_INFO_FIELDS.PIF_CREATION_TIME; } if ((fields & enum_PROCESS_INFO_FIELDS.PIF_FLAGS) != 0) { pProcessInfo[0].Flags = GetProcessStatus(); foundFields |= enum_PROCESS_INFO_FIELDS.PIF_FLAGS; } pProcessInfo[0].Fields = foundFields; return VSConstants.S_OK; }
public int Event(IDebugEngine2 pEngine, IDebugProcess2 pProcess, IDebugProgram2 pProgram, IDebugThread2 pThread, IDebugEvent2 pEvent, ref Guid riidEvent, uint dwAttrib) { try { string threadName = null; if (pThread != null && pEvent != null) { uint attributes; pEvent.GetAttributes(out attributes); if ( (uint)enum_EVENTATTRIBUTES.EVENT_SYNC_STOP == attributes) { HandleException.PrintFrames(pThread); } pThread.GetName(out threadName); //ExtractFrameContent(pThread); //IEnumDebugFrameInfo2 ppEnum = null; } Trace.WriteLine(string.Format("Event {0} Thread {1}", riidEvent, threadName )); if (typeof(IDebugInterceptExceptionCompleteEvent2).GUID == riidEvent) { var interactionEvent = pEvent as IDebugInterceptExceptionCompleteEvent2; HandleException.PrintFrames(pThread); } //HandleException.ProcessEvent(riidEvent, pThread); if (typeof(IDebugProgramCreateEvent2).GUID == riidEvent) { // Add handle } if( false ) { IDebugSessionEvent2 ev = pEvent as IDebugSessionEvent2; var pInfo = new PROCESS_INFO[1]; if (pProcess != null) { pProcess.GetInfo((uint)enum_PROCESS_INFO_FIELDS.PIF_SESSION_ID, pInfo); } } if (typeof(IDebugBreakEvent2).GUID == riidEvent) { // Might be interesting to get the statement line number here and emit. var ev = pEvent as IDebugBreakEvent2; } if (riidEvent == typeof(IDebugEntryPointEvent2).GUID) { // This is when execution is just about to the start. // I can't get the reference to the engine, pEngine is always null, and // there doesn't seem to be an interface to fetch it (there is a query interface in docs, but not in dll!) //string engineStr; Guid engineGuid; //pProgram.GetEngineInfo(out engineStr, out engineGuid); //var superEngine = pEngine as IDebugEngine3; //if (superEngine != null) //{ // superEngine.SetAllExceptions(enum_EXCEPTION_STATE.EXCEPTION_STOP_FIRST_CHANCE); //} } else if (riidEvent == typeof(IDebugMessageEvent2).GUID) { var ev = pEvent as IDebugMessageEvent2; var str = ""; uint type; string helpFile; uint helpId; //var suc = ev.GetMessage(new enum_MESSAGETYPE[] { enum_MESSAGETYPE.MT_REASON_EXCEPTION }, out str, out type, out helpFile, out helpId); uint messageType; var suc = ev.GetMessage( out messageType, out str, out type, out helpFile, out helpId); if (suc == VSConstants.S_OK) { if (str.StartsWith("A first chance exception of type")) { if (pThread != null) { //ExtractFrameContent(pThread); HandleException.PrintFrames(pThread); } // First chance exception thrown...but can't figure out how to get stack trace :( } } } // This interface is sent by the debug engine (DE) to the session debug manager (SDM) when a thread is created in a program being debugged. //if (riidEvent == Guid.Parse("{2090ccfc-70c5-491d-a5e8-bad2dd9ee3ea}")) { if (pThread != null) { // ExtractFrameContent(pThread); } } // Process of exception handling. // http://msdn.microsoft.com/es-es/library/bb146610.aspx if (riidEvent == typeof(IDebugExceptionEvent2).GUID ) { IDebugExceptionEvent2 ev = pEvent as IDebugExceptionEvent2; if (ev != null) { var info = new EXCEPTION_INFO[1]; ev.GetException(info); var name = info[0].bstrExceptionName; var state = info[0].dwState; //state == enum_EXCEPTION_STATE.EXCEPTION_STOP_SECOND_CHANCE //ExtractFrameContent(pThread); } } } catch (Exception ex) { Trace.WriteLine(ex.Message); } if (pEngine != null) { Marshal.ReleaseComObject(pEngine); } if (pProcess != null) { Marshal.ReleaseComObject(pProcess); } if (pProgram != null) { Marshal.ReleaseComObject(pProgram); } if (pThread != null) { Marshal.ReleaseComObject(pThread); } if (pEvent != null) { Marshal.ReleaseComObject(pEvent); } return VSConstants.S_OK; }
public int Event(IDebugEngine2 pEngine, IDebugProcess2 pProcess, IDebugProgram2 pProgram, IDebugThread2 pThread, IDebugEvent2 pEvent, ref Guid riidEvent, uint dwAttrib) { try { string threadName = null; if (pThread != null && pEvent != null) { uint attributes; pEvent.GetAttributes(out attributes); if ((uint)enum_EVENTATTRIBUTES.EVENT_SYNC_STOP == attributes) { HandleException.PrintFrames(pThread); } pThread.GetName(out threadName); //ExtractFrameContent(pThread); //IEnumDebugFrameInfo2 ppEnum = null; } Trace.WriteLine(string.Format("Event {0} Thread {1}", riidEvent, threadName)); if (typeof(IDebugInterceptExceptionCompleteEvent2).GUID == riidEvent) { var interactionEvent = pEvent as IDebugInterceptExceptionCompleteEvent2; HandleException.PrintFrames(pThread); } //HandleException.ProcessEvent(riidEvent, pThread); if (typeof(IDebugProgramCreateEvent2).GUID == riidEvent) { // Add handle } if (false) { IDebugSessionEvent2 ev = pEvent as IDebugSessionEvent2; var pInfo = new PROCESS_INFO[1]; if (pProcess != null) { pProcess.GetInfo((uint)enum_PROCESS_INFO_FIELDS.PIF_SESSION_ID, pInfo); } } if (typeof(IDebugBreakEvent2).GUID == riidEvent) { // Might be interesting to get the statement line number here and emit. var ev = pEvent as IDebugBreakEvent2; } if (riidEvent == typeof(IDebugEntryPointEvent2).GUID) { // This is when execution is just about to the start. // I can't get the reference to the engine, pEngine is always null, and // there doesn't seem to be an interface to fetch it (there is a query interface in docs, but not in dll!) //string engineStr; Guid engineGuid; //pProgram.GetEngineInfo(out engineStr, out engineGuid); //var superEngine = pEngine as IDebugEngine3; //if (superEngine != null) //{ // superEngine.SetAllExceptions(enum_EXCEPTION_STATE.EXCEPTION_STOP_FIRST_CHANCE); //} } else if (riidEvent == typeof(IDebugMessageEvent2).GUID) { var ev = pEvent as IDebugMessageEvent2; var str = ""; uint type; string helpFile; uint helpId; //var suc = ev.GetMessage(new enum_MESSAGETYPE[] { enum_MESSAGETYPE.MT_REASON_EXCEPTION }, out str, out type, out helpFile, out helpId); uint messageType; var suc = ev.GetMessage(out messageType, out str, out type, out helpFile, out helpId); if (suc == VSConstants.S_OK) { if (str.StartsWith("A first chance exception of type")) { if (pThread != null) { //ExtractFrameContent(pThread); HandleException.PrintFrames(pThread); } // First chance exception thrown...but can't figure out how to get stack trace :( } } } // This interface is sent by the debug engine (DE) to the session debug manager (SDM) when a thread is created in a program being debugged. //if (riidEvent == Guid.Parse("{2090ccfc-70c5-491d-a5e8-bad2dd9ee3ea}")) { if (pThread != null) { // ExtractFrameContent(pThread); } } // Process of exception handling. // http://msdn.microsoft.com/es-es/library/bb146610.aspx if (riidEvent == typeof(IDebugExceptionEvent2).GUID ) { IDebugExceptionEvent2 ev = pEvent as IDebugExceptionEvent2; if (ev != null) { var info = new EXCEPTION_INFO[1]; ev.GetException(info); var name = info[0].bstrExceptionName; var state = info[0].dwState; //state == enum_EXCEPTION_STATE.EXCEPTION_STOP_SECOND_CHANCE //ExtractFrameContent(pThread); } } } catch (Exception ex) { Trace.WriteLine(ex.Message); } if (pEngine != null) { Marshal.ReleaseComObject(pEngine); } if (pProcess != null) { Marshal.ReleaseComObject(pProcess); } if (pProgram != null) { Marshal.ReleaseComObject(pProgram); } if (pThread != null) { Marshal.ReleaseComObject(pThread); } if (pEvent != null) { Marshal.ReleaseComObject(pEvent); } return(VSConstants.S_OK); }
/// <summary> /// Gets a description of the process. (http://msdn.microsoft.com/en-us/library/bb145895.aspx) /// </summary> /// <param name="Fields"> A combination of values from the PROCESS_INFO_FIELDS enumeration that specifies which fields of /// the pProcessInfo parameter are to be filled in. </param> /// <param name="pProcessInfo"> A PROCESS_INFO structure that is filled in with a description of the process. </param> /// <returns> VSConstants.S_OK. </returns> public int GetInfo(enum_PROCESS_INFO_FIELDS Fields, PROCESS_INFO[] pProcessInfo) { try { if ((Fields & enum_PROCESS_INFO_FIELDS.PIF_FILE_NAME) != 0) { pProcessInfo[0].bstrFileName = this._name; pProcessInfo[0].Fields |= enum_PROCESS_INFO_FIELDS.PIF_FILE_NAME; } if ((Fields & enum_PROCESS_INFO_FIELDS.PIF_BASE_NAME) != 0) { pProcessInfo[0].bstrBaseName = this._name.Substring(_name.LastIndexOf('/') + 1); pProcessInfo[0].Fields |= enum_PROCESS_INFO_FIELDS.PIF_BASE_NAME; } if ((Fields & enum_PROCESS_INFO_FIELDS.PIF_TITLE) != 0) { pProcessInfo[0].bstrTitle = this._name; pProcessInfo[0].Fields |= enum_PROCESS_INFO_FIELDS.PIF_TITLE; } if ((Fields & enum_PROCESS_INFO_FIELDS.PIF_PROCESS_ID) != 0) { pProcessInfo[0].ProcessId.dwProcessId = Convert.ToUInt32(this._processID); pProcessInfo[0].ProcessId.ProcessIdType = (uint)enum_AD_PROCESS_ID.AD_PROCESS_ID_SYSTEM; pProcessInfo[0].Fields |= enum_PROCESS_INFO_FIELDS.PIF_PROCESS_ID; } if ((Fields & enum_PROCESS_INFO_FIELDS.PIF_SESSION_ID) != 0) { // pProcessInfo[0].dwSessionId = 0; pProcessInfo[0].Fields |= enum_PROCESS_INFO_FIELDS.PIF_SESSION_ID; } if ((Fields & enum_PROCESS_INFO_FIELDS.PIF_ATTACHED_SESSION_NAME) != 0) { // pProcessInfo[0].bstrAttachedSessionName = null; pProcessInfo[0].Fields |= enum_PROCESS_INFO_FIELDS.PIF_ATTACHED_SESSION_NAME; } if ((Fields & enum_PROCESS_INFO_FIELDS.PIF_CREATION_TIME) != 0) { // pProcessInfo[0].CreationTime = null; pProcessInfo[0].Fields |= enum_PROCESS_INFO_FIELDS.PIF_CREATION_TIME; } return VSConstants.S_OK; } catch (Exception e) { return EngineUtils.UnexpectedException(e); } }
public int GetInfo(enum_PROCESS_INFO_FIELDS Fields, PROCESS_INFO[] pProcessInfo) { throw new NotImplementedException(); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public int GetInfo(enum_PROCESS_INFO_FIELDS Fields, PROCESS_INFO [] infoArray) { // // Gets a description of the process. // LoggingUtils.PrintFunction(); try { infoArray [0] = new PROCESS_INFO(); if ((Fields & enum_PROCESS_INFO_FIELDS.PIF_FILE_NAME) != 0) { LoggingUtils.RequireOk(GetName(enum_GETNAME_TYPE.GN_FILENAME, out infoArray [0].bstrFileName)); infoArray [0].Fields |= enum_PROCESS_INFO_FIELDS.PIF_FILE_NAME; } if ((Fields & enum_PROCESS_INFO_FIELDS.PIF_BASE_NAME) != 0) { LoggingUtils.RequireOk(GetName(enum_GETNAME_TYPE.GN_BASENAME, out infoArray [0].bstrBaseName)); infoArray [0].Fields |= enum_PROCESS_INFO_FIELDS.PIF_BASE_NAME; } if ((Fields & enum_PROCESS_INFO_FIELDS.PIF_TITLE) != 0) { LoggingUtils.RequireOk(GetName(enum_GETNAME_TYPE.GN_TITLE, out infoArray [0].bstrTitle)); infoArray [0].Fields |= enum_PROCESS_INFO_FIELDS.PIF_TITLE; } if ((Fields & enum_PROCESS_INFO_FIELDS.PIF_PROCESS_ID) != 0) { AD_PROCESS_ID [] processId = new AD_PROCESS_ID [1]; LoggingUtils.RequireOk(GetPhysicalProcessId(processId)); infoArray [0].ProcessId = processId [0]; infoArray [0].Fields |= enum_PROCESS_INFO_FIELDS.PIF_PROCESS_ID; } if ((Fields & enum_PROCESS_INFO_FIELDS.PIF_SESSION_ID) != 0) { // We currently don't support multiple sessions, so all processes are in session 1. infoArray [0].dwSessionId = 1; infoArray [0].Fields |= enum_PROCESS_INFO_FIELDS.PIF_SESSION_ID; } if ((Fields & enum_PROCESS_INFO_FIELDS.PIF_ATTACHED_SESSION_NAME) != 0) { // Oddly enough, SESSION_NAME is requested... even though the docs clearly state that it's deprecated. infoArray [0].bstrAttachedSessionName = "[Attached session name is deprecated]"; infoArray [0].Fields |= enum_PROCESS_INFO_FIELDS.PIF_ATTACHED_SESSION_NAME; } if ((Fields & enum_PROCESS_INFO_FIELDS.PIF_CREATION_TIME) != 0) { // Not entirely clear how this should be implemented. /*Microsoft.VisualStudio.OLE.Interop.FILETIME filetime; * * infoArray [0].CreationTime = filetime; * * infoArray [0].Fields |= enum_PROCESS_INFO_FIELDS.PIF_CREATION_TIME;*/ } if ((Fields & enum_PROCESS_INFO_FIELDS.PIF_FLAGS) != 0) { infoArray [0].Flags |= enum_PROCESS_INFO_FLAGS.PIFLAG_PROCESS_RUNNING; if (DebuggeeProgram.AttachedEngine != null) { infoArray [0].Flags |= enum_PROCESS_INFO_FLAGS.PIFLAG_DEBUGGER_ATTACHED; } //enum_PROCESS_INFO_FLAGS.PIFLAG_DEBUGGER_ATTACHED //enum_PROCESS_INFO_FLAGS.PIFLAG_PROCESS_STOPPED //enum_PROCESS_INFO_FLAGS.PIFLAG_PROCESS_RUNNING if (!NativeProcess.IsUserProcess) { infoArray [0].Flags |= enum_PROCESS_INFO_FLAGS.PIFLAG_SYSTEM_PROCESS; } infoArray [0].Fields |= enum_PROCESS_INFO_FIELDS.PIF_FLAGS; } return(Constants.S_OK); } catch (Exception e) { LoggingUtils.HandleException(e); return(Constants.E_FAIL); } }