如何编辑我的代码使它做我想要的(下面解释) [英] How to edit my code to make it do what I want (explained below)

查看:64
本文介绍了如何编辑我的代码使它做我想要的(下面解释)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我最后得到了一些代码。基本上我的程序扫描文件,如果任何md5哈希值匹配文本文件中的md5哈希列表。它的工作原理,但基本上我想要做的是在文本文件中使用md5哈希,在earch md5哈希我想举例如(win 32 genic)然后如果我的工具发现病毒我想在标签中显示下面的行(所以如果在数据库中是哈希1234并且在1234哈希下面是win32genic而没有别的。所以如果找到具有相同哈希的文件,它将显示在标签win32genic。下面是没有标签win的现有代码32 genic thing有谁知道如何添加我正在谈论的功能?







So ive got some code ill put at the end. basically my program scans files and and if any of the md5 hashes match a list of md5 hashes from a text file. It works but basically what i want to do is inside the text file with md5 hashes, under earch md5 hash i want to put for example (win 32 genic) and then if my tool finds a virus i want in a label it to show the line below (so if in the database is the hash 1234 and underneath the 1234 hash is win32genic and nothing else. so if a file with the same hash is found it will show in a label win32genic. Below is the existing code without the label win 32 genic thing does anyone know how i can add the feature i was talking about?



Private Sub TimerStart()

       Dim LimitReached As Boolean = Me.InvokeIfRequired(Function() ProgressBar1.Value = ProgressBar1.Maximum)

       'Keep looping until limit is reached.
       While Not LimitReached

           'InvokeIfRequired() can take multiple lines.
           Me.InvokeIfRequired(
           Sub()
               ProgressBar1.Maximum = ListBox1.Items.Count.ToString() 'Calling ToString() is much better than Conversions.ToString().
               total.Text = ListBox1.Items.Count.ToString()
           End Sub) 'End of InvokeIfRequired().

           'Check if the limit is reached.
           LimitReached = Me.InvokeIfRequired(Function() ProgressBar1.Value = ProgressBar1.Maximum)

           If Not LimitReached Then

               Me.InvokeIfRequired(
               Sub()
                   Try
                       ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1
                       Label1.Text = ListBox1.SelectedItem.ToString
                   Catch ex As Exception
                   End Try
               End Sub)

               Try

                   Dim scanbox As String 'This should be a String, NOT a TextBox.
                   Dim read As String = My.Computer.FileSystem.ReadAllText(Application.StartupPath & "\Database\VirusList.dat")

                   Me.InvokeIfRequired(
               Sub()
                   ProgressBar1.Increment(1)
                   detected.Text = Quarantine.ListBox2.Items.Count.ToString() 'Again, use .ToString(), not Conversions.ToString().
                   Label5.Text = String.Format("{0:F2}%", ((ProgressBar1.Value / ProgressBar1.Maximum) * 100))
                   files.Text = ProgressBar1.Value.ToString()
               End Sub)

                   scanbox = read.ToString
                   Dim md5 As New MD5CryptoServiceProvider 'Shortened to "As New" instead of "As ... = New ..."

                   'IMPORTANT: Wrap all streams in "Using .../End Using". This will ensure that the stream is closed and the file handle is released.
                   Using f As New FileStream(ListBox1.SelectedItem, FileMode.Open, FileAccess.Read, FileShare.Read, 8192) 'Again, shortened to "As New".

                       'REMOVED: You were setting "f = New FileStream..." two times. Not a good thing to do.
                       md5.ComputeHash(f)
                       Dim hash As Byte() = md5.Hash
                       Dim buff As New StringBuilder '"As New".
                       'This line is irrelevant: "Dim hashByte As Byte".
                       For Each hashByte As Byte In hash
                           buff.Append(String.Format("{0:X2}", hashByte))
                       Next

                       If scanbox.Contains(buff.ToString) Then

                           Me.InvokeIfRequired(Sub() f.Dispose())
                           Me.InvokeIfRequired(Sub() EncryptFile())
                           Me.InvokeIfRequired(Sub() Quarantine.ListBox2.Items.Add(ListBox1.SelectedItem()))
                           Me.InvokeIfRequired(Sub() WriteToLog("File Quarantined:" + ListBox1.SelectedItem))
                       End If
                   End Using 'Close the FileStream.

               Catch ex As Exception
               End Try
           Else
               'REMOVED: "Timer1.Stop()" is no longer needed.

               Me.InvokeIfRequired(
               Sub()
                   If CheckBox1.Checked = True Then
                       System.Diagnostics.Process.Start("shutdown", "-s -t 00")
                   Else
                       ProgressBar1.Value = 0
                       If ListBox1.Items.Count = 0 Then
                           If Form1.CheckBox1.Checked = True Then
                               full.CancelAsync()
                               quick.CancelAsync()
                               Critical.CancelAsync()
                               cust.CancelAsync()
                           End If
                       Else
                           Form1.CheckBox1.Checked = False
                           Form1.CheckBox2.Checked = False
                           Form1.CheckBox3.Checked = False
                           Form1.CheckBox4.Checked = False
                           Quarantine.Label3.ForeColor = Color.DarkRed
                           Quarantine.Label2.ForeColor = Color.DarkRed
                           full.CancelAsync()
                           quick.CancelAsync()
                           Critical.CancelAsync()
                           cust.CancelAsync()

                       End If
                   End If
               End Sub) 'End of InvokeIfRequired().
           End If
           'Do some more background stuff...
       End While


   End Sub





我尝试了什么:



i没有尝试任何东西,因为我真的不知道从哪里开始。我谷歌但我似乎找到了我需要的任何东西。 (顺便说一下,我需要在vb.net中)



What I have tried:

i havent tried anything as im really not sure where to start from. Ive google but i can seem to find anything that i need. (btw i need it in vb.net)

推荐答案

你确实知道如果病毒更改了文件,生成的文件的MD5哈希将与签名对于任何特定病毒?

当您散列文件时,您生成的值取决于文件的总内容。当病毒更改文件时,新MD5值取决于更改文件的总内容,而不是仅更改位。



例如,如果哈希算法(为了简单起见)将字节加起来并丢弃任何单个字节值的执行然后如果两个文件像这样开始(简单的十六进制值)

You do realize that if a virus changes a file, the MD5 hash for the resulting file will not match the "signature" for any specific virus?
When you hash a file, you generate a value which is dependant on the the total contents of the file. When a virus changes a file, the new MD5 value is dependant on the total content of the changed file, not "just the changed bit".

For example, if the hash algorithm is (for the sake of simplicity) "add up the bytes and throw away any carry out of a single byte value" then if a two files start out like this (hex values for simplicity)
File 1: 01 02 03 04    Hash == 0A hex.
    File 2: 21 22 23 24    Hash == 8A hex.

假设病毒总是将第二个字节更改为十六进制14:

Suppose the virus always changes the second byte to hex 14:

File 1: 01 14 03 04    Hash == 1C hex.
File 2: 21 14 23 24    Hash == 7C hex.

哈希值已经改变,你可以检测到,但你不能说它是#2Is14病毒通过查看新的哈希值。

实际上它可能是#3Is15病毒:

The hash values have changed, and you can detect that, but you can't say "it was #2Is14 virus" just by looking at the new hashes.
In fact it could be "#3Is15 virus":

File 1: 01 02 15 04    Hash == 1C hex.
File 2: 21 22 15 24    Hash == 7C hex.

哪个生成相同的哈希值!



你不能使用用于标识病毒感染文件的哈希值:您只能使用它来检测自上次扫描以来已更改的文件,并且该更改可能是病毒活动的结果。

Which generates the same hash values!

You cannot use hash values to identify a virus infected file: you can only use it to detect a file that has been changed since the last scan, and that change may be as a result of virus activity.


这篇关于如何编辑我的代码使它做我想要的(下面解释)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