8000 pyqbdi for python3 with pybind11 by nsurbay · Pull Request #121 · QBDI/QBDI · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

pyqbdi for python3 with pybind11 #121

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

Merged
merged 25 commits into from
Feb 26, 2020
Merged
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
59 changes: 49 additions & 10 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,29 @@ configuration:
- Release

environment:
PYTHON: "C:\\Python35-x64"
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
CMAKE_TEMPLATE: Visual Studio 14 2015
PYTHON35LIB: "libs\\python35.lib"
PYTHON36LIB: "libs\\python36.lib"
PYTHON37LIB: "libs\\python37.lib"
PYTHON38LIB: "libs\\python38.lib"
matrix:
- platform: X64
qbdi_plateform: win-X86_64
VS_string: "Visual Studio 14 2015 Win64"
cmake_platform_args: "-Thost=x64"
qbdi_plateform: "win-X86_64"
PYTHON35: "C:\\Python35-x64"
PYTHON36: "C:\\Python36-x64"
PYTHON37: "C:\\Python37-x64"
PYTHON38: "C:\\Python38-x64"
- platform: X86
qbdi_plateform: win-X86
VS_string: "Visual Studio 14 2015"
cmake_platform_args: ""

qbdi_plateform: "win-X86"
PYTHON35: "C:\\Python35"
PYTHON36: "C:\\Python36"
PYTHON37: "C:\\Python37"
PYTHON38: "C:\\Python38"

cache:
- deps\llvm\%qbdi_plateform%\lib -> deps\llvm\build.py
Expand All @@ -36,26 +46,55 @@ install:
# Prepend newly installed Python to the PATH of this build (this cannot be
# done from inside the powershell script as it would require to restart
# the parent CMD process).
- "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"

- "SET OLDPATH=%PATH%"
- "SET PATH=%PYTHON35%;%PYTHON35%\\Scripts;%OLDPATH%"
- cmd: mkdir build
- cmd: cd build

build_script:
- "\"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall.bat\" %Platform%"
- cmd: cmake .. -G "%VS_string%" -DCMAKE_CROSSCOMPILING=FALSE -DCMAKE_BUILD_TYPE=%configuration% -DPLATFORM=%qbdi_plateform% -DEXAMPLES=TRUE %cmake_platform_args%
- cmd: cmake .. -G "%VS_string%" -DCMAKE_CROSSCOMPILING=FALSE -DCMAKE_BUILD_TYPE=%configuration% -DPLATFORM=%qbdi_plateform% -DTOOLS_PYQBDI=Off -DEXAMPLES=On %cmake_platform_args%
- ps: if (-not((Test-Path("../deps/llvm/$env:qbdi_plateform/lib")) -and (Test-Path("../deps/llvm/$env:qbdi_plateform/include")))) { MSbuild deps\llvm.vcxproj /p:Configuration=$env:configuration,Platform=$env:platform /m:3 }
- cmd: python ..\deps\llvm\build.py clean %qbdi_plateform%
- ps: if (-not((Test-Path("../deps/gtest/$env:qbdi_plateform/lib")) -and (Test-Path("../deps/gtest/$env:qbdi_plateform/include")))) { MSbuild deps\gtest.vcxproj /p:Configuration=$env:configuration,Platform=$env:platform /m:3 }
- cmd: python ..\deps\gtest\%qbdi_plateform%\build.py clean %qbdi_plateform%
- cmd: cmake .. -G "%VS_string%" -DCMAKE_CROSSCOMPILING=FALSE -DCMAKE_BUILD_TYPE=%configuration% -DPLATFORM=%qbdi_plateform% -DEXAMPLES=TRUE %cmake_platform_args%
- cmd: cmake .. -G "%VS_string%" -DCMAKE_CROSSCOMPILING=FALSE -DCMAKE_BUILD_TYPE=%configuration% -DPLATFORM=%qbdi_plateform% -DTOOLS_PYQBDI=Off -DEXAMPLES=On %cmake_platform_args%
- cmd: MSbuild /p:Configuration=%configuration%,Platform=%platform% ALL_BUILD.vcxproj /m:3

test_script:
- cmd: c:\projects\qbdi\build\test\Release\QBDItest

