/[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.59 Revision 1.60
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.59 2005/05/25 21:58:03 vapier Exp $ 5 * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.60 2005/05/27 02:58:39 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
22 */ 22 */
23 23
24#include <stdio.h> 24#include <stdio.h>
25#include <stdlib.h> 25#include <stdlib.h>
26#include <sys/types.h> 26#include <sys/types.h>
27#include <libgen.h>
28#include <limits.h>
27#define __USE_GNU 29#define __USE_GNU
28#include <string.h> 30#include <string.h>
29#include <errno.h> 31#include <errno.h>
30#include <unistd.h> 32#include <unistd.h>
31#include <sys/stat.h> 33#include <sys/stat.h>
33#include <getopt.h> 35#include <getopt.h>
34#include <assert.h> 36#include <assert.h>
35 37
36#include "paxelf.h" 38#include "paxelf.h"
37 39
38static const char *rcsid = "$Id: scanelf.c,v 1.59 2005/05/25 21:58:03 vapier Exp $"; 40static const char *rcsid = "$Id: scanelf.c,v 1.60 2005/05/27 02:58:39 vapier Exp $";
39#define argv0 "scanelf" 41#define argv0 "scanelf"
40 42
41 43
42 44
43/* prototypes */ 45/* prototypes */
45static void scanelf_dir(const char *path); 47static void scanelf_dir(const char *path);
46static void scanelf_ldpath(); 48static void scanelf_ldpath();
47static void scanelf_envpath(); 49static void scanelf_envpath();
48static void usage(int status); 50static void usage(int status);
49static void parseargs(int argc, char *argv[]); 51static void parseargs(int argc, char *argv[]);
50static char *xstrdup(char *s); 52static char *xstrdup(const char *s);
51static void *xmalloc(size_t size); 53static void *xmalloc(size_t size);
52static void xstrcat(char **dst, const char *src, size_t *curr_len); 54static void xstrcat(char **dst, const char *src, size_t *curr_len);
53static inline void xchrcat(char **dst, const char append, size_t *curr_len); 55static inline void xchrcat(char **dst, const char append, size_t *curr_len);
54 56
55/* variables to control behavior */ 57/* variables to control behavior */
184 Elf ## B ## _Dyn *dyn; \ 186 Elf ## B ## _Dyn *dyn; \
185 Elf ## B ## _Ehdr *ehdr = EHDR ## B (elf->ehdr); \ 187 Elf ## B ## _Ehdr *ehdr = EHDR ## B (elf->ehdr); \
186 Elf ## B ## _Phdr *phdr = PHDR ## B (elf->phdr); \ 188 Elf ## B ## _Phdr *phdr = PHDR ## B (elf->phdr); \
187 Elf ## B ## _Shdr *strtbl = SHDR ## B (strtbl_void); \ 189 Elf ## B ## _Shdr *strtbl = SHDR ## B (strtbl_void); \
188 Elf ## B ## _Off offset; \ 190 Elf ## B ## _Off offset; \
189 Elf ## B ## _Sxword word; \ 191 Elf ## B ## _Xword word; \
190 /* Scan all the program headers */ \ 192 /* Scan all the program headers */ \
191 for (i = 0; i < EGET(ehdr->e_phnum); i++) { \ 193 for (i = 0; i < EGET(ehdr->e_phnum); i++) { \
192 /* Just scan dynamic headers */ \ 194 /* Just scan dynamic headers */ \
193 if (EGET(phdr[i].p_type) != PT_DYNAMIC) continue; \ 195 if (EGET(phdr[i].p_type) != PT_DYNAMIC) continue; \
194 offset = EGET(phdr[i].p_offset); \ 196 offset = EGET(phdr[i].p_offset); \
353 355
354 symtab_void = elf_findsecbyname(elf, ".symtab"); 356 symtab_void = elf_findsecbyname(elf, ".symtab");
355 strtab_void = elf_findsecbyname(elf, ".strtab"); 357 strtab_void = elf_findsecbyname(elf, ".strtab");
356 358
357 if (symtab_void && strtab_void) { 359 if (symtab_void && strtab_void) {
360 char *base, *basemem;
361 basemem = xstrdup(filename);
362 base = basename(basemem);
358#define FIND_SYM(B) \ 363#define FIND_SYM(B) \
359 if (elf->elf_class == ELFCLASS ## B) { \ 364 if (elf->elf_class == ELFCLASS ## B) { \
360 Elf ## B ## _Shdr *symtab = SHDR ## B (symtab_void); \ 365 Elf ## B ## _Shdr *symtab = SHDR ## B (symtab_void); \
361 Elf ## B ## _Shdr *strtab = SHDR ## B (strtab_void); \ 366 Elf ## B ## _Shdr *strtab = SHDR ## B (strtab_void); \
362 Elf ## B ## _Sym *sym = SYM ## B (elf->data + EGET(symtab->sh_offset)); \ 367 Elf ## B ## _Sym *sym = SYM ## B (elf->data + EGET(symtab->sh_offset)); \
366 if (sym->st_name) { \ 371 if (sym->st_name) { \
367 symname = (char *)(elf->data + EGET(strtab->sh_offset) + EGET(sym->st_name)); \ 372 symname = (char *)(elf->data + EGET(strtab->sh_offset) + EGET(sym->st_name)); \
368 if (*find_sym == '*') { \ 373 if (*find_sym == '*') { \
369 printf("%s(%s) %5lX %15s %s\n", \ 374 printf("%s(%s) %5lX %15s %s\n", \
370 ((*found_sym == 0) ? "\n\t" : "\t"), \ 375 ((*found_sym == 0) ? "\n\t" : "\t"), \
371 (char *)basename(filename), \ 376 base, \
372 (long)sym->st_size, \ 377 (long)sym->st_size, \
373 (char *)get_elfstttype(sym->st_info), \ 378 (char *)get_elfstttype(sym->st_info), \
374 symname); \ 379 symname); \
375 *found_sym = 1; \ 380 *found_sym = 1; \
376 } else if ((strcmp(find_sym, symname) == 0) || \ 381 } else if ((strcmp(find_sym, symname) == 0) || \
379 } \ 384 } \
380 ++sym; \ 385 ++sym; \
381 } } 386 } }
382 FIND_SYM(32) 387 FIND_SYM(32)
383 FIND_SYM(64) 388 FIND_SYM(64)
389 free(basemem);
384 } 390 }
385 if (*find_sym != '*' && *found_sym) 391 if (*find_sym != '*' && *found_sym)
386 return find_sym; 392 return find_sym;
387 if (be_quiet) 393 if (be_quiet)
388 return NULL; 394 return NULL;
875} 881}
876 882
877 883
878 884
879/* utility funcs */ 885/* utility funcs */
880static char *xstrdup(char *s) 886static char *xstrdup(const char *s)
881{ 887{
882 char *ret = strdup(s); 888 char *ret = strdup(s);
883 if (!ret) err("Could not strdup(): %s", strerror(errno)); 889 if (!ret) err("Could not strdup(): %s", strerror(errno));
884 return ret; 890 return ret;
885} 891}

Legend:
Removed from v.1.59  
changed lines
  Added in v.1.60

  ViewVC Help
Powered by ViewVC 1.1.20