Share My Creation [B4J] Hex View CustomView

stevel05

Expert
Licensed User
Here is my take on a Hex dump as a custom view.​

1579017399494.png

You can:

  • Explore any size file
  • Load one or more arrays of bytes
  • Search the data
There is a degree of customisation in the designer and subsequently in the class for setting colours used for different highlighting. Turning the headers on/off, Limiting number of found results. Font size is calculated automatically dependant on the views width. You can use any font, but I think the Monospaced font looks best.

You can select data from the right hand column and press F3 or select Find from the find menu to search the file or data.

The library is a b4xlib, but is only available for B4j.

DependsOn : jXUI, JavaObject, jReflection, jRandomAccessFile, ByteConverter

Files:
  • HexView.zip shows example usage.
  • jHexViewer-b4x.b4xlib contains the library.
  • HexViewer.xml contains the libraries documentation xml file that you can drag on to BuildDocs, or use another Library documentation viewer available on the forum.

Update V 1.3
Bug fix sizing window too small caused a read error​

Update V1.4
Implemented Klaus's suggestions, it looks a lot cleaner, thank you Klaus. You only need to download the jHexViewer-b4x.b4xlib file.​


If you try it, please let me know how you get on with it.
 

Attachments

Last edited:

stevel05

Expert
Licensed User
V1.1 Update: Find results are paged if greater than the value set for MaxResults.
 
Last edited:

Peter Meares

Member
Licensed User
I tried it and got an error:

Waiting for debugger to connect...
Program started.
Error occurred on line: 114 (HexView)
java.lang.NumberFormatException: For input string: "null"
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
at java.lang.Double.parseDouble(Double.java:538)
at anywheresoftware.b4a.BA.ObjectToNumber(BA.java:395)
at b4j.example.hexview._designercreateview(hexview.java:1310)
etc

What have I missed out?
 

stevel05

Expert
Licensed User
Try opening layout 1 in the designer and saving it. It appears that a property is not set correctly.

Thanks for reporting it.
 

Informatix

Expert
Licensed User
I'm unable to run the example. I installed jHexViewer-b4x.b4xlib and ByteConverter.jar in my additional libs folder. I selected the jHexViewer-b4x lib in the IDE and compiled. I get:
main._appstart (java line: 60)
java.lang.RuntimeException: java.lang.NumberFormatException: For input string: "null"
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:120)
at anywheresoftware.b4j.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:68)
at anywheresoftware.b4j.objects.LayoutBuilder.loadLayout(LayoutBuilder.java:93)
at anywheresoftware.b4j.objects.PaneWrapper.LoadLayout(PaneWrapper.java:84)
at b4j.example.main._appstart(main.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
at b4j.example.main.start(main.java:37)
...
Caused by: java.lang.NumberFormatException: For input string: "null"
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
at java.lang.Double.parseDouble(Double.java:538)
at anywheresoftware.b4a.BA.ObjectToNumber(BA.java:395)
at b4j.example.hexview._designercreateview(hexview.java:643)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
... 20 more
I use B4J v8.
 

stevel05

Expert
Licensed User
Try opening layout 1 in the designer and saving it. It appears that a property is not set correctly. Sorry, I will upload a new version tomorrow.
 

Informatix

Expert
Licensed User
The new example does not work because some files are missing:
HexView - 229: Type inconnu : keyevent<br />Avez-vous oubli&#233; une r&#233;f&#233;rence de biblioth&#232;que ?
HexView - 77: Type inconnu : numberspinnercv<br />Avez-vous oubli&#233; une r&#233;f&#233;rence de biblioth&#232;que ?
HexView - 58: Type inconnu : keyeventhelper<br />Avez-vous oubli&#233; une r&#233;f&#233;rence de biblioth&#232;que ?
HexView - 31: Type inconnu : scrollbar<br />Avez-vous oubli&#233; une r&#233;f&#233;rence de biblioth&#232;que ?
In this example, the b4xlib is not used, some lines are commented out and there's a custom build action so it looks like these files are not the ones you wanted to publish.
 

klaus

Expert
Licensed User
Very well done :)!
I appreciate also that you share the source code!

Just one small point.
Unknown characters are displayed as dots.
I would suggest you to replace it by another special character, for example "·", like below.

Currently, the spaces are also displayed as dots.
In the HexView module in the DrawLine routine, replacing line 759:
If C < 128 And C > 32 Then
by
If C < 128 And C > 31 Then
solves this problem.

And in the same For/ Next loop replace "." by "·":
Cnv.DrawText(".",X,Y,mFont,mTextColor,"LEFT")
by
Cnv.DrawText("·",X,Y,mFont,mTextColor,"LEFT")

The result with some accentuated characters which have two bytes in UTF-8 and are unknown, beginning of the text "é ü ñ Hey," :
The first character "é" is represented by two unknown characters.
1578754374737.png


I have been using Total Commander for many years.
 
Last edited:

stevel05

Expert
Licensed User
Hi Klaus,

Thanks for taking the time to check this out. I have only used Hex dumps when I needed them and am not really conversant with the finer points, so your comments are much appreciated. I will implement them for the next version.
 

Beja

Expert
Licensed User
Thanks for this useful tool. I remembered the days of DOS debug.com utility when I changed DOS version from 5 to 7.. !!
A few questions:
1. Can this utility edit Intel Hex file and save it?
2. During DOS time Debug only edited .com files, so I changed the .exe extension to .com, edit and saved it, the put the .exe back.
Can the same be done with this utility?
 

stevel05

Expert
Licensed User
There is no editing facility, Feel free to edit the code and create your own editor if you want to.
 
Top