Draco1985 0 Newbie Poster

Hopefully I have come to the right place to ask this question as it has had me stuck for some time now. The complexity of my problem makes it difficult to ask but I will do my best to state my problem as best I can with a few questions as I go along to clarify the issue. I am making an anti-virus Software that scans by means of MD5 hash with the use of a tree-view control. Is it possible to scan the nodes folders and sub-folders to check MD5 hash values for virus signatures? I will supply the code I am working on in hopes that someone here can tell me where I have gone wrong.....

view source
print?
01 Dim md5hashtree As String = DirTree1.SelectedNode.Text
02 Try
03 Using scanbox As New TextBox()
04 Dim read As String = My.Computer.FileSystem.ReadAllText("virusSig.txt")
05 detected.Text = Conversions.ToString(CheckedListBox1.Items.Count)
06 scanbox.Text = read.ToString
07 Using md5 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider()
08 Dim f As FileStream = New FileStream(md5hashtree, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
09 f = New FileStream(md5hashtree, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
10 md5.ComputeHash(f)
11 Dim hash As Byte() = md5.Hash
12 Dim buff As StringBuilder = New StringBuilder()
13 Dim hashByte As Byte
14 For Each hashByte In hash
15 buff.Append(String.Format("{0:X2}", hashByte))
16 Next
17 If scanbox.Text.Contains(buff.ToString) Then
18 CheckedListBox1.Items.Add(md5hashtree)
19 End If
20 End Using
21 End Using
22 Catch ex As Exception
23 End Try

This code works great if md5hashtree is replaced with listview1.selecteditem but I need it to compare my VirusSig.txt file to the current dirtreeview.selectednode in my treeview.

In my earlier program this code is placed into a timer and then that timer is started in the start button but how and where should I add the code to this sub??

view source
print?
01 Public Sub ScanScanner(ByVal dir As String)
02
03 Try
04 With My.Computer.FileSystem
05 Application.DoEvents()
06 If stop_Scan = True Then
07 Exit Sub
08 End If
09 For Each file1 In .GetFiles(dir)
10 If stop_Scan = True Then
11 cmdStartScanning.Enabled = True
12 Exit Sub
13 End If
14 txtScanningNow.Text = file1
15 If gt_extension_zip(IO.Path.GetExtension(file1)) = True Then
16 End If
17 Dim fi As FileInfo = New FileInfo(file1)
18 Call getmyfileatr(file1)
19 Dim fileDetail As IO.FileInfo
20 fileDetail = My.Computer.FileSystem.GetFileInfo(file1)
21 lblSizef.Text = fileDetail.Length & " byte(s)"
22 a1 = 0
23 a1 = (DateTime.Now.Millisecond)
24 a3 = 0
25 a3 = (DateTime.Now.Second)
26 Dim StartTime As New DateTime()
27 Dim EndTime As New DateTime()
28 StartTime = DateTime.Now()
29 txtScanningNow.Text = file1
30 f1 = 0
31 f2 = 0
32 a2 = 0
33 a2 = (DateTime.Now.Millisecond)
34 a4 = 0
35 a4 = (DateTime.Now.Second)
36 If a2 >= a1 Then
37 f1 = a2 - a1
38 End If
39 If a4 >= a1 Then
40 f2 = a4 - a3
41 End If
42 EndTime = DateTime.Now
43 Dim answer1, answer2 As Long
44 answer1 = 0
45 answer1 = EndTime.Ticks() - StartTime.Ticks()
46 txtTime.Text = String.Format("{0}.{1}.{2}", f2, f1, answer1)
47 txtTime.Refresh()
48 Next file1
49 ' Search child directories.
50 For Each folder As Object In .GetDirectories(dir)
51 txtScanningNow.Text = folder
52 ScanScanner(folder)
53 Next folder
54 End With
55 Catch ex As UnauthorizedAccessException
56 End Try
57 Exit Sub
58 End Sub

If anyone knows how to use treeview to scan folders, subfolders and files for MD5 hash I am all ears......

Thank you very much in advance and hope to hear from someone soon.. :)