Friday, November 9, 2012

Read a binary file and display it Hex value (2)

procedure TForm2.Button1Click(Sender: TObject);
var
  I: Integer;
  B: Byte;
  S: String;
begin
  with TMemoryStream.Create do
  begin
    LoadFromFile('c:\windows\notepad.exe');
    for i := 1 to Size do
      begin
        ReadBuffer(B, 1);
        S := S + IntToHex(Trunc(B), 2) + ' ';
        if ( i mod 16 ) = 0 then S := S + #13#10;
      end;
    Free;
  end;
  Memo1.Text := S;
end;

No comments:

Post a Comment