/[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.37 Revision 1.38
1/* 1/*
2 * Copyright 2003 Ned Ludd <solar@gentoo.org> 2 * Copyright 2003 Ned Ludd <solar@gentoo.org>
3 * Copyright 1999-2005 Gentoo Foundation 3 * Copyright 1999-2005 Gentoo Foundation
4 * Distributed under the terms of the GNU General Public License v2 4 * Distributed under the terms of the GNU General Public License v2
5 * $Header: /var/cvsroot/gentoo-projects/pax-utils/Attic/scanelf.c,v 1.37 2005/04/16 06:34:39 vapier Exp $ 5 * $Header: /var/cvsroot/gentoo-projects/pax-utils/Attic/scanelf.c,v 1.38 2005/04/19 22:19:26 vapier Exp $
6 * 6 *
7 ******************************************************************** 7 ********************************************************************
8 * This program is free software; you can redistribute it and/or 8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as 9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the 10 * published by the Free Software Foundation; either version 2 of the
33#include <getopt.h> 33#include <getopt.h>
34#include <assert.h> 34#include <assert.h>
35 35
36#include "paxelf.h" 36#include "paxelf.h"
37 37
38static const char *rcsid = "$Id: scanelf.c,v 1.37 2005/04/16 06:34:39 vapier Exp $"; 38static const char *rcsid = "$Id: scanelf.c,v 1.38 2005/04/19 22:19:26 vapier Exp $";
39#define argv0 "scanelf" 39#define argv0 "scanelf"
40 40
41 41
42 42
43/* prototypes */ 43/* prototypes */
57static char show_pax = 0; 57static char show_pax = 0;
58static char show_stack = 0; 58static char show_stack = 0;
59static char show_textrel = 0; 59static char show_textrel = 0;
60static char show_rpath = 0; 60static char show_rpath = 0;
61static char show_needed = 0; 61static char show_needed = 0;
62static char show_interp = 0;
62static char show_banner = 1; 63static char show_banner = 1;
63static char be_quiet = 0; 64static char be_quiet = 0;
64static char be_verbose = 0; 65static char be_verbose = 0;
65static char *find_sym = NULL; 66static char *find_sym = NULL;
66 67
69/* scan an elf file and show all the fun stuff */ 70/* scan an elf file and show all the fun stuff */
70static void scanelf_file(const char *filename) 71static void scanelf_file(const char *filename)
71{ 72{
72 int i; 73 int i;
73 char found_pax, found_stack, found_relro, found_textrel, 74 char found_pax, found_stack, found_relro, found_textrel,
74 found_rpath, found_needed, found_sym; 75 found_rpath, found_needed, found_interp, found_sym;
75 elfobj *elf; 76 elfobj *elf;
76 struct stat st; 77 struct stat st;
77 78
78 /* make sure 'filename' exists */ 79 /* make sure 'filename' exists */
79 if (lstat(filename, &st) == -1) 80 if (lstat(filename, &st) == -1)
81 /* always handle regular files and handle symlinked files if no -y */ 82 /* always handle regular files and handle symlinked files if no -y */
82 if (!(S_ISREG(st.st_mode) || (S_ISLNK(st.st_mode) && scan_symlink))) 83 if (!(S_ISREG(st.st_mode) || (S_ISLNK(st.st_mode) && scan_symlink)))
83 return; 84 return;
84 85
85 found_pax = found_stack = found_relro = found_textrel = \ 86 found_pax = found_stack = found_relro = found_textrel = \
86 found_rpath = found_needed = found_sym = 0; 87 found_rpath = found_needed = found_interp = found_sym = 0;
87 88
88 /* verify this is real ELF */ 89 /* verify this is real ELF */
89 if ((elf = readelf(filename)) == NULL) { 90 if ((elf = readelf(filename)) == NULL) {
90 if (be_verbose > 2) printf("%s: not an ELF\n", filename); 91 if (be_verbose > 2) printf("%s: not an ELF\n", filename);
91 return; 92 return;
104 if (show_pax) printf(" PAX "); 105 if (show_pax) printf(" PAX ");
105 if (show_stack) printf("STK/REL "); 106 if (show_stack) printf("STK/REL ");
106 if (show_textrel) printf("TEXTREL "); 107 if (show_textrel) printf("TEXTREL ");
107 if (show_rpath) printf("RPATH "); 108 if (show_rpath) printf("RPATH ");
108 if (show_needed) printf("NEEDED "); 109 if (show_needed) printf("NEEDED ");
110 if (show_interp) printf("INTERP ");
109 printf(" FILE\n"); 111 printf(" FILE\n");
110 show_banner = 0; 112 show_banner = 0;
111 } 113 }
112 114
113 /* dump all the good stuff */ 115 /* dump all the good stuff */
251 printf(" - "); 253 printf(" - ");
252 else if (found_needed) 254 else if (found_needed)
253 printf(" "); 255 printf(" ");
254 } 256 }
255 257
258 /* print out all the INTERP info (i.e. glibc is /lib/ld-linux.so.2) */
259 if (show_interp) {
260 void *strtbl_void = elf_findsecbyname(elf, ".interp");
261
262 if (strtbl_void) {
263#define SHOW_INTERP(B) \
264 if (elf->elf_class == ELFCLASS ## B) { \
265 Elf ## B ## _Shdr *strtbl = SHDR ## B (strtbl_void); \
266 printf("%s ", elf->data + EGET(strtbl->sh_offset)); \
267 found_interp = 1; \
268 }
269 SHOW_INTERP(32)
270 SHOW_INTERP(64)
271 }
272 if (!be_quiet && !found_interp)
273 printf(" - ");
274 else if (found_interp)
275 printf(" ");
276 }
277
256 /* search the symbol table for a specified symbol */ 278 /* search the symbol table for a specified symbol */
257 if (find_sym) { 279 if (find_sym) {
258 void *symtab_void, *strtab_void; 280 void *symtab_void, *strtab_void;
259 char *versioned_symname; 281 char *versioned_symname;
260 size_t len; 282 size_t len;
418} 440}
419 441
420 442
421 443
422/* usage / invocation handling functions */ 444/* usage / invocation handling functions */
423#define PARSE_FLAGS "plRmyxetrns:aqvo:BhV" 445#define PARSE_FLAGS "plRmyxetrnis:aqvo:BhV"
424#define a_argument required_argument 446#define a_argument required_argument
425static struct option const long_opts[] = { 447static struct option const long_opts[] = {
426 {"path", no_argument, NULL, 'p'}, 448 {"path", no_argument, NULL, 'p'},
427 {"ldpath", no_argument, NULL, 'l'}, 449 {"ldpath", no_argument, NULL, 'l'},
428 {"recursive", no_argument, NULL, 'R'}, 450 {"recursive", no_argument, NULL, 'R'},
431 {"pax", no_argument, NULL, 'x'}, 453 {"pax", no_argument, NULL, 'x'},
432 {"header", no_argument, NULL, 'e'}, 454 {"header", no_argument, NULL, 'e'},
433 {"textrel", no_argument, NULL, 't'}, 455 {"textrel", no_argument, NULL, 't'},
434 {"rpath", no_argument, NULL, 'r'}, 456 {"rpath", no_argument, NULL, 'r'},
435 {"needed", no_argument, NULL, 'n'}, 457 {"needed", no_argument, NULL, 'n'},
458 {"interp", no_argument, NULL, 'i'},
436 {"symbol", a_argument, NULL, 's'}, 459 {"symbol", a_argument, NULL, 's'},
437 {"all", no_argument, NULL, 'a'}, 460 {"all", no_argument, NULL, 'a'},
438 {"quiet", no_argument, NULL, 'q'}, 461 {"quiet", no_argument, NULL, 'q'},
439 {"verbose", no_argument, NULL, 'v'}, 462 {"verbose", no_argument, NULL, 'v'},
440 {"file", a_argument, NULL, 'o'}, 463 {"file", a_argument, NULL, 'o'},
452 "Print PaX markings", 475 "Print PaX markings",
453 "Print GNU_STACK markings", 476 "Print GNU_STACK markings",
454 "Print TEXTREL information", 477 "Print TEXTREL information",
455 "Print RPATH information", 478 "Print RPATH information",
456 "Print NEEDED information", 479 "Print NEEDED information",
480 "Print INTERP information",
457 "Find a specified symbol", 481 "Find a specified symbol",
458 "Print all scanned info (-x -e -t -r)\n", 482 "Print all scanned info (-x -e -t -r)\n",
459 "Only output 'bad' things", 483 "Only output 'bad' things",
460 "Be verbose (can be specified more than once)", 484 "Be verbose (can be specified more than once)",
461 "Write output stream to a filename", 485 "Write output stream to a filename",
519 case 'x': show_pax = 1; break; 543 case 'x': show_pax = 1; break;
520 case 'e': show_stack = 1; break; 544 case 'e': show_stack = 1; break;
521 case 't': show_textrel = 1; break; 545 case 't': show_textrel = 1; break;
522 case 'r': show_rpath = 1; break; 546 case 'r': show_rpath = 1; break;
523 case 'n': show_needed = 1; break; 547 case 'n': show_needed = 1; break;
548 case 'i': show_interp = 1; break;
524 case 'q': be_quiet = 1; break; 549 case 'q': be_quiet = 1; break;
525 case 'v': be_verbose = (be_verbose % 20) + 1; break; 550 case 'v': be_verbose = (be_verbose % 20) + 1; break;
526 case 'a': show_pax = show_stack = show_textrel = show_needed = show_rpath = 1; break; 551 case 'a': show_pax = show_stack = show_textrel = show_rpath = show_needed = show_interp = 1; break;
527 552
528 case ':': 553 case ':':
529 warn("Option missing parameter"); 554 warn("Option missing parameter");
530 usage(EXIT_FAILURE); 555 usage(EXIT_FAILURE);
531 break; 556 break;

Legend:
Removed from v.1.37  
changed lines
  Added in v.1.38

  ViewVC Help
Powered by ViewVC 1.1.20