From e910f0d9ddbd2f2a6b774ca364ac838c717ebc9f Mon Sep 17 00:00:00 2001 From: comex Date: Sat, 10 Jan 2015 16:31:00 -0500 Subject: substrate --- test/test-find-syms.c | 2 +- test/test-substrate.cpp | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 test/test-substrate.cpp (limited to 'test') diff --git a/test/test-find-syms.c b/test/test-find-syms.c index 6a8d600..acd31ba 100644 --- a/test/test-find-syms.c +++ b/test/test-find-syms.c @@ -13,7 +13,7 @@ int main() { assert(!substitute_find_private_syms(im, names, syms, 1)); assert(syms[0]); - int (*f)(int) = substitute_sym_to_ptr(im, syms[0]); + int (*f)(int) = (int (*)(int)) substitute_sym_to_ptr(im, syms[0]); assert(f(12345) < 0); substitute_close_image(im); diff --git a/test/test-substrate.cpp b/test/test-substrate.cpp new file mode 100644 index 0000000..f30918e --- /dev/null +++ b/test/test-substrate.cpp @@ -0,0 +1,23 @@ +#include +#include +#include +#include +#include + +int main() { + const char *foundation = "/System/Library/Frameworks/Foundation.framework/Foundation"; + dlopen(foundation, RTLD_LAZY); + + MSImageRef im = MSGetImageByName(foundation); + assert(im); + + int (*f)(int); + MSHookSymbol(f, "_absolute_from_gregorian", im); + assert(f(12345) < 0); + clock_t a = clock(); + MSHookSymbol(f, "_absolute_from_gregorian"); + clock_t b = clock(); + printf("%ld\n", (long) (b - a)); + assert(f(12345) < 0); +} + -- cgit v1.2.3