Sunday, October 11, 2009

Living during SVN downtime

We had a svn downtime at the weekend and I decided to work on something different. I was bored because I don't like to work on monodevelop without svn.
I've decided to do something useful and made a little hex editor user control using spare parts of the text editor control and it was very fun.
















The control feels fast (at least compared to the other hex editors I tested). It could re-use red-black tree for data storage and almost all data structures used by the text editor.

Some of the code changed, for example it's no longer needed to have locations as line/columns.
Instead just the offset is used (btw. all calculations done by the hex editor are much simpler than in the text editor). It still needs some work, for example the undo/redo logic and cut&paste needs to be 'translated'. But this should be easy - I may do it during the next svn downtime :)














From the user point of view it feels like the monodevelop text editor. It re-uses some of the drawing code and event handler logic.
  • Styling (could share style files with the text editor)
  • "Margin" model
  • Caret blinking/drawing
  • Bookmarks
  • Mouse behavior (selection etc.)
  • It can do bookmarks, selection, zooming, group bytes, words, longs
After the 2.2 release I'll include a hex editor view in monodevelop. From time to time I need to view the hex code of files, then I can do this without leaving monodevelop.

I wonder if anybody dares to make a stand alone version of the monodevelop hex editor and text editor. Both controls can easily be re-used in a standalone application.

3 comments:

Unknown said...

You should take a look at tweak[1], which is a curses based hex editor which supports insert (which no other hex editor I've used does), and has a nice datastructure which allows it to work on multi-gigabyte files very efficiently (it only loads the parts of the file which are accessed into memory). The algorithm description[2] is well worth reading, too.

A nice UI built on top of tweaks datastructure would be wonderful!

[1] http://www.chiark.greenend.org.uk/~sgtatham/tweak/

[2] http://www.chiark.greenend.org.uk/~sgtatham/tweak/btree.html

Mike Krüger said...

I use something like this - red black trees are self balancing binary search trees. Theoretically I could work with multi-gigabyte files too. I don't need to have the whole buffer in memory.

The "original" file is represented by an interface:

interface IBuffer {
long Length { get; }
byte GetByte (long offset);
}

Only the changes are stored in memory.

I've read about the tweak data structure. I think the idea to use btrees for cut/copy/paste is really cool (he's right - cut/copy large chunks is very fast this way).

Whats funny is that the tweak author did a hex editor and suggested to use trees in a text editor. I've done the opposite :) - ok I admit that in the text editor I use it only partially for the line data structures.

Mike Krüger said...

I've just implemented the interface on base of a FileStream.
I changed the byte GetByte (long offset); to byte[] GetByte (long offset, int count); and tested it on a 2GB file on a nfs ... it's fast.