view objgrep/main.c @ 169:466b3926019c

objgrep: weed out empty source sections
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Fri, 04 Jul 2014 01:45:03 +0000
parents c25367bb7656
children 13a9ce1590fc
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);
	}
	if (!grep_section->size) {
		printf("%s:%s is empty\n", objfilename, grep_section->name);
		exit(1);
	}
	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);
}