view objgrep/main.c @ 168:ed1a06bf525d

objgrep: works after fixing a buglet
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Fri, 04 Jul 2014 01:01:39 +0000
parents c25367bb7656
children 466b3926019c
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 "globals.h"
#include "intstruct.h"

main(argc, argv)
	char **argv;
{
	unsigned n;

	if (argc != 4) {
		fprintf(stderr, "usage: %s <objfile> <section> <binfile>\n",
			argv[0]);
		exit(2);
	}
	objfilename = argv[1];
	mmap_objfile();
	initial_parse_hdr();
	get_int_section_table();
	for (n = 0; n < nsections; n++)
		if (!strcmp(sections[n].name, argv[2])) {
			grep_section = sections + n;
			break;
		}
	if (!grep_section) {
		fprintf(stderr, "no section named \"%s\" found in %s\n",
			argv[2], objfilename);
		exit(2);
	}
	get_int_symbol_table();
	prepare_pattern();
	binfilename = argv[3];
	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);
}