本文整理匯總了C++中ELF_ST_TYPE函數的典型用法代碼示例。如果您正苦於以下問題:C++ ELF_ST_TYPE函數的具體用法?C++ ELF_ST_TYPE怎麽用?C++ ELF_ST_TYPE使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ELF_ST_TYPE函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: syms_new
syms_t* syms_new(bin_obj_t* obj)
{
elfobj_t* elfobj = NULL;
char* sections[] = { ".symtab", ".dynsym" , NULL };
int i;
Elf_Shdr* section;
Elf_Sym* start, * end;
syms_t* list = NULL;
sym_t* sym;
elfobj = (elfobj_t*) obj->luse;
for (i = 0; sections[i]; i++)
{
section = get_elfsection(obj, sections[i]);
if (!section)
continue;
start = (Elf_Sym *) ((char*) elfobj->header + section->sh_offset);
end = (Elf_Sym *) ((char*) elfobj->header + section->sh_offset + section->sh_size);
/*
** Add every symbol to the list.
*/
for (; start < end; start++)
{
/*
** J'ai virer le alloc ?! (TODO)
*/
if (ELF_ST_TYPE(start->st_info) != STT_FUNC && ELF_ST_TYPE(start->st_info) != STT_NOTYPE)
continue;
/*
** Skip unusable symbol.
*/
if (start->st_value == 0x0)
continue;
sym = malloc(sizeof(sym_t));
if (sym == NULL)
goto syms_new_failed;
sym->addr = start->st_value + elfobj->base;
sym->size = start->st_size;
sym->name = (char*) ((char*) elfobj->header +
elfobj->section_headers[section->sh_link]->sh_offset +
start->st_name);
/* printf("Add Sym 0x%x size: %d name: %s\n", sym->addr, sym->size, sym->name); */
list = list_add(list, sym);
if (list == NULL)
goto syms_new_failed;
}
}
return (list);
syms_new_failed:
for (; list; )
{
sym = (sym_t*) list->value;
list = list_del(list, sym);
free(sym);
}
return (NULL);
}
示例2: assert
bool ElfSymbolTable::lookup(address addr, int* stringtableIndex, int* posIndex, int* offset) {
assert(stringtableIndex, "null string table index pointer");
assert(posIndex, "null string table offset pointer");
assert(offset, "null offset pointer");
if (NullDecoder::is_error(m_status)) {
return false;
}
address pc = 0;
size_t sym_size = sizeof(Elf_Sym);
assert((m_shdr.sh_size % sym_size) == 0, "check size");
int count = m_shdr.sh_size / sym_size;
if (m_symbols != NULL) {
for (int index = 0; index < count; index ++) {
if (STT_FUNC == ELF_ST_TYPE(m_symbols[index].st_info)) {
address sym_addr = (address)m_symbols[index].st_value;
if (sym_addr < addr && (addr - sym_addr) < *offset) {
pc = (address)m_symbols[index].st_value;
*offset = (int)(addr - pc);
*posIndex = m_symbols[index].st_name;
*stringtableIndex = m_shdr.sh_link;
}
}
}
} else {
long cur_pos;
if ((cur_pos = ftell(m_file)) == -1 ||
fseek(m_file, m_shdr.sh_offset, SEEK_SET)) {
m_status = NullDecoder::file_invalid;
return false;
}
Elf_Sym sym;
for (int index = 0; index < count; index ++) {
if (fread(&sym, sym_size, 1, m_file) == 1) {
if (STT_FUNC == ELF_ST_TYPE(sym.st_info)) {
address sym_addr = (address)sym.st_value;
if (sym_addr < addr && (addr - sym_addr) < *offset) {
pc = (address)sym.st_value;
*offset = (int)(addr - pc);
*posIndex = sym.st_name;
*stringtableIndex = m_shdr.sh_link;
}
}
} else {
m_status = NullDecoder::file_invalid;
return false;
}
}
fseek(m_file, cur_pos, SEEK_SET);
}
return true;
}
示例3: _rtld_relocate_plt_object
static inline int
_rtld_relocate_plt_object(const Obj_Entry *obj, Elf_Word sym, Elf_Addr *tp)
{
Elf_Addr *got = obj->pltgot;
const Elf_Sym *def;
const Obj_Entry *defobj;
Elf_Addr new_value;
def = _rtld_find_plt_symdef(sym, obj, &defobj, tp != NULL);
if (__predict_false(def == NULL))
return -1;
if (__predict_false(def == &_rtld_sym_zero))
return 0;
if (ELF_ST_TYPE(def->st_info) == STT_GNU_IFUNC) {
if (tp == NULL)
return 0;
new_value = _rtld_resolve_ifunc(defobj, def);
} else {
new_value = (Elf_Addr)(defobj->relocbase + def->st_value);
}
rdbg(("bind now/fixup in %s --> new=%p",
defobj->strtab + def->st_name, (void *)new_value));
got[obj->local_gotno + sym - obj->gotsym] = new_value;
if (tp)
*tp = new_value;
return 0;
}
示例4: generic_get_symbol
bool
generic_get_symbol( Elf_Xword index,
std::string& name, Elf64_Addr& value,
Elf_Xword& size,
unsigned char& bind, unsigned char& type,
Elf_Half& section_index,
unsigned char& other ) const
{
bool ret = false;
if ( index < get_symbols_num() ) {
const T* pSym = reinterpret_cast<const T*>(
symbol_section->get_data() +
index * symbol_section->get_entry_size() );
const endianess_convertor& convertor = elf_file.get_convertor();
section* string_section = elf_file.sections[get_string_table_index()];
string_section_accessor str_reader( string_section );
const char* pStr = str_reader.get_string( convertor( pSym->st_name ) );
if ( 0 != pStr ) {
name = pStr;
}
value = convertor( pSym->st_value );
size = convertor( pSym->st_size );
bind = ELF_ST_BIND( pSym->st_info );
type = ELF_ST_TYPE( pSym->st_info );
section_index = convertor( pSym->st_shndx );
other = pSym->st_other;
ret = true;
}
return ret;
}
示例5: _rtld_relocate_plt_object
static int
_rtld_relocate_plt_object(const Obj_Entry *obj, const Elf_Rel *rel,
Elf_Addr *tp)
{
Elf_Addr *where = (Elf_Addr *)(obj->relocbase + rel->r_offset);
Elf_Addr new_value;
const Elf_Sym *def;
const Obj_Entry *defobj;
unsigned long info = rel->r_info;
assert(ELF_R_TYPE(info) == R_TYPE(JUMP_SLOT));
def = _rtld_find_plt_symdef(ELF_R_SYM(info), obj, &defobj, tp != NULL);
if (__predict_false(def == NULL))
return -1;
if (__predict_false(def == &_rtld_sym_zero))
return 0;
if (ELF_ST_TYPE(def->st_info) == STT_GNU_IFUNC) {
if (tp == NULL)
return 0;
new_value = _rtld_resolve_ifunc(defobj, def);
} else {
new_value = (Elf_Addr)(defobj->relocbase + def->st_value);
}
rdbg(("bind now/fixup in %s --> old=%p new=%p",
defobj->strtab + def->st_name, (void *)*where, (void *)new_value));
if (*where != new_value)
*where = new_value;
if (tp)
*tp = new_value;
return 0;
}
示例6: reloc_gnu_ifunc
int
reloc_gnu_ifunc(Obj_Entry *obj, int flags, RtldLockState *lockstate)
{
const Elf_Rela *relalim;
const Elf_Rela *rela;
if (!obj->gnu_ifunc)
return (0);
relalim = (const Elf_Rela *)((char *)obj->pltrela + obj->pltrelasize);
for (rela = obj->pltrela; rela < relalim; rela++) {
Elf_Addr *where, target;
const Elf_Sym *def;
const Obj_Entry *defobj;
switch (ELF_R_TYPE(rela->r_info)) {
case R_X86_64_JMP_SLOT:
where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
SYMLOOK_IN_PLT | flags, NULL, lockstate);
if (def == NULL)
return (-1);
if (ELF_ST_TYPE(def->st_info) != STT_GNU_IFUNC)
continue;
lock_release(rtld_bind_lock, lockstate);
target = (Elf_Addr)rtld_resolve_ifunc(defobj, def);
wlock_acquire(rtld_bind_lock, lockstate);
reloc_jmpslot(where, target, defobj, obj, (const Elf_Rel *)rela);
break;
}
}
obj->gnu_ifunc = false;
return (0);
}
示例7: wantsym
static bool
wantsym(const Elf_Sym *sym, const char *strtab)
{
int type;
int bind;
type = ELF_ST_TYPE(sym->st_info);
bind = ELF_ST_BIND(sym->st_info);
if (type != STT_FUNC || (aflag && bind == STB_LOCAL))
#if 0
||
(uflag && strchr(strtab + sym->st_name, '.') != NULL))
#endif
return 0;
#ifdef __arm__
/* ignore what gas calls "mapping symbols" */
{
const char *c = strtab + sym->st_name;
if (c[0] == '$')
return 0;
}
#endif
return 1;
}
示例8: sym7
int sym7(void)
{
if(ELF_ST_TYPE(orcSYM->st_info) != STT_FILE)
return 0;
if(mode & REL)
if(rand() % 2)
return 0;
unsigned char st_info = orcSYM->st_info;
Elf_Section st_shndx;
if(rand() % 2)
do
st_info = ELF_ST_INFO(rand() & 0x0f, STT_FILE);
while(ELF_ST_BIND(st_info) == STB_LOCAL);
if(rand() % 4 < 3){
while((st_shndx = rand() % orcHDR->e_shnum))
if(st_shndx != SHN_ABS)
break;
} else
while((st_shndx = getElf_Section()))
if(st_shndx != SHN_ABS)
break;
orcSYM->st_info = st_info;
orcSYM->st_shndx = st_shndx;
fprintf(logfp, "(SYM[%d]->st_info = 0x%.2x,", entry, orcSYM->st_info);
fprintf(logfp, " st_shndx = 0x%x)", orcSYM->st_shndx);
return 1;
}
示例9: elf_sym_to_nlist
/*
* Convert an Elf_Sym into an nlist structure. This fills in only the
* n_value and n_type members.
*/
static void
elf_sym_to_nlist(struct nlist *nl, Elf_Sym *s, Elf_Shdr *shdr, int shnum)
{
nl->n_value = s->st_value;
switch (s->st_shndx) {
case SHN_UNDEF:
case SHN_COMMON:
nl->n_type = N_UNDF;
break;
case SHN_ABS:
nl->n_type = ELF_ST_TYPE(s->st_info) == STT_FILE ?
N_FN : N_ABS;
break;
default:
if (s->st_shndx >= shnum)
nl->n_type = N_UNDF;
else {
Elf_Shdr *sh = shdr + s->st_shndx;
nl->n_type = sh->sh_type == SHT_PROGBITS ?
(sh->sh_flags & SHF_WRITE ? N_DATA : N_TEXT) :
(sh->sh_type == SHT_NOBITS ? N_BSS : N_UNDF);
}
break;
}
if (ELF_ST_BIND(s->st_info) == STB_GLOBAL ||
ELF_ST_BIND(s->st_info) == STB_WEAK)
nl->n_type |= N_EXT;
}
示例10: handle_symbol
//--------------------------------------------------------------------------
//lint -e{1764} could be declared const ref
static int handle_symbol(
reader_t &reader,
int shndx,
int _info,
uint32 st_name,
uval_t st_value,
int namsec,
symbol_visitor_t &sv)
{
if ( shndx == SHN_UNDEF
|| shndx == SHN_LOPROC
|| shndx == SHN_HIPROC
|| shndx == SHN_ABS )
{
return 0;
}
int type = ELF_ST_TYPE(_info);
if ( type != STT_OBJECT && type != STT_FUNC )
return 0;
if ( st_name == 0 )
return 0;
if ( imagebase != uval_t(-1) )
st_value -= imagebase;
qstring name;
reader.sections.get_name(&name, namsec, st_name);
return sv.visit_symbol(st_value, name.c_str());
}
示例11: get_sym
Elf32_Sym *mips_elf_find_address(struct mips_cpu *pcpu, Elf32_Addr addr)
{
Elf32_Shdr *shsymtab = pcpu->shsymtab;
unsigned n = shsymtab->sh_size / shsymtab->sh_entsize;
Elf32_Addr min = (unsigned)-1;
Elf32_Sym *ret = NULL;
unsigned i;
if((shsymtab->sh_offset + shsymtab->sh_size > pcpu->elfsz)
|| (addr >= pcpu->memsz))
return NULL;
for(i = 0; i < n; i++) {
Elf32_Sym *sym = get_sym(pcpu->elf, pcpu->elfsz, shsymtab, i);
if(!sym)
return NULL;
if((ELF_ST_BIND(sym->st_info) != STB_GLOBAL) ||
(ELF_ST_TYPE(sym->st_info) >= STT_SECTION))
continue;
if(sym->st_value <= addr) {
Elf32_Addr diff = addr - sym->st_value;
if(diff < min) {
min = diff;
ret = sym;
if(diff == 0)
break;
}
}
}
return ret;
}
示例12: dump_info
void
dump_info(struct elf_object *object)
{
int numrel, numrela, i;
const Elf_Sym *symt;
const char *strt;
Elf_Word *needed_list;
symt = object->dyn.symtab;
strt = object->dyn.strtab;
for (i = 0; i < object->nchains; i++) {
const Elf_Sym *sym = symt + i;
char *type;
switch (ELF_ST_TYPE(sym->st_info)) {
case STT_FUNC:
type = "func";
break;
case STT_OBJECT:
type = "object";
break;
case STT_NOTYPE:
type = "notype";
break;
default:
type = "UNKNOWN";
}
printf("symbol %d [%s] type %s value %x\n", i,
strt + sym->st_name,
type, sym->st_value);
}
numrel = object->dyn.relsz / sizeof(Elf_Rel);
numrela = object->dyn.relasz / sizeof(Elf_RelA);
printf("numrel %d numrela %d\n", numrel, numrela);
printf("rel relocations:\n");
for (i = 0; i < numrel ; i++) {
Elf_Rel *rel = object->dyn.rel;
printf("%d: %x sym %x type %d\n", i, rel[i].r_offset,
ELF_R_SYM(rel[i].r_info), ELF_R_TYPE(rel[i].r_info));
}
printf("rela relocations:\n");
for (i = 0; i < numrela ; i++) {
Elf_RelA *rela = object->dyn.rela;
printf("%d: %x sym %x type %d\n", i, rela[i].r_offset,
ELF_R_SYM(rela[i].r_info), ELF_R_TYPE(rela[i].r_info));
}
needed_list = (Elf_Addr *)object->dyn.needed;
for (i = 0; needed_list[i] != NULL; i++)
printf("NEEDED %s\n", needed_list[i] + strt);
}
示例13: parse_elf_symbols
static void parse_elf_symbols(uintptr_t mem, size_t size, Phdr_t *load,
struct vdso_symtable *t, uintptr_t dynsymbol_names,
Hash_t *hash, Dyn_t *dyn_symtab)
{
const char *vdso_symbols[VDSO_SYMBOL_MAX] = {
ARCH_VDSO_SYMBOLS
};
const size_t vdso_symbol_length = sizeof(t->symbols[0].name);
Hash_t nbucket, nchain;
Hash_t *bucket, *chain;
unsigned int i, j, k;
uintptr_t addr;
nbucket = hash[0];
nchain = hash[1];
bucket = &hash[2];
chain = &hash[nbucket + 2];
pr_debug("nbucket %lx nchain %lx bucket %lx chain %lx\n",
(long)nbucket, (long)nchain, (unsigned long)bucket, (unsigned long)chain);
for (i = 0; i < VDSO_SYMBOL_MAX; i++) {
const char * symbol = vdso_symbols[i];
k = elf_hash((const unsigned char *)symbol);
for (j = bucket[k % nbucket]; j < nchain && chain[j] != STN_UNDEF; j = chain[j]) {
addr = mem + dyn_symtab->d_un.d_ptr - load->p_vaddr;
Sym_t *sym;
char *name;
addr += sizeof(Sym_t)*j;
if (__ptr_struct_oob(addr, sizeof(Sym_t), mem, size))
continue;
sym = (void *)addr;
if (ELF_ST_TYPE(sym->st_info) != STT_FUNC &&
ELF_ST_BIND(sym->st_info) != STB_GLOBAL)
continue;
addr = dynsymbol_names + sym->st_name;
if (__ptr_struct_oob(addr, vdso_symbol_length, mem, size))
continue;
name = (void *)addr;
if (std_strncmp(name, symbol, vdso_symbol_length))
continue;
memcpy(t->symbols[i].name, name, vdso_symbol_length);
t->symbols[i].offset = (unsigned long)sym->st_value - load->p_vaddr;
break;
}
}
}
示例14: _rtld_relocate_plt_objects
int
_rtld_relocate_plt_objects(const Obj_Entry *obj)
{
const Elf_Sym *sym = obj->symtab + obj->gotsym;
Elf_Word i;
for (i = obj->gotsym; i < obj->symtabno; i++, sym++) {
if (ELF_ST_TYPE(sym->st_info) == STT_FUNC)
if (_rtld_relocate_plt_object(obj, i, NULL) < 0)
return -1;
}
return 0;
}
示例15:
const char *arch_loader_symbol_lookup(addr_t addr, struct section_data *sd)
{
elf64_symtab_entry_t *symtab = (elf64_symtab_entry_t *)(sd->vbase[sd->symtab]);
addr_t strtab = sd->vbase[sd->strtab];
if(!symtab || !strtab)
return NULL;
for(unsigned i=0;i<(sd->symlen / sizeof(elf64_symtab_entry_t));i++) {
if(ELF_ST_TYPE(symtab[i].info) == ELF_ST_TYPE_FUNCTION) {
if(addr >= symtab[i].address && addr < (symtab[i].address + symtab[i].size)) {
return (const char *)(strtab + symtab[i].name);
}
}
}
return NULL;
}