aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile3
-rw-r--r--lib/darwin/substrate-compat.c16
-rw-r--r--lib/strerror.c22
-rw-r--r--lib/substitute.h3
4 files changed, 37 insertions, 7 deletions
diff --git a/Makefile b/Makefile
index 12b55b9..76ac6bd 100644
--- a/Makefile
+++ b/Makefile
@@ -46,9 +46,10 @@ LIB_OBJS := \
out/darwin/objc.o \
out/darwin/read.o \
out/darwin/substrate-compat.o \
+ out/darwin-inject-asm.o \
out/jump-dis.o \
out/transform-dis.o \
- out/darwin-inject-asm.o
+ out/strerror.o
out/libsubstitute.dylib: $(LIB_OBJS)
$(CC) -o $@ $(LIB_OBJS) $(LIB_LDFLAGS)
diff --git a/lib/darwin/substrate-compat.c b/lib/darwin/substrate-compat.c
index cf44b19..345d53f 100644
--- a/lib/darwin/substrate-compat.c
+++ b/lib/darwin/substrate-compat.c
@@ -46,10 +46,14 @@ void SubHookFunction(void *symbol, void *replace, void **result) {
}
*/
-#ifdef __APPLE__
-/*void SubHookMessageEx(Class _class, SEL sel, IMP imp, IMP *result) __asm__("SubHookMessageEx");
-void SubHookMessageEx(Class _class, SEL sel, IMP imp, IMP *result) {
-
-}*/
+EXPORT
+void SubHookMessageEx(Class _class, SEL sel, IMP imp, IMP *result)
+ __asm__("SubHookMessageEx");
-#endif
+void SubHookMessageEx(Class _class, SEL sel, IMP imp, IMP *result) {
+ int ret = substitute_hook_objc_message(_class, sel, imp, result, NULL);
+ if (ret) {
+ panic("SubHookMessageEx: substitute_hook_objc_message returned %s\n",
+ substitute_strerror(ret));
+ }
+}
diff --git a/lib/strerror.c b/lib/strerror.c
new file mode 100644
index 0000000..ac72214
--- /dev/null
+++ b/lib/strerror.c
@@ -0,0 +1,22 @@
+#include "substitute.h"
+#include "substitute-internal.h"
+
+EXPORT
+const char *substitute_strerror(int err) {
+ #define CASE(code) case code: return #code
+ switch (err) {
+ CASE(SUBSTITUTE_OK);
+ CASE(SUBSTITUTE_ERR_FUNC_TOO_SHORT);
+ CASE(SUBSTITUTE_ERR_FUNC_BAD_INSN_AT_START);
+ CASE(SUBSTITUTE_ERR_FUNC_JUMPS_TO_START);
+ CASE(SUBSTITUTE_ERR_OOM);
+ CASE(SUBSTITUTE_ERR_VM);
+ CASE(SUBSTITUTE_ERR_UNKNOWN_RELOCATION_TYPE);
+ CASE(SUBSTITUTE_ERR_NO_SUCH_SELECTOR);
+ CASE(SUBSTITUTE_ERR_TASK_FOR_PID);
+ CASE(SUBSTITUTE_ERR_MISC);
+ default:
+ return "(unknown libsubstitute error)";
+ }
+ #undef CASE
+}
diff --git a/lib/substitute.h b/lib/substitute.h
index 00cc1b8..3adb39a 100644
--- a/lib/substitute.h
+++ b/lib/substitute.h
@@ -59,6 +59,9 @@ struct substitute_function_hook {
void *old_ptr; /* optional: out pointer to function pointer to call old impl */
};
+/* Get a string representation for a SUBSTITUTE_* error code. */
+const char *substitute_strerror(int err);
+
/* TODO doc */
int substitute_hook_functions(const struct substitute_function_hook *hooks,
size_t nhooks,