Sublime Forum

Binary File Reading Plugin

#1

I have just started throwing together a plugin to show the hex output of a binary file. I still have some work to do on it, but I wanted to see if anyone was interested in something like this. I am just looking to see how much time I should spend on polishing it up. If there isn’t any real interest, I will just finish it up for myself.

I plan to have the byte size configurable and the bytes per line configurable.

I don’t plan on making it editable; at least not in the immediate future. I would have to think about how I would implement that.

Anyways, if you like the idea let me know, and I will push for a polished release.

2 Likes

#2

I’ve been wondering if something like this existed, and I was even thinking of trying to do it myself, so yes I’m definitely interested. PM me if you would like any help with it.

0 Likes

#3

Cool. It might be nice if you could give it a try, I think I really need feedback on how I have implemented it. I think I am too close to it to give it a good evaluation. I need to get one more commit in tonight that changes how I do things, but I will PM you after that and maybe you can give it a try.

Feedback, suggestions, and requests are more than welcome.

0 Likes

#4

Go ahead and put it on github.
I use a second editor only for this feature, so I will be more than happy to test it and eventually participate with patches.

0 Likes

#5

I’ll post a link publicly then tonight/tomorrow morning for beta testing. I need to get this last commit in though first; it fixes a lot of things.

I’m glad there is some interest. I have also currently been using another editor to look at binary files, so I am finding this pretty useful.

0 Likes

#6

Thanks for your works.
The printscreen look great, exactly what I need.

0 Likes

#7

Okay here is the link:

HexViewer

The default bit grouping and bytes per line are configurable via the settings file. Currently, to initiate the hex view, you select the command from the command palette.

Just start typing “Hex Viewer” in the command palette to see the commands. One allows you to toggle the hex view on and off. The other two allow you to change the bit grouping and bytes per line on the fly (it will open the quick panel with the available options).

The Hex View tab is a read only tab that replaces the current open file. When you toggle back, the hex view closes and the original file is opened. If you save the hex view as a file, it becomes an actual file that is no longer linked to the source file (the original file will pop back up in this case and you can do it again).

Let me know if you have issues or suggestions…basically, just give me feedback so I know if you like, hate it, etc. I am considering this a beta since I am the only one who has tested it so far.

Enjoy!

0 Likes

#8

Sorry I was always testing with more than one file open. I found a bug when only one file is open and you could not toggle hex view. This has now been fixed.

0 Likes

#9

Just get it a give it a try, I’ve no time right now to look how it works. Maybe later today.

The first (and right now only) issue I have is that the alignment is off on my configuration:
I use Meslo LG font and to make it look right I need to change the font of the view:

view.settings().set('font_face', 'Fixedsys')

This is for Windows 7.

I think that a settings to specify the font and font size is required, I will implement it when I have some times.

Thanks again.

0 Likes

#10

[quote=“bizoo”]The first (and right now only) issue I have is that the alignment is off on my configuration:
I use Meslo LG font and to make it look right I need to change the font of the view:
[/quote]

Completely didn’t think about this. This is a great suggestion. If you get to this, let me know; either that, or I will take care of it. It should be quick easy fix to expose a setting like this.

0 Likes

#11

Don’t worry about a fix. I have one that I will commit tonight. It took only a couple of minutes. Thanks for the feedback. Let me know if you run into anything else or you have any ideas or good pull requests.

0 Likes

#12

The font settings have been committed.

Also, there is a new command to open the hex view in an output panel opposed to the buffer if you like. The panel cannot have its settings change on the fly currently, but it gives you a quick way to peek at the hex and still leave the source file open.

0 Likes

#13

Thanks.
Tried it and work great.

Didn’t have time to look more at it now, but anyway for me it perfectly usable and look nice.

Some ideas for future development (when I have more free time):
-Add visual mark to see which char. link to which byte when you move cursor in chars or bytes column (using 2 cursors or probably better using marked regions)
-Goto address
-Find bytes/chars

0 Likes

#14

I do have some things already on my todo list that align with your ideas:

  1. highlight current byte - highlight a byte when your cursor is inside it
  2. display current address - display the current byte address in status bar (possibly byte range if a range is selected)
  3. goto address - goto requested address
  4. highlight corresponding chars - highlight the currently selected byte’s printable char in the ascii column
  5. reverse select and highlight byte - highlight and select the byte when a printable char is selected.

I am not sure how the definition of the tasks will change when I attempt to do these things, but that is the basic things I am shooting for; these tasks may be modified if I find usability or functionality hindered when attempting them.

I will probably approach the tasks in the mentioned order as well. I want to hit the most important (needed) features first and deal with the wants last.

The output panel view right now is kind of an experiment, it might not make it to the final version. Since panels cannot be searched etc. like normal buffers, it may not prove as useful. General highlighting etc. in the panel should work fine…we will just have to wait and see.

0 Likes

#15

I’ve downloaded this and it looks pretty nice to start with. A few things that I think would be nice (if they’re possible):

  1. Obvious – having edits able to be saved for proper binary editing. I can see that this might be rather difficult though, unless you can control how the user applies edits (in which case, things could get very slow!)
  2. A list of file extensions; if a file with an extension in the list is opened, the real file is closed and the hex_viewer representation is automatically opened.
  3. An ability to add extension-specific representation. For example, if the extension is BMP, rather than just displaying a simple set of words and their ascii, display the BMP structure header and display the body in standard hex format. Perhaps this is well beyond the intention of Hex Viewer.

Is there a way to bind a key to the “Hex Viewer: Toggle Hex View” command?

0 Likes

#16

This is not impossible, but will be a little tricky. I will probably need to restrict some things and give warnings to malformed data. I am saving this for the very very end. The viewer will be released without edit capability and then I will revisit and see how I may go about adding this.

I have experimented with this, but ST2 doesn’t always fire the event for opening a file correctly…or at least as expected. It has caused me some issues to do this. I may revisit this again when I get the essentials in.

Can you provide more in depth explanation to BMP structure headers? Is there an hex editor that does this sort of thing that I could view as an example? I would like to take a look into this before I give a yes or a no.

Yes, you just use the standard key binding methodology. I will post an example in a bit.

0 Likes

#17

Its a work in progress, but following features have been added.

[quote]1. highlight current byte - highlight a byte when your cursor is inside it
4. highlight corresponding chars - highlight the currently selected byte’s printable char in the ascii column[/quote]

It might be a little rough, but it works. I need to make sure and smooth it out and add expose some knobs to be tweaked in settings file.

Overall, not too bad.

0 Likes

#18

Looked at it again this morning and made a couple of tweaks to the highlight code; should be pretty reliable now.

@mah oh yeah…shorcut. As promised. Just change the shortcut to what you want.

{ "keys": "ctrl+shift+b", "ctrl+shift+h"], "command": "hex_viewer" },
0 Likes

#19

The performance of file loading isn’t great right now.
A 2.25MB file take more than 11 seconds to load.

I made some changes in the code and the same file open now in less than 3 seconds.
I suppose that it’s acceptable and it look difficult to optimize the code a lot more.
Note that half this time is spend in the view.replace() call.

I need a little more time to cleanup the code and test it. After that I will put it on github and place a pull request.

0 Likes

#20

Yeah, having to go through python slows things down a bit; doing this in native code would be tremendously faster. I haven’t spent much time optimizing it yet, so this effort is much appreciated. :smile:

I am afraid there is not much we can do about that. Well there might be other ways, but none that I am willing to traverse at this time.

0 Likes