Exemplo n.º 1
0
static int
process_file(Elf *elf, char *cur_file, Cmd_Info *cmd_info)
{
	int error = SUCCESS;
	int x;
	GElf_Ehdr ehdr;
	size_t shnum;

	/*
	 * Initialize
	 */
	if (gelf_getehdr(elf, &ehdr) == NULL) {
		error_message(LIBELF_ERROR,
		LIBelf_ERROR, elf_errmsg(-1), prog);
		return (FAILURE);
	}

	if (elf_getshnum(elf, &shnum) == NULL) {
		error_message(LIBELF_ERROR,
		LIBelf_ERROR, elf_errmsg(-1), prog);
		return (FAILURE);
	}

	initialize(shnum, cmd_info);

	if (ehdr.e_phnum != 0) {
		if (build_segment_table(elf, &ehdr) == FAILURE)
			return (FAILURE);
	}

	if ((x = traverse_file(elf, &ehdr, cur_file, cmd_info)) ==
	    FAILURE) {
		error_message(WRN_MANIPULATED_ERROR,
		PLAIN_ERROR, (char *)0,
		prog, cur_file);
		error = FAILURE;
	} else if (x != DONT_BUILD && x != FAILURE) {
		post_process(cmd_info);
		if (build_file(elf, &ehdr, cmd_info) == FAILURE) {
			error_message(WRN_MANIPULATED_ERROR,
			PLAIN_ERROR, (char *)0,
			prog, cur_file);
			error = FAILURE;
		}
	}

	free(off_table);
	free(sec_table);
	free(nobits_table);

	if (x == DONT_BUILD)
		return (DONT_BUILD);
	else
		return (error);
}
Exemplo n.º 2
0
/* same as traverse_file, except go through a list of files. Return 1
   if there were some non-matching keys and/or bad file formats; 0
   otherwise. */
static void traverse_files(char **filelist, int count) {
  while (count > 0) {
    traverse_file(*filelist);
    ++filelist, --count;
  }
}