aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony G. Basile <blueness@gentoo.org>2011-07-07 21:32:45 -0400
committerAnthony G. Basile <blueness@gentoo.org>2011-07-07 21:32:45 -0400
commitf0351e512de6fbac32d4f04fcbaf2607910b7604 (patch)
treea55e4a73b10f6b49a626536cf9fb16aeafea6238
parentMoved miscellaneous code in its own directory (diff)
downloadelfix-f0351e512de6fbac32d4f04fcbaf2607910b7604.tar.gz
elfix-f0351e512de6fbac32d4f04fcbaf2607910b7604.tar.bz2
elfix-f0351e512de6fbac32d4f04fcbaf2607910b7604.zip
misc/*.c: fixed cycling over section data
-rw-r--r--misc/Makefile2
-rw-r--r--misc/clear-dt-path.c21
-rw-r--r--misc/parse-elf.c7
-rw-r--r--misc/print-sections.c28
4 files changed, 34 insertions, 24 deletions
diff --git a/misc/Makefile b/misc/Makefile
index 0434bb6..8918c54 100644
--- a/misc/Makefile
+++ b/misc/Makefile
@@ -4,4 +4,4 @@ all: clear-dt-path parse-elf print-sections
gcc -o $@ $^ -lelf
clean:
- rm -rf parse-elf print-sections
+ rm -rf clear-dt-path parse-elf print-sections
diff --git a/misc/clear-dt-path.c b/misc/clear-dt-path.c
index ca0117d..ae5ff9a 100644
--- a/misc/clear-dt-path.c
+++ b/misc/clear-dt-path.c
@@ -48,21 +48,24 @@ int main( int argc, char *argv[])
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");
- }
+ data = NULL;
+ while((data = elf_getdata(scn, data)) != NULL)
+ {
+ 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");
+ }
+ }
}
}
diff --git a/misc/parse-elf.c b/misc/parse-elf.c
index c18d277..1ba8024 100644
--- a/misc/parse-elf.c
+++ b/misc/parse-elf.c
@@ -206,7 +206,11 @@ int main( int argc, char *argv[])
shdr.sh_entsize
);
- if((data = elf_getdata(scn, data)) != NULL)
+ if(shdr.sh_type == SHT_NOBITS)
+ continue;
+
+ data = NULL;
+ while((data = elf_getdata(scn, data)) != NULL)
{
printf("\n ***** DATA ***** \n");
printf( "Data:\t\t%s\nType:\t\t%d\nSize:\t\t%lu\n"
@@ -220,7 +224,6 @@ int main( int argc, char *argv[])
);
}
printf("\n\n");
-
}
diff --git a/misc/print-sections.c b/misc/print-sections.c
index 1209077..ba8d4ee 100644
--- a/misc/print-sections.c
+++ b/misc/print-sections.c
@@ -1,21 +1,22 @@
-#include <stdio.h> // printf
-#include <stdlib.h> // EXIT_FAILURE
-#include <error.h> // error
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <error.h>
-#include <gelf.h> // elf_* and gelf_*
+#include <gelf.h>
-#include <sys/types.h> // open
+#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
-#include <unistd.h> // close
+#include <unistd.h>
int main( int argc, char *argv[])
{
int fd, cmd;
size_t i;
- char *p;
+ char shname[1024];
Elf *arf, *elf;
GElf_Ehdr ehdr;
@@ -47,16 +48,20 @@ int main( int argc, char *argv[])
while((scn = elf_nextscn(elf, scn)) != NULL)
{
gelf_getshdr(scn, &shdr);
- printf("Section name: %s\n", elf_strptr(elf, ehdr.e_shstrndx, shdr.sh_name));
- if( elf_getdata(scn, NULL) == NULL)
- printf("no data\n");
+ strcpy(shname, elf_strptr(elf, ehdr.e_shstrndx, shdr.sh_name));
+ printf("%s\n", shname);
/*
+ if( !strcmp(shname, ".bss") || !strcmp(shname, ".tbss") )
+ continue;
+ */
+ if(shdr.sh_type == SHT_NOBITS)
+ continue;
+
data = NULL;
while((data = elf_getdata(scn, data)) != NULL)
{
- printf("%2x\n", data);
printf( "Type:\t\t%d\nSize:\t\t%lu\n"
"Off:\t\t%lu\nAlign:\t\t%lu\nVersion:\t%u\n",
data->d_type,
@@ -75,7 +80,6 @@ int main( int argc, char *argv[])
}
printf("\n\n");
- */
}
}