summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorspv <aquaticvegetable@gmail.com>2022-04-22 13:33:36 -0400
committerspv <aquaticvegetable@gmail.com>2022-04-22 13:33:36 -0400
commitf6a6595c6df8266673decccbd909aecf4cd60cf0 (patch)
treecd06d24ffd1fa8d67d95f4fd298a8133038383ff /src/main.c
parent64ef7cbaf51af9a60c19ff28c8cb5537c8134454 (diff)
wip compile on device
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/main.c b/src/main.c
index c3df450..c3e4077 100644
--- a/src/main.c
+++ b/src/main.c
@@ -11,7 +11,6 @@
#include <string.h>
#include <stdio.h>
-
#include "stage1_primitives.h"
#include "stage0_primitives.h"
#include "patchfinder.h"
@@ -23,6 +22,36 @@
uint32_t DNS4_OFFSET;
uint32_t LC_CONF_OFFSET;
+// https://opensource.apple.com/source/Libc/Libc-825.26/string/FreeBSD/memmem.c.auto.html
+void *
+memmem(const void *l, size_t l_len, const void *s, size_t s_len)
+{
+ register char *cur, *last;
+ const char *cl = (const char *)l;
+ const char *cs = (const char *)s;
+
+ /* we need something to compare */
+ if (l_len == 0 || s_len == 0)
+ return NULL;
+
+ /* "s" must be smaller or equal to "l" */
+ if (l_len < s_len)
+ return NULL;
+
+ /* special case where s_len == 1 */
+ if (s_len == 1)
+ return memchr(l, (int)*cs, l_len);
+
+ /* the last position where its possible to find "s" in "l" */
+ last = (char *)cl + l_len - s_len;
+
+ for (cur = (char *)cl; cur <= last; cur++)
+ if (cur[0] == cs[0] && memcmp(cur, cs, s_len) == 0)
+ return cur;
+
+ return NULL;
+}
+
char* fuck_memory_leaks = NULL;
FILE* fp = NULL;