Installing and Using Pintools and angr on Linux and Windows
Some reversing challenges are more tedious to work through by hand than they need to be. Pintools can help by measuring what a program does for different inputs. I first tried installing it on Windows, ran into command-line and library trouble, and eventually moved to Linux. These are the steps and snags I recorded along the way.
Linux
Download and extract the source
Start by downloading the Pintools source package from Intel.
On Linux, wget will fetch it; unpack the archive with tar -zxvf pin-xxxxxx.tar.gz.
Compile the instruction-counting tool
You will also need make. It is present on most systems; if yours is missing it, install it with sudo apt-get install make.
The sample tools inscount0, inscount1, and inscount2 count the instructions executed during a run. That count can be useful when a challenge checks an input one character at a time. Build the 64-bit sample with:
1 | cd source/tools/ManualExamples |
For a 32-bit target, build the corresponding version instead:
1 | make obj-ia32/inscount0.so |
By default, inscount0.cpp writes the count to a file. I wanted a script to read the result directly, so I changed the output in Fini before recompiling:
1 | 41 VOID Fini(INT32 code, VOID *v) |
Comment out the file-writing lines, add the cout line with whatever label you prefer, and rebuild. Then run the resulting .so through Pin:
1 | pin -t <yourpintool> -- <executable> |
The count now appears in the program’s output. For example:
1 | pin -t myinscout.so -- /bin/sh -c exit |
prints something like:
1 | Count:1089205 |
That makes it possible to automate a challenge. In Xiangyun Cup re1, the input is checked character by character, so I tried candidates in turn and watched the instruction count for changes:
1 | from subprocess import Popen, PIPE |
The script starts a fresh process for each candidate with subprocess, writes the candidate to stdin, and reads the count back from stdout.
Windows
Windows was a much less pleasant experience.
Downloading and modifying the source was not the hard part; getting it to compile with make on Windows was.
I installed Visual Studio and Cygwin’s make, configured the environment, and still could not get the build to succeed.
Other blogs also reported different instruction counts for identical inputs on Windows. At that point, Linux looked much more attractive for this job.
Eventually I gave up on the Windows Pintools setup.
For a Windows challenge, I turned to angr instead.
angr
Install it with pip install angr.
angr supports Python 3 now, so there is no need to follow the old Python 2 setup guides. The example below creates a project and initial state, explores toward a success address while avoiding a failure address, and prints the input it finds:
1 | import angr |



