FreeCalypso > hg > freecalypso-reveng
annotate objgrep/main.c @ 167:c25367bb7656
objgrep: written, compiles
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Fri, 04 Jul 2014 00:54:33 +0000 |
parents | leo-obj/tool/main.c@25d3ead621f8 |
children | 466b3926019c |
rev | line source |
---|---|
70 | 1 /* |
167
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
2 * objgrep main() function |
70 | 3 */ |
4 | |
5 #include <sys/types.h> | |
6 #include <stdio.h> | |
7 #include <stdlib.h> | |
8 #include <string.h> | |
9 #include <strings.h> | |
10 #include "globals.h" | |
167
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
11 #include "intstruct.h" |
70 | 12 |
13 main(argc, argv) | |
14 char **argv; | |
15 { | |
167
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
16 unsigned n; |
70 | 17 |
167
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
18 if (argc != 4) { |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
19 fprintf(stderr, "usage: %s <objfile> <section> <binfile>\n", |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
20 argv[0]); |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
21 exit(2); |
70 | 22 } |
23 objfilename = argv[1]; | |
24 mmap_objfile(); | |
25 initial_parse_hdr(); | |
167
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
26 get_int_section_table(); |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
27 for (n = 0; n < nsections; n++) |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
28 if (!strcmp(sections[n].name, argv[2])) { |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
29 grep_section = sections + n; |
70 | 30 break; |
167
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
31 } |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
32 if (!grep_section) { |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
33 fprintf(stderr, "no section named \"%s\" found in %s\n", |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
34 argv[2], objfilename); |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
35 exit(2); |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
36 } |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
37 get_int_symbol_table(); |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
38 prepare_pattern(); |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
39 binfilename = argv[3]; |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
40 mmap_binfile(); |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
41 if (!do_grep()) { |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
42 printf("no match\n"); |
70 | 43 exit(1); |
44 } | |
167
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
45 printf("%s:%s found in %s at 0x%x\n", objfilename, grep_section->name, |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
46 binfilename, match_offset); |
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
47 exit(0); |
70 | 48 } |