• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ elf_strptr函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中elf_strptr函数的典型用法代码示例。如果您正苦于以下问题:C++ elf_strptr函数的具体用法?C++ elf_strptr怎么用?C++ elf_strptr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了elf_strptr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: elf_version

static elf_info_s *elf_symbols(int fd)
{
    /* Open Elf */
    elf_version(EV_CURRENT);
    elf_info_s *elf = calloc(1, sizeof (elf_info_s));
    elf->elf = elf_begin(fd, ELF_C_READ, NULL);
    gelf_getehdr(elf->elf, &elf->hdr);

    /* Iterate through the sections */
    Elf_Scn *scn = NULL;
    while ((scn = elf_nextscn(elf->elf, scn)) != 0) {
        GElf_Shdr shdr;
        const char *name;
        /* get section header */
        gelf_getshdr(scn, &shdr);
        /* get section name */
        name = elf_strptr(elf->elf, elf->hdr.e_shstrndx, shdr.sh_name);
        //LOG(INFO, "Iter on %s", name);

        if (shdr.sh_type == SHT_DYNSYM)
            handle_dynsym_section(elf, scn, shdr);
        else if (shdr.sh_type == SHT_DYNAMIC)
            handle_dynamic_section(elf, scn, shdr);
        else if ((shdr.sh_type == SHT_PROGBITS || shdr.sh_type == SHT_NOBITS)
                && !strcmp(name, ".plt"))
            handle_plt_section(elf, shdr);
        else if (!strcmp(name, ".got.plt"))
            handle_gotplt_section(elf, shdr);
    }
    return elf;
}
开发者ID:schischi,项目名称:my_ltrace,代码行数:31,代码来源:elfd.c


示例2: resolve_globals

static void resolve_globals( void )
{
    OBJECT_FILE *file;
    global_t *global_sym;
    Elf32_Sym *symbol;
    int i;
    int compare;
    char *sym_name;

    file = objects;
    while (file)
    {
        symbol = file->symbols + file->first_global;
        for ( i = file->first_global ; i < file->symbol_count ; ++i )
        {
            sym_name = elf_strptr( file->elf, file->string_index,
                                   symbol->st_name);
            if (symbol->st_shndx == SHN_UNDEF)
            {
                global_sym = (global_t *)bbtree_preinsert( &globals, sym_name,
                                                           &compare );
                if (compare == 0)
                {
                    symbol->st_value = global_sym->symbol->st_value;
                    /* set to any section other than SHN_UNDEF */
                    symbol->st_shndx = 1;
                }
                /* not an error until a symbol is referenced */
            }
            ++symbol;
        }
        file = file->next_object;
    }
}
开发者ID:wodz,项目名称:open21xx,代码行数:34,代码来源:execfile.c


示例3: get_embedded_repo

std::string get_embedded_repo() {
  GElf_Shdr shdr;
  size_t shstrndx;
  char *name;
  Elf_Scn *scn;

  if (elf_version(EV_CURRENT) == EV_NONE) return "";

  int fd = open("/proc/self/exe", O_RDONLY, 0);
  if (fd < 0) return "";
  Elf* e = elf_begin(fd, ELF_C_READ, nullptr);

  if (!e ||
      elf_kind(e) != ELF_K_ELF ||
      !elf_getshstrndx(e, &shstrndx)) {
    return "";
  }
  scn = nullptr;
  while ((scn = elf_nextscn(e, scn)) != nullptr) {
    if (gelf_getshdr(scn, &shdr) != &shdr ||
        !(name = elf_strptr(e, shstrndx , shdr.sh_name))) {
      return "";
    }
    if (!strcmp("repo", name)) {
      GElf_Shdr ghdr;
      if (gelf_getshdr(scn, &ghdr) != &ghdr) return "";
      char buf[512];
      sprintf(buf, "/proc/self/exe:%lu:%lu", ghdr.sh_offset, ghdr.sh_size);
      sqlite3_embedded_initialize(nullptr, true);
      return buf;
    }
  }
  return "";
}
开发者ID:ChrisOHu,项目名称:hiphop-php,代码行数:34,代码来源:embedded_repo.cpp


示例4: find_symbol

