Thanks for ur reply.
Actually I am creating an antivirus using MD5 hasher. Now it uses hashe (file signatures) and compares the hexadecimal signatures of the files scaned to the virus list. if these signatures found same so mean virus exists, other wise no virus.
i am making "Clean" button to repair the virus effected file.
E.g;
original file A=(1,2,3)
Efected File A=(1,2,4)
Repair file A=(1,2,3) means to recover 4 to 3....
now, this can only be done when i have both info that what is effected file current hash code and what was its original hash code. then replace current hash code with original... actually i m new to vb.net, so have too much trouble...
i am adding code of Custom Scan, Delete, Delete All, Timer1 and Timer 2.
Custome Scan
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
FolderBrowserDialog1.ShowDialog()
ListBox1.Items.Clear()
ListBox2.Items.Clear()
TabControl1.SelectTab(1)
'Enabling Buttons
'Button8.Enabled = True
'Button9.Enabled = True
'Button10.Enabled = True
Try
For Each strDir As String In
System.IO.Directory.GetDirectories(FolderBrowserDialog1.SelectedPath)
For Each strFile As String In System.IO.Directory.GetFiles(strDir)
ListBox1.Items.Add(strFile)
Next
Next
Catch ex As Exception
End Try
Timer1.Start()
End Sub
Delete
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Try
Kill(ListBox2.SelectedItem)
ListBox2.Items.Remove(ListBox2.SelectedItem)
MsgBox("Threat Was Removed Successfully!", MsgBoxStyle.Information)
Catch ex As Exception
End Try
End Sub
delete All
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Timer2.Start()
End Sub
Timer 2
Try
If Not ListBox2.Items.Count = 0 Then
ListBox2.SelectedIndex += 1
Kill(ListBox1.SelectedItem)
ListBox2.Items.Remove(ListBox2.SelectedItem)
Else
Timer1.Stop()
Timer2.Stop()
MsgBox("Threat Was Removed Successfully!", MsgBoxStyle.Information)
End If
Catch ex As Exception
End Try
End Sub
Timer 1
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
ProgressBar1.Maximum = Conversions.ToString(ListBox1.Items.Count)
total.Text = Conversions.ToString(ListBox1.Items.Count)
If Not ProgressBar1.Value = ProgressBar1.Maximum Then
Try
ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1
TextBox1.Text = ListBox1.SelectedItem.ToString
Catch ex As Exception
End Try
Try
Dim scanbox As New TextBox
Dim read As String = My.Computer.FileSystem.ReadAllText("viruslist.txt")
ProgressBar1.Increment(1)
detected.Text = Conversions.ToString(ListBox2.Items.Count)
files.Text = Conversions.ToString(ProgressBar1.Value)
scanbox.Text = read.ToString
Dim md5 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
Dim f As FileStream = New FileStream(ListBox1.SelectedItem, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
f = New FileStream(ListBox1.SelectedItem, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
md5.ComputeHash(f)
Dim hash As Byte() = md5.Hash
Dim buff As StringBuilder = New StringBuilder
Dim hashByte As Byte
For Each hashByte In hash
buff.Append(String.Format("{0:X2}", hashByte))
Next
If scanbox.Text.Contains(buff.ToString) Then
ListBox2.Items.Add(ListBox1.SelectedItem)
End If
Catch ex As Exception
End Try
Else
Timer1.Stop()
MsgBox("Finished Scanning Folder!")
TabControl1.SelectTab(2)
If ListBox1.Items.Count = 0 Then
MsgBox("No Threats were detected, Scan Window will close!", MsgBoxStyle.Information)
End If
End If
End Sub
hope it will help u...
Do you use binary readers to read the file and the guide signatures?
Are always both o the same length?
Do you have a CompareSignatures function to retrieve if the guide signature is the
file signature?
Do you have a ReplaceSignature function?
How do you remove from memory a file already loaded to change their signature?
Just a comment on your delete all process. Lets do an example:
You have 3 Items in the ListBox.
The first Item is the 0, the second is 1 and the third is 2.
You select the first Item 0, kill the file and remove the item from the ListBox.
Actually you'll have 2 Itmes, 0 and 1, then you select the next (+1) SelectedIndex. This will be the 1. and kill the file an remove from the listbox.
Actually you'll have 1 Itmes, 0, then you select the next (+1) SelectedIndex. This will be the 2, probaly throwing an exception.
I would suggest to cicle the SelectecIndex from Items.Count-1 to 0 step -1 to avoid this error.
Hope this helps