static int read_all(struct elf32_info *info, FILE *in) { memset(info, 0, sizeof(info)); if (read_ehdr(info, in) < 0) return -1; if (info->file_ehdr.e_machine != EM_MSP430) printc_err("elf32: warning: unknown machine type: 0x%x 0x%x\n", info->file_ehdr.e_machine, EM_MSP430); if (read_phdr(info, in) < 0) return -1; if (read_shdr(info, in) < 0) return -1; return 0; }
bool ELF::init() { LOG_INFO("initializing library: %s", full_path_.c_str()); bool rval = false; std::ifstream is(full_path_.c_str(), std::ifstream::binary); if (!is) { LOG_ERROR("couldn't open %s", full_path_.c_str()); return false; } if (!read_ehdr(is) || !read_phdr(is) || !iterate_phdr(is) || !iterate_dyn(is)) { rval = false; } else { rval = true; } is.close(); return rval; }
static void create_image(int nfiles, char *files[]) { int ph, nbytes = 0, first = 1; FILE *fp, *img; Elf32_Ehdr ehdr; Elf32_Phdr phdr; /* open the image file */ img = fopen(IMAGE_FILE, "w"); assert(img != NULL); /* for each input file */ while (nfiles-- > 0) { /* open input file */ printf("%s\n", *files); fp = fopen(*files, "r"); assert(fp != NULL); /* read ELF header */ read_ehdr(&ehdr, fp); printf("0x%04x: %s\n", ehdr.e_entry, *files); /* for each program header */ for (ph = 0; ph < ehdr.e_phnum; ph++) { /* read program header */ read_phdr(&phdr, fp, ph, ehdr); /* write segment to the image */ write_segment(ehdr, phdr, fp, img, &nbytes, &first); } fclose(fp); files++; } write_os_size(nbytes, img); fclose(img); }