FreeCalypso > hg > freecalypso-reveng
view objgrep/main.c @ 172:452baa748747
objgrep: -r implemented
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Fri, 04 Jul 2014 03:22:41 +0000 |
parents | ddbfc1a1a811 |
children | 77cd647375e5 |
line wrap: on
line source
/* * objgrep main() function */ #include <sys/types.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <strings.h> #include <unistd.h> #include "globals.h" #include "intstruct.h" static int rflag, sflag; main(argc, argv) char **argv; { unsigned n; int c; extern int optind; while ((c = getopt(argc, argv, "rs")) != EOF) switch (c) { case 'r': rflag++; continue; case 's': sflag++; continue; default: usage: fprintf(stderr, "usage: %s [-rs] objfile section binfile\n", argv[0]); exit(2); } if (argc - optind != 3) goto usage; objfilename = argv[optind]; mmap_objfile(); initial_parse_hdr(); get_int_section_table(); for (n = 0; n < nsections; n++) if (!strcmp(sections[n].name, argv[optind+1])) { grep_section = sections + n; break; } if (!grep_section) { fprintf(stderr, "no section named \"%s\" found in %s\n", argv[optind+1], objfilename); exit(2); } if (!grep_section->size) { printf("%s:%s is empty\n", objfilename, grep_section->name); exit(1); } get_int_symbol_table(); prepare_pattern(); binfilename = argv[optind+2]; mmap_binfile(); if (!do_grep()) { printf("no match\n"); exit(1); } printf("%s:%s found in %s at 0x%x\n", objfilename, grep_section->name, binfilename, match_offset); if (sflag) dump_symtab_on_match(); if (rflag && grep_section->nreloc) dump_relocs_on_match(); exit(0); }