How to create IDA C/C++ plugins with Xcode

This is just a simple post about using Xcode to create IDA C/C++ plugins. Nothing fancy here. For great references about IDA SDK plugin writing check out The IDA Pro Book by Chris Eagle and binarypool.com tutorial.

Xcode 3.2.6 is the reference version used. The resulting project loads and compiles without any issues into Xcode 4. Why not doing this in 4? Human brain is misterious (3.x still loads by default on my system).

Let’s start…
Load Xcode and start a New Project. Use the BSD C Library template, Dynamic type (found in the Framework & Library group). Choose whatever name you want for your plugin (we can rename the binary later).

Next step is to edit project settings. Go to Project menu, Edit Project Settings. Select the Build settings and go to the Linking options group. At the Other Linker Flags insert -lida. Next go to Search Paths options group. You need to set the path to the IDA SDK header files (the idasdk/include folder) in the Header Search Paths and the path to IDA library (libida.dylib). You can copy this from IDA application into the SDK folder or just point it to the IDA application folder. It’s your call!

The last step here is to add a preprocessor macro. Add MAC into Preprocessor Macros at Preprocessing group. You can also define this at your source file. The symbols EA64 and X64 might be useful. Check install_linux.txt at the SDK for their meaning. Probably you should add these at the source file together with the LP64 to distinguish between 32 and 64 bit builds.

To finish this you may want to configure the target options. Since it’s a very simple project you can use the Project, Edit Active Target xxxx menu. Select the Build settings and go to Packaging group. Modify the Executable extension to pmc, remove/change the Executable Prefix, and configure the Product Name if you wish so.

Now add your plugin code (files should be C++ type), compile and install the plugin (you can configure Xcode to execute this step when it finishes compilation – add a new copy files build phase).

If you don’t want to use Xcode you can use the below Makefile (original from binarypool.com tutorial). Adapt it to your own needs. It’s configured for producing 32 bit binaries only.

SRC=formsample.cpp
OBJS=formsample.o
CC=g++
LD=g++
CFLAGS=-arch i386 -D__IDP__ -D__PLUGIN__ -c -D__MAC__ -I/path/to/idasdk/include $(SRC)
LDFLAGS=-arch i386 --shared $(OBJS) -L/path/to/libida -lida --no-undefined -Wl

all:
        $(CC) $(CFLAGS)
        $(LD) $(LDFLAGS) -o formsample.pmc

And that’s it!

fG!