Ggf. tut man sich leichter, die Datei zunächst in einen HEX String zu überführen um dann einfach mit Pos nach Hex Sequenzen zu suchen?
Delphi-Quellcode:
function GetBinToHex(Value: TStream): string;
var
Stream: TMemoryStream;
begin
SetLength(Result, (Value.Size - Value.Position) * 2);
if Length(Result) > 0 then
begin
Stream := TMemoryStream.Create;
try
Stream.CopyFrom(Value, Value.Size - Value.Position);
Stream.Position := 0;
BinToHex(PChar(integer(Stream.Memory) + Stream.Position), PChar(Result),
Stream.Size - Stream.Position);
finally
Stream.Free;
end;
end;
end;
function LoadFromFile(const FileName: string): string;
var
FileStream: TFileStream;
begin
Result := '';
if FileExists(FileName) then
begin
FileStream := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite);
try
FileStream.Position := 0;
Result := GetBinToHex(FileStream);
finally
FileStream.Free;
end;
end;
end;