Click here to Skip to main content
15,885,741 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am creating an antivirus program, my problem is,I need to load text file to my textbox in order to know if my antivirus detected a virus. It basically searches for the given string in the textbox and if it matches then it found a virus using the FIleSystemWatcher. The problem is it takes a lot of time to load and it consumes a lot of RAM, is there a way that I don't have to load the entire textfile to textbox, but to cache the textfile to memory that I my application can read it from there to detect a virus. OR maybe I can buid just Embed the TextFile to my Resourcces section and Read it from there? Heres my code:


Loading frm


Using reader As System.IO.StreamReader = New System.IO.StreamReader("Virusdatabase.txt")
VirusdatabaseTextbox.Text = reader.ReadToEnd()
End Using

FIlesystemwatcher code: Event Created
VB
Try
            Me.OpenFileDialog1.FileName = ""
            Dim md5 As New MD5CryptoServiceProvider
            Dim f As New FileStream(e.FullPath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite, &H2000)
            f = New FileStream(e.FullPath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite, &H2000)
            md5.ComputeHash(f)
            Dim hash As Byte() = md5.Hash
            Dim buff As New StringBuilder
            Dim hashByte As Byte
            For Each hashByte In hash
                buff.Append(String.Format("{0:X2}", hashByte))
            Next
            f.Close()
            If VirusdatabaseTextbox.Text.Contains(buff.ToString) Then 'Heres the comparison string to detect a virus
                Me.OpenFileDialog1.FileName = e.FullPath
				MessageBox.Show("Virus Detected! FilePath: ")
            End If

        Catch exception1 As Exception
            ProjectData.SetProjectError(exception1)
            Dim ex As Exception = exception1
            ProjectData.ClearProjectError()
        End Try


Thank You
Posted
Comments
ZurdoDev 27-Dec-13 20:42pm    
I believe anti-virus programs work at a much lower level than that. I don't think this is the right approach. I also don't know what is though.
Sergey Alexandrovich Kryukov 27-Dec-13 21:02pm    
Virus should not be detected on the text data. You need to read binary data. Anyway, this way of detecting viruses is way too naive.
—SA
sora97 27-Dec-13 21:31pm    
I am using MD5 to detect viruses, I cant do much anything in detecting viruses in VB.net, but I am still learning to program in C++, so is there a way to load up te virus datbase to textboxwithout consuming RAM o..
Sergey Alexandrovich Kryukov 27-Dec-13 22:00pm    
I don't know how your virus database is designed, but nothing in virus definitions or files tested for infection could be string. Just forget the notion of string, work only with binary data (arrays of bytes).
—SA
Ron Beyer 27-Dec-13 21:50pm    
Why use textbox if your program is just searching for some string in it? Why even load the entire file? Just use a file stream and search in the file directly... I doubt the data in the textbox, being so large, is of any interest to the user, unless I'm not understanding what the textbox is for.

1 solution

If all you're doing is searching a text file for a string, why are you even loading it into a TextBox?? Don't.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900