public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] gentoo-projects commit in pax-utils: dumpelf.c
@ 2011-10-13  4:48 Mike Frysinger (vapier)
  0 siblings, 0 replies; 2+ messages in thread
From: Mike Frysinger (vapier) @ 2011-10-13  4:48 UTC (permalink / raw
  To: gentoo-commits

vapier      11/10/13 04:48:44

  Modified:             dumpelf.c
  Log:
  dumpelf: add support for dumping dynamic tags

Revision  Changes    Path
1.31                 pax-utils/dumpelf.c

file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/dumpelf.c?rev=1.31&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/dumpelf.c?rev=1.31&content-type=text/plain
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/pax-utils/dumpelf.c?r1=1.30&r2=1.31

Index: dumpelf.c
===================================================================
RCS file: /var/cvsroot/gentoo-projects/pax-utils/dumpelf.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- dumpelf.c	27 Sep 2011 19:58:09 -0000	1.30
+++ dumpelf.c	13 Oct 2011 04:48:44 -0000	1.31
@@ -1,13 +1,13 @@
 /*
  * Copyright 2005-2007 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/pax-utils/dumpelf.c,v 1.30 2011/09/27 19:58:09 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/pax-utils/dumpelf.c,v 1.31 2011/10/13 04:48:44 vapier Exp $
  *
  * Copyright 2005-2007 Ned Ludd        - <solar@gentoo.org>
  * Copyright 2005-2007 Mike Frysinger  - <vapier@gentoo.org>
  */
 
-static const char rcsid[] = "$Id: dumpelf.c,v 1.30 2011/09/27 19:58:09 vapier Exp $";
+static const char rcsid[] = "$Id: dumpelf.c,v 1.31 2011/10/13 04:48:44 vapier Exp $";
 const char argv0[] = "dumpelf";
 
 #include "paxinc.h"
@@ -17,8 +17,8 @@
 static void dump_ehdr(elfobj *elf, void *ehdr);
 static void dump_phdr(elfobj *elf, void *phdr, long phdr_cnt);
 static void dump_shdr(elfobj *elf, void *shdr, long shdr_cnt, char *name);
+static void dump_dyn(elfobj *elf, void *dyn, long dyn_cnt);
 #if 0
-static void dump_dyn(elfobj *elf, void *dyn);
 static void dump_sym(elfobj *elf, void *sym);
 static void dump_rel(elfobj *elf, void *rel);
 static void dump_rela(elfobj *elf, void *rela);
@@ -29,11 +29,14 @@
 /* variables to control behavior */
 static char be_verbose = 0;
 
+/* misc dynamic tag caches */
+static void *phdr_dynamic_void = NULL;
+
 /* dump all internal elf info */
 static void dumpelf(const char *filename, long file_cnt)
 {
 	elfobj *elf;
-	unsigned long i;
+	unsigned long i, b;
 
 	/* verify this is real ELF */
 	if ((elf = readelf(filename)) == NULL)
@@ -53,12 +56,19 @@
 #define MAKE_STRUCT(B) \
 	if (elf->elf_class == ELFCLASS ## B) { \
 	Elf ## B ## _Ehdr *ehdr = EHDR ## B (elf->ehdr); \
-	printf("struct {\n" \
-	       "\tElf%1$i_Ehdr ehdr;\n" \
-	       "\tElf%1$i_Phdr phdrs[%3$li];\n" \
-	       "\tElf%1$i_Shdr shdrs[%4$li];\n" \
-	       "} dumpedelf_%2$li = {\n\n", \
-	       B, file_cnt, (long)EGET(ehdr->e_phnum), (long)EGET(ehdr->e_shnum)); \
+	b = B; \
+	printf( \
+		"Elf%1$i_Dyn dumpedelf_dyn_%2$li[];\n" \
+		"struct {\n" \
+		"\tElf%1$i_Ehdr ehdr;\n" \
+		"\tElf%1$i_Phdr phdrs[%3$li];\n" \
+		"\tElf%1$i_Shdr shdrs[%4$li];\n" \
+		"\tElf%1$i_Dyn *dyns;\n" \
+		"} dumpedelf_%2$li = {\n\n", \
+		B, file_cnt, \
+		(long)EGET(ehdr->e_phnum), \
+		(long)EGET(ehdr->e_shnum) \
+	); \
 	}
 	MAKE_STRUCT(32)
 	MAKE_STRUCT(64)
@@ -74,17 +84,15 @@
 		Elf ## B ## _Ehdr *ehdr = EHDR ## B (elf->ehdr); \
 		Elf ## B ## _Phdr *phdr = PHDR ## B (elf->phdr); \
 		uint16_t phnum = EGET(ehdr->e_phnum); \
-		for (i = 0; i < phnum; ++i) { \
-			if (i) printf(",\n"); \
+		for (i = 0; i < phnum; ++i, ++phdr) \
 			dump_phdr(elf, phdr, i); \
-			++phdr; \
-		} }
+		}
 		DUMP_PHDRS(32)
 		DUMP_PHDRS(64)
 	} else {
 		printf(" /* no program headers ! */ ");
 	}
