FreeCalypso > hg > freecalypso-reveng
annotate objgrep/grep.c @ 185:a820d9f9adbf
leo-obj: started analyzing tpudrv.lib objects
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Mon, 11 Aug 2014 21:32:30 +0000 |
parents | c25367bb7656 |
children |
rev | line source |
---|---|
167
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * objgrep: the actual grep operation |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 */ |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 #include <sys/types.h> |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <stdio.h> |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <stdint.h> |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <stdlib.h> |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include <string.h> |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 #include <strings.h> |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 #include "globals.h" |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 do_grep() |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 { |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 uint32_t *match, *mask, *haystack; |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 unsigned matchlen_words, haystack_len_words, haystack_limit; |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 unsigned i, j; |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 match = (uint32_t *)pattern_match; |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 mask = (uint32_t *)pattern_mask; |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 haystack = (uint32_t *)binfilemap; |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 matchlen_words = pattern_len >> 2; |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 haystack_len_words = binfile_tot_size >> 2; |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 haystack_limit = haystack_len_words - matchlen_words; |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 for (i = 0; i <= haystack_limit; i++) { |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 for (j = 0; j < matchlen_words; j++) |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 if ((haystack[i+j] & mask[j]) != match[j]) |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 goto haystack_next; |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 /* got a match! */ |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 match_offset = i << 2; |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 return(1); |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 haystack_next: continue; |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 } |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 return(0); |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 } |