/[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.189 Revision 1.190
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.189 2008/01/17 04:37:19 solar Exp $ 4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.190 2008/04/19 22:31:49 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
10static const char *rcsid = "$Id: scanelf.c,v 1.189 2008/01/17 04:37:19 solar Exp $"; 10static const char *rcsid = "$Id: scanelf.c,v 1.190 2008/04/19 22:31:49 solar Exp $";
11const char * const argv0 = "scanelf"; 11const char * const 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 == '+')
38static char scan_archives = 0; 38static char scan_archives = 0;
39static char dir_recurse = 0; 39static char dir_recurse = 0;
40static char dir_crossmount = 1; 40static char dir_crossmount = 1;
41static char show_pax = 0; 41static char show_pax = 0;
42static char show_perms = 0; 42static char show_perms = 0;
43static char show_size = 0;
43static char show_phdr = 0; 44static char show_phdr = 0;
44static char show_textrel = 0; 45static char show_textrel = 0;
45static char show_rpath = 0; 46static char show_rpath = 0;
46static char show_needed = 0; 47static char show_needed = 0;
47static char show_interp = 0; 48static char show_interp = 0;
1144 case 'r': prints("RPATH "); break; 1145 case 'r': prints("RPATH "); break;
1145 case 'M': prints("CLASS "); break; 1146 case 'M': prints("CLASS "); break;
1146 case 'n': prints("NEEDED "); break; 1147 case 'n': prints("NEEDED "); break;
1147 case 'i': prints("INTERP "); break; 1148 case 'i': prints("INTERP "); break;
1148 case 'b': prints("BIND "); break; 1149 case 'b': prints("BIND "); break;
1150 case 'Z': prints("SIZE "); break;
1149 case 'S': prints("SONAME "); break; 1151 case 'S': prints("SONAME "); break;
1150 case 's': prints("SYM "); break; 1152 case 's': prints("SYM "); break;
1151 case 'N': prints("LIB "); break; 1153 case 'N': prints("LIB "); break;
1152 case 'T': prints("TEXTRELS "); break; 1154 case 'T': prints("TEXTRELS "); break;
1153 case 'k': prints("SECTION "); break; 1155 case 'k': prints("SECTION "); break;
1165 1167
1166 /* dump all the good stuff */ 1168 /* dump all the good stuff */
1167 for (i = 0; out_format[i]; ++i) { 1169 for (i = 0; out_format[i]; ++i) {
1168 const char *out; 1170 const char *out;
1169 const char *tmp; 1171 const char *tmp;
1170 1172 static char ubuf[sizeof(unsigned long)*2];
1171 if (!IS_MODIFIER(out_format[i])) { 1173 if (!IS_MODIFIER(out_format[i])) {
1172 xchrcat(&out_buffer, out_format[i], &out_len); 1174 xchrcat(&out_buffer, out_format[i], &out_len);
1173 continue; 1175 continue;
1174 } 1176 }
1175 1177
1222 case 'b': out = scanelf_file_bind(elf, &found_bind); break; 1224 case 'b': out = scanelf_file_bind(elf, &found_bind); break;
1223 case 'S': out = scanelf_file_soname(elf, &found_soname); break; 1225 case 'S': out = scanelf_file_soname(elf, &found_soname); break;
1224 case 's': out = scanelf_file_sym(elf, &found_sym); break; 1226 case 's': out = scanelf_file_sym(elf, &found_sym); break;
1225 case 'k': out = scanelf_file_sections(elf, &found_section); break; 1227 case 'k': out = scanelf_file_sections(elf, &found_section); break;
1226 case 'a': out = get_elfemtype(elf); break; 1228 case 'a': out = get_elfemtype(elf); break;
1229 case 'Z': snprintf(ubuf, sizeof(ubuf), "%lu", elf->len); out = ubuf; break;;
1227 default: warnf("'%c' has no scan code?", out_format[i]); 1230 default: warnf("'%c' has no scan code?", out_format[i]);
1228 } 1231 }
1229 if (out) { 1232 if (out) {
1230 /* hack for comma delimited output like `scanelf -s sym1,sym2,sym3` */ 1233 /* hack for comma delimited output like `scanelf -s sym1,sym2,sym3` */
1231 if (out_format[i] == 's' && (tmp=strchr(out,',')) != NULL) 1234 if (out_format[i] == 's' && (tmp=strchr(out,',')) != NULL)
1586 } 1589 }
1587 1590
1588 free(path); 1591 free(path);
1589} 1592}
1590 1593
1591/* usage / invocation handling functions */ /* Free Flags: c d j u w C G H I J K P Q U W Y Z */ 1594/* usage / invocation handling functions */ /* Free Flags: c d j u w C G H I J K P Q U W Y */
1592#define PARSE_FLAGS "plRmyAXz:xetrnLibSs:k:gN:TaqvF:f:o:E:M:DO:BhV" 1595#define PARSE_FLAGS "plRmyAXz:xetrnLibSs:k:gN:TaqvF:f:o:E:M:DO:ZBhV"
1593#define a_argument required_argument 1596#define a_argument required_argument
1594static struct option const long_opts[] = { 1597static struct option const long_opts[] = {
1595 {"path", no_argument, NULL, 'p'}, 1598 {"path", no_argument, NULL, 'p'},
1596 {"ldpath", no_argument, NULL, 'l'}, 1599 {"ldpath", no_argument, NULL, 'l'},
1597 {"recursive", no_argument, NULL, 'R'}, 1600 {"recursive", no_argument, NULL, 'R'},
1616 {"textrels", no_argument, NULL, 'T'}, 1619 {"textrels", no_argument, NULL, 'T'},
1617 {"etype", a_argument, NULL, 'E'}, 1620 {"etype", a_argument, NULL, 'E'},
1618 {"bits", a_argument, NULL, 'M'}, 1621 {"bits", a_argument, NULL, 'M'},
1619 {"endian", no_argument, NULL, 'D'}, 1622 {"endian", no_argument, NULL, 'D'},
1620 {"perms", a_argument, NULL, 'O'}, 1623 {"perms", a_argument, NULL, 'O'},
1624 {"size", no_argument, NULL, 'Z'},
1621 {"all", no_argument, NULL, 'a'}, 1625 {"all", no_argument, NULL, 'a'},
1622 {"quiet", no_argument, NULL, 'q'}, 1626 {"quiet", no_argument, NULL, 'q'},
1623 {"verbose", no_argument, NULL, 'v'}, 1627 {"verbose", no_argument, NULL, 'v'},
1624 {"format", a_argument, NULL, 'F'}, 1628 {"format", a_argument, NULL, 'F'},
1625 {"from", a_argument, NULL, 'f'}, 1629 {"from", a_argument, NULL, 'f'},
1655 "Locate cause of TEXTREL", 1659 "Locate cause of TEXTREL",
1656 "Print only ELF files matching etype ET_DYN,ET_EXEC ...", 1660 "Print only ELF files matching etype ET_DYN,ET_EXEC ...",
1657 "Print only ELF files matching numeric bits", 1661 "Print only ELF files matching numeric bits",
1658 "Print Endianness", 1662 "Print Endianness",
1659 "Print only ELF files matching octal permissions", 1663 "Print only ELF files matching octal permissions",
1664 "Print ELF file size",
1660 "Print all scanned info (-x -e -t -r -b)\n", 1665 "Print all scanned info (-x -e -t -r -b)\n",
1661 "Only output 'bad' things", 1666 "Only output 'bad' things",
1662 "Be verbose (can be specified more than once)", 1667 "Be verbose (can be specified more than once)",
1663 "Use specified format for output", 1668 "Use specified format for output",
1664 "Read input stream from a filename", 1669 "Read input stream from a filename",
1802 ((flags & PF_EMUTRAMP) && (flags & PF_NOEMUTRAMP)) || 1807 ((flags & PF_EMUTRAMP) && (flags & PF_NOEMUTRAMP)) ||
1803 ((flags & PF_RANDMMAP) && (flags & PF_NORANDMMAP)))) 1808 ((flags & PF_RANDMMAP) && (flags & PF_NORANDMMAP))))
1804 setpax = flags; 1809 setpax = flags;
1805 break; 1810 break;
1806 } 1811 }
1812 case 'Z': show_size = 1; break;
1807 case 'g': g_match = 1; break; 1813 case 'g': g_match = 1; break;
1808 case 'L': use_ldcache = 1; break; 1814 case 'L': use_ldcache = 1; break;
1809 case 'y': scan_symlink = 0; break; 1815 case 'y': scan_symlink = 0; break;
1810 case 'A': scan_archives = 1; break; 1816 case 'A': scan_archives = 1; break;
1811 case 'B': show_banner = 0; break; 1817 case 'B': show_banner = 0; break;
1841 } 1847 }
1842 /* let the format option override all other options */ 1848 /* let the format option override all other options */
1843 if (out_format) { 1849 if (out_format) {
1844 show_pax = show_phdr = show_textrel = show_rpath = \ 1850 show_pax = show_phdr = show_textrel = show_rpath = \
1845 show_needed = show_interp = show_bind = show_soname = \ 1851 show_needed = show_interp = show_bind = show_soname = \
1846 show_textrels = show_perms = show_endian = 0; 1852 show_textrels = show_perms = show_endian = show_size = 0;
1847 for (i = 0; out_format[i]; ++i) { 1853 for (i = 0; out_format[i]; ++i) {
1848 if (!IS_MODIFIER(out_format[i])) continue; 1854 if (!IS_MODIFIER(out_format[i])) continue;
1849 1855
1850 switch (out_format[++i]) { 1856 switch (out_format[++i]) {
1851 case '+': break; 1857 case '+': break;
1858 case 's': break; 1864 case 's': break;
1859 case 'N': break; 1865 case 'N': break;
1860 case 'o': break; 1866 case 'o': break;
1861 case 'a': break; 1867 case 'a': break;
1862 case 'M': break; 1868 case 'M': break;
1869 case 'Z': show_size = 1; break;
1863 case 'D': show_endian = 1; break; 1870 case 'D': show_endian = 1; break;
1864 case 'O': show_perms = 1; break; 1871 case 'O': show_perms = 1; break;
1865 case 'x': show_pax = 1; break; 1872 case 'x': show_pax = 1; break;
1866 case 'e': show_phdr = 1; break; 1873 case 'e': show_phdr = 1; break;
1867 case 't': show_textrel = 1; break; 1874 case 't': show_textrel = 1; break;
1882 size_t fmt_len = 30; 1889 size_t fmt_len = 30;
1883 out_format = xmalloc(sizeof(char) * fmt_len); 1890 out_format = xmalloc(sizeof(char) * fmt_len);
1884 if (!be_quiet) xstrcat(&out_format, "%o ", &fmt_len); 1891 if (!be_quiet) xstrcat(&out_format, "%o ", &fmt_len);
1885 if (show_pax) xstrcat(&out_format, "%x ", &fmt_len); 1892 if (show_pax) xstrcat(&out_format, "%x ", &fmt_len);
1886 if (show_perms) xstrcat(&out_format, "%O ", &fmt_len); 1893 if (show_perms) xstrcat(&out_format, "%O ", &fmt_len);
1894 if (show_size) xstrcat(&out_format, "%Z ", &fmt_len);
1887 if (show_endian) xstrcat(&out_format, "%D ", &fmt_len); 1895 if (show_endian) xstrcat(&out_format, "%D ", &fmt_len);
1888 if (show_phdr) xstrcat(&out_format, "%e ", &fmt_len); 1896 if (show_phdr) xstrcat(&out_format, "%e ", &fmt_len);
1889 if (show_textrel) xstrcat(&out_format, "%t ", &fmt_len); 1897 if (show_textrel) xstrcat(&out_format, "%t ", &fmt_len);
1890 if (show_rpath) xstrcat(&out_format, "%r ", &fmt_len); 1898 if (show_rpath) xstrcat(&out_format, "%r ", &fmt_len);
1891 if (show_needed) xstrcat(&out_format, "%n ", &fmt_len); 1899 if (show_needed) xstrcat(&out_format, "%n ", &fmt_len);

Legend:
Removed from v.1.189  
changed lines
  Added in v.1.190

  ViewVC Help
Powered by ViewVC 1.1.20