FreeCalypso > hg > freecalypso-reveng
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 166:861f5ca49581 | 167:c25367bb7656 |
|---|---|
| 1 /* | |
| 2 * objgrep: the actual grep operation | |
| 3 */ | |
| 4 | |
| 5 #include <sys/types.h> | |
| 6 #include <stdio.h> | |
| 7 #include <stdint.h> | |
| 8 #include <stdlib.h> | |
| 9 #include <string.h> | |
| 10 #include <strings.h> | |
| 11 #include "globals.h" | |
| 12 | |
| 13 do_grep() | |
| 14 { | |
| 15 uint32_t *match, *mask, *haystack; | |
| 16 unsigned matchlen_words, haystack_len_words, haystack_limit; | |
| 17 unsigned i, j; | |
| 18 | |
| 19 match = (uint32_t *)pattern_match; | |
| 20 mask = (uint32_t *)pattern_mask; | |
| 21 haystack = (uint32_t *)binfilemap; | |
| 22 matchlen_words = pattern_len >> 2; | |
| 23 haystack_len_words = binfile_tot_size >> 2; | |
| 24 haystack_limit = haystack_len_words - matchlen_words; | |
| 25 for (i = 0; i <= haystack_limit; i++) { | |
| 26 for (j = 0; j < matchlen_words; j++) | |
| 27 if ((haystack[i+j] & mask[j]) != match[j]) | |
| 28 goto haystack_next; | |
| 29 /* got a match! */ | |
| 30 match_offset = i << 2; | |
| 31 return(1); | |
| 32 haystack_next: continue; | |
| 33 } | |
| 34 return(0); | |
| 35 } |
