All pastes #332850 Raw Edit

Someone

public text v1 · immutable
#332850 ·published 2007-01-30 09:56 UTC
rendered paste body
function ArraySearch(StartAddy, EndAddy, SearchBuf: Pointer; BufLen: DWORD): Pointer; stdcall;
var
  blobLen: DWORD;
  blob: DWORD;
  i, Max: DWORD;
  A, B: DWORD;
  X: Byte;
begin
  Result := nil;
  if DWORD(EndAddy) <= DWORD(StartAddy) then Exit;
  blobLen := DWORD(EndAddy) - DWORD(StartAddy);
  blob := DWORD(StartAddy);
  Max := blobLen - BufLen;
  for i := 0 to Max do
    begin
      A := 0;
      B := i;
      try
        X := PByte(blob+B)^;
      except
        X := PByte(SearchBuf)^+1;
      end;
      while (X = PByte(DWORD(SearchBuf)+A)^) do
        begin
          A := A + 1;
          B := B + 1;
          try
            X := PByte(blob+B)^;
          except
            X := PByte(DWORD(SearchBuf)+A)^+1;
          end;
        end;
      if (A = BufLen) then
        begin
          Result := PByte(blob+B-BufLen);
          Exit;
        end;
    end;
end;