type
TMyByteArray = array of byte;
const
BUFFERSIZE = 2048;
HEXPREFIX = '';
HEXSUFFIX = ' ';
//
function BuffToHex(ByteArray: TMyByteArray): string;
var
i: Integer;
s: string;
foo: string;
HexLength: Integer;
const
HEXSTR = '0123456789ABCDEF';
begin
HexLength := Length(HEXPREFIX) + 2 + Length(HEXSUFFIX);
SetLength(foo, Length(ByteArray) * HexLength);
for i := 0 to High(ByteArray) do
begin
s := HEXPREFIX + HEXSTR[((ByteArray[i] and $F0) shr 4) + 1] +
HEXSTR[(ByteArray[i] and $0F) + 1] + HEXSUFFIX;
Move(s[1], foo[i * HexLength + 1], HexLength);
end;
Result := foo;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
fs: TFileStream;
Buffer: TMyByteArray;
BytesRead: Longint;
s: string;
i: Int64;
HexLength: Integer;
begin
if OpenDialog1.Execute then begin
Progressbar1.Position := 0;
i := 0;
SetLength(Buffer, BUFFERSIZE);
fs := TFileStream.Create(OpenDialog1.FileName, fmOpenRead);
HexLength := Length(HEXPREFIX) + 2 + Length(HEXSUFFIX);
SetLength(s, fs.size * HexLength);
Progressbar1.Max := fs.Size div BUFFERSIZE;
try
repeat
BytesRead := fs.Read(Buffer[0], BUFFERSIZE);
Move(BuffToHex(Buffer)[1],
s[i * (HexLength * BUFFERSIZE) + 1],
HexLength * BytesRead);
Inc(i);
Progressbar1.StepIt;
Application.ProcessMessages;
until
BytesRead < BUFFERSIZE;
Memo1.Text := s;
finally
FreeAndNil(fs);
Progressbar1.Position := Progressbar1.Max;
end;
end;
end;
Load HEX from any File
Abonnieren
Posts (Atom)
Keine Kommentare:
Kommentar veröffentlichen