public static void waitForProcessExitAndInvokeCallBankOncompletion_Thread(Process pProcess,
                                                                           Callbacks.dMethod_Object
                                                                           dProcessCompletionCallback,
                                                                           bool bNoExecutionTimeLimit)
 {
     try
     {
         if (pProcess != null)
         {
             if (bNoExecutionTimeLimit)
             {
                 pProcess.WaitForExit();
             }
             else
             {
                 pProcess.WaitForExit(iMaxProcessExecutionTimeOut);
             }
         }
         Callbacks.raiseRegistedCallbacks(dProcessCompletionCallback, new object[] { pProcess });
     }
     catch (Exception ex)
     {
         PublicDI.log.ex(ex, "In waitForProcessExitAndInvokeCallBankOncompletion:", true);
     }
 }
Exemple #2
0
        public bool scanApplication(string sApplicationToScan, string sPathToSaveAssessmentFile,
                                    Callbacks.dMethod_String logCallback, Callbacks.dMethod_Object onProcessEndCallback)
        {
            string cliParameters = "script \"" +
                                   getCliScript_ScanApplication(sApplicationToScan, sPathToSaveAssessmentFile) + "\"";

            scanProcess = startCliProcessWithParameters(cliParameters, logCallback);


            Processes.waitForProcessExitAndInvokeCallBankOncompletion(scanProcess,
                                                                      executedProcess =>
            {
                if (onProcessEndCallback != null)
                {
                    onProcessEndCallback(executedProcess);
                }
            }, true);
            return(true);

            /*      Process pProcess = Processes.startProcessAsConsoleApplication(
             *  OunceCore.getPathToOunceInstallDirectory() + @"\bin\cli.exe", "script \"" + getCliScript_ScanApplication(sApplicationToScan,sPathToSaveAssessmentFile)+"\"");
             * if (dProcessCompletionCallback != null)
             *  Processes.waitForProcessExitAndInvokeCallBankOncompletion(pProcess, logCallback,  dProcessCompletionCallback, true);
             * return true;*/
        }
        public static bool createCirDump(String sApplicationToScan, String sScanResultsFolder,
                                         Callbacks.dMethod_Object dProcessCompletionCallback, Callbacks.dMethod_String _logCallback,
                                         bool bDeleteAllRulesFromDbBeforeScan,
                                         bool bStoreControlFlowBlockRawDataInsideCirDataFile)
        {
            var srScanResults = new O2scanresults
            {
                bDeleteAllRulesForCirCreation = bDeleteAllRulesFromDbBeforeScan,
                dProcessCompletionCallback    = dProcessCompletionCallback,
                logCallback        = _logCallback,
                bCreateCirDataFile = true,
                bStoreControlFlowBlockRawDataInsideCirDataFile =
                    bStoreControlFlowBlockRawDataInsideCirDataFile,
                bDeleteCreatedAssessmentFile = true
            };
            // srScanResults.sPathToCirDumpFiles = sScanResultsFolder; // o2.rules.scan.CalculateCirDataFileNameInResultsFolder(sApplicationToScan, sScanResultsFolder);

            bool bScanResult = srScanResults.scanApplication(sApplicationToScan);


            //o2.rules.scan.SaveCirDataFile(srScanResults, sScanResultsFolder);
            DebugMsg.saveLogIntoFile(Path.Combine(sScanResultsFolder,
                                                  Path.GetFileNameWithoutExtension(sApplicationToScan) +
                                                  " - CreateConsolidatedCirDump.txt"));

            return(bScanResult);
        }
        public bool executeCatNet(string fileToScan, Callbacks.dMethod_String logCallback,
                                  Callbacks.dMethod_Object onProcessEndCallback, bool convertToOzasmt)
        {
            string resultsFile = Path.Combine(DI.config.O2TempDir,
                                              Path.GetFileNameWithoutExtension(fileToScan) + "xml");

            return(executeCatNet(fileToScan, resultsFile, logCallback, onProcessEndCallback, convertToOzasmt));
        }
Exemple #5
0
        public static void waitForProcessExitAndInvokeCallBankOncompletion(Process pProcess,
                                                                           Callbacks.dMethod_Object
                                                                           dProcessCompletionCallback,
                                                                           bool bNoExecutionTimeLimit)
        {
            ThreadStart tsThreadStart =
                () => waitForProcessExitAndInvokeCallBankOncompletion_Thread(pProcess, dProcessCompletionCallback,
                                                                             bNoExecutionTimeLimit);

            new Thread(tsThreadStart).Start();
        }
 public static bool createCirDump(IScanTarget scScanTarget, Callbacks.dMethod_Object dProcessCompletionCallback, Callbacks.dMethod_String _logCallback,
                                  bool bDeleteAllRulesFromDbBeforeScan,
                                  bool bStoreControlFlowBlockRawDataInsideCirDataFile)
 {
     if (scScanTarget != null)
     {
         return(createCirDump(scScanTarget.ApplicationFile, scScanTarget.WorkDirectory, dProcessCompletionCallback, _logCallback,
                              bDeleteAllRulesFromDbBeforeScan, bStoreControlFlowBlockRawDataInsideCirDataFile));
     }
     return(false);
 }
        public void scan(IScanTarget scanTarget, Callbacks.dMethod_String logCallback,
                         Callbacks.dMethod_Object onProcessEndCallback, bool convertToOzasmt)
        {
            if (false == MsCatNetConfig.isCatScannerAvailable())
            {
                DI.log.error("Could not find MSCatNet Scanner on this box, aborting scan");
            }
            string fileToScan = scanTarget.Target;
            string reportFile = Path.Combine(scanTarget.WorkDirectory, Path.GetFileName(fileToScan) + ".xml");

            executeCatNet(fileToScan, reportFile, logCallback, onProcessEndCallback, convertToOzasmt);
        }
