aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony G. Basile <blueness@gentoo.org>2011-07-07 18:37:14 -0400
committerAnthony G. Basile <blueness@gentoo.org>2011-07-07 18:37:14 -0400
commit2982988deb7765487e1cd6b61382adf09ebb991d (patch)
treea83acf2bfd05f9dc6a47a842655fd007530525e5 /misc/clear-dt-path.c
parentsrc/fix-gnustack.c: minor syntactic change (diff)
downloadelfix-2982988deb7765487e1cd6b61382adf09ebb991d.tar.gz
elfix-2982988deb7765487e1cd6b61382adf09ebb991d.tar.bz2
elfix-2982988deb7765487e1cd6b61382adf09ebb991d.zip
Moved miscellaneous code in its own directory
Diffstat (limited to 'misc/clear-dt-path.c')
-rw-r--r--misc/clear-dt-path.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/misc/clear-dt-path.c b/misc/clear-dt-path.c
new file mode 100644
index 0000000..ca0117d
--- /dev/null
+++ b/misc/clear-dt-path.c
@@ -0,0 +1,77 @@
+
+#include <stdio.h> // printf
+#include <stdlib.h> // EXIT_FAILURE
+#include <error.h> // error
+
+#include <gelf.h> // elf_* and gelf_*
+
+#include <sys/types.h> // open
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h> // close
+
+
+int main( int argc, char *argv[])
+{
+ int fd, cmd;
+ size_t i, n;
+ char *p;
+
+ Elf *arf, *elf;
+ GElf_Ehdr ehdr;
+ Elf_Scn *scn;
+ GElf_Shdr shdr;
+ Elf_Data *data;
+ GElf_Dyn dyn;
+
+ if(elf_version(EV_CURRENT) == EV_NONE)
+ error(EXIT_FAILURE, 0, "Library out of date.");
+
+ if(argc != 2)
+ error(EXIT_FAILURE, 0, "Usage: %s <filename>", argv[0]);
+
+ if((fd = open(argv[1], O_RDONLY)) == -1)
+ error(EXIT_FAILURE, 0, "Failed open file.");
+
+
+ cmd = ELF_C_READ;
+
+ if((arf = elf_begin(fd, cmd, (Elf *)0)) == NULL)
+ error(EXIT_FAILURE, 0, "Failed open elf: %s", elf_errmsg ( -1));
+
+
+ while((elf = elf_begin(fd, cmd, arf)) != NULL)
+ {
+ if(gelf_getehdr(elf,&ehdr) != NULL)
+ {
+ scn = NULL;
+ while((scn = elf_nextscn(elf, scn)) != NULL)
+ {
+ gelf_getshdr(scn, &shdr);
+ data = elf_getdata(scn, NULL);
+
+ if(shdr.sh_type != SHT_DYNAMIC)
+ continue;
+
+ printf("Section name: %s\n", elf_strptr(elf, ehdr.e_shstrndx, shdr.sh_name));
+
+ if(data != NULL)
+ for( i=0; gelf_getdyn(data, i, &dyn) != NULL; i++)
+ {
+ if(dyn.d_tag == DT_RPATH)
+ printf("DT_RPATH found\n");
+ if(dyn.d_tag == DT_RUNPATH)
+ printf("DT_RUNPATH found\n");
+ }
+ }
+ }
+
+ cmd = elf_next(elf);
+ elf_end(elf);
+
+ }
+
+ elf_end(arf);
+
+ close(fd);
+}