public async Task <ActionResult> Report(string requestId) { ScanRequestHandler scanner = new ScanRequestHandler(); MalwareDeterminationResult result = await scanner.GetScanResult(requestId); var reportModel = new ReportViewModel(result); return(View(reportModel)); }
private async Task Process(MalwareDeterminationRequest request) { // Download ZIP WebClient webClient = new WebClient(); byte[] response = await webClient.DownloadDataTaskAsync(request.Uri).ConfigureAwait(false); webClient.Dispose(); // Unzip and try to find "malware" files List <ConfirmedMalwareInfo> detectedFiles = new List <ConfirmedMalwareInfo>(); int unzippedFilesCount = 0; Stream unzippedEntryStream; // Unzipped data from a file in the archive using (Stream data = new MemoryStream(response)) using (ZipArchive archive = new ZipArchive(data)) { unzippedFilesCount = archive.Entries.Count; foreach (ZipArchiveEntry entry in archive.Entries) { if (entry.FullName.Contains("malware")) { using (unzippedEntryStream = entry.Open()) { // convert stream to string using (StreamReader reader = new StreamReader(unzippedEntryStream)) { string text = await reader.ReadToEndAsync().ConfigureAwait(false); // Expected value: <malwarename>:<avengine#1>,...,<avengine#n> string[] arr = text.Split(new char[] { ':' }); ConfirmedMalwareInfo info = new ConfirmedMalwareInfo(); info.FileName = entry.FullName.Substring(entry.FullName.IndexOf('/')); info.MalwareInfo = arr[0]; if (arr.Count() > 1) { info.AvEngines = arr[1].Split(new char[] { ',' }).ToList(); } detectedFiles.Add(info); } } } } // Compose a scan result MalwareDeterminationResult detectionResult = new MalwareDeterminationResult(); if (detectedFiles.Count() > 0) { detectionResult.ClientId = request.ClientId; detectionResult.RequestId = request.RequestId; detectionResult.ConfirmedMalwares = detectedFiles; detectionResult.WorkStatus = WorkStatus.ConfirmedMalware; } else { detectionResult.WorkStatus = WorkStatus.Clean; } ScanResults.Value.TryAdd(request.RequestId, detectionResult); } }
public ReportViewModel(MalwareDeterminationResult result) { Result = result; }