elmago00,
Cita:
Empezado por elmago00
...al fin lo conseguí...
|
Una pequeña corrección
:
Código Delphi
[-]
procedure TForm1.DumpFile(aFileName:TFileName; SG: TStringGrid; const BPF: Word);
var
c, i, r, b : Integer;
Ascii: String;
Aux: Byte;
Col : Integer;
begin
with TMemoryStream.Create do
try
LoadFromFile(aFileName);
Caption:= Format('FileName = %s , FileSize = %d Bytes', [aFileName, Size]);
SG.ShowHeader := False;
SG.ShowHorzLines := False;
SG.ShowVertLines := False;
for i := 1 to BPF + 2 do
SG.AddObject(TStringColumn.Create(nil));
SG.RowCount := (Size div BPF) + 1;
if (Size Mod BPF) <> 0 then
SG.RowCount := SG.RowCount + 1;
for Col := 0 to SG.ColumnCount - 1 do
begin
if (Col = 0) then
SG.Columns[Col].Width := 80;
if (Col <> SG.ColumnCount - 1) and (Col <> 0) then
SG.Columns[Col].Width := 30;
if (Col = SG.ColumnCount - 1) then
SG.Columns[Col].Width := SG.Canvas.TextWidth('X') * BPF;
end;
SG.Cells[0,0]:= 'Offset(h)';
SG.Cells[SG.ColumnCount-1,0]:= 'ASCII';
for i:= 0 to BPF-1 do
begin
SG.Cells[i+1,0]:= IntToHex(i,2);
end;
Seek(0, soBeginning);
c:= 0;
r:= 1;
b := 0;
while c < Size do
begin
Application.ProcessMessages;
if CancelProcess then
begin
CancelProcess := False;
Break;
end;
SG.Cells[0, r]:= Format('%s',[IntToHex(c, 8)]);
Ascii:= EmptyStr;
i:= 0;
while (i < BPF) and (b < Size) do
begin
Read(Aux, SizeOf(Byte));
SG.Cells[i+1,r]:= IntToHex(Aux,2);
if Aux = 0 then Aux := 46;
Ascii:= Ascii + Chr(Aux);
Inc(i);
if (b < Size) then Inc(b);
end;
SG.Cells[SG.ColumnCount-1,r]:= Format('%s',[Ascii]);
Inc(c, BPF);
Inc(r);
Label1.Text := Format('Procesado Byte %d de %d',[b, Size]);
end;
finally
Free;
end;
end;
El código anterior en Delphi XE4 bajo Windows 7 Professional x32, corrige el código del
Msg #15 en los casos en que
los archivos a visualizar no sean múltiplos del factor de visualización (BPF), como se muestra en la siguiente imagen:
El código esta disponible en :
Visualizador de Archivos en Hexadecimal v2 en FireMonkey
Espero sea útil
Nelson.