Tag Archives: Binary Ninja

Running Binary Ninja under WSL

These days, I have access to a Windows 10 laptop, as opposed to my usual set of tools. One feature of Windows 10 that I really like is Windows Subsystem for Linux, or WSL for short. In case you have not followed the developments, it is a way to run native Linux executables under Windows, without the need for a full blown virtual machine (again, more info on the link provided). WSL is under constant development and it looks like a promising technology.

If you have been doing software reverse engineering, chances are you have heard about Binary Ninja, a reversing platform (and if not, click on the link ASAP, you are missing out). Binary Ninja can run natively on Windows, OSX and Linux. Provided you have the (cheap!) professional version you can also run it in headless mode. The following post will show you how you can run Binary Ninja in both GUI and headless mode under WSL.

I decided to take advantage of some sales in MSFT Windows Shop so I am using Pengwin, as my WSL distribution, and X410 as my add-on X-Server, for a total cost of $20.00. In case that you do not want to spend any money (free as in beer) or prefer FOSS alternatives (free as in speech), this list will provide a lot of alternatives, but as always YMMV.

BinaryNinja comes as a zip file. Unzip it at a location of your choice, for the sake of discussion I will assume that it is $HOME. Attempting to run it as-is, will result in a error message, similar to the one below:

qt.qpa.xcb: could not connect to display
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem. Available platform plugins are: xcb. [1] 217 abort (core dumped) ./binaryninja/binaryninja

This is due to the fact that the DISPLAY variable is not set by default. Edit your login script’s rc file (I use the excellent zsh so my rc file is ~/.zshrc, for bash it is ~/.bashrc) and add:

export DISPLAY=127.0.0.1:0.0

retry running and voila! You have GUI Binary Ninja running.

Attempting to run Binary Ninja in headless mode, will give the following error:

ModuleNotFoundError: No module named 'binaryninja'

[EDIT] The canonical solution to this is to go to your Binary Ninja install directory and run the scripts/install_api.py Python script. By doing this, a .pth file is added. Solution courtesy of Binary Ninja Slack (which is a great community to join).

one other solution to this is to set PYTHONPATH, if not set already or expand it if set. Edit your login script’s rc file and add the following one liner that takes care of both cases (adjust for your BinaryNinja installation directory):

[[ ! -z "$PYTHONPATH" ]] && export PYTHONPATH=$PYTHONPATH:$HOME/binaryninja/python || export PYTHONPATH=$HOME/binaryninja/python

Running one of the example programs should work now.

Personally, I made the transition to Python3 (and if you need some reasons, have a look here). BinaryNinja by default uses a Python2 provider – to change this to a Python3 provider, as provided by Pengwin, open advanced settings and select:

/usr/lib/x86_64-linux-gnu/libpython3.7m.so.1.0

These are the basic steps for my BinaryNinja/WSL setup. If something is missing, feel free to drop a comment or a line anytime and I will update the post accordingly. Happy reversing!

[EDIT] Important update: update to version 1.1.1689

By updating to the latest stable version, I was greeted with the following error:

qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem. Available platform plugins are: xcb. [1] 63 abort (core dumped) ./binaryninja/binaryninja

In order to debug this properly, you can set the environmental variable QT_DEBUG_PLUGINS to 1, as shown below:

export QT_DEBUG_PLUGINS=1

Attempting to rerun the app, we see the following [SNIPPED for brevity:

Got keys from plugin meta data ("xcb")
QFactoryLoader::QFactoryLoader() checking directory path "/home/orly/binaryninja/platforms" …
Cannot load library /home/orly/binaryninja/qt/platforms/libqxcb.so: (libxkbcommon-x11.so.0: cannot open shared object file: No such file or directory)
QLibraryPrivate::loadPlugin failed on "/home/orly/binaryninja/qt/platforms/libqxcb.so" : "Cannot load library /home/orly/binaryninja/qt/platforms/libqxcb.so: (libxkbco
mmon-x11.so.0: cannot open shared object file: No such file or directory)"
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem

Now we are getting somewhere, as we have the name of the missing dependency.

sudo apt-get install -y libxkbcommon-x11-0

… and BinaryNinja works again!