From caa2dd77749dc91d621f01187e20327aa413a3d7 Mon Sep 17 00:00:00 2001 From: comex Date: Sat, 17 Jan 2015 14:40:29 -0500 Subject: interpose works; add test --- test/test-interpose.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 test/test-interpose.c (limited to 'test/test-interpose.c') diff --git a/test/test-interpose.c b/test/test-interpose.c new file mode 100644 index 0000000..ea28abb --- /dev/null +++ b/test/test-interpose.c @@ -0,0 +1,35 @@ +#include "substitute.h" + +#include +#include +#include +#include + +static void *getpid_plus = (void *) getpid + 5; + +static pid_t (*old_getpid)(); +static pid_t my_getpid() { + return old_getpid() + 1; +} +static gid_t my_getgid() { + return 42; +} + +int main() { + const char *self = _dyld_get_image_name(0); + void *handle = substitute_open_image(self); + assert(handle); + struct substitute_import_hook hooks[] = { + {"_getpid", my_getpid, &old_getpid}, + {"_getgid", my_getgid, NULL}, + + }; + pid_t (*gp)() = getpid_plus - 5; + printf("original pid: %d\n", (int) gp()); + substitute_interpose_imports(handle, hooks, sizeof(hooks)/sizeof(*hooks), 0); + gp = getpid_plus - 5; + printf("new pid: %d\n", (int) gp()); + printf("new gid: %d\n", (int) getgid()); + + substitute_close_image(handle); +} -- cgit v1.2.3