Random ramblings of a anonymous software engineer. Contains occasional profanity. Personal opinions, not related to employer.

Binwalk on OSX

This is a old post that has been migrated. While the content is probably very obsolete, in case someone needs it, it's here. Also makes great filler for a empty blog.

Note: These steps are no longer needed except for very specific use cases. For normal usage, brew install binwalk will do the trick. (When I wrote this, this formula did not exist.)

Recently I encountered this nifty tool for going through the binary data of firmware images and other random neat things. (of many cases are probably of somewhat questionable nature, but putting minor details aside...) The only catch I had to deal with was a minor quirk in the main distribution that wasn't exactly friendly for those who aren't on Linux - not a first, but still something that needed to be worked around to be able to use the tool on my platform of choice.

First you will need libmagic which this tool depends on, either you can download the version 5.04 here or use a package manager like Homebrew to install. In my case, for the sake of simplicity I used brew install libmagic.

The minor changes that are needed to make it compile on Mac OS X are the following:

  • Add -I/usr/local/Cellar/libmagic/5.04/include (or the path where you have magic.h) to CFLAGS
  • Remove -static from CFLAGS as this doesn't play well on OS X
  • Define LDFLAGS=-L/usr/local/Cellar/libmagic/5.04/lib (or the path where you have libmagic), and add $(LDFLAGS) into the compilation command.
  • (Optional) Add -mmacosx-version-min=10.4 in CFLAGS

I'll probably whip up a brew formula when I happen to find time someday, but for now if you need to use it this should do the trick.