/[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.11 Revision 1.12
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/scanelf.c,v 1.11 2005/03/31 00:03:25 solar Exp $ 5 * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.12 2005/03/31 00:50:56 solar 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
31#include <dirent.h> 31#include <dirent.h>
32#include <getopt.h> 32#include <getopt.h>
33 33
34#include "paxelf.h" 34#include "paxelf.h"
35 35
36static const char *rcsid = "$Id: scanelf.c,v 1.11 2005/03/31 00:03:25 solar Exp $"; 36static const char *rcsid = "$Id: scanelf.c,v 1.12 2005/03/31 00:50:56 solar Exp $";
37 37
38 38
39/* helper functions for showing errors */ 39/* helper functions for showing errors */
40#define argv0 "scanelf\0" /*((*argv != NULL) ? argv[0] : __FILE__ "\b\b")*/ 40#define argv0 "scanelf\0" /*((*argv != NULL) ? argv[0] : __FILE__ "\b\b")*/
41#define warn(fmt, args...) \ 41#define warn(fmt, args...) \
72 72
73/* scan an elf file and show all the fun stuff */ 73/* scan an elf file and show all the fun stuff */
74static void scanelf_file(const char *filename) 74static void scanelf_file(const char *filename)
75{ 75{
76 int i; 76 int i;
77 char found_stack = 0, found_textrel = 0, found_rpath = 0; 77 char found_stack, found_relro, found_textrel, found_rpath;
78 Elf_Dyn *dyn; 78 Elf_Dyn *dyn;
79 elfobj *elf = NULL; 79 elfobj *elf = NULL;
80
81 found_stack = found_relro = found_textrel = found_rpath = 0;
80 82
81 /* verify this is real ELF */ 83 /* verify this is real ELF */
82 if ((elf = readelf(filename)) == NULL) 84 if ((elf = readelf(filename)) == NULL)
83 return; 85 return;
84 if (check_elf_header(elf->ehdr) || !IS_ELF(elf)) 86 if (check_elf_header(elf->ehdr) || !IS_ELF(elf))
85 goto bail; 87 goto bail;
86 88
87 /* show the header */ 89 /* show the header */
88 if (!be_quiet && show_header) { 90 if (!be_quiet && show_header) {
89 printf("TYPE "); 91 fputs(" TYPE ", stderr);
90 if (show_pax) printf("PAX "); 92 if (show_pax) fputs(" PAX ", stderr);
91 if (show_stack) printf("STACK "); 93 if (show_stack) fputs(" STACK ", stderr);
92 if (show_textrel) printf("TEXTREL "); 94 if (show_textrel) fputs(" TEXTREL ", stderr);
93 if (show_rpath) printf("RPATH "); 95 if (show_rpath) fputs(" RPATH ", stderr);
94 printf("FILE\n"); 96 fputs(" FILE\n", stderr);
95 show_header = 0; 97 show_header = 0;
96 } 98 }
97 99
98 /* dump all the good stuff */ 100 /* dump all the good stuff */
99 if (!be_quiet) 101 if (!be_quiet)
109 elf->phdr[i].p_type != PT_GNU_RELRO) continue; 111 elf->phdr[i].p_type != PT_GNU_RELRO) continue;
110 112
111 if (be_quiet && !(elf->phdr[i].p_flags & PF_X)) 113 if (be_quiet && !(elf->phdr[i].p_flags & PF_X))
112 continue; 114 continue;
113 115
116 if (elf->phdr[i].p_type == PT_GNU_STACK)
114 found_stack = 1; 117 found_stack = 1;
118 if (elf->phdr[i].p_type == PT_GNU_RELRO)
119 found_relro = 1;
120
115 printf("%s ", gnu_short_stack_flags(elf->phdr[i].p_flags)); 121 printf("%s ", gnu_short_stack_flags(elf->phdr[i].p_flags));
116 } 122 }
117 if (!be_quiet && !found_stack) printf("- "); 123 if (!be_quiet && !found_stack) fputs("--- ", stdout);
124 if (!be_quiet && !found_relro) fputs("--- ", stdout);
118 } 125 }
119 126
120 /* textrel fun */ 127 /* textrel fun */
121 if (show_textrel) { 128 if (show_textrel) {
122 for (i = 0; i < elf->ehdr->e_phnum; i++) { 129 for (i = 0; i < elf->ehdr->e_phnum; i++) {
125 dyn = (Elf_Dyn *)(elf->data + elf->phdr[i].p_offset); 132 dyn = (Elf_Dyn *)(elf->data + elf->phdr[i].p_offset);
126 while (dyn->d_tag != DT_NULL) { 133 while (dyn->d_tag != DT_NULL) {
127 if (dyn->d_tag == DT_TEXTREL) { //dyn->d_tag != DT_FLAGS) 134 if (dyn->d_tag == DT_TEXTREL) { //dyn->d_tag != DT_FLAGS)
128 found_textrel = 1; 135 found_textrel = 1;
129// if (dyn->d_un.d_val & DF_TEXTREL) 136// if (dyn->d_un.d_val & DF_TEXTREL)
130 printf("TEXTREL "); 137 fputs("TEXTREL ", stdout);
131 } 138 }
132 ++dyn; 139 ++dyn;
133 } 140 }
134 } 141 }
135 if (!be_quiet && !found_textrel) printf("- "); 142 if (!be_quiet && !found_textrel) fputs("------- ", stdout);
136 } 143 }
137 144
138 /* rpath fun */ 145 /* rpath fun */
139 /* TODO: if be_quiet, only output RPATH's which aren't in /etc/ld.so.conf */ 146 /* TODO: if be_quiet, only output RPATH's which aren't in /etc/ld.so.conf */
140 if (show_rpath) { 147 if (show_rpath) {
152 printf("%s ", rpath); 159 printf("%s ", rpath);
153 } 160 }
154 ++dyn; 161 ++dyn;
155 } 162 }
156 } 163 }
157 if (!be_quiet && !found_rpath) printf("- "); 164 if (!be_quiet && !found_rpath) fputs("- ", stdout);
158 } 165 }
159 166
160 if (!be_quiet || show_pax || found_stack || found_textrel || found_rpath) 167 if (!be_quiet || show_pax || found_stack || found_textrel || found_rpath)
161 printf("%s\n", filename); 168 printf("%s\n", filename);
162 169
292static void usage(int status) 299static void usage(int status)
293{ 300{
294 int i; 301 int i;
295 printf(" Scan ELF binaries for stuff\n\n" 302 printf(" Scan ELF binaries for stuff\n\n"
296 "Usage: %s [options] <dir1> [dir2 dirN ...]\n\n", argv0); 303 "Usage: %s [options] <dir1> [dir2 dirN ...]\n\n", argv0);
297 printf("Options:\n"); 304 fputs("Options:\n", stdout);
298 for (i = 0; long_opts[i].name; ++i) 305 for (i = 0; long_opts[i].name; ++i)
299 printf(" -%c, --%-12s %s\n", long_opts[i].val, 306 printf(" -%c, --%-12s %s\n", long_opts[i].val,
300 long_opts[i].name, opts_help[i]); 307 long_opts[i].name, opts_help[i]);
301 exit(status); 308 exit(status);
302} 309}

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.12

  ViewVC Help
Powered by ViewVC 1.1.20