Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pure Python Implementation #32

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 4 additions & 81 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,83 +5,6 @@ cmake_policy(SET CMP0015 NEW)

set(CMAKE_BUILD_TYPE Release)

if (WIN32)
add_definitions(-D__NT__
-DUNICODE
-DWIN32
-D__IDP__)

find_library(IDA32_LIB
NAMES "ida"
PATHS "${IDA_SDK}/lib/x86_win_vc_32")

find_library(IDA64_LIB
NAMES "ida"
PATHS "${IDA_SDK}/lib/x86_win_vc_64")

find_library(MINHOOK_LIB
NAMES "libMinHook-x86-v90-md"
PATHS "lib/MinHook_13_lib/lib")

find_library(PYTHON_LIB
NAMES "python27"
PATHS "${PYTHON_DIR}/libs")

elseif (APPLE)
add_definitions(-D__MAC__=1)
find_library (IDA_LIB
NAMES "ida"
PATHS "${IDA_DIR}")
#TODO...
elseif (UNIX)
add_definitions(-D__LINUX__=1)
#TODO...
endif ( )

set (SOURCES
src/ida_ipython.cpp
src/ipythonEmbed.cpp
src/ipythonEmbed.h
src/persist.h
src/persist.cpp)

include_directories(${IDA_SDK}/include
${PYTHON_DIR}/include
lib/MinHook_13_lib/include)

add_library(ida32_ipython MODULE ${SOURCES})
add_library(ida64_ipython MODULE ${SOURCES})

if (WIN32)
set (IDA32_SUFFIX ".plw")
set (IDA64_SUFFIX ".p64")
elseif (APPLE)
# set (IDA_SUFFIX ".pmc")
elseif (UNIX)
# set (IDA_SUFFIX ".plx")
endif ()

set_target_properties (ida32_ipython
PROPERTIES
SUFFIX ${IDA32_SUFFIX}
OUTPUT_NAME ida_ipython)

set_target_properties (ida64_ipython
PROPERTIES
SUFFIX ${IDA64_SUFFIX}
COMPILE_DEFINITIONS __EA64__
OUTPUT_NAME ida_ipython)

target_link_libraries (ida32_ipython
${IDA32_LIB}
${MINHOOK_LIB}
${PYTHON_LIB})

target_link_libraries (ida64_ipython
${IDA64_LIB}
${MINHOOK_LIB}
${PYTHON_LIB})

#Read the launch script and escape chars
file(READ "launch_ida.py" LAUNCH_IDA_PY)
string(REPLACE "\"" "\\\"" LAUNCH_IDA_PY "${LAUNCH_IDA_PY}")
Expand Down Expand Up @@ -128,7 +51,7 @@ string(REPLACE
file(WRITE notebook/kernels/ida32/kernel.json ${IDA_32_KERNEL})
file(WRITE notebook/kernels/ida64/kernel.json ${IDA_64_KERNEL})

install(TARGETS ida32_ipython DESTINATION ${IDA_DIR}/plugins)
install(TARGETS ida64_ipython DESTINATION ${IDA_DIR}/plugins)
install(FILES python/ipythonEmbed.py DESTINATION ${IDA_DIR}/python)
install(FILES idc/nothing.idc DESTINATION ${IDA_DIR}/idc)
#install(TARGETS ida32_ipython DESTINATION ${IDA_DIR}/plugins)
#install(TARGETS ida64_ipython DESTINATION ${IDA_DIR}/plugins)
#install(FILES python/ipythonEmbed.py DESTINATION ${IDA_DIR}/python)
#install(FILES idc/nothing.idc DESTINATION ${IDA_DIR}/idc)
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# What's New
- Improve python plugin load order (prevents crashes when python does not load correctly)
- Add in safe IDA process termination (Special thanks to @tmr232 for this)
- Pure Python

#What and Why?
This is a plugin to embed an IPython kernel in IDA Pro. The Python ecosystem has amazing libraries (and communities) for scientific computing. IPython itself is great for exploratory data analysis. Using tools such as the IPython notebook make it easy to share code and explanations with rich media. IPython makes using IDAPython and interacting with IDA programmatically really fun and easy.
Expand All @@ -27,25 +28,26 @@ Another useful case is using IPython notebooks.
More examples..soon...

#How the plugin works
IDA is predominantly single threaded application, so we cannot safely run the kernel in a separate thread. So instead of using another thread a hook is created on the QT process events function and the `do_one_iteration` method of the ipython kernel is executed each frame.
IDA is predominantly single threaded application, so we cannot safely run the kernel in a separate thread.
So instead of using another thread, a timer is registered via IDAPython and the `do_one_iteration` method of the ipython kernel is executed each frame.

#Installation
I suggest using the [Anaconda](http://continuum.io/downloads) distribution of Python as it comes with all the required python libraries pre-built and installed. To get IDA to use Anaconda, simply set the PYTHONHOME enviroment variable. Alternatively you can install IPython and the dependencies separately.

This plugin should work on all 6.X x86 QT versions of IDA on Windows.
This plugin should work on all 6.X x86 QT versions of IDA on Windows, Linux, and OSX (only tested on Windows).

##Basic Installation and QTConsole
1. Download and extract the [release](https://github.com/james91b/ida_ipython/releases/latest)
2. Copy the contents of the `plugins` and `python` directories under IDA's installation directory.
4. Launch IDA.
5. At the command line (Windows), start an IPython qtconsole with the kernel instance (outputted in the IDA console) e.g `ipython qtconsole --existing kernel-4264.json`
2. Copy `plugin\ida_ipython.py` into IDA's `plugins` directory
4. Launch IDA
5. Under the `View` menu, click `IDAIPython QtConsole` or
6. At the command line, start an IPython qtconsole with the kernel instance (outputted in the IDA console) e.g `jupyter qtconsole --existing kernel-4264.json`

##Using the Notebook
1. Copy `idc` directory to your IDA directory. (the `nothing.idc` script is used to pass command line parameters to the plugin)
2. Change the paths to the `idaq.exe` and `idaq64.exe` executables in the `kernel.json` under the `notebook\kernels\ida32`
1. Change the paths to the `idaq.exe` and `idaq64.exe` executables in the `kernel.json` under the `notebook\kernels\ida32`
and `notebook\kernels\ida64` directories respectively
3. Install the kernels using `jupyter-kernelspec install` (e.g. `jupyter-kernelspec install --user notebook\kernels\ida64`)
4. When starting a notebook, choose the `IDA32` or `IDA64` kernels, depending on your desired IDA version.
1. Install the kernels using `jupyter-kernelspec install` (e.g. `jupyter-kernelspec install --user notebook\kernels\ida64`)
1. When starting a notebook, choose the `IDA32` or `IDA64` kernels, depending on your desired IDA version.

#How to Build
1. Install cmake
Expand Down
Empty file removed idc/nothing.idc
Empty file.
17 changes: 9 additions & 8 deletions launch_ida.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@
import subprocess
import os

CONNECTION_ARG = '-Snothing.idc -f {file}'

def launch_ida():
print sys.argv
print str(os.getpid())
conn = CONNECTION_ARG.format(file=sys.argv[1])
ida_location=sys.argv[2]
connection_file = sys.argv[1]
ida_location = sys.argv[2]
ida_process = subprocess.Popen(
[ida_location, conn],
env=dict(
PARENT_PROCESS_PID=str(os.getpid()),
**os.environ
)
[ida_location],
env=dict(
PARENT_PROCESS_PID=str(os.getpid()),
JUPYTER_CONNECTION=connection_file,
**os.environ
)
)
ida_process.wait()


if __name__ == '__main__':
launch_ida()
Loading