int open_target( char * file ) { if(!file) error_die("null arg",1); /* there's only 1 target */ if( target_elf ) free_elf( target_elf ); if(!(target_elf = new_elf(file))) error_ret("can't open elf",-1); #ifdef USE_COMMANDS /* check for info saved in xml file */ if( use_info ) if(open_target_info( target_elf ) < 0 ) error_ret("problem getting info",-1); #endif /* USE_COMMANDS */ disasm_init(); crunch_pltmap(); gather_funcs_by_symtab( get_elf() ); gather_funcs_by_section(NULL); get_objs_from_entry(get_elf()); gather_vars( get_elf() ); sync_func_map(); #if 0 if( do_disasm || do_pltmap ||do_disasm_seg ||do_map_dmp){ crunch_pltmap(); } if( do_dump_funcs || do_disasm || do_disasm_seg || do_map_dmp ){ gather_funcs_by_symtab( get_elf() ); gather_funcs_by_section(NULL); get_objs_from_entry(get_elf()); } if( do_vars || do_disasm || do_disasm_seg || do_map_dmp || do_map_dmp ) gather_vars( get_elf() ); sync_func_map(); #endif return(0); }
static void process_executable(const char *filename, GList *entries) { int fd; Elf *e = NULL; GHashTable *fdes = NULL; GHashTable *plt_names = NULL; GHashTable *call_graph = NULL; struct disasm_data ddata = { 0 }; /* Initialize libelf, open the file and get its Elf handle. */ if (elf_version(EV_CURRENT) == EV_NONE) { VERB1 log_elf_error("elf_version", filename); return; } /* Open input file, and parse it. */ fd = open(filename, O_RDONLY); if (fd < 0) { VERB1 log("Unable to open '%s': %s", filename, strerror(errno)); return; } e = elf_begin(fd, ELF_C_READ, NULL); if (e == NULL) { VERB1 log_elf_error("elf_begin", filename); goto ret_fail; } /* Read FDEs into hash, fill startPC and endPC for entries */ fdes = elf_iterate_fdes(filename, entries, e); if (fdes == NULL) { VERB1 log("Failed to read .eh_frame function ranges from %s", filename); goto ret_fail; } /* Read PLT into hash */ plt_names = parse_plt(e, filename); if (plt_names == NULL) { VERB1 log("Failed to parse .plt from %s", filename); goto ret_fail; } /* Initialize disassembler */ ddata = disasm_init(filename); if (ddata.bfd_file == NULL) { VERB1 log("Failed to initialize disassembler for file %s", filename); goto ret_fail; } /* Compute call graph for functions in entries list */ call_graph = compute_call_graph(ddata, fdes, entries); if (call_graph == NULL) { VERB1 log("Failed to compute call graph for file %s", filename); goto ret_fail; } /* Fill in fingerprints for entries (requires disasm, plt, callgraph) */ generate_fingerprints(ddata, plt_names, call_graph, entries); ret_fail: if (call_graph) g_hash_table_destroy(call_graph); disasm_close(ddata); if (plt_names) g_hash_table_destroy(plt_names); if (fdes) g_hash_table_destroy(fdes); if (e) elf_end(e); close(fd); }