Bueno, siguiendo con mi respuesta anterior:
Código Delphi
[-]
type
TBuffer = array[$0000..$FFFF] of Byte;
function Insertar(Str: String; var Buffer: TBuffer): String;
var
i,j,k: Integer;
begin
Result:= EmptyStr;
Str:= Trim(Str);
if Copy(Str,1,1) = ':' then
if TryStrToInt('$' + Copy(Str,2,2),i) then
if Length(Str) = ((2*i) + 11) then
if TryStrToInt('$' + Copy(Str,4,4),j) then
if TryStrToInt('$' + Copy(Str,8,2),k) then
if k = 0 then
begin
Str:= Copy(Str,10,2*i);
for k:= j to (j + i - 1) do
begin
Buffer[k]:= StrToInt('$' + Copy(Str,1,2));
Delete(Str,1,2);
end;
end;
end;
var
i,j: Integer;
Str: String;
Buffer: TBuffer;
begin
Memo1.Clear;
with TStringList.Create do
try
LoadFromFile('d:\test.hex');
FillChar(Buffer,Sizeof(Buffer),#0);
for i:= 0 to Count - 1 do
Insertar(Strings[i],Buffer);
Str:= EmptyStr;
j:= Sizeof(Buffer) - 1;
while (Buffer[j] = 0) and (j > 0) do
dec(j);
for i:= 0 to j do
begin
Str:= Str + #32 + IntToHex(Buffer[i],2);
if ((i+1) mod 16 = 0) then
begin
Memo1.Lines.Add(Str);
Str:= EmptyStr;
end;
end;
finally
Free;
end;
end;
Solo quedaría añadir algunas cosillas, como la comprobación de la "suma de comprobación".