diff options
author | Andrea Fioraldi <andreafioraldi@gmail.com> | 2019-12-02 13:55:51 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-02 13:55:51 +0100 |
commit | 25b435060c399665bb54937664b90c11bef6dd2a (patch) | |
tree | e77ba042707d6fdfb53d5001c2d058246d643b69 /libtokencap/libtokencap.so.c | |
parent | ba1b04be1ea0efb15f2f711e5b843946bb899ecd (diff) | |
parent | 5178a0cbbad2327c38c1fa19ed74c5697518a181 (diff) | |
download | afl++-25b435060c399665bb54937664b90c11bef6dd2a.tar.gz |
Merge pull request #125 from devnexen/libtokencap_memmem
libtokencap, simple optimised memmem implementation enough for this l…
Diffstat (limited to 'libtokencap/libtokencap.so.c')
-rw-r--r-- | libtokencap/libtokencap.so.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/libtokencap/libtokencap.so.c b/libtokencap/libtokencap.so.c index 467be05b..eea6d29f 100644 --- a/libtokencap/libtokencap.so.c +++ b/libtokencap/libtokencap.so.c @@ -425,6 +425,36 @@ char* strcasestr(const char* haystack, const char* needle) { } +#undef memmem + +void* memmem(const void *haystack, size_t haystack_len, const void *needle, size_t needle_len) +{ + if (__tokencap_is_ro(haystack)) + __tokencap_dump(haystack, haystack_len, 1); + + if (__tokencap_is_ro(needle)) __tokencap_dump(needle, needle_len, 1); + + const char *n = (const char *)needle; + const char *h = (const char *)haystack; + if (haystack_len < needle_len) return 0; + if (needle_len == 0) return (void *)haystack; + if (needle_len == 1) return memchr(haystack, *n, haystack_len); + + const char *end = h + (haystack_len - needle_len); + + do { + + if (*h == *n) { + + if (memcmp(h, n, needle_len) == 0) return (void *)h; + } + + } while (h++ <= end); + + return 0; + +} + /* Init code to open the output file (or default to stderr). */ __attribute__((constructor)) void __tokencap_init(void) { |