/[gentoo-projects]/pax-utils/scanelf.c
Gentoo

Diff of /pax-utils/scanelf.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.224 Revision 1.229
1/* 1/*
2 * Copyright 2003-2007 Gentoo Foundation 2 * Copyright 2003-2007 Gentoo Foundation
3 * Distributed under the terms of the GNU General Public License v2 3 * Distributed under the terms of the GNU General Public License v2
4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/Attic/scanelf.c,v 1.224 2011/08/08 01:56:16 vapier Exp $ 4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/Attic/scanelf.c,v 1.229 2011/09/27 19:29:19 vapier Exp $
5 * 5 *
6 * Copyright 2003-2007 Ned Ludd - <solar@gentoo.org> 6 * Copyright 2003-2007 Ned Ludd - <solar@gentoo.org>
7 * Copyright 2004-2007 Mike Frysinger - <vapier@gentoo.org> 7 * Copyright 2004-2007 Mike Frysinger - <vapier@gentoo.org>
8 */ 8 */
9 9
10static const char *rcsid = "$Id: scanelf.c,v 1.224 2011/08/08 01:56:16 vapier Exp $"; 10static const char *rcsid = "$Id: scanelf.c,v 1.229 2011/09/27 19:29:19 vapier Exp $";
11const char argv0[] = "scanelf"; 11const char argv0[] = "scanelf";
12 12
13#include "paxinc.h" 13#include "paxinc.h"
14 14
15#define IS_MODIFIER(c) (c == '%' || c == '#' || c == '+') 15#define IS_MODIFIER(c) (c == '%' || c == '#' || c == '+')
16 16
17/* prototypes */ 17/* prototypes */
18static int file_matches_list(const char *filename, char **matchlist); 18static int file_matches_list(const char *filename, char **matchlist);
19static int scanelf_elfobj(elfobj *elf);
20static int scanelf_elf(const char *filename, int fd, size_t len);
21static int scanelf_archive(const char *filename, int fd, size_t len);
22static int scanelf_file(const char *filename, const struct stat *st_cache);
23static int scanelf_dir(const char *path);
24static void scanelf_ldpath(void);
25static void scanelf_envpath(void);
26static void usage(int status);
27static char **get_split_env(const char *envvar);
28static void parseenv(void);
29static int parseargs(int argc, char *argv[]);
30 19
31/* variables to control behavior */ 20/* variables to control behavior */
32static char match_etypes[126] = ""; 21static char *match_etypes = NULL;
33static char *ldpaths[256]; 22static array_t _ldpaths = array_init_decl, *ldpaths = &_ldpaths;
34static char scan_ldpath = 0; 23static char scan_ldpath = 0;
35static char scan_envpath = 0; 24static char scan_envpath = 0;
36static char scan_symlink = 1; 25static char scan_symlink = 1;
37static char scan_archives = 0; 26static char scan_archives = 0;
38static char dir_recurse = 0; 27static char dir_recurse = 0;
56static char be_verbose = 0; 45static char be_verbose = 0;
57static char be_wewy_wewy_quiet = 0; 46static char be_wewy_wewy_quiet = 0;
58static char be_semi_verbose = 0; 47static char be_semi_verbose = 0;
59static char *find_sym = NULL; 48static char *find_sym = NULL;
60static char *find_lib = NULL; 49static char *find_lib = NULL;
50static array_t _find_lib_arr = array_init_decl, *find_lib_arr = &_find_lib_arr;
61static char *find_section = NULL; 51static char *find_section = NULL;
52static array_t _find_section_arr = array_init_decl, *find_section_arr = &_find_section_arr;
62static char *out_format = NULL; 53static char *out_format = NULL;
63static char *search_path = NULL; 54static char *search_path = NULL;
64static char fix_elf = 0; 55static char fix_elf = 0;
65static char g_match = 0; 56static char g_match = 0;
66static char use_ldcache = 0; 57static char use_ldcache = 0;
504 warnf("ELF %s has TEXTREL markings but doesnt appear to have any real TEXTREL's !?", elf->filename); 495 warnf("ELF %s has TEXTREL markings but doesnt appear to have any real TEXTREL's !?", elf->filename);
505 496
506 return NULL; 497 return NULL;
507} 498}
508 499
509static void rpath_security_checks(elfobj *, char *, const char *);
510static void rpath_security_checks(elfobj *elf, char *item, const char *dt_type) 500static void rpath_security_checks(elfobj *elf, char *item, const char *dt_type)
511{ 501{
512 struct stat st; 502 struct stat st;
513 switch (*item) { 503 switch (*item) {
514 case '/': break; 504 case '/': break;
530 break; 520 break;
531 } 521 }
532} 522}
533static void scanelf_file_rpath(elfobj *elf, char *found_rpath, char **ret, size_t *ret_len) 523static void scanelf_file_rpath(elfobj *elf, char *found_rpath, char **ret, size_t *ret_len)
534{ 524{
535 unsigned long i, s; 525 unsigned long i;
536 char *rpath, *runpath, **r; 526 char *rpath, *runpath, **r;
537 void *strtbl_void; 527 void *strtbl_void;
538 528
539 if (!show_rpath) return; 529 if (!show_rpath) return;
540 530
585 /* scan each path in : delimited list */ \ 575 /* scan each path in : delimited list */ \
586 while (start) { \ 576 while (start) { \
587 rpath_security_checks(elf, start, get_elfdtype(word)); \ 577 rpath_security_checks(elf, start, get_elfdtype(word)); \
588 end = strchr(start, ':'); \ 578 end = strchr(start, ':'); \
589 len = (end ? abs(end - start) : strlen(start)); \ 579 len = (end ? abs(end - start) : strlen(start)); \
590 if (use_ldcache) \ 580 if (use_ldcache) { \
591 for (s = 0; ldpaths[s]; ++s) \ 581 size_t n; \
582 const char *ldpath; \
583 array_for_each(ldpaths, n, ldpath) \
592 if (!strncmp(ldpaths[s], start, len) && !ldpaths[s][len]) { \ 584 if (!strncmp(ldpath, start, len) && !ldpath[len]) { \
593 *r = end; \ 585 *r = end; \
594 /* corner case ... if RPATH reads "/usr/lib:", we want \ 586 /* corner case ... if RPATH reads "/usr/lib:", we want \
595 * to show ':' rather than '' */ \ 587 * to show ':' rather than '' */ \
596 if (end && end[1] != '\0') \ 588 if (end && end[1] != '\0') \
597 (*r)++; \ 589 (*r)++; \
598 break; \ 590 break; \
599 } \ 591 } \
592 } \
600 if (!*r || !end) \ 593 if (!*r || !end) \
601 break; \ 594 break; \
602 else \ 595 else \
603 start = start + len + 1; \ 596 start = start + len + 1; \
604 } \ 597 } \
689#define FLAG_S390_LIB64 0x0400 682#define FLAG_S390_LIB64 0x0400
690#define FLAG_POWERPC_LIB64 0x0500 683#define FLAG_POWERPC_LIB64 0x0500
691#define FLAG_MIPS64_LIBN32 0x0600 684#define FLAG_MIPS64_LIBN32 0x0600
692#define FLAG_MIPS64_LIBN64 0x0700 685#define FLAG_MIPS64_LIBN64 0x0700
693 686
694static char *lookup_cache_lib(elfobj *, char *);
695
696#if defined(__GLIBC__) || defined(__UCLIBC__) 687#if defined(__GLIBC__) || defined(__UCLIBC__)
697 688
698static char *lookup_cache_lib(elfobj *elf, char *fname) 689static char *lookup_cache_lib(elfobj *elf, char *fname)
699{ 690{
700 int fd; 691 int fd;
775#elif defined(__NetBSD__) 766#elif defined(__NetBSD__)
776static char *lookup_cache_lib(elfobj *elf, char *fname) 767static char *lookup_cache_lib(elfobj *elf, char *fname)
777{ 768{
778 static char buf[__PAX_UTILS_PATH_MAX] = ""; 769 static char buf[__PAX_UTILS_PATH_MAX] = "";
779 static struct stat st; 770 static struct stat st;
780 771 size_t n;
781 char **ldpath; 772 char *ldpath;
782 for (ldpath = ldpaths; *ldpath != NULL; ldpath++) { 773
774 array_for_each(ldpath, n, ldpath) {
783 if ((unsigned) snprintf(buf, sizeof(buf), "%s/%s", *ldpath, fname) >= sizeof(buf)) 775 if ((unsigned) snprintf(buf, sizeof(buf), "%s/%s", ldpath, fname) >= sizeof(buf))
784 continue; /* if the pathname is too long, or something went wrong, ignore */ 776 continue; /* if the pathname is too long, or something went wrong, ignore */
785 777
786 if (stat(buf, &st) != 0) 778 if (stat(buf, &st) != 0)
787 continue; /* if the lib doesn't exist in *ldpath, look further */ 779 continue; /* if the lib doesn't exist in *ldpath, look further */
788 780
812 unsigned long i; 804 unsigned long i;
813 char *needed; 805 char *needed;
814 void *strtbl_void; 806 void *strtbl_void;
815 char *p; 807 char *p;
816 808
809 /*
810 * -n -> op==0 -> print all
811 * -N -> op==1 -> print requested
812 */
817 if ((op==0 && !show_needed) || (op==1 && !find_lib)) return NULL; 813 if ((op == 0 && !show_needed) || (op == 1 && !find_lib))
814 return NULL;
818 815
819 strtbl_void = elf_findsecbyname(elf, ".dynstr"); 816 strtbl_void = elf_findsecbyname(elf, ".dynstr");
820 817
821 if (elf->phdr && strtbl_void) { 818 if (elf->phdr && strtbl_void) {
822#define SHOW_NEEDED(B) \ 819#define SHOW_NEEDED(B) \
824 Elf ## B ## _Dyn *dyn; \ 821 Elf ## B ## _Dyn *dyn; \
825 Elf ## B ## _Ehdr *ehdr = EHDR ## B (elf->ehdr); \ 822 Elf ## B ## _Ehdr *ehdr = EHDR ## B (elf->ehdr); \
826 Elf ## B ## _Phdr *phdr = PHDR ## B (elf->phdr); \ 823 Elf ## B ## _Phdr *phdr = PHDR ## B (elf->phdr); \
827 Elf ## B ## _Shdr *strtbl = SHDR ## B (strtbl_void); \ 824 Elf ## B ## _Shdr *strtbl = SHDR ## B (strtbl_void); \
828 Elf ## B ## _Off offset; \ 825 Elf ## B ## _Off offset; \
826 size_t matched = 0; \
827 /* Walk all the program headers to find the PT_DYNAMIC */ \
829 for (i = 0; i < EGET(ehdr->e_phnum); i++) { \ 828 for (i = 0; i < EGET(ehdr->e_phnum); i++) { \
830 if (EGET(phdr[i].p_type) != PT_DYNAMIC || EGET(phdr[i].p_filesz) == 0) continue; \ 829 if (EGET(phdr[i].p_type) != PT_DYNAMIC || EGET(phdr[i].p_filesz) == 0) \
830 continue; \
831 offset = EGET(phdr[i].p_offset); \ 831 offset = EGET(phdr[i].p_offset); \
832 if (offset >= elf->len - sizeof(Elf ## B ## _Dyn)) continue; \ 832 if (offset >= elf->len - sizeof(Elf ## B ## _Dyn)) \
833 continue; \
834 /* Walk all the dynamic tags to find NEEDED entries */ \
833 dyn = DYN ## B (elf->vdata + offset); \ 835 dyn = DYN ## B (elf->vdata + offset); \
834 while (EGET(dyn->d_tag) != DT_NULL) { \ 836 while (EGET(dyn->d_tag) != DT_NULL) { \
835 if (EGET(dyn->d_tag) == DT_NEEDED) { \ 837 if (EGET(dyn->d_tag) == DT_NEEDED) { \
836 offset = EGET(strtbl->sh_offset) + EGET(dyn->d_un.d_ptr); \ 838 offset = EGET(strtbl->sh_offset) + EGET(dyn->d_un.d_ptr); \
837 if (offset >= (Elf ## B ## _Off)elf->len) { \ 839 if (offset >= (Elf ## B ## _Off)elf->len) { \
838 ++dyn; \ 840 ++dyn; \
839 continue; \ 841 continue; \
840 } \ 842 } \
841 needed = elf->data + offset; \ 843 needed = elf->data + offset; \
842 if (op == 0) { \ 844 if (op == 0) { \
845 /* -n -> print all entries */ \
843 if (!be_wewy_wewy_quiet) { \ 846 if (!be_wewy_wewy_quiet) { \
844 if (*found_needed) xchrcat(ret, ',', ret_len); \ 847 if (*found_needed) xchrcat(ret, ',', ret_len); \
845 if (use_ldcache) \ 848 if (use_ldcache) \
846 if ((p = lookup_cache_lib(elf, needed)) != NULL) \ 849 if ((p = lookup_cache_lib(elf, needed)) != NULL) \
847 needed = p; \ 850 needed = p; \
848 xstrcat(ret, needed, ret_len); \ 851 xstrcat(ret, needed, ret_len); \
849 } \ 852 } \
850 *found_needed = 1; \ 853 *found_needed = 1; \
851 } else { \ 854 } else { \
852 if (!strncmp(find_lib, needed, strlen( !g_match ? needed : find_lib))) { \ 855 /* -N -> print matching entries */ \
856 size_t n; \
857 const char *find_lib_name; \
858 \
859 array_for_each(find_lib_arr, n, find_lib_name) \
860 if (!strcmp(find_lib_name, needed)) \
861 ++matched; \
862 \
863 if (matched == array_cnt(find_lib_arr)) { \
853 *found_lib = 1; \ 864 *found_lib = 1; \
854 return (be_wewy_wewy_quiet ? NULL : needed); \ 865 return (be_wewy_wewy_quiet ? NULL : find_lib); \
855 } \ 866 } \
856 } \ 867 } \
857 } \ 868 } \
858 ++dyn; \ 869 ++dyn; \
859 } \ 870 } \
1144 *found_sym = 1; 1155 *found_sym = 1;
1145 if (next_sym) 1156 if (next_sym)
1146 next_sym[-1] = saved; 1157 next_sym[-1] = saved;
1147} 1158}
1148 1159
1149static char *scanelf_file_sym(elfobj *elf, char *found_sym) 1160static const char *scanelf_file_sym(elfobj *elf, char *found_sym)
1150{ 1161{
1151 unsigned long i; 1162 unsigned long i;
1152 char *ret; 1163 char *ret;
1153 void *symtab_void, *strtab_void; 1164 void *symtab_void, *strtab_void;
1154 1165
1201 if (*find_sym != '*' && *found_sym) 1212 if (*find_sym != '*' && *found_sym)
1202 return ret; 1213 return ret;
1203 if (be_quiet) 1214 if (be_quiet)
1204 return NULL; 1215 return NULL;
1205 else 1216 else
1206 return (char *)" - "; 1217 return " - ";
1207} 1218}
1208 1219
1209static char *scanelf_file_sections(elfobj *elf, char *found_section) 1220static const char *scanelf_file_sections(elfobj *elf, char *found_section)
1210{ 1221{
1211 if (!find_section) 1222 if (!find_section)
1212 return NULL; 1223 return NULL;
1213 1224
1214#define FIND_SECTION(B) \ 1225#define FIND_SECTION(B) \
1215 if (elf->elf_class == ELFCLASS ## B) { \ 1226 if (elf->elf_class == ELFCLASS ## B) { \
1227 size_t matched, n; \
1216 int invert; \ 1228 int invert; \
1229 const char *section_name; \
1217 Elf ## B ## _Shdr *section; \ 1230 Elf ## B ## _Shdr *section; \
1231 \
1232 matched = 0; \
1233 array_for_each(find_section_arr, n, section_name) { \
1218 invert = (*find_section == '!' ? 1 : 0); \ 1234 invert = (*section_name == '!' ? 1 : 0); \
1219 section = SHDR ## B (elf_findsecbyname(elf, find_section+invert)); \ 1235 section = SHDR ## B (elf_findsecbyname(elf, section_name + invert)); \
1220 if ((section == NULL && invert) || (section != NULL && !invert)) \ 1236 if ((section == NULL && invert) || (section != NULL && !invert)) \
1237 ++matched; \
1238 } \
1239 \
1240 if (matched == array_cnt(find_section_arr)) \
1221 *found_section = 1; \ 1241 *found_section = 1; \
1222 } 1242 }
1223 FIND_SECTION(32) 1243 FIND_SECTION(32)
1224 FIND_SECTION(64) 1244 FIND_SECTION(64)
1225 1245
1230 return find_section; 1250 return find_section;
1231 1251
1232 if (be_quiet) 1252 if (be_quiet)
1233 return NULL; 1253 return NULL;
1234 else 1254 else
1235 return (char *)" - "; 1255 return " - ";
1236} 1256}
1237 1257
1238/* scan an elf file and show all the fun stuff */ 1258/* scan an elf file and show all the fun stuff */
1239#define prints(str) ({ ssize_t ret = write(fileno(stdout), str, strlen(str)); ret; }) 1259#define prints(str) ({ ssize_t ret = write(fileno(stdout), str, strlen(str)); ret; })
1240static int scanelf_elfobj(elfobj *elf) 1260static int scanelf_elfobj(elfobj *elf)
1412 if (elf->elf_class != ELFCLASS64) 1432 if (elf->elf_class != ELFCLASS64)
1413 goto label_done; 1433 goto label_done;
1414 break; 1434 break;
1415 default: break; 1435 default: break;
1416 } 1436 }
1417 if (strlen(match_etypes)) { 1437 if (match_etypes) {
1418 char sbuf[126]; 1438 char sbuf[126];
1419 strncpy(sbuf, match_etypes, sizeof(sbuf)); 1439 strncpy(sbuf, match_etypes, sizeof(sbuf));
1420 if (strchr(match_etypes, ',') != NULL) { 1440 if (strchr(match_etypes, ',') != NULL) {
1421 char *p; 1441 char *p;
1422 while ((p = strrchr(sbuf, ',')) != NULL) { 1442 while ((p = strrchr(sbuf, ',')) != NULL) {
1595 char path[__PAX_UTILS_PATH_MAX]; 1615 char path[__PAX_UTILS_PATH_MAX];
1596 char _fname[__PAX_UTILS_PATH_MAX]; 1616 char _fname[__PAX_UTILS_PATH_MAX];
1597 1617
1598 fname = maybe_add_root(fname, _fname); 1618 fname = maybe_add_root(fname, _fname);
1599 1619
1600 if (i + 1 == ARRAY_SIZE(ldpaths))
1601 return i;
1602
1603 if ((fp = fopen(fname, "r")) == NULL) 1620 if ((fp = fopen(fname, "r")) == NULL)
1604 return i; 1621 return i;
1605 1622
1606 while ((fgets(path, __PAX_UTILS_PATH_MAX, fp)) != NULL) { 1623 while ((fgets(path, __PAX_UTILS_PATH_MAX, fp)) != NULL) {
1607 if ((p = strrchr(path, '\r')) != NULL) 1624 if ((p = strrchr(path, '\r')) != NULL)
1628 for (x = 0; x < gl.gl_pathc; ++x) { 1645 for (x = 0; x < gl.gl_pathc; ++x) {
1629 /* try to avoid direct loops */ 1646 /* try to avoid direct loops */
1630 if (strcmp(gl.gl_pathv[x], fname) == 0) 1647 if (strcmp(gl.gl_pathv[x], fname) == 0)
1631 continue; 1648 continue;
1632 i = load_ld_cache_config(i, gl.gl_pathv[x]); 1649 i = load_ld_cache_config(i, gl.gl_pathv[x]);
1633 if (i + 1 >= ARRAY_SIZE(ldpaths)) {
1634 globfree(&gl);
1635 return i;
1636 }
1637 } 1650 }
1638 globfree(&gl); 1651 globfree(&gl);
1639 continue; 1652 continue;
1640 } 1653 }
1641 } 1654 }
1642 1655
1643 if (*path != '/') 1656 if (*path != '/')
1644 continue; 1657 continue;
1645 1658
1646 ldpaths[i++] = xstrdup(path); 1659 xarraypush(ldpaths, path, strlen(path));
1647
1648 if (i + 1 == ARRAY_SIZE(ldpaths))
1649 break;
1650 } 1660 }
1651 ldpaths[i] = NULL;
1652 1661
1653 fclose(fp); 1662 fclose(fp);
1654 return i; 1663 return i;
1655} 1664}
1656 1665
1662 char *b = NULL, *p; 1671 char *b = NULL, *p;
1663 struct elfhints_hdr hdr; 1672 struct elfhints_hdr hdr;
1664 char _fname[__PAX_UTILS_PATH_MAX]; 1673 char _fname[__PAX_UTILS_PATH_MAX];
1665 1674
1666 fname = maybe_add_root(fname, _fname); 1675 fname = maybe_add_root(fname, _fname);
1667
1668 if (i + 1 == ARRAY_SIZE(ldpaths))
1669 return i;
1670 1676
1671 if ((fp = fopen(fname, "r")) == NULL) 1677 if ((fp = fopen(fname, "r")) == NULL)
1672 return i; 1678 return i;
1673 1679
1674 if (fread(&hdr, 1, sizeof(hdr), fp) != sizeof(hdr) || 1680 if (fread(&hdr, 1, sizeof(hdr), fp) != sizeof(hdr) ||
1685 free(b); 1691 free(b);
1686 return i; 1692 return i;
1687 } 1693 }
1688 1694
1689 while ((p = strsep(&b, ":"))) { 1695 while ((p = strsep(&b, ":"))) {
1690 if (*p == '\0') continue; 1696 if (*p == '\0')
1691 ldpaths[i++] = xstrdup(p); 1697 continue;
1692 1698 xarraypush(ldpaths, p, strlen(p));
1693 if (i + 1 == ARRAY_SIZE(ldpaths))
1694 break;
1695 } 1699 }
1696 ldpaths[i] = NULL;
1697 1700
1698 free(b); 1701 free(b);
1699 fclose(fp); 1702 fclose(fp);
1700 return i; 1703 return i;
1701} 1704}
1704#ifdef __ELF__ 1707#ifdef __ELF__
1705#warning Cache config support not implemented for your target 1708#warning Cache config support not implemented for your target
1706#endif 1709#endif
1707static int load_ld_cache_config(int i, const char *fname) 1710static int load_ld_cache_config(int i, const char *fname)
1708{ 1711{
1709 memset(ldpaths, 0x00, sizeof(ldpaths));
1710 return 0; 1712 return 0;
1711} 1713}
1712#endif 1714#endif
1713 1715
1714/* scan /etc/ld.so.conf for paths */ 1716/* scan /etc/ld.so.conf for paths */
1715static void scanelf_ldpath(void) 1717static void scanelf_ldpath(void)
1716{ 1718{
1717 char scan_l, scan_ul, scan_ull; 1719 char scan_l, scan_ul, scan_ull;
1720 size_t n;
1721 const char *ldpath;
1718 int i = 0; 1722 int i = 0;
1719 1723
1720 if (!ldpaths[0]) 1724 if (array_cnt(ldpaths) == 0)
1721 err("Unable to load any paths from ld.so.conf"); 1725 err("Unable to load any paths from ld.so.conf");
1722 1726
1723 scan_l = scan_ul = scan_ull = 0; 1727 scan_l = scan_ul = scan_ull = 0;
1724 1728
1725 while (ldpaths[i]) { 1729 array_for_each(ldpaths, n, ldpath) {
1726 if (!scan_l && !strcmp(ldpaths[i], "/lib")) scan_l = 1; 1730 if (!scan_l && !strcmp(ldpath, "/lib")) scan_l = 1;
1727 if (!scan_ul && !strcmp(ldpaths[i], "/usr/lib")) scan_ul = 1; 1731 if (!scan_ul && !strcmp(ldpath, "/usr/lib")) scan_ul = 1;
1728 if (!scan_ull && !strcmp(ldpaths[i], "/usr/local/lib")) scan_ull = 1; 1732 if (!scan_ull && !strcmp(ldpath, "/usr/local/lib")) scan_ull = 1;
1729 scanelf_dir(ldpaths[i]); 1733 scanelf_dir(ldpath);
1730 ++i; 1734 ++i;
1731 } 1735 }
1732 1736
1733 if (!scan_l) scanelf_dir("/lib"); 1737 if (!scan_l) scanelf_dir("/lib");
1734 if (!scan_ul) scanelf_dir("/usr/lib"); 1738 if (!scan_ul) scanelf_dir("/usr/lib");
1820 "Print BIND information", 1824 "Print BIND information",
1821 "Print SONAME information", 1825 "Print SONAME information",
1822 "Find a specified symbol", 1826 "Find a specified symbol",
1823 "Find a specified section", 1827 "Find a specified section",
1824 "Find a specified library", 1828 "Find a specified library",
1825 "Use strncmp to match libraries. (use with -N)", 1829 "Use regex matching rather than string compare (use with -s)",
1826 "Locate cause of TEXTREL", 1830 "Locate cause of TEXTREL",
1827 "Print only ELF files matching etype ET_DYN,ET_EXEC ...", 1831 "Print only ELF files matching etype ET_DYN,ET_EXEC ...",
1828 "Print only ELF files matching numeric bits", 1832 "Print only ELF files matching numeric bits",
1829 "Print Endianness", 1833 "Print Endianness",
1830 "Print OSABI", 1834 "Print OSABI",
1895 case 'f': 1899 case 'f':
1896 if (from_file) warn("You prob don't want to specify -f twice"); 1900 if (from_file) warn("You prob don't want to specify -f twice");
1897 from_file = optarg; 1901 from_file = optarg;
1898 break; 1902 break;
1899 case 'E': 1903 case 'E':
1900 strncpy(match_etypes, optarg, sizeof(match_etypes)); 1904 match_etypes = optarg;
1901 break; 1905 break;
1902 case 'M': 1906 case 'M':
1903 match_bits = atoi(optarg); 1907 match_bits = atoi(optarg);
1904 if (match_bits == 0) { 1908 if (match_bits == 0) {
1905 if (strcmp(optarg, "ELFCLASS32") == 0) 1909 if (strcmp(optarg, "ELFCLASS32") == 0)
1916 if (freopen(optarg, "w", stdout) == NULL) 1920 if (freopen(optarg, "w", stdout) == NULL)
1917 err("Could not open output stream '%s': %s", optarg, strerror(errno)); 1921 err("Could not open output stream '%s': %s", optarg, strerror(errno));
1918 break; 1922 break;
1919 } 1923 }
1920 case 'k': 1924 case 'k':
1921 if (find_section) warn("You prob don't want to specify -k twice"); 1925 xarraypush(find_section_arr, optarg, strlen(optarg));
1922 find_section = optarg;
1923 break; 1926 break;
1924 case 's': { 1927 case 's': {
1925 if (find_sym) warn("You prob don't want to specify -s twice"); 1928 if (find_sym) warn("You prob don't want to specify -s twice");
1926 find_sym = optarg; 1929 find_sym = optarg;
1927 break; 1930 break;
1928 } 1931 }
1929 case 'N': { 1932 case 'N':
1930 if (find_lib) warn("You prob don't want to specify -N twice"); 1933 xarraypush(find_lib_arr, optarg, strlen(optarg));
1931 find_lib = optarg;
1932 break; 1934 break;
1933 }
1934
1935 case 'F': { 1935 case 'F': {
1936 if (out_format) warn("You prob don't want to specify -F twice"); 1936 if (out_format) warn("You prob don't want to specify -F twice");
1937 out_format = optarg; 1937 out_format = optarg;
1938 break; 1938 break;
1939 } 1939 }
2020 } 2020 }
2021 if (show_textrels && be_verbose) { 2021 if (show_textrels && be_verbose) {
2022 if (which("objdump") != NULL) 2022 if (which("objdump") != NULL)
2023 has_objdump = 1; 2023 has_objdump = 1;
2024 } 2024 }
2025 /* flatten arrays for display */
2026 if (array_cnt(find_lib_arr))
2027 find_lib = array_flatten_str(find_lib_arr);
2028 if (array_cnt(find_section_arr))
2029 find_section = array_flatten_str(find_section_arr);
2025 /* let the format option override all other options */ 2030 /* let the format option override all other options */
2026 if (out_format) { 2031 if (out_format) {
2027 show_pax = show_phdr = show_textrel = show_rpath = \ 2032 show_pax = show_phdr = show_textrel = show_rpath = \
2028 show_needed = show_interp = show_bind = show_soname = \ 2033 show_needed = show_interp = show_bind = show_soname = \
2029 show_textrels = show_perms = show_endian = show_size = \ 2034 show_textrels = show_perms = show_endian = show_size = \
2108 search_path = argv[optind++]; 2113 search_path = argv[optind++];
2109 ret = scanelf_dir(search_path); 2114 ret = scanelf_dir(search_path);
2110 } 2115 }
2111 2116
2112 /* clean up */ 2117 /* clean up */
2113 for (i = 0; ldpaths[i]; ++i)
2114 free(ldpaths[i]); 2118 xarrayfree(ldpaths);
2119 xarrayfree(find_lib_arr);
2120 xarrayfree(find_section_arr);
2121 free(find_lib);
2122 free(find_section);
2115 2123
2116 if (ldcache != 0) 2124 if (ldcache != 0)
2117 munmap(ldcache, ldcache_size); 2125 munmap(ldcache, ldcache_size);
2118 return ret; 2126 return ret;
2119} 2127}

Legend:
Removed from v.1.224  
changed lines
  Added in v.1.229

  ViewVC Help
Powered by ViewVC 1.1.20