readelf.c (14a345d92143e15a6769d0bb29b46c1a0b713528) | readelf.c (802c2095b5a6dcf0f63c473cbba1e40445e9052a) |
---|---|
1/*- 2 * Copyright (c) 2009-2015 Kai Wang 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 12 unchanged lines hidden (view full) --- 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/param.h> 28#include <sys/queue.h> | 1/*- 2 * Copyright (c) 2009-2015 Kai Wang 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 12 unchanged lines hidden (view full) --- 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/param.h> 28#include <sys/queue.h> |
29 |
|
29#include <ar.h> 30#include <assert.h> | 30#include <ar.h> 31#include <assert.h> |
32#include <capsicum_helpers.h> |
|
31#include <ctype.h> 32#include <dwarf.h> 33#include <err.h> 34#include <fcntl.h> 35#include <gelf.h> 36#include <getopt.h> 37#include <libdwarf.h> 38#include <libelftc.h> 39#include <libgen.h> 40#include <stdarg.h> 41#include <stdint.h> 42#include <stdio.h> 43#include <stdlib.h> 44#include <string.h> 45#include <time.h> 46#include <unistd.h> 47 | 33#include <ctype.h> 34#include <dwarf.h> 35#include <err.h> 36#include <fcntl.h> 37#include <gelf.h> 38#include <getopt.h> 39#include <libdwarf.h> 40#include <libelftc.h> 41#include <libgen.h> 42#include <stdarg.h> 43#include <stdint.h> 44#include <stdio.h> 45#include <stdlib.h> 46#include <string.h> 47#include <time.h> 48#include <unistd.h> 49 |
50#include <libcasper.h> 51#include <casper/cap_fileargs.h> 52 |
|
48#include "_elftc.h" 49 50ELFTC_VCSID("$Id: readelf.c 3649 2018-11-24 03:26:23Z emaste $"); 51 52/* Backwards compatability for older FreeBSD releases. */ 53#ifndef STB_GNU_UNIQUE 54#define STB_GNU_UNIQUE 10 55#endif --- 7153 unchanged lines hidden (view full) --- 7209 next_member: 7210 cmd = elf_next(re->elf); 7211 elf_end(re->elf); 7212 } 7213 re->elf = re->ar; 7214} 7215 7216static void | 53#include "_elftc.h" 54 55ELFTC_VCSID("$Id: readelf.c 3649 2018-11-24 03:26:23Z emaste $"); 56 57/* Backwards compatability for older FreeBSD releases. */ 58#ifndef STB_GNU_UNIQUE 59#define STB_GNU_UNIQUE 10 60#endif --- 7153 unchanged lines hidden (view full) --- 7214 next_member: 7215 cmd = elf_next(re->elf); 7216 elf_end(re->elf); 7217 } 7218 re->elf = re->ar; 7219} 7220 7221static void |
7217dump_object(struct readelf *re) | 7222dump_object(struct readelf *re, int fd) |
7218{ | 7223{ |
7219 int fd; 7220 7221 if ((fd = open(re->filename, O_RDONLY)) == -1) { 7222 warn("open %s failed", re->filename); 7223 return; 7224 } 7225 | |
7226 if ((re->flags & DISPLAY_FILENAME) != 0) 7227 printf("\nFile: %s\n", re->filename); 7228 7229 if ((re->elf = elf_begin(fd, ELF_C_READ, NULL)) == NULL) { 7230 warnx("elf_begin() failed: %s", elf_errmsg(-1)); 7231 return; 7232 } 7233 --- 350 unchanged lines hidden (view full) --- 7584{ 7585 fprintf(stderr, USAGE_MESSAGE, ELFTC_GETPROGNAME()); 7586 exit(status); 7587} 7588 7589int 7590main(int argc, char **argv) 7591{ | 7224 if ((re->flags & DISPLAY_FILENAME) != 0) 7225 printf("\nFile: %s\n", re->filename); 7226 7227 if ((re->elf = elf_begin(fd, ELF_C_READ, NULL)) == NULL) { 7228 warnx("elf_begin() failed: %s", elf_errmsg(-1)); 7229 return; 7230 } 7231 --- 350 unchanged lines hidden (view full) --- 7582{ 7583 fprintf(stderr, USAGE_MESSAGE, ELFTC_GETPROGNAME()); 7584 exit(status); 7585} 7586 7587int 7588main(int argc, char **argv) 7589{ |
7590 cap_rights_t rights; 7591 fileargs_t *fa; |
|
7592 struct readelf *re, re_storage; 7593 unsigned long si; | 7592 struct readelf *re, re_storage; 7593 unsigned long si; |
7594 int opt, i; | 7594 int fd, opt, i; |
7595 char *ep; 7596 7597 re = &re_storage; 7598 memset(re, 0, sizeof(*re)); 7599 STAILQ_INIT(&re->v_dumpop); 7600 7601 while ((opt = getopt_long(argc, argv, "AacDdegHhIi:lNnp:rSstuVvWw::x:", 7602 longopts, NULL)) != -1) { --- 106 unchanged lines hidden (view full) --- 7709 7710 if (argc > 1) 7711 re->flags |= DISPLAY_FILENAME; 7712 7713 if (elf_version(EV_CURRENT) == EV_NONE) 7714 errx(EXIT_FAILURE, "ELF library initialization failed: %s", 7715 elf_errmsg(-1)); 7716 | 7595 char *ep; 7596 7597 re = &re_storage; 7598 memset(re, 0, sizeof(*re)); 7599 STAILQ_INIT(&re->v_dumpop); 7600 7601 while ((opt = getopt_long(argc, argv, "AacDdegHhIi:lNnp:rSstuVvWw::x:", 7602 longopts, NULL)) != -1) { --- 106 unchanged lines hidden (view full) --- 7709 7710 if (argc > 1) 7711 re->flags |= DISPLAY_FILENAME; 7712 7713 if (elf_version(EV_CURRENT) == EV_NONE) 7714 errx(EXIT_FAILURE, "ELF library initialization failed: %s", 7715 elf_errmsg(-1)); 7716 |
7717 cap_rights_init(&rights, CAP_FCNTL, CAP_FSTAT, CAP_MMAP_R, CAP_SEEK); 7718 fa = fileargs_init(argc, argv, O_RDONLY, 0, &rights, FA_OPEN); 7719 if (fa == NULL) 7720 err(1, "Unable to initialize casper fileargs"); 7721 7722 caph_cache_catpages(); 7723 if (caph_limit_stdio() < 0) { 7724 fileargs_free(fa); 7725 err(1, "Unable to limit stdio rights"); 7726 } 7727 if (caph_enter_casper() < 0) { 7728 fileargs_free(fa); 7729 err(1, "Unable to enter capability mode"); 7730 } 7731 |
|
7717 for (i = 0; i < argc; i++) { 7718 re->filename = argv[i]; | 7732 for (i = 0; i < argc; i++) { 7733 re->filename = argv[i]; |
7719 dump_object(re); | 7734 fd = fileargs_open(fa, re->filename); 7735 if (fd < 0) 7736 warn("open %s failed", re->filename); 7737 else 7738 dump_object(re, fd); |
7720 } 7721 7722 exit(EXIT_SUCCESS); 7723} | 7739 } 7740 7741 exit(EXIT_SUCCESS); 7742} |