需要帮助来优化此代码! [英] Need Help to Optimize this code please!
问题描述
当前,我正在使用此代码检查我的文件系统中是否存在错误的哈希值,但需要知道是否有更好的方法来实现它,以使扫描速度恢复正常.
Currently I am using this code to check my filesystem for bad hashes but need to know if there is a better way to implement it so that my scanning speeds return to normal.
Dim Vname As String = "Infected!! "
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 = mdsc(fs.FullName)
LabelX11.Text = GetCRC32(fs.FullName)
LabelX13.Text = getSHA1Hash(fs.FullName)
LabelX14.Text = getSHA512(fs.FullName)
If My.Computer.FileSystem.ReadAllText("Master MD5 SIG.txt").Contains(LabelX12.Text)Then
CheckedComboBoxEdit1.Properties.Items.Add(Vname + fs.FullName)
CheckedComboBoxEdit1.Text = "!!Attention Infection(s) Found!!"
lblVirus.Text = "(Virus) " & CheckedComboBoxEdit1.Properties.Items.Count
Else
If My.Computer.FileSystem.ReadAllText("MASTER CRC 32 .txt").Contains(LabelX11.Text) Then
CheckedComboBoxEdit1.Properties.Items.Add(Vname + fs.FullName)
CheckedComboBoxEdit1.Text = "!!Attention Infection(s) Found!!"
lblVirus.Text = "(Virus) " & CheckedComboBoxEdit1.Properties.Items.Count
Else
If My.Computer.FileSystem.ReadAllText("SHA1Sig.txt").Contains(LabelX13.Text) Then
CheckedComboBoxEdit1.Properties.Items.Add(Vname + fs.FullName)
CheckedComboBoxEdit1.Text = "!!Attention Infection(s) Found!!"
lblVirus.Text = "(Virus) " & CheckedComboBoxEdit1.Properties.Items.Count
Else
If My.Computer.FileSystem.ReadAllText("SHA512Sig.txt").Contains(LabelX14.Text) Then
CheckedComboBoxEdit1.Properties.Items.Add(Vname + fs.FullName)
CheckedComboBoxEdit1.Text = "!!Attention Infection(s) Found!!"
lblVirus.Text = "(Virus) " & CheckedComboBoxEdit1.Properties.Items.Count
End If
End If
End If
End If
如果有人可以告诉我如何缩短它或使其更有效,那将大有帮助!
预先谢谢您
If anyone could tell me how to shorten this or make it more efficient, it would greatly help!
Thank you in advance
推荐答案
因此,您正在扫描"的每个文件上读取整个哈希文件表?难怪它这么慢.
您可以一次加载has表,并将所有数据保留在内部表中,并可能通过哈希码进行排序,以加快查找速度.
So, you''re reading your entire hash file tables on every file you''re "scanning"? No wonder it''s so slow.
You load the has tables ONCE and keep all that data in an internal table, proabably sorted by hash code to make lookups faster.
1.问题可能出在
.ReadAllText
方法中,该方法未通过定义进行优化.
您可以尝试使用
method which is not optimized by definition.
You may try to use
StreamReader.ReadLine
方法.看看这个讨论. br/>
即使在非常大的文本文件上(我已测试),建议的代码也可以快速运行.
2.检查 ClamWin防病毒软件的开放源代码并阅读有关它的文章可能会很有用. : Hash-AV:来自Stanford.edu的快速病毒签名扫描.
method. Take a look at this discussion.
The proposed there code runs fast even on a very large text files (i tested).
2. It may be useful to check an open source code of ClamWin antivirus and read the article about it: Hash-AV: Fast Virus Signature Scanning from Stanford.edu.
这篇关于需要帮助来优化此代码!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!