int find_symbol(char *fn, struct lsym *lsym, unsigned long baseaddr)
{
	struct lsym *ls;
	int num = 0;
	for (ls = lsym; ls->name; ls++)
		num++;

	elf_version(EV_CURRENT);
	int fd = open(fn, O_RDONLY);
	if (fd < 0)
		return -1;

	long ret = -1;
	Elf *elf = elf_begin(fd, ELF_C_READ, NULL);
	if (elf == NULL)
		goto out;

	GElf_Ehdr header;
	if (!gelf_getehdr(elf, &header))
		goto out_elf;

	Elf_Scn *section = NULL;
	int found = 0;
	while (found < num && (section = elf_nextscn(elf, section)) != 0) {
		GElf_Shdr shdr, *sh;
		sh = gelf_getshdr(section, &shdr);

		if (sh->sh_type == SHT_SYMTAB || sh->sh_type == SHT_DYNSYM) {
			Elf_Data *data = elf_getdata(section, NULL);
			GElf_Sym *sym, symbol;
			int j;

			unsigned numsym = sh->sh_size / sh->sh_entsize;
			for (j = 0; j < numsym; j++) {
				sym = gelf_getsymshndx(data, NULL, j, &symbol, NULL);
				char *symname = elf_strptr(elf, shdr.sh_link, sym->st_name);
				for (ls = lsym; ls->name; ls++) {
					if (!strcmp(symname, ls->name)) {
						Elf_Scn *oscn = elf_getscn(elf, sym->st_shndx);
						GElf_Shdr oshdr, *osh;
						osh = gelf_getshdr(oscn, &oshdr);
						ls->addr = (sym->st_value - osh->sh_addr) + osh->sh_offset + baseaddr;
						found++;
						if (found == num)
							break;
					}
				}
			}
		}
	}
	if (found == num)
		ret = 0;

out_elf:
	elf_end(elf);

out:
	close(fd);
	return ret;
}
开发者ID:gcracker,项目名称:tsx-tools,代码行数:60,代码来源:sym.c


示例5: get_scn_hdr

scn_hdr_t* get_scn_hdr(int idx)
{
	Elf_Scn* scn = g.scns[idx];
	GElf_Shdr shdr = g.shdrs[idx];

	Elf_Data* data;
	size_t n;
	
	// if ( gelf_getshdr(scn , &shdr) != &shdr ) {
	// 	errx ( EXIT_FAILURE,
	// 	       " getshdr( shstrndx ) failed : %s.",
	// 	       elf_errmsg ( -1));
	// 	return NULL;
	// }

	// data = NULL; size_t buf_sz = 0;
	// while ((data=elf_getdata(scn, data)) != NULL) {
	// 	printf("+%d", data->d_size);
	// 	buf_sz += data->d_size;
	// }

	uint8_t* buf = (uint8_t*) malloc(shdr.sh_size);
	if (buf == NULL) {		
		errx (EXIT_FAILURE, "malloc failed");
		return NULL;
	}

	data = NULL; n = 0;
	while (n < shdr.sh_size &&
	       (data = elf_getdata(scn, data)) != NULL) {
		uint8_t* p = (uint8_t*)data->d_buf;
		size_t dsize = data->d_size;
		if(p != NULL)
			memcpy(buf+n, p, dsize);
		else //FIXME: seems some sections are empty in file
			memset(buf+n, 0, dsize);
		n += dsize;
	}

	// get the name string
	char* name;
	if ((name = elf_strptr(g.e, g.shstrndx, shdr.sh_name)) == NULL)
	  errx(EXIT_FAILURE , " elf_strptr()  failed : %s.",
	       elf_errmsg (-1));
	

	scn_hdr_t* scn_hdr_p = (scn_hdr_t*)malloc(sizeof(scn_hdr_t));
	if (scn_hdr_p == NULL) {
		errx (EXIT_FAILURE , "scn_hdr_t malloc failed");
		return NULL;
	}

	scn_hdr_p->sh_idx = idx;
	scn_hdr_p->name = name;
	scn_hdr_p->sh_addr = shdr.sh_addr;
	scn_hdr_p->sh_size = n;
	scn_hdr_p->data = buf;

	return scn_hdr_p;
}
开发者ID:grasshopyx,项目名称:luaelf,代码行数:60,代码来源:libelfconn.c


示例6: find_injected_secaddr