-	printf("\n},\n");
+	printf("},\n");
 
 	/* dump the section headers */
 	printf("\n.shdrs = {\n");
@@ -96,20 +104,40 @@
 		uint16_t shstrndx = EGET(ehdr->e_shstrndx); \
 		Elf ## B ## _Off offset = EGET(shdr[shstrndx].sh_offset); \
 		uint16_t shnum = EGET(ehdr->e_shnum); \
-		for (i = 0; i < shnum; ++i) { \
-			if (i) printf(",\n"); \
+		for (i = 0; i < shnum; ++i, ++shdr) \
 			dump_shdr(elf, shdr, i, elf->vdata + offset + EGET(shdr->sh_name)); \
-			++shdr; \
-		} }
+		}
 		DUMP_SHDRS(32)
 		DUMP_SHDRS(64)
 	} else {
 		printf(" /* no section headers ! */ ");
 	}
-	printf("\n}\n");
+	printf("},\n");
 
-	/* finish the namespace struct and get out of here */
+	/* finish the namespace struct and start the abitrary ones */
+	printf("\n.dyns = dumpedelf_dyn_%li,\n", file_cnt);
+	printf("};\n");
+
+	/* start the arbitrary structs */
+	printf("Elf%lu_Dyn dumpedelf_dyn_%li[] = {\n", b, file_cnt);
+	if (phdr_dynamic_void) {
+#define DUMP_DYNS(B) \
+		if (elf->elf_class == ELFCLASS ## B) { \
+		Elf ## B ## _Phdr *phdr = phdr_dynamic_void; \
+		Elf ## B ## _Dyn *dyn = elf->vdata + EGET(phdr->p_offset); \
+		i = 0; \
+		do { \
+			dump_dyn(elf, dyn++, i++); \
+		} while (EGET(dyn->d_tag) != DT_NULL); \
+		}
+		DUMP_DYNS(32)
+		DUMP_DYNS(64)
+	} else {
+		printf(" /* no dynamic tags ! */ ");
+	}
 	printf("};\n");
+
+	/* get out of here */
 	unreadelf(elf);
 }
 static void dump_ehdr(elfobj *elf, void *ehdr_void)
@@ -160,6 +188,9 @@
 #define DUMP_PHDR(B) \
 	if (elf->elf_class == ELFCLASS ## B) { \
 	Elf ## B ## _Phdr *phdr = PHDR ## B (phdr_void); \
+	switch (EGET(phdr->p_type)) { \
+	case PT_DYNAMIC: phdr_dynamic_void = phdr_void; break; \
+	} \
 	printf("/* Program Header #%li 0x%lX */\n{\n", phdr_cnt, (unsigned long)phdr_void - (unsigned long)elf->data); \
 	printf("\t.p_type   = %-10li , /* [%s] */\n", (long)EGET(phdr->p_type), get_elfptype(EGET(phdr->p_type))); \
 	printf("\t.p_offset = %-10li ,\n", (long)EGET(phdr->p_offset)); \
@@ -169,7 +200,7 @@
 	printf("\t.p_memsz  = %-10li ,\n", (long)EGET(phdr->p_memsz)); \
 	printf("\t.p_flags  = %-10li ,\n", (long)EGET(phdr->p_flags)); \
 	printf("\t.p_align  = %-10li\n", (long)EGET(phdr->p_align)); \
-	printf("}"); \
+	printf("},\n"); \
 	}
 	DUMP_PHDR(32)
 	DUMP_PHDR(64)
@@ -257,11 +288,29 @@
 		} \
 		} \
 	} \
