Fork me on GitHub

Project Notes

#493 Hex Fiend

About Hex Fiend, an open source hex editor for macOS, with a test of using it to modify macOS executables.

Notes

I think I first heard about Hex Fiend on the Unnamed Reverse Engineering Podcast. Finally decided to check it out

Installation is straight-forward from the DMG. A menu option installs cli support for hexf.

Testing Binary Edit

Let’s modify a binary, say c/hello. First let’s compile and run the original program:

$ cd c/hello/
$ make clean
rm -f hello *.o
rm -fR *.dSYM
$ make
gcc -Wall -O3    hello.c   -o hello
$ ./hello
Hello, world.
$ strings -t x hello
48c Hello, world.

Now edit with Hex Fiend

hexf hello

original

Let’s modify the strings, keeping the same string length to avoid issues with offsets etc.

modified

After save, we can find the modified string, but the OS refuses to run it because the signature is now invalid.

$ strings -t x hello
48c HELLO, WORLD!
$ ./hello
Killed: 9                  ./hello
$ codesign -vvv ./hello
./hello: invalid signature (code or signature have been modified)
In architecture: arm64

So let’s resign to fix that:

$ codesign -s - hello
$ codesign -vvv ./hello
./hello: valid on disk
./hello: satisfies its Designated Requirement
$ ./hello
HELLO, WORLD!

Now running with our modified strings.

Credits and References

About LCK#493
toolsmacOS

This page is a web-friendly rendering of my project notes shared in the LittleCodingKata GitHub repository.

Project Source on GitHub Return to the LittleCodingKata Catalog
About LittleCodingKata

LittleCodingKata is my collection of programming exercises, research and code toys broadly spanning things that relate to programming and software development (languages, frameworks and tools).

These range from the trivial to the complex and serious. Many are inspired by existing work and I'll note credits and references where applicable. The focus is quite scattered, as I variously work on things new and important in the moment, or go back to revisit things from the past.

This is primarily a personal collection for my own edification and learning, but anyone who stumbles by is welcome to borrow, steal or reference the work here. And if you spot errors or issues I'd really appreciate some feedback - create an issue, send me an email or even send a pull-request.

Follow the Blog follow projects and notes as they are published in your favourite feed reader