int
find_injected_secaddr(elf_data_t *elf, inject_data_t *inject)
{
  Elf_Scn *scn;
  GElf_Shdr shdr;
  uint64_t max_inject_addr = 0;
  char* s;
  size_t shstrndx;

  if(elf_getshdrstrndx(elf->e, &shstrndx) < 0) {
    return -1;
  }

  scn = NULL;
  while((scn = elf_nextscn(elf->e, scn))) {
    if(!gelf_getshdr(scn, &shdr)) {
      return -1;
    }
    s = elf_strptr(elf->e, shstrndx, shdr.sh_name);
    if(!s) {
      return -1;
    }

    if(!strcmp(s, DYNINST_NAME))
		fprintf(finfo,"dyninst end=%lx\n",shdr.sh_addr + shdr.sh_size);
	if (shdr.sh_addr + shdr.sh_offset > max_inject_addr)
		max_inject_addr = shdr.sh_addr + shdr.sh_size;
  }
  inject->secaddr = max_inject_addr + inject->len + 0x4000;
  return 0;
}
开发者ID:sirmc,项目名称:XnRmor,代码行数:31,代码来源:elfinject.c


示例7: elf_scn_getsymaddr_byname

/**
 * @brief Search a single, particular ELF symbol table for a named symbol
 *
 * @param elf The open ELF object
 * @param symtab The ELF symbol table section
 * @param name The symbol name to find
 *
 * @returns The address to which the symbol points, 0 otherwise.
 */
static GElf_Addr elf_scn_getsymaddr_byname(Elf *elf, Elf_Scn *symtab,
                                           const char * name) {
    GElf_Shdr shdr;
    Elf_Data *data;
    uint32_t syms, i;
    GElf_Sym sym;

    if (gelf_getshdr(symtab, &shdr) == NULL || shdr.sh_type != SHT_SYMTAB) {
        return 0;
    }

    data = elf_getdata(symtab, NULL);
    if (data == NULL) {
        return 0;
    }

    syms = shdr.sh_size / shdr.sh_entsize;

    for(i=0; i<syms; i++) {
        gelf_getsym(data, i, &sym);
        if (strcmp(elf_strptr(elf, shdr.sh_link, sym.st_name), name) == 0) {
            return sym.st_value;
        }
    }

    return 0;
}
开发者ID:girling-morgan,项目名称:bootrom-tools,代码行数:36,代码来源:tftf_in.c


示例8: readSymbols

static void readSymbols(Elf *e, Elf_Scn *scn, const GElf_Shdr &shdr,
                        unsigned low, unsigned high,
                        std::auto_ptr<CoreSymbolInfo> &SI)
{
  Elf_Data *data = elf_getdata(scn, NULL);
  if (data == NULL) {
    return;
  }
  unsigned count = shdr.sh_size / shdr.sh_entsize;

  CoreSymbolInfoBuilder builder;

  for (unsigned i = 0; i < count; i++) {
    GElf_Sym sym;
    if (gelf_getsym(data, i, &sym) == NULL) {
      continue;
    }
    if (sym.st_shndx == SHN_ABS)
      continue;
    if (sym.st_value < low || sym.st_value >= high)
      continue;
    builder.addSymbol(elf_strptr(e, shdr.sh_link, sym.st_name),
                      sym.st_value,
                      sym.st_info);
  }
  SI = builder.getSymbolInfo();
}
开发者ID:hoangt,项目名称:tool_axe,代码行数:27,代码来源:main.cpp


示例9: elf_getscn_byname

/**
 * @brief Search an elf for a named section
 *
 * @param elf The open elf object
 * @param name The section name to find
 *
 * @returns A pointer to the section if successful, NULL otherwise.
 */
static Elf_Scn * elf_getscn_byname(Elf *elf, const char * name) {
    Elf_Scn *scn = NULL;
    size_t shstrndx;
    GElf_Shdr shdr;
    char *section_name;

    if (elf_getshdrstrndx(elf, &shstrndx) != 0) {
        fprintf(stderr, "elf_getshdrstrndx() failed: %s\n", elf_errmsg(-1));
    } else {
        /**
         * Iterate over the sections in the ELF descriptor to get the indices
         * of the .text and .data descriptors
         */
        while ((scn = elf_nextscn(elf, scn)) != NULL) {
            if (gelf_getshdr(scn, &shdr) != &shdr) {
                fprintf(stderr, "getshdr() failed: %s\n",
                    elf_errmsg(-1));
            } else {
                section_name = elf_strptr(elf, shstrndx, shdr.sh_name);
                if (section_name == NULL) {
                    fprintf(stderr, "elf_strptr() failed: %s\n",
                        elf_errmsg(-1));
                } else if (strcmp(section_name, name) == 0) {
                    break;
                }
            }
        }
    }

    return scn;
}
开发者ID:girling-morgan,项目名称:bootrom-tools,代码行数:39,代码来源:tftf_in.c


