在一个exe文件中查找指定内容,找到则返回起始位置, 否则返回0
//在一个exe文件中查找指定内容,找到则返回起始位置, 否则返回0
//如果某字符串, 直接传入字符串进来
//如果要查找16进制,则用如下格式传参进来: #$1A#$2A#$3A
function FindString(FileName, FindStr: string): Int64;
var
FileStream: TFileStream;
i: Int64;
Buff: string;
begin
FileStream := TFileStream.Create(FileName, fmOpenRead);
SetLength(Buff, FileStream.Size);
FileStream.Position := 0;
FileStream.ReadBuffer(PChar(Buff)^, FileStream.Size);
i := Pos(FindStr, Buff);
if i > 0 then Result := i-1 else Result := 0;
FileStream.Destroy;
end;
var
FileStream: TFileStream;
i: Int64;
Buff: string;
begin
FileStream := TFileStream.Create(FileName, fmOpenRead);
SetLength(Buff, FileStream.Size);
FileStream.Position := 0;
FileStream.ReadBuffer(PChar(Buff)^, FileStream.Size);
i := Pos(FindStr, Buff);
if i > 0 then Result := i-1 else Result := 0;
FileStream.Destroy;
end;