BuFile* buFileOpen(const char* path, bool preload, int offset) { iovecStreamParams p = {path, preload, offset}; // set default target; without a default target some logic inside bfd goes horribly wrong bfd_set_default_target("binary"); // open file std::unique_ptr<bfd, bfd_boolean (*)(bfd*)> abfd(bfd_openr_iovec(path, 0, iovecOpen, &p, iovecRead, iovecClose, iovecStat), bfd_close); if (!abfd) return 0; // we should be working with an object file now if (!checkFormat(abfd.get(), bfd_object)) return 0; // decompress sections (we don't know if we'll need it) abfd->flags |= BFD_DECOMPRESS; // slurp symtab since all operations need it anyway std::vector<asymbol*> symtab = slurpSymtab(abfd.get()); std::vector<asymbol*> dyntab = slurpDynamicSymtab(abfd.get()); symtab.insert(symtab.end(), dyntab.begin(), dyntab.end()); symtab.push_back(0); return new BuFile(std::move(abfd), std::move(symtab)); }
static struct bfd * bfd_open_from_target_memory (CORE_ADDR addr, ULONGEST size, char *target) { const char *filename = xstrdup ("<in-memory>"); struct target_buffer *buffer = xmalloc (sizeof (struct target_buffer)); buffer->base = addr; buffer->size = size; return bfd_openr_iovec (filename, target, mem_bfd_iovec_open, buffer, mem_bfd_iovec_pread, mem_bfd_iovec_close, mem_bfd_iovec_stat); }