示例10: while

static Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
				    GElf_Shdr *shp, const char *name,
				    size_t *idx)
{
	Elf_Scn *sec = NULL;
	size_t cnt = 1;

	/* Elf is corrupted/truncated, avoid calling elf_strptr. */
	if (!elf_rawdata(elf_getscn(elf, ep->e_shstrndx), NULL))
		return NULL;

	while ((sec = elf_nextscn(elf, sec)) != NULL) {
		char *str;

		gelf_getshdr(sec, shp);
		str = elf_strptr(elf, ep->e_shstrndx, shp->sh_name);
		if (!strcmp(name, str)) {
			if (idx)
				*idx = cnt;
			break;
		}
		++cnt;
	}

	return sec;
}
开发者ID:alexey-pelykh,项目名称:linux,代码行数:26,代码来源:symbol-elf.c


示例11: rewrite_section_name

int
rewrite_section_name(elf_data_t *elf, inject_data_t *inject, char **err)
{
  Elf_Scn *scn;
  GElf_Shdr shdr;
  char *s;
  size_t shstrndx, stroff, strbase;

  if(strlen(inject->secname) > strlen(ABITAG_NAME)) {
    (*err) = "section name too long";
    return -1;
  }

  if(elf_getshdrstrndx(elf->e, &shstrndx) < 0) {
    (*err) = "failed to get string table section index";
    return -1;
  }

  stroff = 0;
  strbase = 0;
  scn = NULL;
  while((scn = elf_nextscn(elf->e, scn))) {
    if(!gelf_getshdr(scn, &shdr)) {
      (*err) = "failed to get section header";
      return -1;
    }

    s = elf_strptr(elf->e, shstrndx, shdr.sh_name);
    if(!s) {
      (*err) = "failed to get section name";
      return -1;
    }

    if(!strcmp(s, ABITAG_NAME)) {
      stroff = shdr.sh_name;   /* offset into shstrtab */
    } else if(!strcmp(s, SHSTRTAB_NAME)) {
      strbase = shdr.sh_offset; /* offset to start of shstrtab */
    }
  }

  if(stroff == 0) {
    (*err) = "cannot find shstrtab entry for injected section";
    return -1;
  } else if(strbase == 0) {
    (*err) = "cannot find shstrtab";
    return -1;
  }

  inject->shstroff = strbase + stroff;

  verbose("renaming rewritten section to \"%s\"", inject->secname);
  verbose("writing section string table to file");

  if(write_secname(elf, inject, err) < 0) {
    return -1;
  }

  return 0;
}
开发者ID:sirmc,项目名称:XnRmor,代码行数:59,代码来源:elfinject.c


示例12: drsym_obj_symbol_name

const char *
drsym_obj_symbol_name(void *mod_in, uint idx)
{
    elf_info_t *mod = (elf_info_t *) mod_in;
    if (mod == NULL || idx >= mod->num_syms || mod->syms == NULL)
        return NULL;
    return elf_strptr(mod->elf, mod->strtab_idx, mod->syms[idx].st_name);
}
开发者ID:unbaiat,项目名称:robocheck,代码行数:8,代码来源:drsyms_elf.c


示例13: find_elf_section_by_name

/**
 * Finds a section by its name in an ELF file.
 * @param elf
 *   A libelf handle representing the file.
 * @param section_name
 *   Name of section to be found.
 * @param data_dest
 *   Save the resulting elf data pointer here.  Cannot be NULL.
 * @param shdr_dest
 *   Save the section header here. Cannot be NULL.
 * @param error_message
 *   Will be filled by an error message if the function fails (returns
 *   zero).  Caller is responsible for calling free() on the string
 *   pointer.  If function succeeds, the pointer is not touched by the
 *   function.
 * @returns
 *   Zero on error, index of the section on success.
 */
