Skip to content

Commit

Permalink
Added python binding #4
Browse files Browse the repository at this point in the history
  • Loading branch information
loonydev committed Aug 6, 2019
1 parent ba4c345 commit 506b1fd
Show file tree
Hide file tree
Showing 7 changed files with 1,131 additions and 4 deletions.
126 changes: 126 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,128 @@
.vscode/
build/
config.json

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
10 changes: 6 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
cmake_minimum_required(VERSION 2.8.2 FATAL_ERROR)
cmake_policy(VERSION 2.8)

include(cmake/modules/GolangSimple.cmake)
project( RACEPWN )

set (CMAKE_C_FLAGS "-Werror -Wall -Wextra -Wno-unused-parameter -D_GNU_SOURCE -std=c11 -O3 -g ${CMAKE_C_FLAGS}")
set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_LIST_DIR}/cmake/modules )

include( GolangSimple )

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
set (CMAKE_C_FLAGS "-Werror -Wall -Wextra -Wno-unused-parameter -D_GNU_SOURCE -std=c11 -O3 -g ${CMAKE_C_FLAGS}")

include(GNUInstallDirs)
include( GNUInstallDirs )

add_subdirectory(lib)
add_subdirectory(racepwn)
54 changes: 54 additions & 0 deletions bindings/python/build_wrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import os
from sys import platform as _platform

# If you want to use local build, change this path to build folder
#
# Example:
# RACE_INC_DIR = "~/github/racepwn/lib/include/"
# RACE_LIB_DIR = "~/github/racepwn/build/lib/"
# RACE_LIB = "~/github/racepwn/build/lib/librace.so (or .dylib for OSX)
# RACE_HEADERS = "~/github/racepwn/lib/include/race.h"

def detect_lib():
if _platform == "linux" or _platform == "linux2":
return ".so"
elif _platform == "darwin":
return ".dylib"

RACE_INC_DIR = "/usr/local/include/race/"
RACE_LIB_DIR = "/usr/local/lib/"
RACE_LIB = "librace"+detect_lib()
RACE_HEADERS = "/usr/local/include/race/race.h"
RACE_RAW_HEADERS = "/usr/local/include/race/race_raw.h"

# WARNING!!!!
# Enum broken in ctypesgen.
# https://github.com/davidjamesca/ctypesgen/issues/60
#
# My pull still pending.
# So use my fork https://github.com/loonydev/ctypesgen

# WARNING2!!!!
# If you use python3 you may have problem with librace after generation
#
# Known issues:
# unicode - just delete, in python3 str is equesl to unicode

# Set location of ctypesgen.py installed or copied from
# https://github.com/davidjamesca/ctypesgen
#
# Example:
# ctypesgen_path = '~/github/ctypesgen/ctypesgen.py' # - local
# ctypesgen_path = 'ctypesgen.py' # - installed
#
# For Python3 use this fork https://github.com/Sillern/ctypesgen.git
ctypesgen_path = '~/github/ctypesgen_python3/ctypesgen/ctypesgen.py' # - local
# ctypesgen_path = 'ctypesgen.py' # - installed

wrapper_filename = 'librace.py'
cmd = "LD_LIBRARY_PATH={} {} -I {} -L {} -l {} {} {} -o {} ".format(
RACE_LIB_DIR, ctypesgen_path, RACE_INC_DIR, RACE_LIB_DIR, RACE_LIB,
RACE_HEADERS,RACE_RAW_HEADERS, wrapper_filename)

print(cmd)
os.system(cmd)
Loading

0 comments on commit 506b1fd

Please sign in to comment.