From 749c1d3e310a3df5d6f2ce10135129aa3f6142b7 Mon Sep 17 00:00:00 2001 From: jakob Date: Tue, 29 Aug 2017 16:02:44 -0400 Subject: setup.py and the makefile both install the wrapper library properly now --- hypodermic/ptrace.py | 18 +++++++++++++++--- setup.py | 8 ++++++-- wrapper/Makefile | 12 +++++++++++- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/hypodermic/ptrace.py b/hypodermic/ptrace.py index 7a14dea..f54d982 100644 --- a/hypodermic/ptrace.py +++ b/hypodermic/ptrace.py @@ -18,6 +18,7 @@ """ctypes wrapper for ptrace.""" import ctypes +import os.path class Process(object): @@ -38,8 +39,9 @@ class Process(object): Raises: TypeError: If the pid argument is not an int, or if the path argument is not a string. - OSError: If the pid cannot be attached to, or if the process - could not be created for the given binary. + OSError: If the pid cannot be attached to, if the process could + not be created for the given binary, or if any wrapper + libraries could not be loaded. """ def __init__(self, pid=0, path=""): @@ -64,7 +66,17 @@ class Process(object): self.detach() def _load_ffi_methods(self): - self._so = ctypes.cdll.LoadLibrary("/tmp/libhypodermicw.so") + # setuptools/cython hack. + script_path = os.path.abspath(os.path.dirname(__file__)) + + for filename in os.listdir(os.path.join(script_path, "..")): + if filename.startswith("libhypodermicw"): + lib_path = os.path.join(script_path, "..", filename) + break + else: + raise OSError("Could not find wrapper library.") + + self._so = ctypes.cdll.LoadLibrary(lib_path) self._new_proc = self._so.new_proc self._attach = self._so.attach self._detach = self._so.detach diff --git a/setup.py b/setup.py index 118ca85..58ca457 100644 --- a/setup.py +++ b/setup.py @@ -1,11 +1,14 @@ #!/usr/bin/env python try: - from setuptools import setup + from setuptools import setup, Extension except ImportError: - from distutils.core import setup + from distutils.core import setup, Extension +from glob import glob + from hypodermic import __version__ +lib = Extension("libhypodermicw", sources = ["wrapper/ptrace.c"]) def long_description(): with open("README.md") as description: @@ -26,6 +29,7 @@ setup( download_url="https://github.com/TsarFox/hypodermic", packages=["hypodermic"], include_package_data=True, + ext_modules=[lib], install_requires=[], extras_require={}, tests_require=[], diff --git a/wrapper/Makefile b/wrapper/Makefile index 19fa189..2e7efee 100644 --- a/wrapper/Makefile +++ b/wrapper/Makefile @@ -6,7 +6,17 @@ CFLAGS += $(USER_CFLAGS) LDFLAGS = -shared LDFLAGS += $(USER_LDFLAGS) +BIN = libhypodermicw.so + all: libhypodermicw.so -libhypodermicw.so: ptrace.c +$(BIN): ptrace.c $(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) + ln -s $@ ../$@ + + +clean: + rm -f $(BIN) + rm -f ../$(BIN) + +.PHONY: all clean -- cgit v1.3