static unsigned
find_elf_section_by_name(Elf *elf,
                         const char *section_name,
                         Elf_Data **data_dest,
                         GElf_Shdr *shdr_dest,
                         char **error_message)
{
    /* Find the string table index */
    size_t shdr_string_index;
    if (0 != elf_getshdrstrndx(elf, &shdr_string_index))
    {
        *error_message = sr_asprintf("elf_getshdrstrndx failed");
        return 0;
    }

    unsigned section_index = 0;
    Elf_Scn *section = NULL;
    while ((section = elf_nextscn(elf, section)) != NULL)
    {
        /* Starting index is 1. */
        ++section_index;

        GElf_Shdr shdr;
        if (gelf_getshdr(section, &shdr) != &shdr)
        {
            *error_message = sr_asprintf("gelf_getshdr failed");
            return 0;
        }

        const char *current_section_name = elf_strptr(elf,
                                                      shdr_string_index,
                                                      shdr.sh_name);

        if (!current_section_name)
        {
            *error_message = sr_asprintf("elf_strptr failed");
            return 0;
        }

        if (0 == strcmp(current_section_name, section_name))
        {
            /* We found the right section!  Save the data. */
            *data_dest = elf_getdata(section, NULL);
            if (!*data_dest)
            {
                *error_message = sr_asprintf("elf_getdata failed");
                return 0;
            }

            /* Save the section header. */
            *shdr_dest = shdr;
            return section_index;
        }
    }

    *error_message = sr_asprintf("Section %s not found", section_name);
    return 0;
}
开发者ID:abrt,项目名称:satyr,代码行数:76,代码来源:elves.c


示例14: find_section_base

static void
find_section_base(const char *exe, Elf *e, const char *section)
{
	Dwarf_Addr off;
	Elf_Scn *scn;
	GElf_Ehdr eh;
	GElf_Shdr sh;
	size_t shstrndx;
	int elferr;
	const char *name;

	if (gelf_getehdr(e, &eh) != &eh) {
		warnx("gelf_getehdr failed: %s", elf_errmsg(-1));
		return;
	}

	if (!elf_getshstrndx(e, &shstrndx)) {
		warnx("elf_getshstrndx failed: %s", elf_errmsg(-1));
		return;
	}

	(void) elf_errno();
	off = 0;
	scn = NULL;
	while ((scn = elf_nextscn(e, scn)) != NULL) {
		if (gelf_getshdr(scn, &sh) == NULL) {
			warnx("gelf_getshdr failed: %s", elf_errmsg(-1));
			continue;
		}
		if ((name = elf_strptr(e, shstrndx, sh.sh_name)) == NULL)
			goto next;
		if (!strcmp(section, name)) {
			if (eh.e_type == ET_EXEC || eh.e_type == ET_DYN) {
				/*
				 * For executables, section base is the virtual
				 * address of the specified section.
				 */
				section_base = sh.sh_addr;
			} else if (eh.e_type == ET_REL) {
				/*
				 * For relocatables, section base is the
				 * relative offset of the specified section
				 * to the start of the first section.
				 */
				section_base = off;
			} else
				warnx("unknown e_type %u", eh.e_type);
			return;
		}
	next:
		off += sh.sh_size;
	}
	elferr = elf_errno();
	if (elferr != 0)
		warnx("elf_nextscn failed: %s", elf_errmsg(elferr));

	errx(EXIT_FAILURE, "%s: cannot find section %s", exe, section);
}
开发者ID:jhofstee,项目名称:freebsd,代码行数:58,代码来源:addr2line.c


示例15: elf_getshdrstrndx

const char *get_scn_name(vita_elf_t *ve, Elf_Scn *scn)
{
	size_t shstrndx;
	GElf_Shdr shdr;

	elf_getshdrstrndx(ve->elf, &shstrndx);
	gelf_getshdr(scn, &shdr);
	return elf_strptr(ve->elf, shstrndx, shdr.sh_name);
}
开发者ID:nterry,项目名称:vita-toolchain,代码行数:9,代码来源:vita-elf-create.c


示例16: xelf_section_by_name

/*
 * @param e         elf handle
 * @param name      name of section to be found
 * @param filename  filename for logging messages
 * @param dest      save the resulting elf data pointer here (can be NULL)
 * @param shdr_dest save the section header here (can be NULL)
 * @returns zero on error, index of the section on success
 */
