Link to home
Start Free TrialLog in
Avatar of jploettner
jploettner

asked on

search large byte[] for the existiance of a smaller byte[] with C# and .NET 2.0

I'm reading a binary file into a byte array and need to search the bytes for patterns..

for file i read into:
byte[] fileBuffer = new byte[filesize];

and I'm trying to search for:
byte[] targetDLL = { 0x2E, 0x64, 0x6C, 0x6C, 0, 0 }; (and a few others)

A C#.NET 2.0 example of how to search the large file byte array for my smaller 'patterns' would be greatly appreciated!  
ASKER CERTIFIED SOLUTION
Avatar of gregoryyoung
gregoryyoung
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Expert1701
Expert1701

* Not for points, but I believe a minor change is required:

  if(current == targetDLL.Length) {
    Console.WriteLine("Found pattern at index " + (i - targetDLL.Length).ToString());
    current = 0;
  }