本文整理汇总了C++中elf_version函数的典型用法代码示例。如果您正苦于以下问题:C++ elf_version函数的具体用法?C++ elf_version怎么用?C++ elf_version使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了elf_version函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: nlist
int
nlist(const char *filename, struct nlist *nl) {
int result = -1;
unsigned oldver;
Elf *elf;
int fd;
if ((oldver = elf_version(EV_CURRENT)) != EV_NONE) {
if ((fd = open(filename, O_RDONLY)) != -1) {
if ((elf = elf_begin(fd, ELF_C_READ, NULL))) {
result = _elf_nlist(elf, nl);
elf_end(elf);
}
close(fd);
}
elf_version(oldver);
}
if (result) {
while (nl->n_name && *nl->n_name) {
nl->n_value = 0;
nl++;
}
}
return result;
}
开发者ID:Masshat,项目名称:Systeme-LI324,代码行数:25,代码来源:nlist2.c
示例2: pkg_analyse_files
int
pkg_analyse_files(struct pkgdb *db, struct pkg *pkg)
{
struct pkg_file *file = NULL;
int ret = EPKG_OK;
const char *fpath;
bool shlibs = false;
bool autodeps = false;
bool developer = false;
int (*action)(void *, struct pkg *, const char *, const char *, bool);
pkg_config_bool(PKG_CONFIG_SHLIBS, &shlibs);
pkg_config_bool(PKG_CONFIG_AUTODEPS, &autodeps);
pkg_config_bool(PKG_CONFIG_DEVELOPER_MODE, &developer);
if (!autodeps && !shlibs && !developer)
return (EPKG_OK);
if (elf_version(EV_CURRENT) == EV_NONE)
return (EPKG_FATAL);
if (autodeps)
action = test_depends;
else if (shlibs)
action = add_shlibs_to_pkg;
else
action = do_nothing;
if (autodeps || shlibs) {
shlib_list_init();
ret = shlib_list_from_elf_hints(_PATH_ELF_HINTS);
if (ret != EPKG_OK)
goto cleanup;
}
/* Assume no architecture dependence, for contradiction */
if (developer)
pkg->flags &= ~(PKG_CONTAINS_ELF_OBJECTS |
PKG_CONTAINS_STATIC_LIBS |
PKG_CONTAINS_H_OR_LA);
while (pkg_files(pkg, &file) == EPKG_OK) {
fpath = pkg_file_path(file);
ret = analyse_elf(pkg, fpath, action, db);
if (developer) {
if (ret != EPKG_OK && ret != EPKG_END)
goto cleanup;
analyse_fpath(pkg, fpath);
}
}
ret = EPKG_OK;
cleanup:
if (autodeps || shlibs)
shlib_list_free();
return (ret);
}
开发者ID:varju,项目名称:pkgng,代码行数:60,代码来源:pkg_elf.c
示例3: get_elf
static Elf *
get_elf (const gchar *file,
gint *fd)
{
Elf *elf;
if (elf_version (EV_CURRENT) == EV_NONE )
return NULL;
*fd = g_open (file, O_RDONLY, 0);
if (*fd < 0)
return NULL;
elf = elf_begin (*fd, ELF_C_READ, NULL);
if (elf == NULL)
{
g_close (*fd, NULL);
*fd = -1;
return NULL;
}
if (elf_kind (elf) != ELF_K_ELF)
{
g_close (*fd, NULL);
*fd = -1;
return NULL;
}
return elf;
}
开发者ID:DreaminginCodeZH,项目名称:glib,代码行数:30,代码来源:gresource-tool.c
示例4: get_syms
void
get_syms(char *filename, mod_info_t *mi)
{
int fd;
Elf *elf;
if ((fd = open(filename, O_RDONLY)) == -1) {
perror(filename);
exit(ERR_SYSCALL);
}
if (elf_version(EV_CURRENT) == EV_NONE) {
(void) fprintf(stderr, "%s: libelf out of date\n", cmdname);
exit(ERR_ELF);
}
if ((elf = elf_begin(fd, ELF_C_READ, NULL)) == NULL) {
(void) fprintf(stderr, "%s: elf_begin failed\n", cmdname);
exit(ERR_ELF);
}
if (gelf_getclass(elf) != ELFCLASS64) {
(void) fprintf(stderr, "%s: unsupported mon.out format for "
"this class of object\n", cmdname);
exit(ERR_ELF);
}
mi->txt_origin = get_txtorigin(elf, filename);
fetch_symtab(elf, filename, mi);
}
开发者ID:andreiw,项目名称:polaris,代码行数:31,代码来源:rdelf.c
示例5: get_elf_class
/*
* get_elf_class - get the target executable elf class
* i.e. ELFCLASS64 or ELFCLASS32.
*/
static int
get_elf_class(char *filename)
{
int elfclass = -1;
int elffd = get_executable(filename);
Elf *elf;
size_t size;
char *ident;
GElf_Ehdr ehdr;
if (elffd < 0)
return (elfclass);
if (elf_version(EV_CURRENT) == EV_NONE) {
(void) close(elffd);
return (elfclass);
}
elf = elf_begin(elffd, ELF_C_READ, (Elf *) 0);
/*
* verify information in file header
*/
if (gelf_getehdr(elf, &ehdr) == (GElf_Ehdr *) 0) {
close(elffd);
return (elfclass);
}
ident = elf_getident(elf, &size);
if (ident[EI_CLASS] == ELFCLASS32)
elfclass = ELFCLASS32;
if (ident[EI_CLASS] == ELFCLASS64)
elfclass = ELFCLASS64;
close(elffd);
return (elfclass);
}
开发者ID:AlfredArouna,项目名称:illumos-gate,代码行数:36,代码来源:main.c
示例6: extract_functions_internal
/* Below code adapted from libelf tutorial example */
static u32 extract_functions_internal (const char *str, func_entry *func_list) {
Elf *e;
Elf_Kind ek;
Elf_Scn *scn;
Elf_Data *edata;
u32 fd, i, symbol_count;
GElf_Sym sym;
GElf_Shdr shdr;
u32 func_count = 0;
if(elf_version(EV_CURRENT) == EV_NONE) {
printf("Error initializing ELF: %s\n", elf_errmsg(-1));
return -1;
}
if ((fd = open(str, O_RDONLY, 0)) < 0) {
printf("Unable to open %s\n", str);
return -1;
}
if ((e = elf_begin(fd, ELF_C_READ, NULL)) == NULL) {
printf("elf_begin failed: %s\n", elf_errmsg(-1));
}
ek = elf_kind(e);
if(ek != ELF_K_ELF) {
printf("not an ELF object");
} else {
scn = NULL;
edata = NULL;
while((scn = elf_nextscn(e, scn)) != NULL) {
gelf_getshdr(scn, &shdr);
if(shdr.sh_type == SHT_SYMTAB) {
edata = elf_getdata(scn, edata);
symbol_count = shdr.sh_size / shdr.sh_entsize;
for(i = 0; i < symbol_count; i++) {
gelf_getsym(edata, i, &sym);
if(ELF32_ST_TYPE(sym.st_info) != STT_FUNC) {
check_for_end_marker(elf_strptr(e, shdr.sh_link, sym.st_name), sym.st_value);
continue;
}
if(sym.st_size == 0) continue;
func_list[func_count].offset = sym.st_value;
func_list[func_count++].func_name = strdup(elf_strptr(e, shdr.sh_link, sym.st_name));
if(func_count >= MAXFNS) {
printf("Func limit (%"PRId32") reached, please increase MAXFNS & rebuild\n", MAXFNS);
raise(SIGABRT);
}
// printf("%08x %08x\t%s\n", sym.st_value, sym.st_size, elf_strptr(e, shdr.sh_link, sym.st_name));
}
}
}
}
elf_end(e);
close(fd);
return func_count;
}
开发者ID:shamouda,项目名称:ocr,代码行数:61,代码来源:elf-utils.c
示例7: pkg_register_shlibs
int
pkg_register_shlibs(struct pkg *pkg)
{
struct pkg_file *file = NULL;
bool shlibs;
pkg_config_bool(PKG_CONFIG_SHLIBS, &shlibs);
pkg_list_free(pkg, PKG_SHLIBS_REQUIRED);
if (!shlibs)
return (EPKG_OK);
if (elf_version(EV_CURRENT) == EV_NONE)
return (EPKG_FATAL);
shlib_list_init();
if (shlib_list_from_elf_hints(_PATH_ELF_HINTS) != EPKG_OK) {
shlib_list_free();
return (EPKG_FATAL);
}
while(pkg_files(pkg, &file) == EPKG_OK)
analyse_elf(pkg, pkg_file_path(file), add_shlibs_to_pkg, NULL);
shlib_list_free();
return (EPKG_OK);
}
开发者ID:varju,项目名称:pkgng,代码行数:28,代码来源:pkg_elf.c
示例8: exec_open
int exec_open( NAME_LIST *fnames, Elf32_Half machine,
int code_size, int data_size )
{
if (!fnames)
{
yyerror("No output file specified");
}
else if (fnames->next)
{
yyerror("Multiple output files specified");
}
else if (elf_version(EV_CURRENT) == EV_NONE)
{
yyerror( "Elf library is out of date" );
}
else
{
outfile_init( fnames->name, machine, TRUE,
code_size, data_size );
out_file_machine = machine;
out_file_name = strdup( fnames->name );
if ( !fixup_code_map( machine, &fixup_code ) )
{
yyerror( "Relocations for this machine type are not supported" );
return FALSE;
}
return TRUE;
}
return FALSE;
}
开发者ID:wodz,项目名称:open21xx,代码行数:30,代码来源:execfile.c
示例9: initElfHeader
bool ElfWriter::initElfHeader() {
if (elf_version(EV_CURRENT) == EV_NONE) {
logError("ELF library initialization failed");
return false;
}
m_elf = elf_begin(m_fd, ELF_C_WRITE, 0);
if (!m_elf) {
logError("Unable to create elf with elf_begin()");
return false;
}
m_ehdr = elf64_newehdr(m_elf);
if (!m_ehdr) {
logError("Unable to create elf header with elf64_newehdr()");
return false;
}
m_ehdr->e_ident[EI_MAG0] = ELFMAG0;
m_ehdr->e_ident[EI_MAG1] = ELFMAG1;
m_ehdr->e_ident[EI_MAG2] = ELFMAG2;
m_ehdr->e_ident[EI_MAG3] = ELFMAG3;
m_ehdr->e_ident[EI_CLASS] = ELFCLASS64;
m_ehdr->e_ident[EI_DATA] = ELFDATA2LSB;
m_ehdr->e_ident[EI_VERSION] = EV_CURRENT;
m_ehdr->e_machine = EM_X86_64;
m_ehdr->e_type = ET_EXEC;
m_ehdr->e_version = EV_CURRENT;
return true;
}
开发者ID:Hillgod,项目名称:hiphop-php,代码行数:31,代码来源:elfwriter.cpp
示例10: __bpf_object__open
static struct bpf_object *
__bpf_object__open(const char *path, void *obj_buf, size_t obj_buf_sz)
{
struct bpf_object *obj;
int err;
if (elf_version(EV_CURRENT) == EV_NONE) {
pr_warning("failed to init libelf for %s\n", path);
return ERR_PTR(-LIBBPF_ERRNO__LIBELF);
}
obj = bpf_object__new(path, obj_buf, obj_buf_sz);
if (IS_ERR(obj))
return obj;
CHECK_ERR(bpf_object__elf_init(obj), err, out);
CHECK_ERR(bpf_object__check_endianness(obj), err, out);
CHECK_ERR(bpf_object__elf_collect(obj), err, out);
CHECK_ERR(bpf_object__collect_reloc(obj), err, out);
CHECK_ERR(bpf_object__validate(obj), err, out);
bpf_object__elf_finish(obj);
return obj;
out:
bpf_object__close(obj);
return ERR_PTR(err);
}
开发者ID:020gzh,项目名称:linux,代码行数:27,代码来源:libbpf.c
示例11: perf_session__list_build_ids
static int perf_session__list_build_ids(void)
{
struct perf_session *session;
elf_version(EV_CURRENT);
session = perf_session__new(input_name, O_RDONLY, force, false,
&build_id__mark_dso_hit_ops);
if (session == NULL)
return -1;
/*
* See if this is an ELF file first:
*/
if (filename__fprintf_build_id(session->filename, stdout))
goto out;
if (with_hits)
perf_session__process_events(session, &build_id__mark_dso_hit_ops);
perf_session__fprintf_dsos_buildid(session, stdout, with_hits);
out:
perf_session__delete(session);
return 0;
}
开发者ID:openube,项目名称:android_kernel_sony_c2305,代码行数:25,代码来源:builtin-buildid-list.c
示例12: 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
示例13: binary_diff
int binary_diff(int fd1, int fd2, char *sections, int verbose) {
Elf *elf1, *elf2;
Elf_Kind kind1, kind2;
if (elf_version(EV_CURRENT) == EV_NONE) {
if (verbose) fprintf(stderr, "elfdiff: ELF Version mismatch\n");
return ED_ELFFAIL;
}
if ((elf1 = elf_begin(fd1, ELF_C_READ, NULL)) != NULL) {
kind1 = elf_kind(elf1);
elf_end(elf1);
} else {
if (verbose) fprintf(stderr, "elfdiff: Error reading ELF information from first input file.\n");
return ED_NOELF1;
}
if ((elf2 = elf_begin(fd2, ELF_C_READ, NULL)) != NULL) {
kind2 = elf_kind(elf2);
elf_end(elf2);
} else {
if (verbose) fprintf(stderr, "elfdiff: Error reading ELF information from second input file.\n");
return ED_NOELF2;
}
if ((kind1 == ELF_K_ELF) && (kind2 == ELF_K_ELF)){
return elf_diff (fd1, fd2, sections, verbose);
} else if ((kind1 == ELF_K_AR) && (kind2 == ELF_K_AR)) {
return ar_diff (fd1, fd2, sections, verbose);
} else {
if (verbose) fprintf(stderr, "elfdiff: The specified files are not of matching/supported types.\n");
return ED_ELFFAIL;
}
}
开发者ID:vocho,项目名称:openqnx,代码行数:34,代码来源:elfdiff.c
示例14: ELF_initial
int ELF_initial(char *input_file){
if(elf_version(EV_CURRENT) == EV_NONE){
fprintf(stderr, "ELF library initialization failed: %s.\n",
elf_errmsg(-1));
exit(1);
}
if((fd = open(input_file, O_RDONLY, 0)) < 0){
fprintf(stderr, "Open \"%s\" failed.\n", input_file);
exit(1);
}
if((e = elf_begin(fd, ELF_C_READ, NULL)) == NULL){
fprintf(stderr, "elf_begin() failed: %s.\n", elf_errmsg(-1));
exit(1);
}
if(elf_kind(e) != ELF_K_ELF){
fprintf(stderr, "\"%s\" is not an ELF object.\n", input_file);
exit(1);
}
if(gelf_getehdr(e, &ehdr) == NULL){
fprintf(stderr, "getehdr() failed: %s.\n",
elf_errmsg(-1));
exit(1);
}
if(ehdr.e_flags != 2){
fprintf(stderr, "\"%s\" is not an execution file.\n", input_file);
exit(1);
}
phdr_index = 0;
// printf("Entry point: 0x%jx\n", ehdr.e_entry);
// printf("Flags: %d\n", ehdr.e_flags);
return 0;
}
开发者ID:hualiansheng,项目名称:minic,代码行数:34,代码来源:ELF_parser.c
示例15: 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
示例16: main
int
main(int argc, char **argv)
{
Elf *elf;
ctf_file_t *ctfp;
int errp, fd;
if (ctf_version(CTF_VERSION) == -1)
errx(1, "mismatched libctf versions\n");
if (elf_version(EV_CURRENT) == EV_NONE)
errx(1, "mismatched libelf versions\n");
if (argc != 2)
errx(2, "usage: %s <file>\n", __progname);
if ((ctfp = ctf_open(argv[1], &errp)) == NULL)
errx(1, "failed to ctf_open file: %s: %s\n", argv[1],
ctf_errmsg(errp));
if ((fd = open(argv[1], O_RDONLY)) == -1)
errx(1, "could not open %s\n", argv[1]);
if ((elf = elf_begin(fd, ELF_C_READ, NULL)) == NULL)
errx(1, "could not interpret ELF from %s\n",
argv[1]);
walk_symtab(elf, argv[1], ctfp, check_sym);
(void) elf_end(elf);
(void) close(fd);
return (0);
}
开发者ID:apprisi,项目名称:illumos-gate,代码行数:34,代码来源:dump.c
示例17: 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
示例18: pkg_register_shlibs
int
pkg_register_shlibs(struct pkg *pkg, const char *root)
{
struct pkg_file *file = NULL;
char fpath[MAXPATHLEN];
pkg_list_free(pkg, PKG_SHLIBS_REQUIRED);
if (elf_version(EV_CURRENT) == EV_NONE)
return (EPKG_FATAL);
shlib_list_init();
if (shlib_list_from_elf_hints(_PATH_ELF_HINTS) != EPKG_OK) {
shlib_list_free();
return (EPKG_FATAL);
}
while(pkg_files(pkg, &file) == EPKG_OK) {
if (root != NULL) {
snprintf(fpath, sizeof(fpath), "%s%s", root, pkg_file_path(file));
analyse_elf(pkg, fpath, add_shlibs_to_pkg, NULL);
} else
analyse_elf(pkg, pkg_file_path(file), add_shlibs_to_pkg, NULL);
}
shlib_list_free();
return (EPKG_OK);
}
开发者ID:dschossig,项目名称:pkg,代码行数:28,代码来源:pkg_elf.c
示例19: xelf_init
void xelf_init(void)
{
if (elf_version(EV_CURRENT) == EV_NONE)
{
eprintf("ELF library initialization failed: %s", elf_errmsg(-1));
exit(EXIT_FAILURE);
}
}
开发者ID:RPG-7,项目名称:lemberg,代码行数:8,代码来源:elflemberg.c
示例20: check_libelf_version
static void check_libelf_version()
{
if (elf_version(EV_CURRENT) == EV_NONE) {
fprintf(stderr, "elf initialization failed: %s\n",
elf_errmsg(elf_errno()));
exit(1);
}
}
开发者ID:credmon,项目名称:tbstack,代码行数:8,代码来源:tbstack.c
注:本文中的elf_version函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论