public override ScanOutput Scan(string FilePath) { try { ScanOutput output = new ScanOutput(); fileLog.Status = ScanStatus.Queued; fileLog.FilePath = FilePath; fileLog.Scanner = _serviceName; Task <List <VTScanResult> > task = Task.Run <List <VTScanResult> >(async() => await RunExample(FilePath, fileLog)); _message = "File is queued! Please check back after some time"; output.Result = false; output.Message = "Please check back in a while"; output.ServiceName = _serviceName; return(output); } catch (Exception ex) { fileLog.Status = ScanStatus.Error; fileLog.Message = ex.Message; throw new AvscanException(ex); } finally { ScanFileLogRepo.Record(fileLog); } }
public override ScanOutput Scan(string FilePath) { ScanOutput output = new ScanOutput(); VTScanResult scanResult = new VTScanResult(); List <VTScanResult> logresult = new List <VTScanResult>(); bool result = false; try { _filepath = FilePath; fileLog.StartTime = DateTime.Now.ToString(); fileLog.Status = ScanStatus.Started; fileLog.FilePath = FilePath; fileLog.Scanner = _serviceName; ScanUtility.ExecuteCommand(RunUtil, RunCommand); _message = (String.IsNullOrEmpty(ScanUtility.Output) ? "(none)" : ScanUtility.Output); result = (ScanUtility.Result == 0) ? false : true; fileLog.FinishTime = DateTime.Now.ToString(); fileLog.Status = (ScanUtility.Result == 0) ? ScanStatus.Passed : ScanStatus.Failed; fileLog.Message = _message; output.Result = result; output.Message = _message; output.ServiceName = _serviceName; } catch (Exception ex) { _message = ex.Message; fileLog.Status = ScanStatus.Error; result = false; //throw new AvscanException(ex); } finally { scanResult.ScanId = _serviceName; scanResult.VirusFound = result; scanResult.Result = _message; logresult.Add(scanResult); fileLog.ScanResults = logresult; ScanFileLogRepo.Record(fileLog); } return(output); }
/// <summary> /// Generated in the console the resulted PIF , ST and if any, the Lexical errors, also writes the PIF and the ST to a txt file /// </summary> /// <param name="scanResult">The result of the scan</param> private void GenerateOutput(ScanOutput scanResult, string pifFileNameOutput, string stFileNameOutput) { var pif = scanResult.PIFTable.GetTable(); var st = scanResult.SymbolTable.GetSymbolTable(); var errors = scanResult.LexicalErrors; Console.WriteLine("Scanned output:"); Console.WriteLine("PIF:"); using (var file = new StreamWriter(pifFileNameOutput, false)) { foreach (var pifValue in pif) { file.WriteLine("Token: " + pifValue.Token + " Code: " + pifValue.Position); Console.WriteLine("Token: " + pifValue.Token + " Code: " + pifValue.Position); } } Console.WriteLine("ST:"); using (var file = new StreamWriter(stFileNameOutput, false)) { for (var pos = 0; pos < st.Count; pos++) { file.WriteLine("Token: " + st[pos] + " Position: " + (pos + 1)); Console.WriteLine("Token: " + st[pos] + " Position: " + (pos + 1)); } } foreach (var error in scanResult.LexicalErrors) { Console.WriteLine("Error: " + error.Token + " Line: " + error.Position); } if (errors.Count == 0) { Console.WriteLine("Lexically correct"); } Console.WriteLine("Check the output files manually in bin\'debug :D"); }