ridiculous_fish Open-Sources HexFiend!
Thomas Ptacek | December 5th, 2006 | Filed Under: Apple, Reversing, Uncategorized
Oh, glory of glories. Oh heavenly testament to the eternal majesty of God’s creation.
ridiculous_fish opened the code for HexFiend, our favorite OS X hex editor. HexFiend is fast, well-designed, and handles huge files. There’s a developer wiki; the page on how HexFiend saves large files is good reading even if you don’t plan on hacking on OS X hex editors.
Several weeks ago I posted my wish list for an ideal hex editor. Now that the “writing a hex editor” obstacle has been cleared from our path, less talk, more action!
The feature I want most: show me the IP address that corresponds to the bytes I’ve got selected in the editor. HexFiend already has an inspector that shows the 32 bit LE/BE value I’ve selected, so that should be easy. Let’s open the Xcode project and see how far I can get becore the vendor I’m waiting on calls me back.
Uh, I’m somewhere where I don’t know where I am!
Yeah, so, I’m really not a Cocoa developer. Constructive criticism would be peachy. That said, here’s what I did:
Find the model code for the Inspector widget. It loops over a list of fields defined in the header file on a “reloadFields” event thingy. Add a field, and an IBOutlet instance member, for IPv4 address.

Find the NIB file that includes the Inspector. It’s in MainMenu. Crack it open. Click aimlessly around the Inspector trying to find how widgets connect to model classes. Copy the “32 bit integer” fields to create an “IPv4 address” field.

Find the top-secret “outline view” for class instances that shows outlets and connections. This took me more time than any other step. Control-drag from my new IPv4 field in the Inspector to the model class. Connect the outlet.

Write the 15 lines of C code to turn a 32 bit integer into a string IP address. I lost more time trying to figure out how to make a C-string into an NSString than anything else.
“Build and go”. Oops, got the endianness wrong; addresses are backwards. Fix. “Build and go”. Yay, HexFiend prints IP addresses now! I’m a real Cocoa developer.

What have we learned?
HexFiend’s code is clean, simple, and straightforward enough for a Cocoa novice to add features to it while on telephone hold.
HexFiend uses a dependency graph and topological sort to save byte ranges to files. I don’t know that you care about that, but it’s fun to say.
To connect UI widgets you draw in Interface Builder to Objective C classes, locate the secret “outline view” button under “Instances”, and control-drag from your UI element to a class with an appropriate Outlet.
To convert a c-string to NSString, use NSString::stringWithCString:encoding.
Objective C is incredibly verbose.
You can download my (trivial) patches here. More to come. We need to embed an interpreter into HexFiend and make it Emacs for Reversing.


Spiff
December 5th, 2006 6:42 pmIn your search for an “Emacs for Reversing”, you might want to look at Quadrivio’s “General Edit”, which appears to be a hex editor with special features to let you create data structure templates to help you decode complex binary formats.
Peter Hosey
December 5th, 2006 9:57 pmYou don’t need to switch to the outline view. You can ctrl-drag to things in the icon view too.
The only reason why you need the outline view is to connect an outlet to the content view of a window (that is, [myWindow contentView], the top-level view of a window), or to a submenu of an NSMenuItem.
Thomas Ptacek
December 5th, 2006 10:34 pmThanks for the tip. gcal takes atmosphere parameters so it can accurately report sunrise time.
tom ferris
December 6th, 2006 1:33 aman ultracompare type of feature would be nice..
yan
March 3rd, 2007 6:29 pmis there any chance you can rehost the tarball?
Leave a reply