static unsigned xelf_section_by_name(Elf *e, const char *name, const char *filename, Elf_Data **dest, GElf_Shdr *shdr_dest)
{
    Elf_Scn *scn = NULL;
    GElf_Shdr shdr;
    unsigned section_index = 0;
    size_t shstrndx;

    /* Find the string table index */
    if (elf_getshdrstrndx(e, &shstrndx) != 0)
    {
        VERB1 log_elf_error("elf_getshdrstrndx", filename);
        return 0;
    }

    while ((scn = elf_nextscn(e, scn)) != NULL)
    {
        section_index++; /* starting index is 1 */

        if (gelf_getshdr(scn, &shdr) != &shdr)
        {
            VERB1 log_elf_error("gelf_getshdr", filename);
            continue;
        }

        const char *scnname = elf_strptr(e, shstrndx, shdr.sh_name);
        if (scnname == NULL)
        {
            VERB1 log_elf_error("elf_strptr", filename);
            continue;
        }

        if (strcmp(scnname, name) == 0)
        {
            /* Found, save data */
            if (dest)
            {
                *dest = elf_getdata(scn, NULL);
                if (*dest == NULL)
                {
                    VERB1 log_elf_error("elf_getdata", filename);
                    break;
                }
            }

            /* save shdr */
            if (shdr_dest)
            {
                *shdr_dest = shdr;
            }

            return section_index;
        }
    }

    VERB1 log("Section %s not found in %s\n", name, filename);
    return 0;
}
开发者ID:abrt,项目名称:btparser,代码行数:65,代码来源:core-backtrace-fingerprints.c


示例17: check_section

static void
check_section (Dwarf *result, GElf_Ehdr *ehdr, Elf_Scn *scn, bool inscngrp)
{
  GElf_Shdr shdr_mem;
  GElf_Shdr *shdr;

  /* Get the section header data.  */
  shdr = gelf_getshdr (scn, &shdr_mem);
  if (shdr == NULL)
    /* This should never happen.  If it does something is
       wrong in the libelf library.  */
    abort ();


  /* Make sure the section is part of a section group only iff we
     really need it.  If we are looking for the global (= non-section
     group debug info) we have to ignore all the info in section
     groups.  If we are looking into a section group we cannot look at
     a section which isn't part of the section group.  */
  if (! inscngrp && (shdr->sh_flags & SHF_GROUP) != 0)
    /* Ignore the section.  */
    return;


  /* We recognize the DWARF section by their names.  This is not very
     safe and stable but the best we can do.  */
  const char *scnname = elf_strptr (result->elf, ehdr->e_shstrndx,
				    shdr->sh_name);
  if (scnname == NULL)
    {
      /* The section name must be valid.  Otherwise is the ELF file
	 invalid.  */
      __libdw_seterrno (DWARF_E_INVALID_ELF);
      free (result);
      return;
    }


  /* Recognize the various sections.  Most names start with .debug_.  */
  size_t cnt;
  for (cnt = 0; cnt < ndwarf_scnnames; ++cnt)
    if (strcmp (scnname, dwarf_scnnames[cnt]) == 0)
      {
	/* Found it.  Remember where the data is.  */
	if (unlikely (result->sectiondata[cnt] != NULL))
	  /* A section appears twice.  That's bad.  We ignore the section.  */
	  break;

	/* Get the section data.  */
	Elf_Data *data = elf_getdata (scn, NULL);
	if (data != NULL && data->d_size != 0)
	  /* Yep, there is actually data available.  */
	  result->sectiondata[cnt] = data;

	break;
      }
}
开发者ID:325116067,项目名称:semc-qsd8x50,代码行数:57,代码来源:dwarf_begin_elf.c


示例18: elf_getshdrnum

