/[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.180 Revision 1.181
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/scanelf.c,v 1.180 2007/06/09 21:43:53 solar Exp $ 4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.181 2007/06/29 17:09:12 solar 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
10#include "paxinc.h" 10#include "paxinc.h"
11 11
12static const char *rcsid = "$Id: scanelf.c,v 1.180 2007/06/09 21:43:53 solar Exp $"; 12static const char *rcsid = "$Id: scanelf.c,v 1.181 2007/06/29 17:09:12 solar Exp $";
13#define argv0 "scanelf" 13#define argv0 "scanelf"
14 14
15#define IS_MODIFIER(c) (c == '%' || c == '#' || c == '+') 15#define IS_MODIFIER(c) (c == '%' || c == '#' || c == '+')
16 16
17/* prototypes */ 17/* prototypes */
53static char show_interp = 0; 53static char show_interp = 0;
54static char show_bind = 0; 54static char show_bind = 0;
55static char show_soname = 0; 55static char show_soname = 0;
56static char show_textrels = 0; 56static char show_textrels = 0;
57static char show_banner = 1; 57static char show_banner = 1;
58static char show_endian = 0;
58static char be_quiet = 0; 59static char be_quiet = 0;
59static char be_verbose = 0; 60static char be_verbose = 0;
60static char be_wewy_wewy_quiet = 0; 61static char be_wewy_wewy_quiet = 0;
61static char be_semi_verbose = 0; 62static char be_semi_verbose = 0;
62static char *find_sym = NULL, *versioned_symname = NULL; 63static char *find_sym = NULL, *versioned_symname = NULL;
1151 case 'N': prints("LIB "); break; 1152 case 'N': prints("LIB "); break;
1152 case 'T': prints("TEXTRELS "); break; 1153 case 'T': prints("TEXTRELS "); break;
1153 case 'k': prints("SECTION "); break; 1154 case 'k': prints("SECTION "); break;
1154 case 'a': prints("ARCH "); break; 1155 case 'a': prints("ARCH "); break;
1155 case 'O': prints("PERM "); break; 1156 case 'O': prints("PERM "); break;
1157 case 'D': prints("ENDIAN "); break;
1156 default: warnf("'%c' has no title ?", out_format[i]); 1158 default: warnf("'%c' has no title ?", out_format[i]);
1157 } 1159 }
1158 } 1160 }
1159 if (!found_file) prints("FILE "); 1161 if (!found_file) prints("FILE ");
1160 prints("\n"); 1162 prints("\n");
1211 case 'e': out = scanelf_file_phdr(elf, &found_phdr, &found_relro, &found_load); break; 1213 case 'e': out = scanelf_file_phdr(elf, &found_phdr, &found_relro, &found_load); break;
1212 case 't': out = scanelf_file_textrel(elf, &found_textrel); break; 1214 case 't': out = scanelf_file_textrel(elf, &found_textrel); break;
1213 case 'T': out = scanelf_file_textrels(elf, &found_textrels, &found_textrel); break; 1215 case 'T': out = scanelf_file_textrels(elf, &found_textrels, &found_textrel); break;
1214 case 'r': scanelf_file_rpath(elf, &found_rpath, &out_buffer, &out_len); break; 1216 case 'r': scanelf_file_rpath(elf, &found_rpath, &out_buffer, &out_len); break;
1215 case 'M': out = get_elfeitype(EI_CLASS, elf->data[EI_CLASS]); break; 1217 case 'M': out = get_elfeitype(EI_CLASS, elf->data[EI_CLASS]); break;
1218 case 'D': out = get_endian(elf); break;
1216 case 'O': out = getstr_perms(elf->filename); break; 1219 case 'O': out = getstr_perms(elf->filename); break;
1217 case 'n': 1220 case 'n':
1218 case 'N': out = scanelf_file_needed_lib(elf, &found_needed, &found_lib, (out_format[i]=='N'), &out_buffer, &out_len); break; 1221 case 'N': out = scanelf_file_needed_lib(elf, &found_needed, &found_lib, (out_format[i]=='N'), &out_buffer, &out_len); break;
1219 case 'i': out = scanelf_file_interp(elf, &found_interp); break; 1222 case 'i': out = scanelf_file_interp(elf, &found_interp); break;
1220 case 'b': out = scanelf_file_bind(elf, &found_bind); break; 1223 case 'b': out = scanelf_file_bind(elf, &found_bind); break;
1584 } 1587 }
1585 1588
1586 free(path); 1589 free(path);
1587} 1590}
1588 1591
1589/* usage / invocation handling functions */ 1592
1593/* usage / invocation handling functions */ /* Free Flags: c d j u w C G H I J K P Q U W Y Z */
1590#define PARSE_FLAGS "plRmyAXz:xetrnLibSs:k:gN:TaqvF:f:o:E:M:O:BhV" 1594#define PARSE_FLAGS "plRmyAXz:xetrnLibSs:k:gN:TaqvF:f:o:E:M:DO:BhV"
1591#define a_argument required_argument 1595#define a_argument required_argument
1592static struct option const long_opts[] = { 1596static struct option const long_opts[] = {
1593 {"path", no_argument, NULL, 'p'}, 1597 {"path", no_argument, NULL, 'p'},
1594 {"ldpath", no_argument, NULL, 'l'}, 1598 {"ldpath", no_argument, NULL, 'l'},
1595 {"recursive", no_argument, NULL, 'R'}, 1599 {"recursive", no_argument, NULL, 'R'},
1612 {"lib", a_argument, NULL, 'N'}, 1616 {"lib", a_argument, NULL, 'N'},
1613 {"gmatch", no_argument, NULL, 'g'}, 1617 {"gmatch", no_argument, NULL, 'g'},
1614 {"textrels", no_argument, NULL, 'T'}, 1618 {"textrels", no_argument, NULL, 'T'},
1615 {"etype", a_argument, NULL, 'E'}, 1619 {"etype", a_argument, NULL, 'E'},
1616 {"bits", a_argument, NULL, 'M'}, 1620 {"bits", a_argument, NULL, 'M'},
1621 {"endian", no_argument, NULL, 'D'},
1617 {"perms", a_argument, NULL, 'O'}, 1622 {"perms", a_argument, NULL, 'O'},
1618 {"all", no_argument, NULL, 'a'}, 1623 {"all", no_argument, NULL, 'a'},
1619 {"quiet", no_argument, NULL, 'q'}, 1624 {"quiet", no_argument, NULL, 'q'},
1620 {"verbose", no_argument, NULL, 'v'}, 1625 {"verbose", no_argument, NULL, 'v'},
1621 {"format", a_argument, NULL, 'F'}, 1626 {"format", a_argument, NULL, 'F'},
1650 "Find a specified library", 1655 "Find a specified library",
1651 "Use strncmp to match libraries. (use with -N)", 1656 "Use strncmp to match libraries. (use with -N)",
1652 "Locate cause of TEXTREL", 1657 "Locate cause of TEXTREL",
1653 "Print only ELF files matching etype ET_DYN,ET_EXEC ...", 1658 "Print only ELF files matching etype ET_DYN,ET_EXEC ...",
1654 "Print only ELF files matching numeric bits", 1659 "Print only ELF files matching numeric bits",
1660 "Print Endianness",
1655 "Print only ELF files matching octal permissions", 1661 "Print only ELF files matching octal permissions",
1656 "Print all scanned info (-x -e -t -r -b)\n", 1662 "Print all scanned info (-x -e -t -r -b)\n",
1657 "Only output 'bad' things", 1663 "Only output 'bad' things",
1658 "Be verbose (can be specified more than once)", 1664 "Be verbose (can be specified more than once)",
1659 "Use specified format for output", 1665 "Use specified format for output",
1814 case 'S': show_soname = 1; break; 1820 case 'S': show_soname = 1; break;
1815 case 'T': show_textrels = 1; break; 1821 case 'T': show_textrels = 1; break;
1816 case 'q': be_quiet = 1; break; 1822 case 'q': be_quiet = 1; break;
1817 case 'v': be_verbose = (be_verbose % 20) + 1; break; 1823 case 'v': be_verbose = (be_verbose % 20) + 1; break;
1818 case 'a': show_perms = show_pax = show_phdr = show_textrel = show_rpath = show_bind = 1; break; 1824 case 'a': show_perms = show_pax = show_phdr = show_textrel = show_rpath = show_bind = 1; break;
1819 1825 case 'D': show_endian = 1; break;
1820 case ':': 1826 case ':':
1821 err("Option '%c' is missing parameter", optopt); 1827 err("Option '%c' is missing parameter", optopt);
1822 case '?': 1828 case '?':
1823 err("Unknown option '%c' or argument missing", optopt); 1829 err("Unknown option '%c' or argument missing", optopt);
1824 default: 1830 default:
1831 } 1837 }
1832 /* let the format option override all other options */ 1838 /* let the format option override all other options */
1833 if (out_format) { 1839 if (out_format) {
1834 show_pax = show_phdr = show_textrel = show_rpath = \ 1840 show_pax = show_phdr = show_textrel = show_rpath = \
1835 show_needed = show_interp = show_bind = show_soname = \ 1841 show_needed = show_interp = show_bind = show_soname = \
1836 show_textrels = show_perms = 0; 1842 show_textrels = show_perms = show_endian = 0;
1837 for (i = 0; out_format[i]; ++i) { 1843 for (i = 0; out_format[i]; ++i) {
1838 if (!IS_MODIFIER(out_format[i])) continue; 1844 if (!IS_MODIFIER(out_format[i])) continue;
1839 1845
1840 switch (out_format[++i]) { 1846 switch (out_format[++i]) {
1841 case '+': break; 1847 case '+': break;
1848 case 's': break; 1854 case 's': break;
1849 case 'N': break; 1855 case 'N': break;
1850 case 'o': break; 1856 case 'o': break;
1851 case 'a': break; 1857 case 'a': break;
1852 case 'M': break; 1858 case 'M': break;
1859 case 'D': show_endian = 1; break;
1853 case 'O': show_perms = 1; break; 1860 case 'O': show_perms = 1; break;
1854 case 'x': show_pax = 1; break; 1861 case 'x': show_pax = 1; break;
1855 case 'e': show_phdr = 1; break; 1862 case 'e': show_phdr = 1; break;
1856 case 't': show_textrel = 1; break; 1863 case 't': show_textrel = 1; break;
1857 case 'r': show_rpath = 1; break; 1864 case 'r': show_rpath = 1; break;
1871 size_t fmt_len = 30; 1878 size_t fmt_len = 30;
1872 out_format = (char*)xmalloc(sizeof(char) * fmt_len); 1879 out_format = (char*)xmalloc(sizeof(char) * fmt_len);
1873 if (!be_quiet) xstrcat(&out_format, "%o ", &fmt_len); 1880 if (!be_quiet) xstrcat(&out_format, "%o ", &fmt_len);
1874 if (show_pax) xstrcat(&out_format, "%x ", &fmt_len); 1881 if (show_pax) xstrcat(&out_format, "%x ", &fmt_len);
1875 if (show_perms) xstrcat(&out_format, "%O ", &fmt_len); 1882 if (show_perms) xstrcat(&out_format, "%O ", &fmt_len);
1883 if (show_endian) xstrcat(&out_format, "%D ", &fmt_len);
1876 if (show_phdr) xstrcat(&out_format, "%e ", &fmt_len); 1884 if (show_phdr) xstrcat(&out_format, "%e ", &fmt_len);
1877 if (show_textrel) xstrcat(&out_format, "%t ", &fmt_len); 1885 if (show_textrel) xstrcat(&out_format, "%t ", &fmt_len);
1878 if (show_rpath) xstrcat(&out_format, "%r ", &fmt_len); 1886 if (show_rpath) xstrcat(&out_format, "%r ", &fmt_len);
1879 if (show_needed) xstrcat(&out_format, "%n ", &fmt_len); 1887 if (show_needed) xstrcat(&out_format, "%n ", &fmt_len);
1880 if (show_interp) xstrcat(&out_format, "%i ", &fmt_len); 1888 if (show_interp) xstrcat(&out_format, "%i ", &fmt_len);
1947 1955
1948 /* don't want to free(env) as it contains the memory that backs 1956 /* don't want to free(env) as it contains the memory that backs
1949 * the envvals array of strings */ 1957 * the envvals array of strings */
1950 return envvals; 1958 return envvals;
1951} 1959}
1960
1952static void parseenv() 1961static void parseenv()
1953{ 1962{
1954 qa_textrels = get_split_env("QA_TEXTRELS"); 1963 qa_textrels = get_split_env("QA_TEXTRELS");
1955 qa_execstack = get_split_env("QA_EXECSTACK"); 1964 qa_execstack = get_split_env("QA_EXECSTACK");
1956 qa_wx_load = get_split_env("QA_WX_LOAD"); 1965 qa_wx_load = get_split_env("QA_WX_LOAD");

Legend:
Removed from v.1.180  
changed lines
  Added in v.1.181

  ViewVC Help
Powered by ViewVC 1.1.20