FreeCalypso > hg > freecalypso-reveng
view objgrep/main.c @ 170:13a9ce1590fc
objgrep: parsing of -r and -s options implemented, no functionality yet
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Fri, 04 Jul 2014 02:56:21 +0000 |
parents | 466b3926019c |
children | ddbfc1a1a811 |
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); exit(0); }