为十六进制值创建搜索栏

时间:2014-10-29 15:02:45

标签: vb.net hex bytearray

我当前的代码要求我在项目仍处于VB时编辑搜索值。我无法弄清楚如何编码输入值以使用文本框进行搜索。我真的希望能够构建这个项目并在不打开VB的情况下使用它。以下是我的代码:

Dim filePath As String = Me.TextBox1.Text 'The path for the file you want to search
    Dim fInfo As New FileInfo("C:\MyFile.File")
    Dim numBytes As Long = fInfo.Length
    Dim fStream As New FileStream("C:\MyFile.File", FileMode.Open, FileAccess.Read)
    Dim br As New BinaryReader(fStream)
    Dim data As Byte() = br.ReadBytes(CInt(numBytes))
    Dim pos As Integer = -1
    Dim searchItem As String = "b6" 'The hex values of what you want to search
    Dim searchItemAsInteger As Integer
    Dim locationsFound As New List(Of Integer)
    MessageBox.Show("Wait while I Scan?")
    br.Close()
    fStream.Close()
    Integer.TryParse(searchItem, Globalization.NumberStyles.AllowHexSpecifier, CultureInfo.CurrentCulture, searchItemAsInteger)

    For Each byteItem As Byte In data
        pos += 1
        If CInt(byteItem) = searchItemAsInteger Then
            locationsFound.Add(pos)
            Me.ListBox1.Items.Add(Hex(pos))
        End If
    Next
    For i As Integer = 0 To Me.ListBox1.Items.Count - 1
        Me.ListBox1.SetSelected(i, True)
    Next

End Sub

1 个答案:

答案 0 :(得分:0)

放置一个名为" txtHexValueToSearch"的文本框在Form1中。然后替换注释的代码:

' Dim searchItem As String = "b6" 'The hex values of what you want to search
Dim searchItem As String = Me.txtHexValueToSearch.Text 'The hex values of what you want to search