[RESOLVED] Help with Function
I found this code and I think it could be useful for some members. The code search for the specified bytes in jpg file and when first match is founded msgbox gives you position of the bytes in the file and Function stops.
Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim B() As Byte = My.Computer.FileSystem.ReadAllBytes("C:\users\Public\SIMG1374.jpg")
Dim C() As Byte = {164, 114, 78, 88, 245, 164, 83, 158, 43}
Dim P As Integer = ByteMatch(B, C)
If P = -1 Then MsgBox("No Match") Else MsgBox("Matched at " & P.ToString)
End Sub
Function ByteMatch(ByVal Source As Byte(), ByVal Match As Byte()) As Integer
For I As Integer = 0 To Source.Count - 1
Dim Matched As Boolean = False
If Match(0) = Source(I) Then
For J As Integer = 1 To Match.Count - 1
Matched = True
If Match(J) <> Source(I + J) Then
Matched = False
Exit For
End If
If Matched Then Return I
Exit For
Next J
End If
Next I
Return -1
End Function
End Class
Now, because I am newbie to VB I have one question. How can I change the Function so that Function search the whole file for all byte matches ?
Thanks in advance