after_build:
- cmd: cpack
- cmd: cd ..
# build 3.5
- "SET PATH=%PYTHON35%;%PYTHON35%\\Scripts;%OLDPATH%"
- "SET PYTHON_LIBRARIES=%PYTHON35%\\%PYTHON35LIB%"
- "SET PYTHON_INCLUDE_DIRS=%PYTHON35%\\include"
- cmd: "%PYTHON35%\\python.exe -m pip install setuptools wheel"
- cmd: "%PYTHON35%\\python.exe setup.py bdist_wheel"
# build 3.6
- "SET PATH=%PYTHON36%;%PYTHON36%\\Scripts;%OLDPATH%"
- "SET PYTHON_LIBRARIES=%PYTHON36%\\%PYTHON36LIB%"
- "SET PYTHON_INCLUDE_DIRS=%PYTHON36%\\include"
- cmd: "%PYTHON36%\\python.exe -m pip install setuptools wheel"
- cmd: "%PYTHON36%\\python.exe setup.py bdist_wheel"
# build 3.7
- "SET PATH=%PYTHON37%;%PYTHON37%\\Scripts;%OLDPATH%"
- "SET PYTHON_LIBRARIES=%PYTHON37%\\%PYTHON37LIB%"
- "SET PYTHON_INCLUDE_DIRS=%PYTHON37%\\include"
- cmd: "%PYTHON37%\\python.exe -m pip install setuptools wheel"
- cmd: "%PYTHON37%\\python.exe setup.py bdist_wheel"
# build 3.8
- "SET PATH=%PYTHON38%;%PYTHON38%\\Scripts;%OLDPATH%"
- "SET PYTHON_LIBRARIES=%PYTHON38%\\%PYTHON38LIB%"
- "SET PYTHON_INCLUDE_DIRS=%PYTHON38%\\include"
- cmd: "%PYTHON38%\\python.exe -m pip install setuptools wheel"
- cmd: "%PYTHON38%\\python.exe setup.py bdist_wheel"

test_script:
- cmd: c:\projects\qbdi\build\test\Release\QBDItest

artifacts:
- name: Installer
path: 'build\QBDI-*.exe'
- name: Python package
path: 'dist\PyQBDI-*.whl'
13 changes: 13 additions & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: 2

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/source/conf.py

formats: all

python:
version: 3.7
install:
- requirements: docs/requirements.txt
- requirements: docs/requirements.pyqbdi.txt
36 changes: 14 additions & 22 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,41 @@
language: cpp

addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++
- ccache
homebrew:
packages:
- ccache
- g++
- python3

linux_target: &linux_target
_linux_target: &linux_target
os: linux
dist: xenial
compiler: gcc
env:
QBDI_PLATFORM="linux-X86_64"

linux_target32: &linux_target32
_linux_target32: &linux_target32
os: linux
dist: xenial
compiler: gcc
env:
QBDI_PLATFORM="linux-X86"

osx_target: &osx_target
_osx_target: &osx_target
os: osx
osx_image: xcode9.4
env:
- QBDI_PLATFORM="macOS-X86_64"
- CMAKE_ARGS="-DCMAKE_BUILD_TYPE=Release -DCMAKE_CROSSCOMPILING=FALSE -DPLATFORM=${QBDI_PLATFORM} -DTOOLS_VALIDATOR=TRUE -DEXAMPLES=TRUE"

osx_target32: &osx_target32
_osx_target32: &osx_target32
os: osx
osx_image: xcode9.4
env:
- QBDI_PLATFORM="macOS-X86"
- CMAKE_ARGS="-DCMAKE_BUILD_TYPE=Release -DCMAKE_CROSSCOMPILING=FALSE -DPLATFORM=${QBDI_PLATFORM} -DTOOLS_VALIDATOR=TRUE -DEXAMPLES=TRUE"

install_llvm: &install_llvm
_install_llvm: &install_llvm
script:
- mkdir build && cd build
- cmake .. ${CMAKE_ARGS}
Expand All @@ -48,7 +44,7 @@ install_llvm: &install_llvm
# Reduce cache size
- python3 ../deps/llvm/build.py clean ${QBDI_PLATFORM}

install_gtest: &install_gtest
_install_gtest: &install_gtest
script:
- mkdir build && cd build
- cmake .. ${CMAKE_ARGS}
Expand All @@ -57,36 +53,34 @@ install_gtest: &install_gtest
# Reduce cache size
- sh ../deps/gtest/${QBDI_PLATFORM}/build.sh clean

docker_llvm: &docker_llvm
_docker_llvm: &docker_llvm
services:
- docker
script:
- bash ./docker/travis_linux/llvm.sh

install_gtest: &docker_gtest
_docker_gtest: &docker_gtest
services:
- docker
script:
- bash ./docker/travis_linux/gtest.sh

compile_and_test: &compile_and_test
_compile_and_test: &compile_and_test
script:
- mkdir build && cd build
- cmake .. ${CMAKE_ARGS}
- make -j2
- ./test/QBDITest

