public void ScanFile(string filePath) { ThreadPool.QueueUserWorkItem(async i => { var scanJob = new ScanJob(filePath); Task <InfoModel> infoModel = VirusTotalScanner.ScanFile(scanJob); List <YaraResult> yaraResults = new List <YaraResult>(); string scanMessage = null; try { yaraResults = YaraScanner.ScanFile(scanJob); } catch (Exception e) { scanMessage = e.Message; } InfoModel model = await infoModel; model.YaraResults = yaraResults; // Check if virus total throw error model.Date = DateTime.Now; if (model.ScandId == null) { byte[] modelToBytes = Encoding.UTF8.GetBytes(model.GetHashCode().ToString()); model.SHA1 = HashHandler.ComputeSha1Hash(modelToBytes); model.SHA256 = HashHandler.ComputeSha256Hash(modelToBytes); model.ScandId = model.SHA256; model.FilePath = scanJob.mFilePath; model.Positives = 0; model.Total = 0; model.ReportTag = Tag.WARNING; } else { if (model.Positives == 0 && model.YaraResults.Count == 0) { model.ReportTag = Tag.OK; } else if (model.Positives == 0 && model.YaraResults.Count > 0) { model.ReportTag = Tag.WARNING; } else { model.ReportTag = Tag.DANGER; } } if (scanMessage != null) { model.Messages.Add(scanMessage); } foreach (IListener listener in GetListeners().Keys) { listener.OnFileScanned(model); } }); }
public void ComputeSha256Hash_AreEqual_True() { string Input = "cryptographic hash functions"; string ExpectedOutput = "b8921348ed613a01d5ace11c754f459214b6f81d5e7937354c561eb25fb9e7ce"; string Output = HashHandler.ComputeSha256Hash(Input); string ErrorFeedback = $"Incorrect Values: Expected - {ExpectedOutput}, Received - {Output} "; Assert.AreEqual(ExpectedOutput, Output, ErrorFeedback); }
public void Node_ManualSetCheck_Equal() { Node L1 = new Node(); Node L2 = new Node(); Node L1_L2 = new Node(); Node L3 = new Node(); Node L4 = new Node(); Node L3_L4 = new Node(); Node MerkleRoot = new Node(); //Set Values L1.Value = HashHandler.ComputeSha256Hash("test1"); L2.Value = HashHandler.ComputeSha256Hash("test2"); string test = L1.Value + L1.Value; L1_L2.Value = HashHandler.ComputeSha256Hash(L1.Value + L1.Value); L3.Value = HashHandler.ComputeSha256Hash("test4"); L4.Value = HashHandler.ComputeSha256Hash("test5"); L3_L4.Value = HashHandler.ComputeSha256Hash(L3.Value + L4.Value); MerkleRoot.Value = HashHandler.ComputeSha256Hash(L1_L2.Value + L3_L4.Value); //Set Left & Right Nodes L1_L2.Left = L1; L1_L2.Right = L2; L3_L4.Left = L3; L3_L4.Right = L4; MerkleRoot.Left = L1_L2; MerkleRoot.Right = L3_L4; //Verify Values string ExpectedL1Value = "1b4f0e9851971998e732078544c96b36c3d01cedf7caa332359d6f1d83567014"; string ExpectedL2Value = "60303ae22b998861bce3b28f33eec1be758a213c86c93c076dbe9f558c11c752"; string ExpectedL1L2Value = "98866d999ba299056e0e79ba9137709a181fbccd230d6d3a6cc004da6e7bce83"; string ExpectedL3Value = "a4e624d686e03ed2767c0abd85c14426b0b1157d2ce81d27bb4fe4f6f01d688a"; string ExpectedL4Value = "a140c0c1eda2def2b830363ba362aa4d7d255c262960544821f556e16661b6ff"; string ExpectedL3L4Value = "e6a5f59435aef23f707527906a695fc6efcf12eea365eec4020e763e94efe8e7"; string ExpectedRootValue = "7f9878cb4a60aceec0bad755a979b015f415196c69be854629cb5db4e6661aae"; Assert.AreEqual(ExpectedL1Value, L1.Value); Assert.AreEqual(ExpectedL2Value, L2.Value); Assert.AreEqual(ExpectedL1L2Value, L1_L2.Value); Assert.AreEqual(ExpectedL3Value, L3.Value); Assert.AreEqual(ExpectedL4Value, L4.Value); Assert.AreEqual(ExpectedL3L4Value, L3_L4.Value); Assert.AreEqual(ExpectedRootValue, MerkleRoot.Value); //Verify if the Object Reference is the same Assert.AreSame(L1, L1_L2.Left); Assert.AreSame(L2, L1_L2.Right); Assert.AreSame(L3, L3_L4.Left); Assert.AreSame(L4, L3_L4.Right); Assert.AreSame(L1_L2, MerkleRoot.Left); Assert.AreSame(L3_L4, MerkleRoot.Right); }