本文整理匯總了C++中ElfW函數的典型用法代碼示例。如果您正苦於以下問題:C++ ElfW函數的具體用法?C++ ElfW怎麽用?C++ ElfW使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ElfW函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: find_matching_file
static int
find_matching_file (struct dl_phdr_info *info, size_t size, void *data)
{
struct file_match *match = data;
/* This code is modeled from Gfind_proc_info-lsb.c:callback() from libunwind */
long n;
const ElfW(Phdr) *phdr;
ElfW(Addr) load_base = info->dlpi_addr;
phdr = info->dlpi_phdr;
for (n = info->dlpi_phnum; --n >= 0; phdr++) {
if (phdr->p_type == PT_LOAD) {
ElfW(Addr) vaddr = phdr->p_vaddr + load_base;
if (match->address >= vaddr &&
match->address < vaddr + phdr->p_memsz)
{
/* we found a match */
match->file = info->dlpi_name;
match->base = info->dlpi_addr;
return 1;
}
}
}
return 0;
}
示例2: _dl_unprotect_relro
static void
_dl_unprotect_relro (struct link_map *l)
{
ElfW(Addr) start = ((l->l_addr + l->l_relro_addr)
& ~(GLRO(dl_pagesize) - 1));
ElfW(Addr) end = ((l->l_addr + l->l_relro_addr + l->l_relro_size)
& ~(GLRO(dl_pagesize) - 1));
if (start != end)
__mprotect ((void *) start, end - start, PROT_READ | PROT_WRITE);
}
示例3: _dl_protect_relro
void
_dl_protect_relro (struct elf_resolve *l)
{
ElfW(Addr) base = (ElfW(Addr)) DL_RELOC_ADDR(l->loadaddr, l->relro_addr);
ElfW(Addr) start = (base & PAGE_ALIGN);
ElfW(Addr) end = ((base + l->relro_size) & PAGE_ALIGN);
_dl_if_debug_dprint("RELRO protecting %s: start:%x, end:%x\n", l->libname, start, end);
if (start != end &&
_dl_mprotect ((void *) start, end - start, PROT_READ) < 0) {
_dl_dprintf(2, "%s: cannot apply additional memory protection after relocation", l->libname);
_dl_exit(0);
}
}
示例4: assert
bool
CrashInfo::GetDSOInfo()
{
Phdr* phdrAddr = reinterpret_cast<Phdr*>(m_auxvValues[AT_PHDR]);
int phnum = m_auxvValues[AT_PHNUM];
assert(m_auxvValues[AT_PHENT] == sizeof(Phdr));
if (phnum <= 0 || phdrAddr == nullptr) {
return false;
}
TRACE("DSO: phdr %p phnum %d\n", phdrAddr, phnum);
// Search for the program PT_DYNAMIC header
ElfW(Dyn)* dynamicAddr = nullptr;
for (int i = 0; i < phnum; i++, phdrAddr++)
{
Phdr ph;
if (!ReadMemory(phdrAddr, &ph, sizeof(ph))) {
return false;
}
TRACE("DSO: phdr %p type %d (%x) vaddr %016lx memsz %016lx offset %016lx\n",
phdrAddr, ph.p_type, ph.p_type, ph.p_vaddr, ph.p_memsz, ph.p_offset);
if (ph.p_type == PT_DYNAMIC)
{
dynamicAddr = reinterpret_cast<ElfW(Dyn)*>(ph.p_vaddr);
}
else if (ph.p_type == PT_GNU_EH_FRAME)
示例5: elf_platform
static const char *
elf_platform (void)
{
int fd;
fd = open ("/proc/self/auxv", O_RDONLY);
if (fd != -1)
{
char buf[1024];
ElfW(auxv_t) *av;
ssize_t n;
n = read (fd, buf, sizeof (buf));
close (fd);
if (n > 0)
{
for (av = (ElfW(auxv_t) *) buf; av->a_type != AT_NULL; ++av)
switch (av->a_type)
{
case AT_PLATFORM:
return (const char *) av->a_un.a_val;
default:
break;
}
}
}
示例6: _dl_tlsdesc_lazy_resolver_fixup
void
attribute_hidden
_dl_tlsdesc_lazy_resolver_fixup (struct tlsdesc volatile *td,
Elf32_Addr *got)
{
struct link_map *l = (struct link_map *)got[1];
lookup_t result;
unsigned long value;
if (_dl_tlsdesc_resolve_early_return_p
(td, (void*)(D_PTR (l, l_info[ADDRIDX (DT_TLSDESC_PLT)]) + l->l_addr)))
return;
if (td->argument.value & 0x80000000)
{
/* A global symbol, this is the symbol index. */
/* The code below was borrowed from _dl_fixup(). */
const Elf_Symndx symndx = td->argument.value ^ 0x80000000;
const ElfW(Sym) *const symtab
= (const void *) D_PTR (l, l_info[DT_SYMTAB]);
const char *strtab = (const void *) D_PTR (l, l_info[DT_STRTAB]);
const ElfW(Sym) *sym = &symtab[symndx];
/* Look up the target symbol. If the normal lookup rules are not
used don't look in the global scope. */
if (ELFW(ST_BIND) (sym->st_info) != STB_LOCAL
&& __builtin_expect (ELFW(ST_VISIBILITY) (sym->st_other), 0) == 0)
{
const struct r_found_version *version = NULL;
if (l->l_info[VERSYMIDX (DT_VERSYM)] != NULL)
{
const ElfW(Half) *vernum =
(const void *) D_PTR (l, l_info[VERSYMIDX (DT_VERSYM)]);
ElfW(Half) ndx = vernum[symndx] & 0x7fff;
version = &l->l_versions[ndx];
if (version->hash == 0)
version = NULL;
}
result = _dl_lookup_symbol_x
(strtab + sym->st_name, l, &sym,
l->l_scope, version, ELF_RTYPE_CLASS_PLT,
DL_LOOKUP_ADD_DEPENDENCY, NULL);
if (sym)
value = sym->st_value;
else
{
td->entry = _dl_tlsdesc_undefweak;
goto done;
}
}
else
{
/* We already found the symbol. The module (and therefore its load
address) is also known. */
result = l;
value = sym->st_value;
}
}
示例7: find_dynamic_entry_addr
static int
find_dynamic_entry_addr(Process *proc, void *pvAddr, int d_tag, void **addr) {
int i = 0, done = 0;
ElfW(Dyn) entry;
debug(DEBUG_FUNCTION, "find_dynamic_entry()");
if (addr == NULL || pvAddr == NULL || d_tag < 0 || d_tag > DT_NUM) {
return -1;
}
while ((!done) && (i < ELF_MAX_SEGMENTS) &&
(sizeof(entry) == umovebytes(proc, pvAddr, &entry, sizeof(entry))) &&
(entry.d_tag != DT_NULL)) {
if (entry.d_tag == d_tag) {
done = 1;
*addr = (void *)entry.d_un.d_val;
}
pvAddr += sizeof(entry);
i++;
}
if (done) {
debug(2, "found address: 0x%p in dtag %d\n", *addr, d_tag);
return 0;
}
else {
debug(2, "Couldn't address for dtag!\n");
return -1;
}
}
示例8: hook_libdl_cb
static void
hook_libdl_cb(void *data) {
struct cb_data *hook_data = data;
const char *lib_name = NULL;
ElfW(Addr) addr;
struct ltelf *lte = NULL;
debug(DEBUG_FUNCTION, "add_library_cb");
if (!data) {
debug(2, "No callback data");
return;
}
lib_name = hook_data->lib_name;
addr = hook_data->addr;
lte = hook_data->lte;
if (library_num < MAX_LIBRARIES) {
lte[library_num].base_addr = addr;
library[library_num++] = strdup(lib_name);
}
else {
fprintf (stderr, "MAX LIBS REACHED\n");
exit(EXIT_FAILURE);
}
}
示例9: headerfs_release_ident
static telf_status
headerfs_release_ident(void *obj_hdl)
{
telf_obj *obj = obj_hdl;
telf_status ret;
telf_default_content *content = NULL;
ElfW(Ehdr) *ehdr = obj->ctx->ehdr;
DEBUG("name:%s data=%p", obj->name, obj->data);
content = obj->data;
if (content) {
int i;
for (i = 0; i < EI_NIDENT; i++) {
char tmp[3] = {
content->buf[2*i],
content->buf[2*i+1],
0
};
ehdr->e_ident[i] = (uint8_t) strtoul(tmp, NULL, 16);
}
}
ret = ELF_SUCCESS;
return ret;
}
示例10: __libc_init_AT_SECURE
void __libc_init_AT_SECURE(KernelArgumentBlock& args) {
__libc_auxv = args.auxv;
// Check that the kernel provided a value for AT_SECURE.
bool found_AT_SECURE = false;
for (ElfW(auxv_t)* v = __libc_auxv; v->a_type != AT_NULL; ++v) {
if (v->a_type == AT_SECURE) {
found_AT_SECURE = true;
break;
}
}
if (!found_AT_SECURE) __early_abort(__LINE__);
if (getauxval(AT_SECURE)) {
// If this is a setuid/setgid program, close the security hole described in
// https://www.freebsd.org/security/advisories/FreeBSD-SA-02:23.stdio.asc
__nullify_closed_stdio();
__sanitize_environment_variables(args.envp);
}
// Now the environment has been sanitized, make it available.
environ = args.envp;
__initialize_personality();
}
示例11: symentryfs_read_info
static telf_status
symentryfs_read_info(void *obj_hdl,
char **bufp,
size_t *buf_lenp)
{
telf_obj *obj = obj_hdl;
char *symname = NULL;
char *buf = NULL;
size_t buf_len = 0;
telf_status ret;
FILE *out = NULL;
ElfW(Sym) *sym = obj->parent->data;
/* default value */
symname = "NONAME";
if (sym->st_name) {
symname = ((ELF_SECTION_SYMTAB == obj->parent->type) ?
elf_getsymname :
elf_getdsymname)(obj->ctx, sym);
if (! symname || ! *symname)
symname = "UNRESOLVED";
}
out = open_memstream(&buf, &buf_len);
if (! out) {
ERR("open_memstream: %s", strerror(errno));
ret = ELF_ENOMEM;
goto end;
}
fprintf(out,
"value: %p\n"
"size: %zu\n"
"type: %s\n"
"bind: %s\n"
"name: %s\n",
(void *) sym->st_value,
sym->st_size,
sym_type_to_str(sym),
sym_bind_to_str(sym),
symname);
ret = ELF_SUCCESS;
end:
if (out)
fclose(out);
if (bufp)
*bufp = buf;
else
free(buf);
if (buf_lenp)
*buf_lenp = buf_len;
return ret;
}
示例12: getauxval
extern "C" unsigned long int getauxval(unsigned long int type) {
for (ElfW(auxv_t)* v = __libc_auxv; v->a_type != AT_NULL; ++v) {
if (v->a_type == type) {
return v->a_un.a_val;
}
}
return 0;
}
示例13: FileGetElfType
// Returns elf_header.e_type if the file pointed by fd is an ELF binary.
static int FileGetElfType(const int fd) {
ElfW(Ehdr) elf_header;
if (!ReadFromOffsetExact(fd, &elf_header, sizeof(elf_header), 0)) {
return -1;
}
if (memcmp(elf_header.e_ident, ELFMAG, SELFMAG) != 0) {
return -1;
}
return elf_header.e_type;
}
示例14: main
int main(int argc, char *argv[]){
long i;
ElfW(Addr) a_type;
ElfW(Addr) a_val;
if(argc == 1){
printf("No arguments specified.\n\n");
print_help();
return 0;
}
for(i = 1; i < argc; i++){
if(!strcasecmp("--help", argv[i]) || !strcasecmp("-help", argv[i])){
print_help();
return 0;
}
if(!strcasecmp("--info", argv[i]) || !strcasecmp("-info", argv[i])){
print_info();
return 0;
}
if(!strcasecmp("--list", argv[i]) || !strcasecmp("-list", argv[i])){
print_list();
return 0;
}
if(!strcasecmp("--hwcap", argv[i]) || !strcasecmp("-hwcap", argv[i])){
print_hwcap();
return 0;
}
}
for(i = 1; i < argc; i++){
a_type = translate_a_type(argv[i]);
a_val = query_auxv(a_type);
#ifdef __powerpc64__
printf("%lu\n", a_val);
#else
printf("%u\n", a_val);
#endif
}
return 0;
}
示例15: headerfs_release_entrypoint
static telf_status
headerfs_release_entrypoint(void *obj_hdl)
{
telf_obj *obj = obj_hdl;
telf_status ret;
telf_default_content *content = NULL;
DEBUG("name:%s data=%p", obj->name, obj->data);
content = obj->data;
if (content) {
ElfW(Addr) addr = (ElfW(Addr)) strtoull(content->buf, NULL, 0);
DEBUG("new entry point: %p", (void *) addr);
obj->ctx->ehdr->e_entry = addr;
}
ret = ELF_SUCCESS;
return ret;
}