comparison 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
comparison
equal deleted inserted replaced
166:861f5ca49581 167:c25367bb7656
1 /*
2 * objgrep main() function
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"
11 #include "intstruct.h"
12
13 main(argc, argv)
14 char **argv;
15 {
16 unsigned n;
17
18 if (argc != 4) {
19 fprintf(stderr, "usage: %s <objfile> <section> <binfile>\n",
20 argv[0]);
21 exit(2);
22 }
23 objfilename = argv[1];
24 mmap_objfile();
25 initial_parse_hdr();
26 get_int_section_table();
27 for (n = 0; n < nsections; n++)
28 if (!strcmp(sections[n].name, argv[2])) {
29 grep_section = sections + n;
30 break;
31 }
32 if (!grep_section) {
33 fprintf(stderr, "no section named \"%s\" found in %s\n",
34 argv[2], objfilename);
35 exit(2);
36 }
37 get_int_symbol_table();
38 prepare_pattern();
39 binfilename = argv[3];
40 mmap_binfile();
41 if (!do_grep()) {
42 printf("no match\n");
43 exit(1);
44 }
45 printf("%s:%s found in %s at 0x%x\n", objfilename, grep_section->name,
46 binfilename, match_offset);
47 exit(0);
48 }