/[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.22 Revision 1.23
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.22 2005/04/03 18:03:22 vapier Exp $ 5 * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.23 2005/04/03 18:27:45 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
32#include <getopt.h> 32#include <getopt.h>
33#include <assert.h> 33#include <assert.h>
34 34
35#include "paxelf.h" 35#include "paxelf.h"
36 36
37static const char *rcsid = "$Id: scanelf.c,v 1.22 2005/04/03 18:03:22 vapier Exp $"; 37static const char *rcsid = "$Id: scanelf.c,v 1.23 2005/04/03 18:27:45 vapier Exp $";
38 38
39 39
40/* helper functions for showing errors */ 40/* helper functions for showing errors */
41#define argv0 "scanelf" /*((*argv != NULL) ? argv[0] : __FILE__ "\b\b")*/ 41#define argv0 "scanelf" /*((*argv != NULL) ? argv[0] : __FILE__ "\b\b")*/
42#define warn(fmt, args...) \ 42#define warn(fmt, args...) \
91 91
92 if (be_verbose) printf("%s: scanning file\n", filename); 92 if (be_verbose) printf("%s: scanning file\n", filename);
93 93
94 /* show the header */ 94 /* show the header */
95 if (!be_quiet && show_banner) { 95 if (!be_quiet && show_banner) {
96 fputs(" TYPE ", stdout); 96 printf(" TYPE ");
97 if (show_pax) fputs(" PAX ", stdout); 97 if (show_pax) printf(" PAX ");
98 if (show_stack) fputs(" STK/REL ", stdout); 98 if (show_stack) printf(" STK/REL ");
99 if (show_textrel) fputs("TEXTREL ", stdout); 99 if (show_textrel) printf("TEXTREL ");
100 if (show_rpath) fputs("RPATH ", stdout); 100 if (show_rpath) printf("RPATH ");
101 fputs(" FILE\n", stdout); 101 printf(" FILE\n");
102 show_banner = 0; 102 show_banner = 0;
103 } 103 }
104 104
105 /* dump all the good stuff */ 105 /* dump all the good stuff */
106 if (!be_quiet) 106 if (!be_quiet)
128 if (elf->phdr[i].p_type == PT_GNU_RELRO) 128 if (elf->phdr[i].p_type == PT_GNU_RELRO)
129 found_relro = 1; 129 found_relro = 1;
130 130
131 printf("%s ", gnu_short_stack_flags(elf->phdr[i].p_flags)); 131 printf("%s ", gnu_short_stack_flags(elf->phdr[i].p_flags));
132 } 132 }
133 if (!be_quiet && !found_stack) fputs("--- ", stdout); 133 if (!be_quiet && !found_stack) printf("--- ");
134 if (!be_quiet && !found_relro) fputs("--- ", stdout); 134 if (!be_quiet && !found_relro) printf("--- ");
135 } 135 }
136 136
137 /* textrel fun */ 137 /* textrel fun */
138 if (show_textrel) { 138 if (show_textrel) {
139 for (i = 0; i < elf->ehdr->e_phnum; i++) { 139 for (i = 0; i < elf->ehdr->e_phnum; i++) {
142 dyn = (Elf_Dyn *)(elf->data + elf->phdr[i].p_offset); 142 dyn = (Elf_Dyn *)(elf->data + elf->phdr[i].p_offset);
143 while (dyn->d_tag != DT_NULL) { 143 while (dyn->d_tag != DT_NULL) {
144 if (dyn->d_tag == DT_TEXTREL) { //dyn->d_tag != DT_FLAGS) 144 if (dyn->d_tag == DT_TEXTREL) { //dyn->d_tag != DT_FLAGS)
145 found_textrel = 1; 145 found_textrel = 1;
146// if (dyn->d_un.d_val & DF_TEXTREL) 146// if (dyn->d_un.d_val & DF_TEXTREL)
147 fputs("TEXTREL ", stdout); 147 printf("TEXTREL ");
148 } 148 }
149 ++dyn; 149 ++dyn;
150 } 150 }
151 } 151 }
152 if (!be_quiet && !found_textrel) fputs("------- ", stdout); 152 if (!be_quiet && !found_textrel) printf("------- ");
153 } 153 }
154 154
155 /* rpath fun */ 155 /* rpath fun */
156 /* TODO: if be_quiet, only output RPATH's which aren't in /etc/ld.so.conf */ 156 /* TODO: if be_quiet, only output RPATH's which aren't in /etc/ld.so.conf */
157 if (show_rpath) { 157 if (show_rpath) {
158 char *rpath, *runpath;
158 Elf_Shdr *strtbl = elf_findsecbyname(elf, ".dynstr"); 159 Elf_Shdr *strtbl = elf_findsecbyname(elf, ".dynstr");
160 rpath = runpath = NULL;
159 161
160 if (strtbl) 162 if (strtbl)
161 for (i = 0; i < elf->ehdr->e_phnum; i++) { 163 for (i = 0; i < elf->ehdr->e_phnum; i++) {
162 if (elf->phdr[i].p_type != PT_DYNAMIC) continue; 164 if (elf->phdr[i].p_type != PT_DYNAMIC) continue;
163 165
164 dyn = (Elf_Dyn *)(elf->data + elf->phdr[i].p_offset); 166 dyn = (Elf_Dyn *)(elf->data + elf->phdr[i].p_offset);
165 while (dyn->d_tag != DT_NULL) { 167 while (dyn->d_tag != DT_NULL) {
166 if (dyn->d_tag == DT_RPATH) { //|| dyn->d_tag != DT_RUNPATH) 168 if (dyn->d_tag == DT_RPATH) { //|| dyn->d_tag != DT_RUNPATH)
167 char *rpath = elf->data + strtbl->sh_offset + dyn->d_un.d_ptr; 169 rpath = elf->data + strtbl->sh_offset + dyn->d_un.d_ptr;
168 found_rpath = 1; 170 found_rpath = 1;
169 printf("%s ", rpath); 171 } else if (dyn->d_tag == DT_RUNPATH) {
172 runpath = elf->data + strtbl->sh_offset + dyn->d_un.d_ptr;
173 found_rpath = 1;
170 } 174 }
171 ++dyn; 175 ++dyn;
172 } 176 }
173 } 177 }
174 if (!be_quiet && !found_rpath) fputs(" - ", stdout); 178 if (rpath && runpath) {
179 if (!strcmp(rpath, runpath))
180 printf("%-5s ", runpath);
181 else {
182 fprintf(stderr, "%s's RPATH [%s] != RUNPATH [%s]\n", filename, rpath, runpath);
183 printf("{%s,%s} ", rpath, runpath);
184 }
185 } else if (rpath || runpath)
186 printf("%-5s ", (runpath ? runpath : rpath));
187 else if (!be_quiet && !found_rpath)
188 printf(" - ");
175 } 189 }
176 190
177 if (!be_quiet || found_pax || found_stack || found_textrel || found_rpath) 191 if (!be_quiet || found_pax || found_stack || found_textrel || found_rpath)
178 puts(filename); 192 puts(filename);
179 193
325static void usage(int status) 339static void usage(int status)
326{ 340{
327 int i; 341 int i;
328 printf(" Scan ELF binaries for stuff\n\n" 342 printf(" Scan ELF binaries for stuff\n\n"
329 "Usage: %s [options] <dir1> [dir2 dirN ...]\n\n", argv0); 343 "Usage: %s [options] <dir1> [dir2 dirN ...]\n\n", argv0);
330 fputs("Options:\n", stdout); 344 printf("Options:\n");
331 for (i = 0; long_opts[i].name; ++i) 345 for (i = 0; long_opts[i].name; ++i)
332 printf(" -%c, --%-12s %s\n", long_opts[i].val, 346 printf(" -%c, --%-12s %s\n", long_opts[i].val,
333 long_opts[i].name, opts_help[i]); 347 long_opts[i].name, opts_help[i]);
334#ifdef MANLYPAGE 348#ifdef MANLYPAGE
335 for (i = 0; long_opts[i].name; ++i) 349 for (i = 0; long_opts[i].name; ++i)

Legend:
Removed from v.1.22  
changed lines
  Added in v.1.23

  ViewVC Help
Powered by ViewVC 1.1.20