Einzelnen Beitrag anzeigen

Benutzerbild von Union
Union

Registriert seit: 18. Mär 2004
Ort: Luxembourg
3.492 Beiträge
 
Delphi 7 Enterprise
 
#2

AW: Look for specified sequence in stream

  Alt 19. Sep 2013, 12:59
You should use a TMemoryStream. Then, you should iterate directly through the stream's memory like:
Delphi-Quellcode:
Size := MyStream.Size;
Memory := MyStream.Memory;
StreamPos := 0;
while StreamPos < Size do
begin
  FirstStreamPos := StreamPos;
  Buffer := Byte(Pointer(Longint(Memory)+StreamPos)^);
  inc(StreamPos);
if the Buffer variable corresponds to the first byte of the sequence searched, then iterate through the sequence as long as buffer and sequence's bytes are the same. When a difference is found, exit. If you reach the end of the sequence without finding a difference, you found the sequence and have the starting position in a value previously saved (e.g. FirstStreamPos). You could also incorprate asm code and split the sequnce in 4, 2, 1 byte parts to increase comparison and copy operations speed.
Ibi fas ubi proxima merces
sudo /Developer/Library/uninstall-devtools --mode=all
  Mit Zitat antworten Zitat