Fun with KHexEdit

One project in KDE I work at are modules for binary editing. This is the one project that brought me to programming inside KDE. Those times I was working at a viewer for executables and libraries (stalled soon), for that I wanted a widget for displaying bytes. Looked at KHexEdit, but found nothing that could be cleanly ripped out and be reused. So I started to code a widget from scratch.

That was 2003, and when that year I joined the KDE crowd at the “Kastle” conference, I applied to have it included inside kdelibs. That was rejected, as obviously only a few programs need a binary edit widget 😉
Still those, e.g. the general database editor in KPilot, did not want an extra dependancy on a third module like kdeutlils, home of khexedit and the new widget lib. So the concept of plugin loading was applied, adding some interfaces to kdelibs and loading the plugin dynamically at runtime.
Pro: no bloat of kdelibs, in the case of the khexedit widget at least due to headers only ;).
Contra: a little more complicated code due to dynamic loading and calling of interface methods.

The good old KHexEdit program from Espen Sand was never changed to use the new widget, as I planned to write a completly new program from scratch. Well, planned, never happened for the complete span of KDE 3. The KPart I did for binary viewing of all files e.g. in Konqueror was brought offside by setting it’s service mimetype to octetstream, because it started to appear as fallback view part for all mimetypes without a special installed handler, like flash files embedded in html pages. And this did not look good for some. In fact there is a flaw in the kpart loading system, but that needs some deep thougts, so the easy way was to banish that viewer. Well, no big loss for the world, I guess. And KPilot stayed the only program to my knowledge to use that widget plugin, oh yeah. Since recently the new debugger plugin for KDevelop done by Vladimir Prus is using the binary widget, too, but I have not yet seen it in action. So, not a lot did happen to the widget for more than two years. Chances are you do not even know about it.

Now, with KDE 4 in creation, I started to work again at it. Already ported the binary edit widget library completly to Qt4 and current KDE4, all working fine (except for crashes in D’n’D, which I did not yet have a look at). And more, I am tackling the construction of a successor to KHexEdit again, projectname “Okteta”. It will be the playground for some concepts for program frameworks of mine, like controllets/toolets or repository style of working at documents/models. Nothing of this yet commited into SVN, though. I am very curious what will come out of this 🙂

A month ago Simon Hausmann blogged about
“Fun with QTextEdit”, being able to have multiple views of the same QTextDocument with Qt 4. Well, I can (now) have the very same fun also with a byte array and binary views:

// qt specific
#include [QSplitter]
// kde specific
#include [kapplication.h]
#include [kmainwindow.h]
#include [kcmdlineargs.h]
// lib specific
#include [kbytearraymodel.h]
#include [khexedit.h]

using namespace KHECore;
using namespace KHEUI;

int main( int argc, char* argv[] )
  KCmdLineArgs::init( argc, argv, "Example","","","" );
  KApplication app;

  KByteArrayModel sharedArray;
  sharedArray.setReadOnly( false );

  KHexEdit *he1 = new KHexEdit;
  KHexEdit *he2 = new KHexEdit;
  KHexEdit *he3 = new KHexEdit;
  he1->setDataBuffer( &sharedArray);
  he2->setDataBuffer( &sharedArray);
  he3->setDataBuffer( &sharedArray);

  KMainWindow *mw = new KMainWindow;
  QSplitter *verticalSplitter = new QSplitter(Qt::Vertical);
  QSplitter *horizontalSplitter = new QSplitter;


  mw->setCentralWidget( verticalSplitter );

  return app.exec();

Things are moving forward 🙂


One thought on “Fun with KHexEdit

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.