当前位置: 首页>>代码示例>>C++>>正文


C++ elf_getscn函数代码示例

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


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

示例1: elf_strptr

char *
elf_strptr(Elf * elf, size_t ndx, size_t off)
{
	Elf_Scn *	s;
	Elf_Data *	d;
	char *		rc;

	if (elf == 0)
		return (0);
		
	extern const char *elf_macho_str_off(size_t off);
	
	if (elf->ed_kind == ELF_K_MACHO && (ndx == SHN_MACHO || ndx == SHN_MACHO_64))
		return (char *)elf_macho_str_off(off);

	if ((s = elf_getscn(elf, ndx)) == 0) {
		_elf_seterr(EREQ_STRSCN, 0);
		return (0);
	}
	READLOCKS(elf, s)
	if (elf->ed_class == ELFCLASS32) {
		Elf32_Shdr* sh = (Elf32_Shdr*)s->s_shdr;

		if ((sh == 0) || (sh->sh_type != SHT_STRTAB)) {
			_elf_seterr(EREQ_STRSCN, 0);
			READUNLOCKS(elf, s)
			return (0);
		}
开发者ID:Leon555,项目名称:Mac-src-essentials,代码行数:28,代码来源:strptr.c

示例2: scngrp_read

static Dwarf *
scngrp_read (Dwarf *result, Elf *elf, GElf_Ehdr *ehdr, Dwarf_Cmd cmd,
	     Elf_Scn *scngrp)
{
  /* SCNGRP is the section descriptor for a section group which might
     contain debug sections.  */
  Elf_Data *data = elf_getdata (scngrp, NULL);
  if (data == NULL)
    {
      /* We cannot read the section content.  Fail!  */
      free (result);
      return NULL;
    }

  /* The content of the section is a number of 32-bit words which
     represent section indices.  The first word is a flag word.  */
  Elf32_Word *scnidx = (Elf32_Word *) data->d_buf;
  size_t cnt;
  for (cnt = 1; cnt * sizeof (Elf32_Word) <= data->d_size; ++cnt)
    {
      Elf_Scn *scn = elf_getscn (elf, scnidx[cnt]);
      if (scn == NULL)
	{
	  /* A section group refers to a non-existing section.  Should
	     never happen.  */
	  __libdw_seterrno (DWARF_E_INVALID_ELF);
	  free (result);
	  return NULL;
	}

      check_section (result, ehdr, scn, true);
    }

  return valid_p (result);
}
开发者ID:325116067,项目名称:semc-qsd8x50,代码行数:35,代码来源:dwarf_begin_elf.c

示例3:

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

示例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: elf_getphnum

int
elf_getphnum(Elf *elf, size_t *phnum)
{
	GElf_Ehdr	ehdr;
	Elf_Scn		*scn;
	GElf_Shdr	shdr0;

	if (gelf_getehdr(elf, &ehdr) == NULL)
		return (0);

	if (ehdr.e_phnum != PN_XNUM) {
		*phnum = ehdr.e_phnum;
		return (1);
	}

	if ((scn = elf_getscn(elf, 0)) == NULL ||
	    gelf_getshdr(scn, &shdr0) == NULL)
		return (0);

	if (shdr0.sh_info == 0)
		*phnum = ehdr.e_phnum;
	else
		*phnum = shdr0.sh_info;

	return (1);
}
开发者ID:Andromeda-OS,项目名称:Kernel,代码行数:26,代码来源:getphnum.c

示例6: handle_dynamic_section

static void handle_dynamic_section(elf_info_s *elf, Elf_Scn *scn, GElf_Shdr shdr)
{
    Elf_Data *data;
    GElf_Addr replt_addr;
    size_t replt_count;

    /* get data of .dynamic */
    data = elf_getdata(scn, NULL);

    /* iterate through .dynamic */
    for (size_t i = 0; i < shdr.sh_size / shdr.sh_entsize; ++i) {
        GElf_Dyn dyn;

        // get entries i
        gelf_getdyn(data, i, &dyn);
        // if replt
        if (dyn.d_tag == DT_JMPREL)
            replt_addr = dyn.d_un.d_ptr;
        // if replt_size
        if (dyn.d_tag == DT_PLTRELSZ)
            replt_count = dyn.d_un.d_val;
    }
    LOG(INFO, "Section relplt at 0x%lx (%zu)", replt_addr, replt_count);
    for (size_t i = 1; i < elf->hdr.e_shnum; ++i) {
        Elf_Scn *scn;
        GElf_Shdr shdr;
        scn = elf_getscn(elf->elf, i);
        gelf_getshdr(scn, &shdr);
        if (shdr.sh_addr == replt_addr && shdr.sh_size == replt_count) {
            elf->replt = elf_getdata(scn, NULL);
            elf->replt_count = shdr.sh_size / shdr.sh_entsize;
            break;
        }
    }
}
开发者ID:schischi,项目名称:my_ltrace,代码行数:35,代码来源:elfd.c

示例7: get_scnbyname

Elf_Scn *
get_scnbyname(Elf *elf, char *name, int *num)
{
	Elf32_Ehdr	* ehdr;
	Elf_Scn		* scn;
	Elf32_Shdr	* shdr;
	Elf_Data	* data;
	int		  cnt,
			  tmp;

	if (!num)
		num = &tmp;
	
	*num = 0;

	if ((ehdr = elf32_getehdr(elf))==NULL)
		return NULL;

	if (((scn = elf_getscn(elf, ehdr->e_shstrndx)) == NULL) ||
	    ((data = elf_getdata(scn, NULL)) == NULL))
		return NULL;

	for (cnt = 1, scn = NULL; (scn = elf_nextscn(elf, scn)); cnt++) {
		if ((shdr = elf32_getshdr(scn)) == NULL)
			return NULL;

		if (! strcmp(name, (char *)data->d_buf + shdr->sh_name)) {
			*num = cnt;
			return scn;
		}
	}
	return NULL;
}
开发者ID:akpotter,项目名称:binary-encryption,代码行数:33,代码来源:util.c

示例8: elf_strptr

char*
elf_strptr(Elf *elf, size_t section, size_t offset) {
    Elf_Scn *scn;
    Elf_Data *sd;

    if (!elf) {
	return NULL;
    }
    elf_assert(elf->e_magic == ELF_MAGIC);
    if (!(scn = elf_getscn(elf, section))) {
	return NULL;
    }
    if (scn->s_type != SHT_STRTAB) {
	seterr(ERROR_NOSTRTAB);
	return NULL;
    }
    if (offset >= 0 && offset < scn->s_size) {
	sd = NULL;
	while ((sd = elf_getdata(scn, sd))) {
	    if (sd->d_buf
	     && offset >= (size_t)sd->d_off
	     && offset < (size_t)sd->d_off + sd->d_size) {
		return (char*)sd->d_buf + (offset - sd->d_off);
	    }
	}
    }
    seterr(ERROR_BADSTROFF);
    return NULL;
}
开发者ID:rdeforest,项目名称:ColdStore,代码行数:29,代码来源:strptr.c

示例9: ELF_ASSERT

Elf_Scn *elf_utils_new_scn_with_name(Elf *e, const char *scn_name)
{
	Elf_Scn *scn;
	GElf_Shdr shdr;
	size_t shstrndx, index, namelen;
	Elf_Data *shstrdata;
	void *ptr;

	ELF_ASSERT(elf_getshdrstrndx(e, &shstrndx) == 0);

	ELF_ASSERT(scn = elf_getscn(e, shstrndx));
	ELF_ASSERT(shstrdata = elf_getdata(scn, NULL));

	namelen = strlen(scn_name) + 1;
	ELF_ASSERT(gelf_getshdr(scn, &shdr));
	if (!elf_utils_shift_contents(e, shdr.sh_offset + shdr.sh_size, namelen))
		goto failure;
	ASSERT(ptr = realloc(shstrdata->d_buf, shstrdata->d_size + namelen));
	index = shstrdata->d_size;
	strcpy(ptr+index, scn_name);
	shstrdata->d_buf = ptr;
	shstrdata->d_size += namelen;
	shdr.sh_size += namelen;
	ELF_ASSERT(gelf_update_shdr(scn, &shdr));

	ELF_ASSERT(scn = elf_newscn(e));
	ELF_ASSERT(gelf_getshdr(scn, &shdr));
	shdr.sh_name = index;
	ELF_ASSERT(gelf_update_shdr(scn, &shdr));
	
	return scn;
failure:
	return NULL;
}
开发者ID:nterry,项目名称:vita-toolchain,代码行数:34,代码来源:elf-utils.c

示例10: addr_in_section

bool
addr_in_section (Elf *elf, GElf_Word shndx, GElf_Addr addr)
{
  GElf_Shdr shdr;
  Elf_Scn *scn = elf_getscn (elf, shndx);
  gelf_getshdr (scn, &shdr);
  return addr >= shdr.sh_addr && addr < shdr.sh_addr + shdr.sh_size;
}
开发者ID:CongLi,项目名称:autotest-client-tests,代码行数:8,代码来源:dwflsyms.c

示例11: set_flag

static void
set_flag(char *ifile, ulong_t flval)
{
	Elf *elf;
	Elf_Scn *scn;
	Elf_Data *data;
	GElf_Shdr shdr;
	GElf_Dyn dyn;
	int fd, secidx, nent, i;

	(void) elf_version(EV_CURRENT);

	if ((fd = open(ifile, O_RDWR)) < 0)
		die("Can't open %s", ifile);

	if ((elf = elf_begin(fd, ELF_C_RDWR, NULL)) == NULL)
		elfdie("Can't start ELF for %s", ifile);

	if ((secidx = findelfsecidx(elf, ".dynamic")) == -1)
		die("Can't find .dynamic section in %s\n", ifile);

	if ((scn = elf_getscn(elf, secidx)) == NULL)
		elfdie("elf_getscn (%d)", secidx);

	if (gelf_getshdr(scn, &shdr) == NULL)
		elfdie("gelf_shdr");

	if ((data = elf_getdata(scn, NULL)) == NULL)
		elfdie("elf_getdata");

	nent = shdr.sh_size / shdr.sh_entsize;
	for (i = 0; i < nent; i++) {
		if (gelf_getdyn(data, i, &dyn) == NULL)
			elfdie("gelf_getdyn");

		if (dyn.d_tag == DT_FLAGS_1) {
			dyn.d_un.d_val |= (Elf64_Xword)flval;

			if (gelf_update_dyn(data, i, &dyn) == 0)
				elfdie("gelf_update_dyn");

			break;
		}
	}

	if (i == nent) {
		die("%s's .dynamic section doesn't have a DT_FLAGS_1 "
		    "field\n", ifile);
	}

	if (elf_update(elf, ELF_C_WRITE) == -1)
		elfdie("Couldn't update %s with changes", ifile);

	(void) elf_end(elf);
	(void) close(fd);
}
开发者ID:andreiw,项目名称:polaris,代码行数:56,代码来源:setdynflag.c

示例12: elf_getscn

Elf_Scn *xelf_getscn(Elf *e, size_t idx)
{
  Elf_Scn *scn = elf_getscn(e, idx);
  if (scn == NULL)
	{
	  eprintf("elf_getscn() failed: %s", elf_errmsg(-1));
	  exit(EXIT_FAILURE);
	}
  return scn;
}
开发者ID:RPG-7,项目名称:lemberg,代码行数:10,代码来源:elflemberg.c

示例13: 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

示例14: _dwarf_load_section

/*
	Load the ELF section with the specified index and set the
	pointer pointed to by section_data to the memory where it
	was loaded.
 */
int
_dwarf_load_section(Dwarf_Debug dbg,
		    Dwarf_Half section_index,
		    Dwarf_Small ** section_data,
		    Dwarf_Error * error)
{
    if (section_index == 0) {
	return DW_DLV_NO_ENTRY;
    }

    /* check to see if the section is already loaded */
    if (*section_data != NULL) {
	return DW_DLV_OK;
    }

    {
#ifdef __SGI_FAST_LIBELF
        enum elf_sgi_error_type sres;

        sres = elf_sgi_section(dbg->de_elf,
		               section_index,
			       (void**) section_data);
        if (sres != ELF_SGI_ERROR_OK) {
	    DWARF_DBG_ERROR(dbg, _dwarf_error_code_from_elf_sgi_error_code(sres),
			    DW_DLV_ERROR);
        }
#else
        Elf_Scn* scn;
        Elf_Data* data;

        scn = elf_getscn(dbg->de_elf, section_index);
        if (scn == NULL) {
	    _dwarf_error(dbg, error, DW_DLE_MDE);
	    return DW_DLV_ERROR;
        }

	/* 
	    When using libelf as a producer, section data may be stored
	    in multiple buffers. In libdwarf however, we only use libelf
	    as a consumer (there is a dwarf producer API, but it doesn't
	    use libelf). Because of this, this single call to elf_getdata
	    will retrieve the entire section in a single contiguous buffer.
	 */
        data = elf_getdata(scn, NULL);
        if (data == NULL) {
	    _dwarf_error(dbg, error, DW_DLE_MDE);
	    return DW_DLV_ERROR;
        }

        *section_data = data->d_buf;
#endif /* !defined(__SGI_FAST_LIBELF) */
    }

    return DW_DLV_OK;
}
开发者ID:manojxantony,项目名称:compiler,代码行数:60,代码来源:dwarf_init_finish.c

示例15: _libelf_checksum

unsigned long
_libelf_checksum(Elf *e, int elfclass)
{
	size_t shn;
	Elf_Scn *scn;
	Elf_Data *d;
	unsigned long checksum;
	GElf_Ehdr eh;
	GElf_Shdr shdr;

	if (e == NULL) {
		LIBELF_SET_ERROR(ARGUMENT, 0);
		return (0L);
	}

	if (e->e_class != elfclass) {
		LIBELF_SET_ERROR(CLASS, 0);
		return (0L);
	}

	if (gelf_getehdr(e, &eh) == NULL)
		return (0);

	/*
	 * Iterate over all sections in the ELF file, computing the
	 * checksum along the way.
	 *
	 * The first section is always SHN_UNDEF and can be skipped.
	 * Non-allocatable sections are skipped, as are sections that
	 * could be affected by utilities such as strip(1).
	 */

	checksum = 0;
	for (shn = 1; shn < e->e_u.e_elf.e_nscn; shn++) {
		if ((scn = elf_getscn(e, shn)) == NULL)
			return (0);
		if (gelf_getshdr(scn, &shdr) == NULL)
			return (0);
		if ((shdr.sh_flags & SHF_ALLOC) == 0 ||
		    shdr.sh_type == SHT_DYNAMIC ||
		    shdr.sh_type == SHT_DYNSYM)
			continue;

		d = NULL;
		while ((d = elf_rawdata(scn, d)) != NULL)
			checksum = _libelf_sum(checksum,
			    (unsigned char *) d->d_buf, d->d_size);
	}

	/*
	 * Return a 16-bit checksum compatible with Solaris.
	 */
	return (((checksum >> 16) & 0xFFFFUL) + (checksum & 0xFFFFUL));
}
开发者ID:AhmadTux,项目名称:freebsd,代码行数:54,代码来源:libelf_checksum.c


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