本文整理汇总了C++中ELFObjectFile::getELFFile方法的典型用法代码示例。如果您正苦于以下问题:C++ ELFObjectFile::getELFFile方法的具体用法?C++ ELFObjectFile::getELFFile怎么用?C++ ELFObjectFile::getELFFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ELFObjectFile
的用法示例。
在下文中一共展示了ELFObjectFile::getELFFile方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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);
}
}
示例3: 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);
}
示例4: 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);
}
示例5: 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;
}
示例6: 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 '?';
}
示例7: success
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);
}
示例8: getSymbolNMTypeChar
error_code getSymbolNMTypeChar(ELFObjectFile<ELFT> &Obj, symbol_iterator I,
char &Result) {
typedef typename ELFObjectFile<ELFT>::Elf_Sym Elf_Sym;
typedef typename ELFObjectFile<ELFT>::Elf_Shdr Elf_Shdr;
DataRefImpl Symb = I->getRawDataRefImpl();
const Elf_Sym *ESym = Obj.getSymbol(Symb);
const ELFFile<ELFT> &EF = *Obj.getELFFile();
const Elf_Shdr *ESec = EF.getSection(ESym);
char ret = '?';
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) :
ret = 't';
break;
case(ELF::SHF_ALLOC | ELF::SHF_WRITE) :
ret = 'd';
break;
case ELF::SHF_ALLOC:
case(ELF::SHF_ALLOC | ELF::SHF_MERGE) :
case(ELF::SHF_ALLOC | ELF::SHF_MERGE | ELF::SHF_STRINGS) :
ret = 'r';
break;
}
break;
case ELF::SHT_NOBITS:
ret = 'b';
}
}
switch (EF.getSymbolTableIndex(ESym)) {
case ELF::SHN_UNDEF:
if (ret == '?')
ret = 'U';
break;
case ELF::SHN_ABS:
ret = 'a';
break;
case ELF::SHN_COMMON:
ret = 'c';
break;
}
switch (ESym->getBinding()) {
case ELF::STB_GLOBAL:
ret = ::toupper(ret);
break;
case ELF::STB_WEAK:
if (EF.getSymbolTableIndex(ESym) == ELF::SHN_UNDEF)
ret = 'w';
else if (ESym->getType() == ELF::STT_OBJECT)
ret = 'V';
else
ret = 'W';
}
if (ret == '?' && ESym->getType() == ELF::STT_SECTION) {
StringRef Name;
error_code EC = I->getName(Name);
if (EC)
return EC;
Result = StringSwitch<char>(Name)
.StartsWith(".debug", 'N')
.StartsWith(".note", 'n')
.Default('?');
return object_error::success;
}
Result = ret;
return object_error::success;
}
示例9: is_rel
bool is_rel(const ELFObjectFile<T> &obj) {
auto hdr = obj.getELFFile()->getHeader();
return (hdr->e_type == ELF::ET_REL);
}
示例10: image_entry
uint64_t image_entry(const ELFObjectFile<ELFT>& obj) {
return obj.getELFFile()->getHeader()->e_entry;
}
示例11: 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);
}
示例12: 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());
}
示例13: file_header
void file_header(const ELFObjectFile<T> &obj, ogre_doc &s) {
auto hdr = obj.getELFFile()->getHeader();
auto base = base_address(obj);
s.entry("relocatable") << is_rel(obj);
s.entry("entry") << hdr->e_entry - base;
}