public void NotifyListenersWeAreDone(ClousotAnalysisResults results)
        {
            Contract.Requires(results != null);

            results.NotifyDone();
            var namedPipeClient = new NamedPipeClientStream(".", CommonNames.GetPipeNameForCCCheckPulseCallBack(0), PipeDirection.InOut);

            try
            {
#if DEBUG && DEBUG_PRINT
                Console.WriteLine("[Debug] Trying to connect to the server to write back (we also wait {0})", TIMEOUTFORCONNECTION);
#endif
                namedPipeClient.Connect(TIMEOUTFORCONNECTION);
                new PipeStreamSimple(namedPipeClient).WriteIfConnected(results.ToList());

#if DEBUG && DEBUG_PRINT
                Console.WriteLine("[Debug] We are done writing back");
#endif
            }
            catch (Exception
#if DEBUG && DEBUG_PRINT
                   e
#endif
                   )
            {
#if DEBUG && DEBUG_PRINT
                Console.WriteLine("[Debug] We failed in writing back: {0}", e.Message);
#endif
                // do nothing
            }
            finally
            {
                namedPipeClient.Close();
            }
        }
        /// <summary>
        /// Creates and starts the ClousotPulse server
        /// </summary>
        public ClousotPulseServer(Func <ClousotAnalysisState> GetClousotCurrentAnalysisState)
        {
            Contract.Requires(GetClousotCurrentAnalysisState != null);

            this.GetClousotCurrentAnalysisState = GetClousotCurrentAnalysisState;
            this.callbackNames   = new Set <string>();
            this.namedPipeServer = new NamedPipeServerStream(CommonNames.GetPipeNameForCCCheckPulse(), PipeDirection.InOut, 254);

            // Start the server
            this.server = new Thread(MainProcess);
            //this.server.IsBackground = true; // If we set it to true, then the server will die when the main one will. However, this is bad as it may cause the server to be killed while it is still sending the info back to the clients
            this.server.Start();
        }
 public void Kill()
 {
     // We send ourself a shutdown message, to deblock the wait above
     // Should interrupt the WaitForConnection in a better way?
     // see: http://stackoverflow.com/questions/607872/what-is-a-good-way-to-shutdown-threads-blocked-on-namedpipeserverwaitforconnect
     try
     {
         var client = new NamedPipeClientStream(".", CommonNames.GetPipeNameForCCCheckPulse(), PipeDirection.InOut);
         client.Connect(); // we know we succed?
         new PipeStreamSimple(client).WriteIfConnected("shutdown");
     }
     catch
     {
     }
 }
Ejemplo n.º 4
0
        public CCCheckPulseForm()
        {
            InitializeComponent();
            SetUpGrids();
            SetUpTimer();

            //this.myCallBackPipe = CommonNames.GetPipeNameForCallBack(Process.GetCurrentProcess().Id);
            this.myCallBackPipe = CommonNames.GetPipeNameForCCCheckPulseCallBack(0);

            // Start the worker thread for call backs
            var listenerThread = new Thread(CallBack);

            listenerThread.IsBackground = true; // To make sure that when we close the window, we exit even if the background listener is still waiting for a connection
            listenerThread.Start();
        }
        private void MainProcess(object data)
        {
#if DEBUG && DEBUG_PRINT
            Console.WriteLine("[DEBUG] Pulse Clousot at named channel {0}", CommonNames.GetPipeNameForCCCheckPulse());
#endif

            while (true)
            {
                try
                {
                    this.namedPipeServer.WaitForConnection(); // wait for connection

                    var stream = new PipeStreamSimple(namedPipeServer);

                    string obj;

                    if (stream.TryRead(out obj))
                    {
                        if (obj == "shutdown")
                        {
                            goto done;
                        }

                        this.callbackNames.AddIfNotNull(obj);
                    }
                    // Write what Clousot is doing now
                    stream.WriteIfConnected(GetClousotCurrentAnalysisState().ToList());

                    this.namedPipeServer.Disconnect();
                }
                catch
                {
                    // just swallow the error
                }
            }

done:
            ;
        }
Ejemplo n.º 6
0
        private void UpdateGrids()
        {
            // Clear the pulse grid
            this.clousotPulseGrid.Rows.Clear();

            var ClousotProcesses = Process.GetProcessesByName("Clousot").Union(Process.GetProcessesByName("cccheck"));

            foreach (var proc in ClousotProcesses)
            {
                var pipeName        = CommonNames.GetPipeNameForCCCheckPulse(proc.Id);
                var namedPipeClient = new NamedPipeClientStream(".", pipeName, PipeDirection.InOut);
                try
                {
                    InsertOrUpdateRowToProcessesGrid(proc);

                    namedPipeClient.Connect(20);
                    var stream = new PipeStreamSimple(namedPipeClient);

                    stream.WriteIfConnected(this.myCallBackPipe);

                    List <Tuple <string, object> > result;
                    if (stream.TryRead(out result))
                    {
                        var obj = new ClousotAnalysisState(result);
                        AddRowToPulseGrid(proc.Id, obj);
                    }
                    else
                    {
                        Trace.TraceWarning("failed to get a meaningfull answer from proc id {0}", proc.Id);
                    }
                }
                catch
                {
                    // does nothing
                }
                namedPipeClient.Close();
            }
        }
Ejemplo n.º 7
0
        private void SendWorkToProcess(Process exeProcess, string[] args)
        {
            Contract.Requires(exeProcess != null);
            Contract.Requires(args != null);

            CloudotLogging.WriteLine("Dispatching the analysis to worker process {0}", exeProcess.Id);

            var pipeName = CommonNames.GetPipeNameForCloudotWorker(exeProcess.Id);

            var namedPipeClient = new NamedPipeClientStream(pipeName);

            try
            {
                // Try to connect to the process via the pipe
                namedPipeClient.Connect(200);

                // Send the arguments -- our protocol is that once the clousot process received the arguments, it will proceed with the analysis, as usual
                new BinaryFormatter().Serialize(namedPipeClient, args);
            }
            catch (Exception e)
            {
                CloudotLogging.WriteLine("Something went wrong while sending the arguments to process {0}{1}{2}", exeProcess.Id, Environment.NewLine, e.Message);
            }
        }