This is a guest entry written by Elias Bachaalany. His views and opinions are his own and not those of Hex-Rays. Any questions with regards to the content of this blog post should be directed to the author.
During the IDA Advanced training, I get asked a lot about how to set up the IDA SDK and how to buid IDAPython and extend it. In this article, we will show you how to build IDAPython on Windows.
On Linux/macOS, the process is straightforward as per the BUILDING.txt.
In this article:
Make sure you already installed the latest IDA for Windows and grabbed yourself a copy of the SDK.
Let's get started.
IDA SDK's default configuration is targeted towards VS 2019. Just to keep this article simple, let's stick with that.
Grab VS2019 from here https://visualstudio.microsoft.com/vs/older-downloads/
When you install it, make sure you leave all the default installation location (in the C:\Program Files (x86)
, etc.)
Download Cygwin 64 and install the following components:
make
from the Devel
category.unzip
from the Archive
category.Download Python 3.x AMD64 (say 3.4 to 3.11) and select custom install:
After Python is installed, install the six
module:
C:\PythonXY\Scripts\pip install six
In this section, we will build SWIG for Windows from scratch. We need a special patched version of SWIG (version 4.0.1, with support for -py3-limited-api
) and we cannot use the pre-built binaries.
Whether you are using a Linux distro (for example Ubuntu 20) or WSL on Windows 10/11, all the steps below still apply.
Depending on your Linux setup, you may have already installed the needed packages. Just to be on the safe side, you need the following:
sudo apt update
sudo apt install wget build-essential mingw-w64 byacc bison automake autotools-dev patchelf -y
If mingw-64 failed to install:
sudo apt-add-repository ppa:mingw-w64/ppa && sudo apt-get update && sudo apt-get install mingw-w64
git clone --branch py3-stable-abi https://github.com/idapython/swig.git swig-py3-stable-abi
Download PCRE directly into SWIG's source directory:
wget https://master.dl.sourceforge.net/project/pcre/pcre/8.10/pcre-8.10.tar.bz2
Then edit the PCRE build script in SWIG to specify the host compiler:
Open ./Tools/pcre-build.sh
and change this line:
cd pcre && ./configure --prefix=$pcre_install_dir --disable-shared $* || bail "PCRE configure failed"
To:
cd pcre && ./configure --host=x86_64-w64-mingw32 --prefix=$pcre_install_dir --disable-shared $* || bail "PCRE configure failed"
(we only added the --host
switch)
Now just run the PCRE build script again:
./Tools/pcre-build.sh
You are now ready to build SWIG.
First run ./autogen.sh
, then run the configure script with the --host
switch, while also specifying static linking:
LDFLAGS="-static -static-libgcc -static-libstdc++" \
./configure --host=x86_64-w64-mingw32 --prefix=/tmp/swig4-win
Now you can run make
and make install
as usual.
Alternatively, you can download the pre-build version from here.
Copy the SWIG Windows binaries from /tmp/swig4-win
to your Windows machine. Let's put them in C:\idasdk\swig4
.
Download the IDA SDK and unzip to a folder, for example c:\idasdk
.
If you have the Decompiler installed, then copy the Decompiler headers from <ida_install>/plugins/hexrays_sdk/include/hexrays.hpp
to c:\idasdk\include
.
We need to configure various configurations. Open the "Developer Command Prompt for VS 2019".
If Cygwin was not in the path, then typing 'make' will cause an error. If that's the case, just add it to the PATH:
set PATH=c:\cygwin64\bin;%PATH%
(Keep that command prompt open for the remainder of this article.)
From c:\idasdk
, type the following commands:
cd c:\idasdk
set __NT__=1
set __X64__=1
Now let's generate the various config files:
cmd /c "set __EA64__=1 && make env"
cmd /c "set __EA64__=1 && set NDEBUG=1 && make env"
make env
cmd /c "set NDEBUG=1 && make env
If you have done everything right, you should have these files in c:\idasdk
:
To test if everything is okay, let's try building the hello
plugin:
cd c:\idasdk\plugins\hello
make
Last but not least, let's put the IDA binaries in the correct place in accordance with the SDK make system. Assuming that IDA was installed in C:\Tools\IDA82
:
xcopy /s c:\Tools\IDA82 c:\idasdk\bin
Now, anything we build will go to c:\idasdk\bin\[plugins|loaders|procs]
:
plugins
: for plugin binariesloaders
: for loader modulesprocs
: for processor modulesOkay, now we are ready to build IDAPython!
Navigate to c:\idasdk\plugins
and clone IDAPython there:
git clone https://github.com/idapython/src.git idapython
Now we have all the prerequisit steps completed, let's build IDAPython:
set PYTHON_VERSION_MAJOR=X
set PYTHON_VERSION_MINOR=Y
C:\PythonXY\python.exe build.py --with-hexrays --swig-home c:\ida\swig4 --ida-install c:\idasdk\bin --debug
X
and Y
with the proper values--with-hexrays
switch--debug
for optimized builds.build.py --help
for more informationBe patient, this can take between 5 and 30 minutes to complete the first time.
I know, this has been tedious but I hope it is helpful.
Contributions and suggestions to IDAPython. We are happy to discuss and merge your changes as applicable.