Recent

Author Topic: My hex viewer project completed in less than 30 minutes!  (Read 645 times)

anyone

  • Guest
My hex viewer project completed in less than 30 minutes!
« on: October 03, 2020, 05:25:06 pm »
Thanks to Free Pascal's sysutils IntToHext, I can complete my Hex Viewer project in less than 30 minutes, and I could not believe it myself!!
(Although the accuracy of the hexadecimal dump has not been fully verified file by file)

If anyone of you are interested in this project, I am more than happy to share the 72 lines of code with you. 

(Currently the file offset is fixed at 8 digits of hexadecimal range, would it be enough?)

EDIT: The source file in the attachment has an extra line of Write('    '), you can remove it:

Code: Pascal  [Select][+][-]
  1.   while not EOF(f) do
  2.   begin
  3.     Write(IntToHex(ofs, 8));
  4.     Write('    ');
  5.     for i:=0 to 15 do
  6.     begin
  7.       if EOF(f) then
  8.       begin
  9.         c:=i-1;
  10. { Remove this line: Write('    '); }
  11.         break;
  12.       end
  13.       else
  14.         Read(f,b);
  15.  

UPDATE: Sample hexdump.exe output:

Code: [Select]
C:\FPC>hexdump sample.txt
00000000    68  65  6C  6C  6F  20  77  6F  72  6C  64  0D  0A  0D  0A  68      hello world....h
00000010    6F  77  20  69  73  20  65  76  65  72  79  6F  6E  65  3F  0D      ow is everyone?.
00000020    0A                                                                  .

C:\FPC>
« Last Edit: October 03, 2020, 07:34:42 pm by anyone »

Awkward

  • Jr. Member
  • **
  • Posts: 68
Re: My hex viewer project completed in less than 30 minutes!
« Reply #1 on: October 03, 2020, 06:14:15 pm »
BTW. check HexStr function from "system" unit

Handoko

  • Hero Member
  • *****
  • Posts: 3913
  • My goal: build my own game engine using Lazarus
Re: My hex viewer project completed in less than 30 minutes!
« Reply #2 on: October 03, 2020, 06:36:26 pm »
Nice to meet someone has passion for learning and writing programs. anyone, my text file to hex console mode only has 47 LOC and it has colors. You may also interested to see the GUI version:

https://forum.lazarus.freepascal.org/index.php/topic,46759.msg371103.html#msg371103

Keep learning friend!
You will become a great programmer someday.

anyone

  • Guest
Re: My hex viewer project completed in less than 30 minutes!
« Reply #3 on: October 03, 2020, 07:10:20 pm »
BTW. check HexStr function from "system" unit

Oh, I didn't know that. HexStr is identical to IntToHex except it does not need extra unit. But I still need sysutils unit because of FileExists function. Thanks.

anyone

  • Guest
Re: My hex viewer project completed in less than 30 minutes!
« Reply #4 on: October 03, 2020, 07:14:16 pm »
Nice to meet someone has passion for learning and writing programs. anyone, my text file to hex console mode only has 47 LOC and it has colors. You may also interested to see the GUI version:

https://forum.lazarus.freepascal.org/index.php/topic,46759.msg371103.html#msg371103

Keep learning friend!
You will become a great programmer someday.

Thank you, Handoko, for your encouraging word. I tried your ReadLnConsole and it works wonder (there are many new functions such as WideString that I am not aware of until now). But looks like I cannot compile ReadLnGUI code with FPC... Must download Lazarus?

GUI (Desktop app) is something I am eager to try if they are less dependent on external library units.

Handoko

  • Hero Member
  • *****
  • Posts: 3913
  • My goal: build my own game engine using Lazarus
Re: My hex viewer project completed in less than 30 minutes!
« Reply #5 on: October 04, 2020, 03:17:51 am »
I haven't tried but I believe you can create GUI applications using FPC only without Lazarus. But that won't be easy I think.

Download Lazarus and try it maybe you will like it too. You can build portable programs (which means can run without installation) using Lazarus and if you choose the components to use carefully, your program can be distributed and run without external dll or so files.

For example I ever built a simple stock control program. It uses TDBF. The result program contains only 1 single exe file. It can be distributed and run without install. When the programs starts, it will check the existence of the config and dbf files. If it can't find them then it will automatically generate them using the default values. The user asked me, how to do backup and restore. That's easy, simply copy/paste the folder to a usb flash drive or other computer. The restoration is easy too, just copy them back.

But if you choose to use certain components for example MySQL, Allegro, etc, then your program will need third party libraries and/or you have to configure them first before user can run the program.

Lazarus is awesome. The performance is good, you can build nice looking GUI applications, it has wide selection of components. If you develop carefully, you can build portable programs and the result binary is relatively small. For the stock control I built, the size of the exe + all dbf + config files is less than 10 MB.

If you're interested to learn Lazarus, here has a lot of short demos:
https://wiki.freepascal.org/Portal:HowTo_Demos

440bx

  • Hero Member
  • *****
  • Posts: 2048
Re: My hex viewer project completed in less than 30 minutes!
« Reply #6 on: October 04, 2020, 04:06:25 am »
I haven't tried but I believe you can create GUI applications using FPC only without Lazarus. But that won't be easy I think.
This comment applies to Windows, I don't know if it applies to other O/Ss. It's easy to create GUI apps using FPC only but, it requires knowledge of the Windows API and it's more work/typing.

It is possible to use Lazarus just as an editor and front end to FPC and GDB.  The combination is very usable.  That's the extent of my use of Lazarus (except for editing, I use a different editor)

The other thing that is needed is a resource compiler to create the .res file.  I use BRCC32.exe that came with Delphi 2 and occasionally ResourceHacker.

The resulting executables are smaller and faster than doing it the RAD way but, it's more work.




FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

PascalDragon

  • Hero Member
  • *****
  • Posts: 2435
  • Compiler Developer
Re: My hex viewer project completed in less than 30 minutes!
« Reply #7 on: October 04, 2020, 01:33:35 pm »
This comment applies to Windows, I don't know if it applies to other O/Ss. It's easy to create GUI apps using FPC only but, it requires knowledge of the Windows API and it's more work/typing.

It's not really much different for the other platforms. One simply needs to know the corresponding GUI API (Qt, Gtk, Cocoa, MUI, etc.) to work with them.

The other thing that is needed is a resource compiler to create the .res file.  I use BRCC32.exe that came with Delphi 2 and occasionally ResourceHacker.

The fpcres utility from trunk now supports compiling rc-files as well. The trunk compiler will use it if called with -FF (at least until 3.2.2 is released, then it will switch to being the default).

 

TinyPortal © 2005-2018