summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjakob <jakob@memeware.net>2017-08-29 16:02:44 -0400
committerjakob <jakob@memeware.net>2017-08-29 16:02:44 -0400
commit749c1d3e310a3df5d6f2ce10135129aa3f6142b7 (patch)
tree6c7b00c7b9b1ec462bb5e63ff765754df183a860
parenta0aac5609c87443ea12d04ffb280234c24d13e3f (diff)
setup.py and the makefile both install the wrapper library properly now
-rw-r--r--hypodermic/ptrace.py18
-rw-r--r--setup.py8
-rw-r--r--wrapper/Makefile12
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