Exemple #8
0
        public static bool ScanWithNoRules(String sApplicationToScan, String sScanResultsFolder,
                                           Callbacks.dMethod_Object dProcessCompletionCallback)
        {
            var srScanResults = new O2scanresults();

            srScanResults.bScanWithNoRules = true;
            bool bScanResult = srScanResults.scanApplication(sApplicationToScan);

            DebugMsg.saveLogIntoFile(Path.Combine(sScanResultsFolder,
                                                  Path.GetFileNameWithoutExtension(sApplicationToScan) +
                                                  " - Scan_WithNoRules.txt"));
            return(bScanResult);
        }
        private bool executeCatNet(string fileToScan, string resultsFile,
                                   Callbacks.dMethod_String logCallback,
                                   Callbacks.dMethod_Object onProcessEndCallback,
                                   bool convertToOzasmt)
        {
            //string targetDirectory = (Path.GetDirectoryName(fileToScan));
            try
            {
                // if ("" != Files.checkIfDirectoryExistsAndCreateIfNot(targetDirectory))
                if (File.Exists(fileToScan))
                {
                    DI.log.info("Scanning Dll {0} and saving results here {1}", fileToScan, resultsFile);
                    string sExecArguments = String.Format("/file:\"{0}\" /report:\"{1}\"", fileToScan, resultsFile);

                    Process msCatNetProcess = startCatNetProcessWithParameters(sExecArguments, logCallback);


                    Processes.waitForProcessExitAndInvokeCallBankOncompletion(msCatNetProcess,
                                                                              (executedProcess) =>
                    {
                        if (onProcessEndCallback !=
                            null)
                        {
                            onProcessEndCallback(
                                executedProcess);
                        }
                        if (convertToOzasmt &&
                            File.Exists(resultsFile))
                        {
                            new CatNetConverter(
                                resultsFile).convert();
                        }
                    }, true);
                    return(true);
                }

                DI.log.error("File to scan doesn't exist: {0}", fileToScan);
                //executeCatNetCommand(sExecArguments, logCallback, onProcessEndCallback, convertToOzasmt);
            }
            catch (Exception ex)
            {
                DI.log.ex(ex, "in MsCatScan.executeCatNetCommandWithArguments");
            }

            return(false);
        }
Exemple #10
0
        public static void ScanWithSelectedAutomaticRuleSets(String sApplicationToScan, String sScanResultsFolder,
                                                             bool bCallBacksOnControlFlowGraphs_And_ExternalSinks,
                                                             bool bCallBacksOnEdges_And_ExternalSinks,
                                                             bool bSourcesAndSinks, String sExtraLogNameText,
                                                             Callbacks.dMethod_Object dProcessCompletionCallback,
                                                             Callbacks.dMethod_String logCallback)
        {
            O2Thread.mtaThread(() =>
            {
                DebugMsg.bLogCache = true;                        // enable LogCache (so that we can save it at the end
                var srScanResults  = new O2scanresults();
                //if (File.Exists(CalculateCirDataFileNameInResultsFolder(sApplicationToScan, sScanResultsFolder)))
                //   srScanResults.sCirDataFile = CalculateCirDataFileNameInResultsFolder(sApplicationToScan, sScanResultsFolder);
                // load or create CirData file
                if (File.Exists(sApplicationToScan + ".CirData"))
                {
                    srScanResults.sCirDataFile = sApplicationToScan + ".CirData";
                }
                else
                {
                    srScanResults.bCreateCirDataFile = true;
                }
                // set scanning options (i.e. what to scan)
                srScanResults.bCallBacksOnControlFlowGraphs_And_ExternalSinks =
                    bCallBacksOnControlFlowGraphs_And_ExternalSinks;
                srScanResults.bCallBacksOnEdges_And_ExternalSinks =
                    bCallBacksOnEdges_And_ExternalSinks;
                srScanResults.bSourcesAndSinks = bSourcesAndSinks;

                srScanResults.dProcessCompletionCallback = dProcessCompletionCallback;
                srScanResults.logCallback = logCallback;

                // trigger scan
                bool bScanResult = srScanResults.scanApplication(sApplicationToScan);


                //  SaveCirDataFile(srScanResults, sScanResultsFolder);
                //SaveAssessmentFiles(srScanResults, sScanResultsFolder);
                DebugMsg.saveLogIntoFile(Path.Combine(sScanResultsFolder,
                                                      Path.GetFileNameWithoutExtension(
                                                          sApplicationToScan) + " - " +
                                                      sExtraLogNameText + ".txt"));
                DebugMsg.bLogCache = false;
            });
        }
Exemple #11
0
 public void registerSelectedFindingEventCallback(Callbacks.dMethod_Object callback)
 {
     eventFindingSelected += callback;
 }
 public void registerSelectedFindingEventCallback(Callbacks.dMethod_Object callback)
 {
     eventFindingSelected += callback;
 }