Пример #1
0
int SHOW_MODULE_INFO(const char *filename, const char *fmtstr)
{
	int fp;
	struct obj_file *f;

	/* Locate the file to be loaded.  */
	if (!strchr(filename, '/') && !strchr(filename, '.')) {
		char *tmp = search_module_path(filename);
		if (tmp == NULL) {
			error("%s: no module by that name found", filename);
			return 1;
		}
		filename = tmp;
	}
	error_file = filename;

	/* Attempt to open and parse the module file. */
	if ((fp = gzf_open(filename, O_RDONLY)) < 0) {
		error("%s: %m", filename);
		return -1;
	} else if ((f = obj_load(fp, ET_REL, filename)) == NULL)
		return -1;
	gzf_close(fp);

	format_query_string(f, fmtstr);
	return 0;
}
Пример #2
0
int KALLSYMS_MAIN (int argc, char **argv)
{
    struct option long_opts[] = {
	    {"version", 0, 0, 'V'},
	    {"help", 0, 0, 'h'},
	    {0, 0, 0, 0}
    };
    char *filename = NULL;
    int fp;
    struct obj_file *fin, *fout;
    int i, c;

    error_file = "kallsyms";

    /* To handle repeated calls from combined modprobe */
    errors = optind = 0;

    /* Process the command line.  */
    while ((c = getopt_long(argc, argv, "Vh",
			    &long_opts[0], NULL)) != EOF)
	switch (c) {
	case 'V':
	    fputs("kallsyms version " MODUTILS_VERSION "\n", stderr);
	    return(0);
	case 'h':       /* Print the usage message. */
	    kallsyms_usage();
	    return(0);
	default:
	    kallsyms_usage();
	    return(1);
	}

    if (optind != argc-1) {
	kallsyms_usage();
	return(1);
    }

    filename = argv[optind++];
    error_file = filename;
    if ((fp = gzf_open(filename, O_RDONLY)) < 0) {
	error("%s: %m", filename);
	return 1;
    }

    if ((fin = obj_load(fp, ET_EXEC, filename)) == NULL) {
	gzf_close(fp);
	return 1;
    }
    gzf_close(fp);

    error_file = "kallsyms";
    if (obj_kallsyms(fin, &fout))
	return 1;

    /* Write the extracted data */
    fwrite(&fout->header, sizeof(fout->header), 1, stdout);
    for (i = 0; i < fout->header.e_shnum; ++i)
	fwrite(&fout->sections[i]->header, fout->header.e_shentsize, 1, stdout);
    for (i = 0; i < fout->header.e_shnum; ++i) {
	if (fout->sections[i]->header.sh_size) {
	    fseek(stdout, fout->sections[i]->header.sh_offset, SEEK_SET);
	    fwrite(fout->sections[i]->contents,
	    	fout->sections[i]->header.sh_size, 1, stdout);
	}
    }

    return 0;
}