|
@@ -9,11 +9,21 @@
|
|
#include <errno.h>
|
|
#include <errno.h>
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
#ifdef HAVE_CONFIG_H
|
|
-#include "config.h"
|
|
|
|
|
|
+# include "config.h"
|
|
#endif
|
|
#endif
|
|
#include "readelf.h"
|
|
#include "readelf.h"
|
|
#include "file.h"
|
|
#include "file.h"
|
|
|
|
|
|
|
|
+#ifndef lint
|
|
|
|
+FILE_RCSID("@(#)$Id: readelf.c,v 1.9 1998/09/12 13:21:01 christos Exp $")
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
+#ifdef ELFCORE
|
|
|
|
+static void dophn_core __P((int, off_t, int, size_t, char *));
|
|
|
|
+#endif
|
|
|
|
+static void dophn_exec __P((int, off_t, int, size_t, char *));
|
|
|
|
+static void doshn __P((int, off_t, int, size_t, char *));
|
|
|
|
+
|
|
static void
|
|
static void
|
|
doshn(fd, off, num, size, buf)
|
|
doshn(fd, off, num, size, buf)
|
|
int fd;
|
|
int fd;
|
|
@@ -61,6 +71,8 @@ dophn_exec(fd, off, num, size, buf)
|
|
{
|
|
{
|
|
/* I am not sure if this works for 64 bit elf formats */
|
|
/* I am not sure if this works for 64 bit elf formats */
|
|
Elf32_Phdr *ph = (Elf32_Phdr *) buf;
|
|
Elf32_Phdr *ph = (Elf32_Phdr *) buf;
|
|
|
|
+ char *linking_style = "statically";
|
|
|
|
+ char *shared_libraries = "";
|
|
|
|
|
|
if (lseek(fd, off, SEEK_SET) == -1)
|
|
if (lseek(fd, off, SEEK_SET) == -1)
|
|
error("lseek failed (%s).\n", strerror(errno));
|
|
error("lseek failed (%s).\n", strerror(errno));
|
|
@@ -68,18 +80,20 @@ dophn_exec(fd, off, num, size, buf)
|
|
for ( ; num; num--) {
|
|
for ( ; num; num--) {
|
|
if (read(fd, buf, size) == -1)
|
|
if (read(fd, buf, size) == -1)
|
|
error("read failed (%s).\n", strerror(errno));
|
|
error("read failed (%s).\n", strerror(errno));
|
|
- if (ph->p_type == PT_INTERP) {
|
|
|
|
- /*
|
|
|
|
- * Has an interpreter - must be a dynamically-linked
|
|
|
|
- * executable.
|
|
|
|
- */
|
|
|
|
- printf(", dynamically linked");
|
|
|
|
- return;
|
|
|
|
|
|
+
|
|
|
|
+ switch (ph->p_type) {
|
|
|
|
+ case PT_DYNAMIC:
|
|
|
|
+ linking_style = "dynamically";
|
|
|
|
+ break;
|
|
|
|
+ case PT_INTERP:
|
|
|
|
+ shared_libraries = " (uses shared libs)";
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- printf(", statically linked");
|
|
|
|
|
|
+ printf(", %s linked%s", linking_style, shared_libraries);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+#ifdef ELFCORE
|
|
size_t prpsoffsets[] = {
|
|
size_t prpsoffsets[] = {
|
|
84, /* SunOS 5.x */
|
|
84, /* SunOS 5.x */
|
|
32, /* Linux */
|
|
32, /* Linux */
|
|
@@ -217,6 +231,7 @@ dophn_core(fd, off, num, size, buf)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+#endif
|
|
|
|
|
|
void
|
|
void
|
|
tryelf(fd, buf, nbytes)
|
|
tryelf(fd, buf, nbytes)
|
|
@@ -235,7 +250,8 @@ tryelf(fd, buf, nbytes)
|
|
* Instead we traverse thru all section headers until a symbol table
|
|
* Instead we traverse thru all section headers until a symbol table
|
|
* one is found or else the binary is stripped.
|
|
* one is found or else the binary is stripped.
|
|
*/
|
|
*/
|
|
- if (buf[EI_MAG0] != ELFMAG0 || buf[EI_MAG1] != ELFMAG1
|
|
|
|
|
|
+ if (buf[EI_MAG0] != ELFMAG0
|
|
|
|
+ || (buf[EI_MAG1] != ELFMAG1 && buf[EI_MAG1] != OLFMAG1)
|
|
|| buf[EI_MAG2] != ELFMAG2 || buf[EI_MAG3] != ELFMAG3)
|
|
|| buf[EI_MAG2] != ELFMAG2 || buf[EI_MAG3] != ELFMAG3)
|
|
return;
|
|
return;
|
|
|
|
|
|
@@ -257,13 +273,18 @@ tryelf(fd, buf, nbytes)
|
|
*/
|
|
*/
|
|
if ((u.c[sizeof(long) - 1] + 1) == elfhdr.e_ident[5]) {
|
|
if ((u.c[sizeof(long) - 1] + 1) == elfhdr.e_ident[5]) {
|
|
if (elfhdr.e_type == ET_CORE)
|
|
if (elfhdr.e_type == ET_CORE)
|
|
|
|
+#ifdef ELFCORE
|
|
dophn_core(fd, elfhdr.e_phoff, elfhdr.e_phnum,
|
|
dophn_core(fd, elfhdr.e_phoff, elfhdr.e_phnum,
|
|
elfhdr.e_phentsize, buf);
|
|
elfhdr.e_phentsize, buf);
|
|
|
|
+#else
|
|
|
|
+ ;
|
|
|
|
+#endif
|
|
else {
|
|
else {
|
|
if (elfhdr.e_type == ET_EXEC) {
|
|
if (elfhdr.e_type == ET_EXEC) {
|
|
- dophn_exec(fd, elfhdr.e_phoff,
|
|
|
|
- elfhdr.e_phnum,
|
|
|
|
- elfhdr.e_phentsize, buf);
|
|
|
|
|
|
+ dophn_exec(fd,
|
|
|
|
+ elfhdr.e_phoff,
|
|
|
|
+ elfhdr.e_phnum,
|
|
|
|
+ elfhdr.e_phentsize, buf);
|
|
}
|
|
}
|
|
doshn(fd, elfhdr.e_shoff, elfhdr.e_shnum,
|
|
doshn(fd, elfhdr.e_shoff, elfhdr.e_shnum,
|
|
elfhdr.e_shentsize, buf);
|
|
elfhdr.e_shentsize, buf);
|
|
@@ -289,22 +310,37 @@ tryelf(fd, buf, nbytes)
|
|
* byte order....
|
|
* byte order....
|
|
*/
|
|
*/
|
|
if ((u.c[sizeof(long) - 1] + 1) == elfhdr.e_ident[5]) {
|
|
if ((u.c[sizeof(long) - 1] + 1) == elfhdr.e_ident[5]) {
|
|
-#ifdef notyet
|
|
|
|
if (elfhdr.e_type == ET_CORE)
|
|
if (elfhdr.e_type == ET_CORE)
|
|
- dophn_core(fd, elfhdr.e_phoff[1],
|
|
|
|
|
|
+#ifdef ELFCORE
|
|
|
|
+ dophn_core(fd,
|
|
|
|
+#ifndef __GNUC__
|
|
|
|
+ elfhdr.e_phoff[1],
|
|
|
|
+#else
|
|
|
|
+ elfhdr.e_phoff,
|
|
|
|
+#endif
|
|
elfhdr.e_phnum,
|
|
elfhdr.e_phnum,
|
|
elfhdr.e_phentsize, buf);
|
|
elfhdr.e_phentsize, buf);
|
|
- else
|
|
|
|
|
|
+#else
|
|
|
|
+ ;
|
|
#endif
|
|
#endif
|
|
|
|
+ else
|
|
{
|
|
{
|
|
-#ifdef notyet
|
|
|
|
if (elfhdr.e_type == ET_EXEC) {
|
|
if (elfhdr.e_type == ET_EXEC) {
|
|
- dophn_exec(fd, elfhdr.e_phoff[1],
|
|
|
|
|
|
+ dophn_exec(fd,
|
|
|
|
+#ifndef __GNUC__
|
|
|
|
+ elfhdr.e_phoff[1],
|
|
|
|
+#else
|
|
|
|
+ elfhdr.e_phoff,
|
|
|
|
+#endif
|
|
elfhdr.e_phnum,
|
|
elfhdr.e_phnum,
|
|
elfhdr.e_phentsize, buf);
|
|
elfhdr.e_phentsize, buf);
|
|
}
|
|
}
|
|
|
|
+ doshn(fd,
|
|
|
|
+#ifndef __GNUC__
|
|
|
|
+ elfhdr.e_shoff[1],
|
|
|
|
+#else
|
|
|
|
+ elfhdr.e_shoff,
|
|
#endif
|
|
#endif
|
|
- doshn(fd, elfhdr.e_shoff[1],
|
|
|
|
elfhdr.e_shnum,
|
|
elfhdr.e_shnum,
|
|
elfhdr.e_shentsize, buf);
|
|
elfhdr.e_shentsize, buf);
|
|
}
|
|
}
|