pattern
- байты, которые надо найти. Совпадений может быть много.
public static void DisassembleDefault(Stream streamInput,
Action<long, long> progress, Action<long> matchFound,
ComparerDelegate comparer, byte[] pattern, int matchOffset)
{
if (pattern == null || comparer == null || matchFound == null) { return; }
int patternLength = pattern.Length;
int bufferSize = patternLength * 100000;
int diff = bufferSize - patternLength;
long max = streamInput.Length - bufferSize;
DateTime lastTime = DateTime.Now;
for (long streamPositionByte = 0L; streamPositionByte < max; streamPositionByte += diff)
{
byte[] buffer = streamInput.GetChunk(streamPositionByte, bufferSize);
if (buffer == null) { break; }
for (int j = 0; j < diff; ++j)
{
if (comparer.Invoke(buffer, pattern, j))
{
matchFound.Invoke(j + streamPositionByte - matchOffset);
}
if (progress != null)
{
TimeSpan timeSpan = DateTime.Now - lastTime;
if (timeSpan.TotalMilliseconds >= 100)
{
progress.Invoke(streamPositionByte, streamInput.Length);
lastTime = DateTime.Now;
}
}
}
}
}
public static byte[] GetChunk(this Stream stream, long pos, int len)
{
stream.Position = pos;
byte[] bytes = new byte[len];
int read = stream.Read(bytes, 0, len);
if (read == 0)
{
return null;
}
return bytes;
}
}
Можно как-то ускорить сиё непотребство?