FreeCalypso > hg > freecalypso-reveng
annotate objgrep/main.c @ 351:0ca005dbab30
fluid-mnf/devices.txt: OM support, safe S71PL-J defaults
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Fri, 13 Mar 2020 07:19:37 +0000 |
| parents | 77cd647375e5 |
| children |
| 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> | |
|
170
13a9ce1590fc
objgrep: parsing of -r and -s options implemented, no functionality yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
169
diff
changeset
|
10 #include <unistd.h> |
| 70 | 11 #include "globals.h" |
|
167
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
12 #include "intstruct.h" |
| 70 | 13 |
|
170
13a9ce1590fc
objgrep: parsing of -r and -s options implemented, no functionality yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
169
diff
changeset
|
14 static int rflag, sflag; |
|
13a9ce1590fc
objgrep: parsing of -r and -s options implemented, no functionality yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
169
diff
changeset
|
15 |
| 70 | 16 main(argc, argv) |
| 17 char **argv; | |
| 18 { | |
|
167
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
19 unsigned n; |
|
170
13a9ce1590fc
objgrep: parsing of -r and -s options implemented, no functionality yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
169
diff
changeset
|
20 int c; |
|
13a9ce1590fc
objgrep: parsing of -r and -s options implemented, no functionality yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
169
diff
changeset
|
21 extern int optind; |
| 70 | 22 |
|
170
13a9ce1590fc
objgrep: parsing of -r and -s options implemented, no functionality yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
169
diff
changeset
|
23 while ((c = getopt(argc, argv, "rs")) != EOF) |
|
13a9ce1590fc
objgrep: parsing of -r and -s options implemented, no functionality yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
169
diff
changeset
|
24 switch (c) { |
|
13a9ce1590fc
objgrep: parsing of -r and -s options implemented, no functionality yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
169
diff
changeset
|
25 case 'r': |
|
13a9ce1590fc
objgrep: parsing of -r and -s options implemented, no functionality yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
169
diff
changeset
|
26 rflag++; |
|
13a9ce1590fc
objgrep: parsing of -r and -s options implemented, no functionality yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
169
diff
changeset
|
27 continue; |
|
13a9ce1590fc
objgrep: parsing of -r and -s options implemented, no functionality yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
169
diff
changeset
|
28 case 's': |
|
13a9ce1590fc
objgrep: parsing of -r and -s options implemented, no functionality yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
169
diff
changeset
|
29 sflag++; |
|
13a9ce1590fc
objgrep: parsing of -r and -s options implemented, no functionality yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
169
diff
changeset
|
30 continue; |
|
13a9ce1590fc
objgrep: parsing of -r and -s options implemented, no functionality yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
169
diff
changeset
|
31 default: |
|
13a9ce1590fc
objgrep: parsing of -r and -s options implemented, no functionality yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
169
diff
changeset
|
32 usage: |
|
13a9ce1590fc
objgrep: parsing of -r and -s options implemented, no functionality yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
169
diff
changeset
|
33 fprintf(stderr, |
|
13a9ce1590fc
objgrep: parsing of -r and -s options implemented, no functionality yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
169
diff
changeset
|
34 "usage: %s [-rs] objfile section binfile\n", |
|
13a9ce1590fc
objgrep: parsing of -r and -s options implemented, no functionality yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
169
diff
changeset
|
35 argv[0]); |
|
13a9ce1590fc
objgrep: parsing of -r and -s options implemented, no functionality yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
169
diff
changeset
|
36 exit(2); |
|
13a9ce1590fc
objgrep: parsing of -r and -s options implemented, no functionality yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
169
diff
changeset
|
37 } |
|
13a9ce1590fc
objgrep: parsing of -r and -s options implemented, no functionality yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
169
diff
changeset
|
38 if (argc - optind != 3) |
|
13a9ce1590fc
objgrep: parsing of -r and -s options implemented, no functionality yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
169
diff
changeset
|
39 goto usage; |
|
13a9ce1590fc
objgrep: parsing of -r and -s options implemented, no functionality yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
169
diff
changeset
|
40 |
|
13a9ce1590fc
objgrep: parsing of -r and -s options implemented, no functionality yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
169
diff
changeset
|
41 objfilename = argv[optind]; |
| 70 | 42 mmap_objfile(); |
| 43 initial_parse_hdr(); | |
|
167
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
44 get_int_section_table(); |
|
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
45 for (n = 0; n < nsections; n++) |
|
170
13a9ce1590fc
objgrep: parsing of -r and -s options implemented, no functionality yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
169
diff
changeset
|
46 if (!strcmp(sections[n].name, argv[optind+1])) { |
|
167
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
47 grep_section = sections + n; |
| 70 | 48 break; |
|
167
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
49 } |
|
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
50 if (!grep_section) { |
|
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
51 fprintf(stderr, "no section named \"%s\" found in %s\n", |
|
170
13a9ce1590fc
objgrep: parsing of -r and -s options implemented, no functionality yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
169
diff
changeset
|
52 argv[optind+1], objfilename); |
|
167
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
53 exit(2); |
|
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
54 } |
|
169
466b3926019c
objgrep: weed out empty source sections
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
167
diff
changeset
|
55 if (!grep_section->size) { |
|
466b3926019c
objgrep: weed out empty source sections
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
167
diff
changeset
|
56 printf("%s:%s is empty\n", objfilename, grep_section->name); |
|
466b3926019c
objgrep: weed out empty source sections
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
167
diff
changeset
|
57 exit(1); |
|
466b3926019c
objgrep: weed out empty source sections
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
167
diff
changeset
|
58 } |
|
167
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
59 get_int_symbol_table(); |
|
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
60 prepare_pattern(); |
|
170
13a9ce1590fc
objgrep: parsing of -r and -s options implemented, no functionality yet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
169
diff
changeset
|
61 binfilename = argv[optind+2]; |
|
167
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
62 mmap_binfile(); |
|
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
63 if (!do_grep()) { |
|
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
64 printf("no match\n"); |
| 70 | 65 exit(1); |
| 66 } | |
|
167
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
67 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
|
68 binfilename, match_offset); |
|
171
ddbfc1a1a811
objgrep: -s implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
170
diff
changeset
|
69 if (sflag) |
|
ddbfc1a1a811
objgrep: -s implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
170
diff
changeset
|
70 dump_symtab_on_match(); |
|
173
77cd647375e5
objgrep -r: dump symbols in other sections recovered through relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
172
diff
changeset
|
71 if (rflag && grep_section->nreloc) { |
|
77cd647375e5
objgrep -r: dump symbols in other sections recovered through relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
172
diff
changeset
|
72 process_relocs_on_match(); |
|
77cd647375e5
objgrep -r: dump symbols in other sections recovered through relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
172
diff
changeset
|
73 if (nreloc_ext) |
|
77cd647375e5
objgrep -r: dump symbols in other sections recovered through relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
172
diff
changeset
|
74 dump_ext_relocs_on_match(); |
|
77cd647375e5
objgrep -r: dump symbols in other sections recovered through relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
172
diff
changeset
|
75 if (nreloc_int) |
|
77cd647375e5
objgrep -r: dump symbols in other sections recovered through relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
172
diff
changeset
|
76 dump_reloc_symtab_on_match(); |
|
77cd647375e5
objgrep -r: dump symbols in other sections recovered through relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
172
diff
changeset
|
77 } |
|
167
c25367bb7656
objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
145
diff
changeset
|
78 exit(0); |
| 70 | 79 } |