docker_compile_and_test: &docker_compile_and_test
_docker_compile_and_test: &docker_compile_and_test
services:
- docker
script:
- bash ./docker/travis_linux/qbdi.sh

cache:
- apt
- ccache

cache:
apt: TRUE
ccache: TRUE
directories:
- deps/llvm/linux-X86_64/include
- deps/llvm/linux-X86_64/lib
Expand All @@ -106,8 +100,6 @@ cache:
- deps/gtest/macOS-X86/lib
- tools/validation_runner/travis_db

sudo: required

jobs:
include:
- stage: deps_llvm
Expand Down
11 changes: 3 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,9 @@ ENDFUNCTION(PREPEND)
set(_LLVM_STATIC_LIBS LLVMBinaryFormat.a LLVMMCDisassembler.a LLVMSelectionDAG.a LLVMAsmPrinter.a LLVMCodeGen.a LLVMScalarOpts.a LLVMInstCombine.a LLVMTransformUtils.a LLVMAnalysis.a LLVMTarget.a LLVMObject.a LLVMMCParser.a LLVMBitReader.a LLVMCore.a LLVMMC.a LLVMSupport.a)

if(${PLATFORM} STREQUAL "linux-X86" OR ${PLATFORM} STREQUAL "linux-X86_64")
find_package(Curses REQUIRED)
set(NCURSES_LDFLAGS "-lncurses")
if(CURSES_EXTRA_LIBRARY)
set(NCURSES_LDFLAGS "${NCURSES_LDFLAGS} -ltinfo")
endif()

set(_LLVM_STATIC_LIBS ${_LLVM_STATIC_LIBS} LLVMProfileData.a LLVMX86Disassembler.a LLVMX86AsmParser.a LLVMX86CodeGen.a LLVMX86Desc.a LLVMX86Info.a LLVMX86AsmPrinter.a LLVMX86Utils.a)
set(LLVM_LIBS -lrt -ldl ${NCURSES_LDFLAGS} -latomic -lpthread -lz -lm -lstdc++)
set(LLVM_LIBS -lrt -ldl -lpthread -lz -lm -lstdc++)

elseif((${PLATFORM} STREQUAL "win-X86_64") OR (${PLATFORM} STREQUAL "win-X86"))

Expand All @@ -204,7 +199,7 @@ elseif(${PLATFORM} STREQUAL "linux-ARM")
elseif(${PLATFORM} STREQUAL "macOS-X86" OR ${PLATFORM} STREQUAL "macOS-X86_64")

set(_LLVM_STATIC_LIBS ${_LLVM_STATIC_LIBS} LLVMDemangle.a LLVMX86Disassembler.a LLVMX86AsmParser.a LLVMX86CodeGen.a LLVMX86Desc.a LLVMX86Info.a LLVMX86AsmPrinter.a LLVMX86Utils.a)
set(LLVM_LIBS -lz -lpthread -lffi -ledit -lcurses -lm -lc++)
set(LLVM_LIBS -lz -lpthread -lffi -ledit -lm -lc++)

elseif(${PLATFORM} STREQUAL "android-ARM")

