本文整理汇总了C++中ELFObjectFile类的典型用法代码示例。如果您正苦于以下问题:C++ ELFObjectFile类的具体用法?C++ ELFObjectFile怎么用?C++ ELFObjectFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ELFObjectFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: symbol_entries
void symbol_entries(const ELFObjectFile<T> &obj, ogre_doc &s) {
typedef typename ELFFile<T>::Elf_Shdr sec_hdr;
auto elf = obj.getELFFile();
symbol_entries(obj, obj.symbol_begin(), obj.symbol_end(), s);
auto secs = prim::elf_sections(*elf);
bool is_dyn = std::any_of(secs.begin(), secs.end(),
[](const sec_hdr &hdr) { return (hdr.sh_type == ELF::SHT_DYNSYM); });
if (is_dyn) // preventing from llvm 3.8 fail in case of .dynsym absence
symbol_entries(obj, obj.dynamic_symbol_begin(), obj.dynamic_symbol_end(), s);
}
示例2: checked
bool checked(const ELFObjectFile<T> &obj, SectionRef sec_ref) {
typedef typename ELFObjectFile<T>::Elf_Shdr Elf_Shdr;
auto &elf = *obj.getELFFile();
const Elf_Shdr *RelSec = obj.getSection(sec_ref.getRawDataRefImpl());
auto symsec = elf.getSection(RelSec->sh_link);
if (!symsec) return false;
uint32_t sec_typ = (*symsec)->sh_type;
return
(sec_typ == ELF::SHT_SYMTAB || sec_typ == ELF::SHT_DYNSYM);
}
示例3: section_offset
uint64_t section_offset(const ELFObjectFile<T> &obj, section_iterator it) {
typedef typename ELFObjectFile<T>::Elf_Shdr_Iter elf_shdr_iterator;
if (it == obj.end_sections()) return 0; // check for special elf sections
auto elf = obj.getELFFile();
auto raw = it->getRawDataRefImpl();
auto elf_sec_it = elf_shdr_iterator(elf->getHeader()->e_shentsize,
reinterpret_cast<const char *>(raw.p));
return elf_sec_it->sh_offset;
}
示例4: read
std::vector<segment> read(const ELFObjectFile<T>& obj) {
auto begin = obj.getELFFile()->begin_program_headers();
auto end = obj.getELFFile()->end_program_headers();
std::vector<segment> segments;
segments.reserve(std::distance(begin, end));
for (int pos = 0; begin != end; ++begin, ++pos) {
if (begin -> p_type == ELF::PT_LOAD) {
segments.push_back(segment(*begin, pos));
}
}
return segments;
}
示例5: isObject
static bool isObject(ELFObjectFile<ELFT> &Obj, symbol_iterator I) {
typedef typename ELFObjectFile<ELFT>::Elf_Sym Elf_Sym;
DataRefImpl Symb = I->getRawDataRefImpl();
const Elf_Sym *ESym = Obj.getSymbol(Symb);
return ESym->getType() == ELF::STT_OBJECT;
}
示例6: relocations
void relocations(const ELFObjectFile<T> &obj, ogre_doc &s) {
for (auto sec : obj.sections()) {
auto rel_sec = sec.getRelocatedSection();
if (!checked(obj, sec)) continue;
for (auto rel : sec.relocations())
symbol_reference(obj, rel, rel_sec, s);
}
}
示例7: getSymbolNMTypeChar
static char getSymbolNMTypeChar(ELFObjectFile<ELFT> &Obj,
basic_symbol_iterator I) {
typedef typename ELFObjectFile<ELFT>::Elf_Sym Elf_Sym;
typedef typename ELFObjectFile<ELFT>::Elf_Shdr Elf_Shdr;
// OK, this is ELF
symbol_iterator SymI(I);
DataRefImpl Symb = I->getRawDataRefImpl();
const Elf_Sym *ESym = Obj.getSymbol(Symb);
const ELFFile<ELFT> &EF = *Obj.getELFFile();
const Elf_Shdr *ESec = EF.getSection(ESym);
if (ESec) {
switch (ESec->sh_type) {
case ELF::SHT_PROGBITS:
case ELF::SHT_DYNAMIC:
switch (ESec->sh_flags) {
case (ELF::SHF_ALLOC | ELF::SHF_EXECINSTR):
return 't';
case (ELF::SHF_TLS | ELF::SHF_ALLOC | ELF::SHF_WRITE):
case (ELF::SHF_ALLOC | ELF::SHF_WRITE):
return 'd';
case ELF::SHF_ALLOC:
case (ELF::SHF_ALLOC | ELF::SHF_MERGE):
case (ELF::SHF_ALLOC | ELF::SHF_MERGE | ELF::SHF_STRINGS):
return 'r';
}
break;
case ELF::SHT_NOBITS:
return 'b';
}
}
if (ESym->getType() == ELF::STT_SECTION) {
StringRef Name;
if (error(SymI->getName(Name)))
return '?';
return StringSwitch<char>(Name)
.StartsWith(".debug", 'N')
.StartsWith(".note", 'n')
.Default('?');
}
return '?';
}
示例8: section_headers
void section_headers(const ELFObjectFile<T> &obj, ogre_doc &s) {
auto elf = obj.getELFFile();
auto base = base_address(obj);
for (auto sec : prim::elf_sections(*elf)) {
auto name = prim::elf_section_name(*elf, &sec);
if (name)
section_header(sec, *name, base, s);
}
}
示例9: symbol_address
error_or<int64_t> symbol_address(const ELFObjectFile<T> &obj, const SymbolRef &sym) {
auto sym_elf = obj.getSymbol(sym.getRawDataRefImpl());
if (is_rel(obj) && !is_abs_symbol(*sym_elf)) { // abs symbols does not affected by relocations
return success(int64_t(0));
} else {
auto addr = prim::symbol_address(sym);
if (!addr) return addr;
auto base = base_address(obj);
return success(prim::relative_address(base, *addr));
}
}
示例10: getSymbolSizes
error_or<symbol_sizes> getSymbolSizes(const ELFObjectFile<ELFT> &obj) {
typedef typename ELFFile<ELFT>::Elf_Shdr sec_hdr;
symbol_sizes syms;
for (auto sym : obj.symbols())
syms.push_back({sym, sym.getSize()});
auto sections = prim::elf_sections(*obj.getELFFile());
bool is_dyn = std::any_of(sections.begin(), sections.end(),
[](const sec_hdr &hdr) { return (hdr.sh_type == ELF::SHT_DYNSYM); });
if (!syms.size() && !is_dyn)
return success(symbol_sizes());
if (is_dyn) // we aren't able to rely on iterators because of bug in llvm
for (auto sym : obj.getDynamicSymbolIterators())
syms.push_back({sym, sym.getSize()});
return success(syms);
}
示例11: symbol_entry
void symbol_entry(const ELFObjectFile<T> &obj, const SymbolRef &sym, ogre_doc &s) {
auto sym_elf = obj.getSymbol(sym.getRawDataRefImpl());
if (is_abs_symbol(*sym_elf)) {
return;
}
auto name = prim::symbol_name(sym);
auto addr = symbol_address(obj, sym);
auto off = symbol_file_offset(obj, sym);
if (name && addr && off) {
s.entry("symbol-entry") << *name << *addr << sym_elf->st_size << *off;
if (sym_elf->getType() == ELF::STT_FUNC)
s.entry("code-entry") << *name << *off << sym_elf->st_size ;
}
}
示例12: symbol_reference
void symbol_reference(const ELFObjectFile<T> &obj, const RelocationRef &rel, section_iterator sec, ogre_doc &s) {
auto it = rel.getSymbol();
if (it == prim::end_symbols(obj)) return;
auto sym_elf = obj.getSymbol(it->getRawDataRefImpl());
auto sec_offset = section_offset(obj, sec);
auto off = prim::relocation_offset(rel) + sec_offset; // relocation file offset
if (is_external_symbol(*sym_elf)) {
if (auto name = prim::symbol_name(*it))
s.entry("ref-external") << off << *name;
} else {
if (auto file_offset = symbol_file_offset(obj, *it))
s.entry("ref-internal") << *file_offset << off;
}
}
示例13: program_headers
void program_headers(const ELFObjectFile<T> &obj, ogre_doc &s) {
auto elf = obj.getELFFile();
program_headers(elf->begin_program_headers(), elf->end_program_headers(), s);
}
示例14: base_address
uint64_t base_address(const ELFObjectFile<T> &obj) {
auto elf = obj.getELFFile();
return base_address(elf->begin_program_headers(), elf->end_program_headers());
}
示例15: is_rel
bool is_rel(const ELFObjectFile<T> &obj) {
auto hdr = obj.getELFFile()->getHeader();
return (hdr->e_type == ELF::ET_REL);
}