/**
 * main - program entrypoint
 *
 * @ac: argument count
 * @av: argument vector
 *
 * Return: 0 on success, 1 for failure
 */
int main(int ac, char **av)
{
	FILE *fp;
	Elf64_Ehdr e_hdr;

	if (ac != 2)
	{
		printf("Usage\n\t%s <binary_file>\n", av[0]);
		return (1);
	}
	fp = fopen(av[1], "rb");
	if (fp == NULL)
	{
		fprintf(stderr, "Error - Can't open %s: %s\n", av[1], strerror(errno));
		return (1);
	}
	fread(&e_hdr, sizeof(e_hdr), 1, fp);
	if (ferror(fp))
	{
		fprintf(stderr, "fread error: %s\n", strerror(errno));
		fclose(fp);
		return (1);
	}
	if (check_elf_file(&e_hdr))
	{
		fprintf(stderr, "'%s' isn't an ELF file\n", av[1]);
		fclose(fp);
		return (1);
	}
	print_sections(fp, &e_hdr);
	

	fclose(fp);
	return (0);
}
Esempio n. 2
0
void	save_scale(scale *s) {
	FILE	*fd = fopen(s->o_file, "w+");

	tab = 0;
	if (!fd) {
		ERROR("Cannot open %s for writing\n", s->o_file);
	}
	fprintf(fd, "#############################################\n# This scale has been generated by 42_scale #\n#############################################\n");
	write_s(fd, "name", s->name.buf, 0);
	if (s->lang.val == LANG_EN) {
		write_s(fd, "lg", "en", 0);
	} else if (s->lang.val == LANG_FR) {
		write_s(fd, "lg", "fr", 0);
	} else if (s->lang.val == LANG_RU) {
		write_s(fd, "lg", "ru", 0);
	}
	fprintf(fd, "is_primary: true\n\n");
	write_s(fd, "comment", s->comment.buf, 0);
	write_s(fd, "introduction_md", s->intro.buf, 1);
	write_s(fd, "disclaimer_md", s->disclaimer.buf, 1);
	write_s(fd, "guidelines_md", s->guidelines.buf, 1);
	write_i(fd, "correction_number", s->correction_n.val);
	write_i(fd, "duration", s->duration.val);
	fprintf(fd, "\n# **************************************************************************** #\n\n");
	fprintf(fd, "sections:\n");
	print_sections(s, fd);
	fclose(fd);
}
Esempio n. 3
0
int main(int argc, char *argv[])
{
	PE_FILE pe;
	FILE *fp = NULL;
	
	if (argc < 2)
	{
		usage();
		exit(1);
	}

	parse_options(argc, argv); // opcoes

	if ((fp = fopen(argv[argc-1], "rb")) == NULL)
		EXIT_ERROR("file not found or unreadable");

	pe_init(&pe, fp); // inicializa o struct pe

	if (!is_pe(&pe))
		EXIT_ERROR("not a valid PE file");

	// dos header
	if (config.dos || config.all_headers || config.all)
	{
		IMAGE_DOS_HEADER dos;

		if (pe_get_dos(&pe, &dos))
			print_dos_header(&dos);
		else { EXIT_ERROR("unable to read DOS header"); }
	}

	// coff/file header
	if (config.coff || config.all_headers || config.all)
	{
		IMAGE_COFF_HEADER coff;

		if (pe_get_coff(&pe, &coff))
			print_coff_header(&coff);
		else { EXIT_ERROR("unable to read COFF file header"); }
	}

	// optional header
	if (config.opt || config.all_headers || config.all)
	{
		if (pe_get_optional(&pe))
			print_optional_header(&pe);
		else { EXIT_ERROR("unable to read Optional (Image) file header"); }
	}

	// directories
	if (config.dirs || config.all)
	{
		if (pe_get_directories(&pe))
			print_directories(&pe);
		else { EXIT_ERROR("unable to read the Directories entry from Optional header"); }
	}
	
	// imports
	if (config.imports || config.all)
	{
		if (pe_get_directories(&pe))
			print_imports(&pe);
		else { EXIT_ERROR("unable to read the Directories entry from Optional header"); }
	}	

	// exports
	if (config.exports || config.all)
	{
		if (pe_get_directories(&pe))
			print_exports(&pe);
		else
			{ EXIT_ERROR("unable to read directories from optional header"); }
	}

	// sections
	if (config.all_sections || config.all)
	{
		if (pe_get_sections(&pe))
			print_sections(&pe);
		else { EXIT_ERROR("unable to read sections"); }
	}

	// free
	pe_deinit(&pe);
	return 0;
}