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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
70
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
167
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 145
diff changeset
2 * objgrep main() function
70
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 */
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <sys/types.h>
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <stdio.h>
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdlib.h>
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <string.h>
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <strings.h>
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include "globals.h"
167
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 145
diff changeset
11 #include "intstruct.h"
70
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 main(argc, argv)
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 char **argv;
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 {
167
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 145
diff changeset
16 unsigned n;
70
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
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
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 }
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 objfilename = argv[1];
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 mmap_objfile();
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
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
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
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
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 exit(1);
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
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
6799a5c57a49 tiobjd started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 }