【发布时间】:2016-04-09 01:00:00
【问题描述】:
要将文件内容加载为十六进制,我在 Delphi 7 中使用此代码:
procedure ReadFileAsHex(const AFileName: string; ADestination: TStrings);
var fs: TFileStream;
buff: Byte;
linecount: Byte;
line: string;
begin
linecount := 0;
line := '';
fs := TFileStream.Create(AFileName, fmOpenRead);
try
while fs.Position < fs.Size do begin
fs.Read(buff, 1);
line := line + IntToHex(buff, 2) + ' ';
Inc(linecount);
if linecount = 16 then begin
ADestination.Add(line);
line := '';
linecount := 0;
end;
end;
if Length(line) <> 0 then
ADestination.Add(line);
finally
fs.Free;
end;
end;
这向我显示了像这样以十六进制加载的文件:
34 01 00 00 13 00 00 00 13 00 00 00 04 00 00 00
01 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00
34 01 00 00 13 00 00 00 13 00 00 00 04 00 00 00
01 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00
我想替换实际文件中的一些数据
例如 我想将数据从 Offset(00000060) 替换为 Offset(00000070) 例如用 00 all 有没有可能,或者我需要一些特殊的组件?
谢谢
【问题讨论】:
-
不清楚你在问什么。您要替换
ADestination(字符串表示)还是实际文件本身(fs)中的内容? -
嗨,这只是我如何加载文件的示例,我想替换实际文件中的内容