i want to create a method to scan arrays of bytes for a specific array i have already done this, but there is something else i want, i want to extend it so that it can scan arrays with some indexes being unknowns by replacing them with 256(0xff) e.g if i have an array like this [1,2,3,4,5,6,7,8,9,20,30,50] normally, i can search for [5,6,7] and it would index [4] because that is where 5 begins i want to be able to search for something like [5,256,7] which means if i dont know the actual value of 256, i would still get a correct answer
my solution is grab a chunk of 256/512 bytes,use a for loop to read a chunk of x bytes(in this case, 3 bytes), and replace 256 with the corresponding value of the corresponding index in the bytes being read
here is the code i have tried, but it isnt working properly
p.s, this method is meant to scan really big arrays that is why there are some large values
public long arraySearch(byte[] scanFor, long startIndex, long endIndex)
{
if (scanFor.Length == 0 || startIndex == 0 || endIndex == 0 || endIndex
<= startIndex - scanFor.Length) return 0;
long tempStart = startAddress;
long foundIndex = 0;
long tmpAd = 0;
long maxChunk = endIndex - startIndex;
float parts = maxChunk / 256;
int x = 0;
byte[] tmp = new byte[scanFor.Length];
byte[] buf = new byte[256];
for (x = 0; x < parts; x++)
{
//the 'byte[] ReadArray(int64 index,int length)' method returns a byte array
(byte[]) at the given index of the specified size
buf = ReadArray(tempStart, 256);
for (int i = 0; i < 256; i++)
{
if (buf[i] == scanFor[0])
{
tmp = ReadArray(tempStart + i, scanFor.Length);
for (int iii = 0; iii < scanFor.Length; iii++)
{
if (scanFor[iii] == 0xff) scanFor[iii] = tmp[iii];
}
tmpAd = tempStart + i;
//the 'ByteArrayCompare' method compares all elements of an array and
returns true if all are equal
if (ByteArrayCompare(tmp, scanFor))
{
foundIndex = tmpAd;
break;
}
}
}
tempStart += 256;
}
return foundIndex;
}