FreeCalypso > hg > freecalypso-reveng
diff objgrep/grep.c @ 167:c25367bb7656
objgrep: written, compiles
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Fri, 04 Jul 2014 00:54:33 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/objgrep/grep.c Fri Jul 04 00:54:33 2014 +0000 @@ -0,0 +1,35 @@ +/* + * objgrep: the actual grep operation + */ + +#include <sys/types.h> +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include "globals.h" + +do_grep() +{ + uint32_t *match, *mask, *haystack; + unsigned matchlen_words, haystack_len_words, haystack_limit; + unsigned i, j; + + match = (uint32_t *)pattern_match; + mask = (uint32_t *)pattern_mask; + haystack = (uint32_t *)binfilemap; + matchlen_words = pattern_len >> 2; + haystack_len_words = binfile_tot_size >> 2; + haystack_limit = haystack_len_words - matchlen_words; + for (i = 0; i <= haystack_limit; i++) { + for (j = 0; j < matchlen_words; j++) + if ((haystack[i+j] & mask[j]) != match[j]) + goto haystack_next; + /* got a match! */ + match_offset = i << 2; + return(1); +haystack_next: continue; + } + return(0); +}