Как отредактировать мой код, чтобы он делал то, что я хочу (объяснено ниже)
So ive got some code ill put at the end. basically my program scans files and and if any of the md5 hashes match a list of md5 hashes from a text file. It works but basically what i want to do is inside the text file with md5 hashes, under earch md5 hash i want to put for example (win 32 genic) and then if my tool finds a virus i want in a label it to show the line below (so if in the database is the hash 1234 and underneath the 1234 hash is win32genic and nothing else. so if a file with the same hash is found it will show in a label win32genic. Below is the existing code without the label win 32 genic thing does anyone know how i can add the feature i was talking about?
Private Sub TimerStart() Dim LimitReached As Boolean = Me.InvokeIfRequired(Function() ProgressBar1.Value = ProgressBar1.Maximum) 'Keep looping until limit is reached. While Not LimitReached 'InvokeIfRequired() can take multiple lines. Me.InvokeIfRequired( Sub() ProgressBar1.Maximum = ListBox1.Items.Count.ToString() 'Calling ToString() is much better than Conversions.ToString(). total.Text = ListBox1.Items.Count.ToString() End Sub) 'End of InvokeIfRequired(). 'Check if the limit is reached. LimitReached = Me.InvokeIfRequired(Function() ProgressBar1.Value = ProgressBar1.Maximum) If Not LimitReached Then Me.InvokeIfRequired( Sub() Try ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1 Label1.Text = ListBox1.SelectedItem.ToString Catch ex As Exception End Try End Sub) Try Dim scanbox As String 'This should be a String, NOT a TextBox. Dim read As String = My.Computer.FileSystem.ReadAllText(Application.StartupPath & "\Database\VirusList.dat") Me.InvokeIfRequired( Sub() ProgressBar1.Increment(1) detected.Text = Quarantine.ListBox2.Items.Count.ToString() 'Again, use .ToString(), not Conversions.ToString(). Label5.Text = String.Format("{0:F2}%", ((ProgressBar1.Value / ProgressBar1.Maximum) * 100)) files.Text = ProgressBar1.Value.ToString() End Sub) scanbox = read.ToString Dim md5 As New MD5CryptoServiceProvider 'Shortened to "As New" instead of "As ... = New ..." 'IMPORTANT: Wrap all streams in "Using .../End Using". This will ensure that the stream is closed and the file handle is released. Using f As New FileStream(ListBox1.SelectedItem, FileMode.Open, FileAccess.Read, FileShare.Read, 8192) 'Again, shortened to "As New". 'REMOVED: You were setting "f = New FileStream..." two times. Not a good thing to do. md5.ComputeHash(f) Dim hash As Byte() = md5.Hash Dim buff As New StringBuilder '"As New". 'This line is irrelevant: "Dim hashByte As Byte". For Each hashByte As Byte In hash buff.Append(String.Format("{0:X2}", hashByte)) Next If scanbox.Contains(buff.ToString) Then Me.InvokeIfRequired(Sub() f.Dispose()) Me.InvokeIfRequired(Sub() EncryptFile()) Me.InvokeIfRequired(Sub() Quarantine.ListBox2.Items.Add(ListBox1.SelectedItem())) Me.InvokeIfRequired(Sub() WriteToLog("File Quarantined:" + ListBox1.SelectedItem)) End If End Using 'Close the FileStream. Catch ex As Exception End Try Else 'REMOVED: "Timer1.Stop()" is no longer needed. Me.InvokeIfRequired( Sub() If CheckBox1.Checked = True Then System.Diagnostics.Process.Start("shutdown", "-s -t 00") Else ProgressBar1.Value = 0 If ListBox1.Items.Count = 0 Then If Form1.CheckBox1.Checked = True Then full.CancelAsync() quick.CancelAsync() Critical.CancelAsync() cust.CancelAsync() End If Else Form1.CheckBox1.Checked = False Form1.CheckBox2.Checked = False Form1.CheckBox3.Checked = False Form1.CheckBox4.Checked = False Quarantine.Label3.ForeColor = Color.DarkRed Quarantine.Label2.ForeColor = Color.DarkRed full.CancelAsync() quick.CancelAsync() Critical.CancelAsync() cust.CancelAsync() End If End If End Sub) 'End of InvokeIfRequired(). End If 'Do some more background stuff... End While End Sub
Что я уже пробовал:
я ничего не пробовал, так как действительно не знаю, с чего начать. Я гуглю, но, кажется, могу найти все, что мне нужно. (кстати, мне это нужно vb.net)
Richard MacCutchan
Вы продолжаете перепечатывать этот вопрос, но на самом деле не добиваетесь прогресса из-за вашего непонимания того, что на самом деле делает вирус. Использование любой формы сравнения хэшей не даст вам ответа.