view objgrep/main.c @ 224:148b5fd6c10e

pirelli/charging/i2v: note added
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 28 Nov 2017 02:14:44 +0000
parents 77cd647375e5
children
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) {
		process_relocs_on_match();
		if (nreloc_ext)
			dump_ext_relocs_on_match();
		if (nreloc_int)
			dump_reloc_symtab_on_match();
	}
	exit(0);
}