Expand All @@ -219,7 +214,7 @@ elseif((${PLATFORM} STREQUAL "android-X86") OR (${PLATFORM} STREQUAL "android-X8
elseif(${PLATFORM} STREQUAL "iOS-ARM")

set(_LLVM_STATIC_LIBS ${_LLVM_STATIC_LIBS} LLVMDemangle.a LLVMProfileData.a LLVMARMDisassembler.a LLVMARMCodeGen.a LLVMARMAsmParser.a LLVMARMDesc.a LLVMARMInfo.a LLVMARMAsmPrinter.a LLVMARMUtils.a)
set(LLVM_LIBS -lz -lpthread -ledit -lcurses -lm -lc++)
set(LLVM_LIBS -lz -lpthread -ledit -lm -lc++)

endif()

Expand Down
59 changes: 59 additions & 0 deletions README-pypi.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
Introduction
============

.. image:: https://readthedocs.org/projects/qbdi/badge/?version=stable
:target: https://qbdi.readthedocs.io/en/stable/?badge=stable
:alt: Documentation Status

.. image:: https://travis-ci.com/QBDI/QBDI.svg?branch=master
:target: https://travis-ci.com/QBDI/QBDI

.. image:: https://ci.appveyor.com/api/projects/status/s2qvpu8k8yiau647/branch/master?svg=true
:target: https://ci.appveyor.com/project/QBDI/qbdi/branch/master

.. intro

QuarkslaB Dynamic binary Instrumentation (QBDI) is a modular, cross-platform and cross-architecture
DBI framework. It aims to support Linux, macOS, Android, iOS and Windows operating systems running on
x86, x86-64, ARM and AArch64 architectures. Information about what is a DBI framework and how QBDI
works can be found in the user documentation introduction (`User Documentation <https://qbdi.readthedocs.io/en/stable/user.html>`_).

QBDI modularity means it doesn't contain a preferred injection method and it is designed to be
used in conjunction with an external injection tool. QBDI includes a tiny (``LD_PRELOAD`` based)
Linux and macOS injector for dynamic executables (QBDIPreload), which acts as the foundation for our
Python bindings (pyQBDI).
QBDI is also fully integrated with `Frida <https://frida.re>`_, a reference dynamic instrumentation toolkit,
allowing anybody to use their combined powers.

x86-64 support is mature (even if SIMD memory access are not yet reported). The support of x86
is new and some bug may occur. ARM architecture is
a work in progress but already sufficient to execute simple CLI program like *ls* or *cat*.
AArch64 is planned, but currently unsupported.

A current limitation is that QBDI doesn't handle signals, multithreading (it doesn't deal with new
threads creation) and C++ exception mechanisms.
However, those system-dependent features will probably not be part of the core library (KISS),
and should be integrated as a new layer (to be determined how).

Status
------

.. role:: green
.. role:: yellow
.. role:: orange
.. role:: red

======= ============================== ====================== =================================
CPU Operating Systems Execution Memory Access Information
======= ============================== ====================== =================================
x86-64 Android, Linux, macOS, Windows :green:`Supported` :yellow:`Partial (only non SIMD)`
x86 Android, Linux, macOS, Windows :green:`Supported` :yellow:`Partial (only non SIMD)`
ARM Linux, Android, iOS :orange:`Planned (*)` :orange:`Planned (*)`
AArch64 Android :orange:`Planned (*)` :orange:`Planned (*)`
======= ============================== ====================== =================================

.. warning::

The ARM and AArch64 instruction sets are supported but they still need to be integrated along with x86 and x86-64.


44 changes: 44 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
.. image:: https://readthedocs.org/projects/qbdi/badge/?version=stable
:target: https://qbdi.readthedocs.io/en/stable/?badge=stable
:alt: Documentation Status

.. image:: https://travis-ci.com/QBDI/QBDI.svg?branch=master
:target: https://travis-ci.com/QBDI/QBDI

.. image:: https://ci.appveyor.com/api/projects/status/s2qvpu8k8yiau647/branch/master?svg=true
:target: https://ci.appveyor.com/project/QBDI/qbdi/branch/master

.. image:: https://img.shields.io/github/v/release/QBDI/QBDI
:target: https://github.com/QBDI/QBDI/releases

.. image:: https://img.shields.io/pypi/pyversions/PyQBDI
:target: https://pypi.org/project/PyQBDI/

.. image:: https://img.shields.io/pypi/v/PyQBDI
:target: https://pypi.org/project/PyQBDI/

Introduction
============
.. intro
Expand Down Expand Up @@ -48,6 +67,10 @@ AArch64 Android :orange:`Planned (*)` :orange:`Pla

**stable**

.. image:: https://readthedocs.org/projects/qbdi/badge/?version=stable
:target: https://qbdi.readthedocs.io/en/stable/?badge=stable
:alt: Documentation Status

.. image:: https://travis-ci.com/QBDI/QBDI.svg?branch=master
:target: https://travis-ci.com/QBDI/QBDI

Expand All @@ -56,6 +79,10 @@ AArch64 Android :orange:`Planned (*)` :orange:`Pla

**dev**

.. image:: https://readthedocs.org/projects/qbdi/badge/?version=dev-next
:target: https://qbdi.readthedocs.io/en/stable/?badge=dev-next
:alt: Documentation Status

.. image:: https://travis-ci.com/QBDI/QBDI.svg?branch=dev-next
:target: https://travis-ci.com/QBDI/QBDI/branches

Expand All @@ -64,6 +91,23 @@ AArch64 Android :orange:`Planned (*)` :orange:`Pla

.. intro-end

Installation
============

C/C++/Frida API
---------------

Each new version of QBDI is compiled and available on Github release page (https://github.com/QBDI/QBDI/releases).

Python API (PyQBDI)
-------------------

PyQBDI is available on Pypi. The wheel package can be downloaded (https://pypi.org/project/PyQBDI/#files) or installed with pip command.::

pip install PyQBDI

PyQBDI package is independent of C/C++ package.

Compilation
===========
.. compil
Expand Down
Loading
0