Jump to content
Welcome, welcome! Come in and register, and have some developer coffee. 👨‍💻 ×

My Hex Viewer for Windows Console


Recommended Posts

Introduction

I am using my own Hex Viewer in command prompt window to open binary files when working on projects.

It dumps the binary file as text file first then only open it as editor window.   Users can then save the editor window as text file and open in Notepad!

 

Code Snippet

The Pascal source code worth highlighting is below: 

    PROCEDURE HexDump(FN:String); 
    var
      F: File of Byte;
      T: Text;
      B: Byte;
      Ofs: Longint;
      S: String;
      I, C: Integer;
      ASCII:array [0..15] of Char;

    begin
      Assign(F, FN);
      Reset(F);

      Assign(T, FN+'.TXT');
      Rewrite(T);

      Ofs:=0;
      while not EOF(F) do
      begin
        Write(T, IntToHex(Ofs, 8));
        Write(T, '    ');

        for I:=0 to 15 do
        begin
          if EOF(F) then
          begin
            C:=I-1;
            break;
          end
          else
            Read(F,B);

          Write(T, IntToHex(B, 2));
          Write(T, '  ');
          if (B>=32) and (B<127) then
            ASCII[I]:=Chr(B)
          else
            ASCII[I]:='.';
          C:=I;
        end;
        for I:=C to 15 do
          Write(T,'    ');

        for I:=0 to C do
        begin
          Write(T,ASCII[I]);
        end;
        WriteLn(T);
        Ofs:=Ofs+16;
      end;

      Close(F);
      Close(T);
    end;

 

Screenshots

PIC 1: Use "Open File" dialog to choose file to open.

H01.thumb.JPG.0d6424daa83a5b90f86c7e617da19b8f.JPG

PIC 2: You can open multiple files in multiple editor window.

H02.thumb.JPG.2f08ee16eb0b50abfba7bd032598533b.JPG

PIC 3: Save the editor window in Hex Viewer and open it in Notepad!

H03.thumb.JPG.eecb42245b87420826da12243187dc75.JPG

 

This source code and binary executable (i386-Win32) of Hex Viewer are included in the HEXVIEW.zip (Please sign in to download).

 You are freely to modify, compile and redistribute this project with Free Pascal (FPC) provided that you keep my copyright notice in About dialog box.

This tiny HEXVIEW.exe is standalone executable.

HEXVIEW.zip

Edited by FlierMate
  • Love 1
Link to post
Share on other sites
13 minutes ago, Malkuth said:

Wow this is an amazing project! I'll take a look when I have some free time soon. Really thanks for sharing!

Thank you for the compliment. I hope you and more people will find it useful. Although users can view binary files with this little console app, they cannot edit them. 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...