Registriert seit: 17. Mai 2007
482 Beiträge
Delphi XE6 Professional
|
Re: Look for specified sequence in stream
19. Sep 2013, 14:04
Ok, I wrote this and don't know how implement your description
Delphi-Quellcode:
type
TOffsets = array of Cardinal;
function OffsetsLookup(const AStream: TStream; const APattern: TBytes): TOffsets; overload;
var
Memory: TMemoryStream;
Buffer: Byte;
Offset: Cardinal;
begin
SetLength(Result, 0);
Memory := TMemoryStream.Create;
try
Memory.CopyFrom(AStream, 0);
Memory.Position := 0;
while Memory.Size - Memory.Position < Length(APattern) do
begin
Offset := Memory.Position;
Buffer := Byte(Pointer(Longint(Memory) + Offset)^);
// ????? :(
end;
finally
Memory.Free;
end;
end;
function OffsetsLookup(const AFileName, APattern: string): TOffsets; overload;
var
Stream: TStream;
Pattern: TBytes;
I: Integer;
begin
Stream := TMemoryStream.Create;
try
TMemoryStream(Stream).LoadFromFile(AFileName);
SetLength(Pattern, Length(APattern));
for I := 1 to Length(Pattern) do
Pattern[I] := Ord(AnsiChar(APattern[I]));
;
Result := OffsetsLookup(Stream, Pattern);
finally
Stream.Free;
end;
{Stream := TFileStream.Create(AFileName, fmOpenRead);
try
SetLength(Pattern, Length(APattern));
for I := 1 to Length(Pattern) do
Pattern[I] := Ord(AnsiChar(APattern[I]));
;
Result := OffsetsLookup(Stream, Pattern);
finally
Stream.Free;
end;}
end;
OffsetsLookup('binary.dat', 'ABC')
Geändert von WojTec (19. Sep 2013 um 14:20 Uhr)
Grund: Code update
|
|
Zitat
|