-	printf("}"); \
+	printf("},\n"); \
 	}
 	DUMP_SHDR(32)
 	DUMP_SHDR(64)
 }
+static void dump_dyn(elfobj *elf, void *dyn_void, long dyn_cnt)
+{
+#define DUMP_DYN(B) \
+	if (elf->elf_class == ELFCLASS ## B) { \
+	Elf ## B ## _Dyn *dyn = dyn_void; \
+	unsigned long tag = EGET(dyn->d_tag); \
+	printf("/* Dynamic tag #%li '%s' 0x%lX */\n{\n", \
+	       dyn_cnt, get_elfdtype(tag), (unsigned long)dyn_void - (unsigned long)elf->data); \
+	printf("\t.d_tag     = 0x%-8lX ,\n", tag); \
+	printf("\t.d_un      = {\n"); \
+	printf("\t\t.d_val = 0x%-8lX ,\n", (unsigned long)EGET(dyn->d_un.d_val)); \
+	printf("\t\t.d_ptr = 0x%-8lX ,\n", (unsigned long)EGET(dyn->d_un.d_val)); \
+	printf("\t},\n"); \
+	printf("},\n"); \
+	}
+	DUMP_DYN(32)
+	DUMP_DYN(64)
+}
 
 /* usage / invocation handling functions */
 #define PARSE_FLAGS "vhV"






^ permalink raw reply	[flat|nested] 2+ messages in thread
* [gentoo-commits] gentoo-projects commit in pax-utils: dumpelf.c
@ 2009-12-01  5:48 Mike Frysinger (vapier)
  0 siblings, 0 replies; 2+ messages in thread
From: Mike Frysinger (vapier) @ 2009-12-01  5:48 UTC (permalink / raw
  To: gentoo-commits

vapier      09/12/01 05:48:18

  Modified:             dumpelf.c
  Log:
  avoid using reserved keyword "bool"

Revision  Changes    Path
1.25                 pax-utils/dumpelf.c

file : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/dumpelf.c?rev=1.25&view=markup
plain: http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/dumpelf.c?rev=1.25&content-type=text/plain
diff : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/dumpelf.c?r1=1.24&r2=1.25

Index: dumpelf.c
===================================================================
RCS file: /var/cvsroot/gentoo-projects/pax-utils/dumpelf.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- dumpelf.c	17 Jan 2008 04:37:19 -0000	1.24
+++ dumpelf.c	1 Dec 2009 05:48:18 -0000	1.25
@@ -1,13 +1,13 @@
 /*
  * Copyright 2005-2007 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/pax-utils/dumpelf.c,v 1.24 2008/01/17 04:37:19 solar Exp $
+ * $Header: /var/cvsroot/gentoo-projects/pax-utils/dumpelf.c,v 1.25 2009/12/01 05:48:18 vapier Exp $
  *
  * Copyright 2005-2007 Ned Ludd        - <solar@gentoo.org>
  * Copyright 2005-2007 Mike Frysinger  - <vapier@gentoo.org>
  */
 
-static const char *rcsid = "$Id: dumpelf.c,v 1.24 2008/01/17 04:37:19 solar Exp $";
+static const char *rcsid = "$Id: dumpelf.c,v 1.25 2009/12/01 05:48:18 vapier Exp $";
 const char * const argv0 = "dumpelf";
 
 #include "paxinc.h"
@@ -206,19 +206,19 @@
 				break; \
 		} \
 		case SHT_STRTAB: { \
-			char bool; \
+			char b; \
 			printf("\n\t/%c section dump:\n", '*'); \
-			bool = 1; \
+			b = 1; \
 			if (type == SHT_PROGBITS) --data; \
 			for (i = 0; i < size; ++i) { \
 				++data; \
 				if (*data) { \
-					if (bool) printf("\t * "); \
+					if (b) printf("\t * "); \
 					printf("%c", *data); \
-					bool = 0; \
-				} else if (!bool) { \
+					b = 0; \
+				} else if (!b) { \
 					printf("\n"); \
-					bool = 1; \
+					b = 1; \
 				} \
 			} \
 			printf("\t */\n"); \






^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-10-13  4:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-13  4:48 [gentoo-commits] gentoo-projects commit in pax-utils: dumpelf.c Mike Frysinger (vapier)
  -- strict thread matches above, loose matches on Subject: below --
2009-12-01  5:48 Mike Frysinger (vapier)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox