Что не так с моим кодом? Vb.net
привет всем я так запутался у меня есть этот код :
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 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) Dim SHA256 As New SHA256CryptoServiceProvider '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. SHA256.ComputeHash(f) Dim hash As Byte() = SHA256.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 Dim MyFilesList As String() = Directory.GetFiles(Application.StartupPath & "\Database\Sigs\Sha1\", "*.txt") Dim FoundedSearch As New List(Of String)() For Each filename As String In MyFilesList Dim textFile As String = File.ReadAllText(filename) If textFile.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 Next 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
И
Dim SHA256 As New SHA256CryptoServiceProviderбыл md5, и он работал и сканировал список хэшей md5, но теперь я хочу сделать sha256, и я использовал список хэшей sha256, и он не обнаруживает файл(файл-это тот же самый хэш, который я проверил с помощью virus total)
Что я уже пробовал:
как вы можете видеть выше, я попытался изменить его на sha256-единственное, что мне нужно изменить, но нет, не работает. :-(