aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcomex2015-01-10 14:00:50 -0500
committercomex2015-01-10 14:00:50 -0500
commite582e5ee1ada9a3d24b4eca5a954ca326c54872a (patch)
treecb84b9e91fe36b21994355439030e773129207cd
parentInitial commit (diff)
downloadsubstitute-e582e5ee1ada9a3d24b4eca5a954ca326c54872a.tar.gz
nah - this is nice looking but nonportable
-rw-r--r--lib/substitute.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/substitute.h b/lib/substitute.h
new file mode 100644
index 0000000..cadfa80
--- /dev/null
+++ b/lib/substitute.h
@@ -0,0 +1,39 @@
+/*
+ libsubstitute - https://github.com/comex/substitute
+ This header file is in the public domain.
+*/
+
+#pragma once
+
+// TODO add numbers
+enum {
+ SUBSTITUTE_OK = 0,
+
+ SUBSTITUTE_ERR_MODULE_NOT_FOUND,
+};
+
+int substitute_hook_function(void *function, void *replacement, int options, void *result);
+
+/* Darwin specific */
+#ifdef __APPLE__
+#include <mach-o/nlist.h>
+#ifdef __LP64__
+typedef struct nlist_64 substitute_nlist;
+#else
+typedef struct nlist substitute_nlist;
+#endif
+
+/* Look up private symbols in an image currently loaded into the process.
+ * Vaguely inspired by nlist(3), but somewhat different.
+ *
+ * @filename the executable/library path (c.f. dyld(3))
+ * @names an array of symbol names to search for
+ * @nlist an array of substitute_nlist *, one per name; on return, each entry
+ * will be a pointer into the symbol table for that image, or NULL if the
+ * symbol wasn't found
+ * @count number of names
+ *
+ * @return SUBSTITUTE_OK or SUBSTITUTE_ERR_MODULE_NOT_FOUND
+ */
+int substitute_nlist(const char *filename, const char **names,
+ substitute_nlist **nlist, size_t count);