Click here to Skip to main content
16,005,682 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am confused about the functions of the hash table. I would like to add the contents of my txt file to the hash table. The contents of the txt file is MD5 hashes and even though it seems to be working there are some known virus files such as the eicar test file which is no longer detected for some reason.

this is the code I have wrote so far

VB
Dim Hashdatabase As New Hashtable
Dim md5Compare As New TextBox
Dim md5textload as new textbox
Dim labelX12 As New Label
Dim labelX13 As New Label

MD5Textload.text = my.computer.filesystem.readalltext("Sig.txt")
Hashdatabase.Contains(MD5Textload.Text)
md5Compare.Text = Hashdatabase.Values.ToString

Try
            With My.Computer.FileSystem
                If stop_Scan = True Then
                    Exit Sub
                End If
                For Each file1 In System.IO.Directory.GetFiles(dir)
                    Dim fs As New FileInfo(file1)
                    labelX12.Text = getMd5Hash(fs.FullName)
                    labelX13.Text = getSHA1Hash(fs.FullName)
                    If md5Compare.Text.Contains(labelX12.Text) Then
                        CheckedListBox1.Items.Add(fs.FullName)
                        CheckedListBox1.Text = "!!Attention Infection(s) Found!!"
                        lblvirus.Text = CheckedListBox1.Items.Count





Can someone please tell me if I am adding the text file to hashtable incorrectly? if so how can I do this so that it works?
Posted
Comments
Timberbird 2-Sep-11 2:20am    
Is it your complete code? Because I cannot see anything being added to hashtable :)
Dale 2012 2-Sep-11 2:54am    
MD5Textload.text = my.computer.filesystem.readalltext("Sig.txt")
Hashdatabase.Contains(MD5Textload.Text)

this is not the full code but I felt it was enough to try and show what I am trying to do. The "sig.txt" is the text file that I am trying to load into the md5hashtable so I have dim the MD5Textload.text to load all the md5textload textbox which is easy enough. then I say Hashdatabase.Contains(MD5Textload.Text) hoping that it will take what is in the md5textload and add its contents to the hashtable. then I say md5compare.text = the contents of the hashtable so if the current computer file being scanned matches the values in the hashtable to add it to the checkedlistbox as a potential threat.
Timberbird 2-Sep-11 3:25am    
And does md5compare get filled after Hashdatabase.Contains(MD5Textload.Text)? If it does, that's strange, because nothing in Contains() method description declares it can load anything into hashtable

1 solution

You are confusing two different topics together:

1. HashTables are in memory data structures not file based.

2. MD5 cryptographic hash functions compute a result based on the input to the function


I presume you want to create a "virus checking system" to detect changes to files.

1. You need disk based storage for the filename and md5 hash results as you cannot keep them all in memory and it would be time consuming to go through them all every time.

2. You need an optimal way of extracting data from that storage system.

For this check my RaptorDB code as it is a disk based hash storage system
 
Share this answer
 
Comments
Dale 2012 2-Sep-11 5:00am    
Thank you very very much for this as it seems very in depth. How may I implement this raptorBD into my problem? would you be willing to ever look at the program I have to offer in hopes that you may help in some areas that will otherwise take me weeks to understand? or even months! lol I would like to get some seemingly simple issues out of the way and know that you know how to. If I need to hire your services would that be an option?
Dale 2012 2-Sep-11 5:13am    
I have also taken the time to read everything I can about this but have no idea how to add this to my program. I have tried to load it but it has no target exe and of course fails. Please advise
Mehdi Gholam 2-Sep-11 5:29am    
RaptorDB is a disk based dictionary. You can use it like the following :

string val = "";
if(rap.Get(filename, out val))
{
string md5 = getmd5forfile(filename);
if(val != md5) --> handle not equals
}
else
{
// not found in dictionary
rap.Set(filename, getmd5forfile(filename));
}


Dale 2012 2-Sep-11 18:21pm    
i have converted the raptor database that you have lead me to but there are 44 errors which are small but its hard for me to know what the variables are without the knowledge of what each section does. my I please email you the VB.Net conversion in hopes you can quickly resolve the syntax errors?. Thank you
Mehdi Gholam 2-Sep-11 20:46pm    
Arrgh, you don't need to convert raptordb to vb, just build the project as is then include the dll as a reference in your vb.net project.

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