uint8_t *dump_section_data(Elf *elf_object, int *size)
{
	uint8_t *buffer = NULL;
	Elf_Data *data = NULL;
	size_t shdr_num;
	size_t max_saddr = 0;
	GElf_Shdr shdr;
	size_t shstrndx;
	char *name = NULL;

	*size = 0;

	int ret = elf_getshdrnum(elf_object, &shdr_num);
	if (ret) {
		printf("Problem during ELF parsing\n");
		return NULL;
	}

	if (shdr_num == 0)
		return NULL;

	Elf_Scn *cur_section = NULL;
	ret = elf_getshdrstrndx(elf_object, &shstrndx);
	if (ret)
		printf("No string table found\n");

	while ((cur_section = elf_nextscn(elf_object, cur_section)) != NULL ) {
		if (gelf_getshdr(cur_section, &shdr) != &shdr) {
			printf("Problem during ELF parsing\n");
			return NULL;
		}

		if ((shdr.sh_type == SHT_PROGBITS) && (shdr.sh_flags & SHF_ALLOC) && shdr.sh_size != 0) {

			name = elf_strptr(elf_object, shstrndx , shdr.sh_name);
			printf("Loading section %s, size 0x%08X lma 0x%08X\n",
				name ? name : "??", (unsigned int)shdr.sh_size, (unsigned int)shdr.sh_addr);

			if (shdr.sh_addr + shdr.sh_size >= max_saddr) {
				max_saddr = shdr.sh_addr + shdr.sh_size;
				buffer = realloc(buffer, max_saddr);
			}

			data = elf_getdata(cur_section, data);
			if (data != NULL)
				memcpy(buffer + shdr.sh_addr, data->d_buf, data->d_size);
			else {
				printf("Couldn't load section data chunk\n");
				return NULL;
			}
		}
	}

	*size = max_saddr;
	return buffer;
}
开发者ID:davidecitterio,项目名称:Mor1kx_sakura,代码行数:56,代码来源:elf-loader.c


示例19: elf_section_name

static const char *
elf_section_name (Elf *elf, GElf_Word shndx)
{
  GElf_Ehdr ehdr;
  GElf_Shdr shdr;
  Elf_Scn *scn = elf_getscn (elf, shndx);
  gelf_getshdr (scn, &shdr);
  gelf_getehdr (elf, &ehdr);
  return elf_strptr (elf, ehdr.e_shstrndx, shdr.sh_name);
}
开发者ID:CongLi,项目名称:autotest-client-tests,代码行数:10,代码来源:dwflsyms.c


示例20: radeon_elf_read

void radeon_elf_read(const char *elf_data, unsigned elf_size,
					struct radeon_shader_binary *binary,
					unsigned debug)
{
	char *elf_buffer;
	Elf *elf;
	Elf_Scn *section = NULL;
	size_t section_str_index;

	/* One of the libelf implementations
	 * (http://www.mr511.de/software/english.htm) requires calling
	 * elf_version() before elf_memory().
	 */
	elf_version(EV_CURRENT);
	elf_buffer = MALLOC(elf_size);
	memcpy(elf_buffer, elf_data, elf_size);

	elf = elf_memory(elf_buffer, elf_size);

	elf_getshdrstrndx(elf, &section_str_index);
	binary->disassembled = 0;

	while ((section = elf_nextscn(elf, section))) {
		const char *name;
		Elf_Data *section_data = NULL;
		GElf_Shdr section_header;
		if (gelf_getshdr(section, &section_header) != &section_header) {
			fprintf(stderr, "Failed to read ELF section header\n");
			return;
		}
		name = elf_strptr(elf, section_str_index, section_header.sh_name);
		if (!strcmp(name, ".text")) {
			section_data = elf_getdata(section, section_data);
			binary->code_size = section_data->d_size;
			binary->code = MALLOC(binary->code_size * sizeof(unsigned char));
			memcpy(binary->code, section_data->d_buf, binary->code_size);
		} else if (!strcmp(name, ".AMDGPU.config")) {
			section_data = elf_getdata(section, section_data);
			binary->config_size = section_data->d_size;
			binary->config = MALLOC(binary->config_size * sizeof(unsigned char));
			memcpy(binary->config, section_data->d_buf, binary->config_size);
		} else if (debug && !strcmp(name, ".AMDGPU.disasm")) {
			binary->disassembled = 1;
			section_data = elf_getdata(section, section_data);
			fprintf(stderr, "\nShader Disassembly:\n\n");
			fprintf(stderr, "%.*s\n", (int)section_data->d_size,
						  (char *)section_data->d_buf);
		}
	}

	if (elf){
		elf_end(elf);
	}
	FREE(elf_buffer);
}
开发者ID:Haifen,项目名称:Mesa-3D,代码行数:55,代码来源:radeon_elf_util.c



注:本文中的elf_strptr函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ elf_version函数代码示例发布时间:2022-05-30
下一篇:
C++ elf_kind函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap