003 File Manager
Current Path:
/usr/src/contrib/elftoolchain/libelf
usr
/
src
/
contrib
/
elftoolchain
/
libelf
/
📁
..
📄
Makefile
(3.83 KB)
📄
Version.map
(1.49 KB)
📄
_libelf.h
(8.22 KB)
📄
_libelf_ar.h
(2.25 KB)
📄
_libelf_config.h
(5.2 KB)
📄
elf.3
(17.82 KB)
📄
elf.c
(1.64 KB)
📄
elf_begin.3
(7.24 KB)
📄
elf_begin.c
(2.55 KB)
📄
elf_cntl.3
(3.11 KB)
📄
elf_cntl.c
(1.81 KB)
📄
elf_data.c
(7.25 KB)
📄
elf_end.3
(2.38 KB)
📄
elf_end.c
(2.61 KB)
📄
elf_errmsg.3
(3.5 KB)
📄
elf_errmsg.c
(2.99 KB)
📄
elf_errno.c
(1.57 KB)
📄
elf_fill.3
(1.94 KB)
📄
elf_fill.c
(1.5 KB)
📄
elf_flag.c
(4.46 KB)
📄
elf_flagdata.3
(5.98 KB)
📄
elf_getarhdr.3
(3 KB)
📄
elf_getarhdr.c
(1.65 KB)
📄
elf_getarsym.3
(3.64 KB)
📄
elf_getarsym.c
(1.96 KB)
📄
elf_getbase.3
(2.29 KB)
📄
elf_getbase.c
(1.68 KB)
📄
elf_getdata.3
(6.26 KB)
📄
elf_getident.3
(2.58 KB)
📄
elf_getident.c
(1.98 KB)
📄
elf_getphdrnum.3
(2.68 KB)
📄
elf_getphnum.3
(2.78 KB)
📄
elf_getscn.3
(4.22 KB)
📄
elf_getshdrnum.3
(2.5 KB)
📄
elf_getshdrstrndx.3
(2.62 KB)
📄
elf_getshnum.3
(2.57 KB)
📄
elf_getshstrndx.3
(2.89 KB)
📄
elf_hash.3
(2.13 KB)
📄
elf_hash.c
(1.76 KB)
📄
elf_kind.3
(2.19 KB)
📄
elf_kind.c
(1.6 KB)
📄
elf_memory.3
(3.47 KB)
📄
elf_memory.c
(1.72 KB)
📄
elf_next.3
(2.81 KB)
📄
elf_next.c
(2.55 KB)
📄
elf_open.3
(3.41 KB)
📄
elf_open.c
(2.01 KB)
📄
elf_phnum.c
(1.98 KB)
📄
elf_rand.3
(3.1 KB)
📄
elf_rand.c
(2.14 KB)
📄
elf_rawfile.3
(2.38 KB)
📄
elf_rawfile.c
(1.73 KB)
📄
elf_scn.c
(6.17 KB)
📄
elf_shnum.c
(1.98 KB)
📄
elf_shstrndx.c
(2.32 KB)
📄
elf_strptr.3
(3.3 KB)
📄
elf_strptr.c
(3.58 KB)
📄
elf_types.m4
(6.35 KB)
📄
elf_update.3
(10.84 KB)
📄
elf_update.c
(29.37 KB)
📄
elf_version.3
(2.91 KB)
📄
elf_version.c
(1.72 KB)
📄
gelf.3
(6.43 KB)
📄
gelf.h
(5 KB)
📄
gelf_cap.c
(3.64 KB)
📄
gelf_chdr.c
(2.31 KB)
📄
gelf_checksum.3
(3.28 KB)
📄
gelf_checksum.c
(1.81 KB)
📄
gelf_dyn.c
(3.68 KB)
📄
gelf_ehdr.c
(4.1 KB)
📄
gelf_fsize.3
(2.83 KB)
📄
gelf_fsize.c
(1.95 KB)
📄
gelf_getcap.3
(3.55 KB)
📄
gelf_getchdr.3
(3.24 KB)
📄
gelf_getclass.3
(2 KB)
📄
gelf_getclass.c
(1.52 KB)
📄
gelf_getdyn.3
(3.59 KB)
📄
gelf_getehdr.3
(3.47 KB)
📄
gelf_getmove.3
(3.61 KB)
📄
gelf_getphdr.3
(3.91 KB)
📄
gelf_getrel.3
(3.55 KB)
📄
gelf_getrela.3
(3.59 KB)
📄
gelf_getshdr.3
(3.18 KB)
📄
gelf_getsym.3
(3.68 KB)
📄
gelf_getsyminfo.3
(3.47 KB)
📄
gelf_getsymshndx.3
(4.27 KB)
📄
gelf_mips64el.c
(2.65 KB)
📄
gelf_move.c
(3.93 KB)
📄
gelf_newehdr.3
(5.06 KB)
📄
gelf_newphdr.3
(3.78 KB)
📄
gelf_phdr.c
(4.19 KB)
📄
gelf_rel.c
(4.16 KB)
📄
gelf_rela.c
(4.29 KB)
📄
gelf_shdr.c
(3.43 KB)
📄
gelf_sym.c
(3.95 KB)
📄
gelf_syminfo.c
(3.75 KB)
📄
gelf_symshndx.c
(3.55 KB)
📄
gelf_update_ehdr.3
(3.63 KB)
📄
gelf_xlate.c
(2.67 KB)
📄
gelf_xlatetof.3
(7.41 KB)
📄
libelf.h
(7.72 KB)
📄
libelf_align.c
(3.86 KB)
📄
libelf_allocate.c
(4 KB)
📄
libelf_ar.c
(13.03 KB)
📄
libelf_ar_util.c
(8.33 KB)
📄
libelf_chdr.c
(2.86 KB)
📄
libelf_checksum.c
(2.81 KB)
📄
libelf_convert.m4
(28.16 KB)
📄
libelf_data.c
(3.18 KB)
📄
libelf_ehdr.c
(5.99 KB)
📄
libelf_elfmachine.c
(1.94 KB)
📄
libelf_extended.c
(3.38 KB)
📄
libelf_fsize.m4
(4.35 KB)
📄
libelf_memory.c
(2.89 KB)
📄
libelf_msize.m4
(3.2 KB)
📄
libelf_open.c
(5.49 KB)
📄
libelf_phdr.c
(4.04 KB)
📄
libelf_shdr.c
(1.79 KB)
📄
libelf_xlate.c
(4.25 KB)
📄
os.FreeBSD.mk
(182 B)
📄
os.Linux.mk
(761 B)
📄
os.NetBSD.mk
(128 B)
Editing: libelf_ar_util.c
/*- * Copyright (c) 2006,2009,2010 Joseph Koshy * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS `AS IS' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include <assert.h> #include <libelf.h> #include <stdlib.h> #include <string.h> #include "_libelf.h" #include "_libelf_ar.h" ELFTC_VCSID("$Id: libelf_ar_util.c 3174 2015-03-27 17:13:41Z emaste $"); /* * Convert a string bounded by `start' and `start+sz' (exclusive) to a * number in the specified base. */ int _libelf_ar_get_number(const char *src, size_t sz, unsigned int base, size_t *ret) { size_t r; unsigned int c, v; const unsigned char *e, *s; assert(base <= 10); s = (const unsigned char *) src; e = s + sz; /* skip leading blanks */ for (;s < e && (c = *s) == ' '; s++) ; r = 0L; for (;s < e; s++) { if ((c = *s) == ' ') break; if (c < '0' || c > '9') return (0); v = c - '0'; if (v >= base) /* Illegal digit. */ break; r *= base; r += v; } *ret = r; return (1); } /* * Return the translated name for an archive member. */ char * _libelf_ar_get_translated_name(const struct ar_hdr *arh, Elf *ar) { char *s; unsigned char c; size_t len, offset; const unsigned char *buf, *p, *q, *r; const size_t bufsize = sizeof(arh->ar_name); assert(arh != NULL); assert(ar->e_kind == ELF_K_AR); assert((const unsigned char *) arh >= ar->e_rawfile && (const unsigned char *) arh < ar->e_rawfile + ar->e_rawsize); buf = (const unsigned char *) arh->ar_name; /* * Check for extended naming. * * If the name matches the pattern "^/[0-9]+", it is an * SVR4-style extended name. If the name matches the pattern * "#1/[0-9]+", the entry uses BSD style extended naming. */ if (buf[0] == '/' && (c = buf[1]) >= '0' && c <= '9') { /* * The value in field ar_name is a decimal offset into * the archive string table where the actual name * resides. */ if (_libelf_ar_get_number((const char *) (buf + 1), bufsize - 1, 10, &offset) == 0) { LIBELF_SET_ERROR(ARCHIVE, 0); return (NULL); } if (offset > ar->e_u.e_ar.e_rawstrtabsz) { LIBELF_SET_ERROR(ARCHIVE, 0); return (NULL); } p = q = ar->e_u.e_ar.e_rawstrtab + offset; r = ar->e_u.e_ar.e_rawstrtab + ar->e_u.e_ar.e_rawstrtabsz; for (; p < r && *p != '/'; p++) ; len = (size_t) (p - q + 1); /* space for the trailing NUL */ if ((s = malloc(len)) == NULL) { LIBELF_SET_ERROR(RESOURCE, 0); return (NULL); } (void) strncpy(s, (const char *) q, len - 1); s[len - 1] = '\0'; return (s); } else if (IS_EXTENDED_BSD_NAME(buf)) { r = buf + LIBELF_AR_BSD_EXTENDED_NAME_PREFIX_SIZE; if (_libelf_ar_get_number((const char *) r, bufsize - LIBELF_AR_BSD_EXTENDED_NAME_PREFIX_SIZE, 10, &len) == 0) { LIBELF_SET_ERROR(ARCHIVE, 0); return (NULL); } /* * Allocate space for the file name plus a * trailing NUL. */ if ((s = malloc(len + 1)) == NULL) { LIBELF_SET_ERROR(RESOURCE, 0); return (NULL); } /* * The file name follows the archive header. */ q = (const unsigned char *) (arh + 1); (void) strncpy(s, (const char *) q, len); s[len] = '\0'; return (s); } /* * A 'normal' name. * * Skip back over trailing blanks from the end of the field. * In the SVR4 format, a '/' is used as a terminator for * non-special names. */ for (q = buf + bufsize - 1; q >= buf && *q == ' '; --q) ; if (q >= buf) { if (*q == '/') { /* * SVR4 style names: ignore the trailing * character '/', but only if the name is not * one of the special names "/" and "//". */ if (q > buf + 1 || (q == (buf + 1) && *buf != '/')) q--; } len = (size_t) (q - buf + 2); /* Space for a trailing NUL. */ } else { /* The buffer only had blanks. */ buf = (const unsigned char *) ""; len = 1; } if ((s = malloc(len)) == NULL) { LIBELF_SET_ERROR(RESOURCE, 0); return (NULL); } (void) strncpy(s, (const char *) buf, len - 1); s[len - 1] = '\0'; return (s); } /* * Return the raw name for an archive member, inclusive of any * formatting characters. */ char * _libelf_ar_get_raw_name(const struct ar_hdr *arh) { char *rawname; const size_t namesz = sizeof(arh->ar_name); if ((rawname = malloc(namesz + 1)) == NULL) { LIBELF_SET_ERROR(RESOURCE, 0); return (NULL); } (void) strncpy(rawname, arh->ar_name, namesz); rawname[namesz] = '\0'; return (rawname); } /* * Open an 'ar' archive. */ Elf * _libelf_ar_open(Elf *e, int reporterror) { size_t sz; int scanahead; struct ar_hdr arh; unsigned char *s, *end; _libelf_init_elf(e, ELF_K_AR); e->e_u.e_ar.e_nchildren = 0; e->e_u.e_ar.e_next = (off_t) -1; /* * Look for special members. */ s = e->e_rawfile + SARMAG; end = e->e_rawfile + e->e_rawsize; assert(e->e_rawsize > 0); /* * We use heuristics to determine the flavor of the archive we * are examining. * * SVR4 flavor archives use the name "/ " and "// " for * special members. * * In BSD flavor archives the symbol table, if present, is the * first archive with name "__.SYMDEF". */ #define READ_AR_HEADER(S, ARH, SZ, END) \ do { \ if ((S) + sizeof((ARH)) > (END)) \ goto error; \ (void) memcpy(&(ARH), (S), sizeof((ARH))); \ if ((ARH).ar_fmag[0] != '`' || (ARH).ar_fmag[1] != '\n') \ goto error; \ if (_libelf_ar_get_number((char *) (ARH).ar_size, \ sizeof((ARH).ar_size), 10, &(SZ)) == 0) \ goto error; \ } while (0) READ_AR_HEADER(s, arh, sz, end); /* * Handle special archive members for the SVR4 format. */ if (arh.ar_name[0] == '/') { if (sz == 0) goto error; e->e_flags |= LIBELF_F_AR_VARIANT_SVR4; scanahead = 0; /* * The symbol table (file name "/ ") always comes before the * string table (file name "// "). */ if (arh.ar_name[1] == ' ') { /* "/ " => symbol table. */ scanahead = 1; /* The string table to follow. */ s += sizeof(arh); e->e_u.e_ar.e_rawsymtab = s; e->e_u.e_ar.e_rawsymtabsz = sz; sz = LIBELF_ADJUST_AR_SIZE(sz); s += sz; } else if (arh.ar_name[1] == '/' && arh.ar_name[2] == ' ') { /* "// " => string table for long file names. */ s += sizeof(arh); e->e_u.e_ar.e_rawstrtab = s; e->e_u.e_ar.e_rawstrtabsz = sz; sz = LIBELF_ADJUST_AR_SIZE(sz); s += sz; } /* * If the string table hasn't been seen yet, look for * it in the next member. */ if (scanahead) { READ_AR_HEADER(s, arh, sz, end); /* "// " => string table for long file names. */ if (arh.ar_name[0] == '/' && arh.ar_name[1] == '/' && arh.ar_name[2] == ' ') { s += sizeof(arh); e->e_u.e_ar.e_rawstrtab = s; e->e_u.e_ar.e_rawstrtabsz = sz; sz = LIBELF_ADJUST_AR_SIZE(sz); s += sz; } } } else if (strncmp(arh.ar_name, LIBELF_AR_BSD_SYMTAB_NAME, sizeof(LIBELF_AR_BSD_SYMTAB_NAME) - 1) == 0) { /* * BSD style archive symbol table. */ s += sizeof(arh); e->e_u.e_ar.e_rawsymtab = s; e->e_u.e_ar.e_rawsymtabsz = sz; sz = LIBELF_ADJUST_AR_SIZE(sz); s += sz; } /* * Update the 'next' offset, so that a subsequent elf_begin() * works as expected. */ e->e_u.e_ar.e_next = (off_t) (s - e->e_rawfile); return (e); error: if (!reporterror) { e->e_kind = ELF_K_NONE; return (e); } LIBELF_SET_ERROR(ARCHIVE, 0); return (NULL); }
Upload File
Create Folder