var F:TMemoryStream; Buffer: array [0..Max] of Char; begin F := TMemoryStream.Create; F.LoadFromFile(''); F.Position := $0000006E; while F.Position <= $0000006F do begin F.ReadBuffer(Buffer,SizeOf(Buffer)); //将buffer内容写到文件代码 end; end;Max:你可以自己设置数值,如果你的数据段长度比buffer小,那就不用while循环了,直接读写一次就可以了
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Edit1: TEdit; Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}function StrToHexStr(const S:Ansistring):Ansistring; var I:Integer; begin for I:=1 to Length(S) do begin if I=1 then Result:=Ansistring(IntToHex(Ord(S[1]),2)) else Result:=Result+' '+Ansistring(IntToHex(Ord(S[I]),2)); end; end; procedure TForm1.Button1Click(Sender: TObject); var fs : TFileStream; bt : array[0..1023] of Char; begin fs := TFileStream.Create('E:\tools\SkypeMate 3.2.0.21.exe',fmOpenRead ); try fs.Position := $6E; fs.ReadBuffer(bt,1); edit1.Text := StrToHexStr(bt); finally FreeAndNil(fs); end; end;end.
首先创建流并打开org文件设置流的position为你要的数据的开始位置
然后一次往下读取,知道结束位置为止
F:TMemoryStream;
Buffer: array [0..Max] of Char;
begin
F := TMemoryStream.Create;
F.LoadFromFile('');
F.Position := $0000006E;
while F.Position <= $0000006F do
begin
F.ReadBuffer(Buffer,SizeOf(Buffer));
//将buffer内容写到文件代码
end;
end;Max:你可以自己设置数值,如果你的数据段长度比buffer小,那就不用while循环了,直接读写一次就可以了
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}function StrToHexStr(const S:Ansistring):Ansistring;
var
I:Integer;
begin
for I:=1 to Length(S) do
begin
if I=1 then
Result:=Ansistring(IntToHex(Ord(S[1]),2))
else Result:=Result+' '+Ansistring(IntToHex(Ord(S[I]),2));
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
fs : TFileStream;
bt : array[0..1023] of Char;
begin
fs := TFileStream.Create('E:\tools\SkypeMate 3.2.0.21.exe',fmOpenRead );
try
fs.Position := $6E;
fs.ReadBuffer(bt,1);
edit1.Text := StrToHexStr(bt);
finally
FreeAndNil(fs);
end;
end;end.