]> granicus.if.org Git - file/commitdiff
Added core file for efl
authorChristos Zoulas <christos@zoulas.com>
Fri, 25 Oct 1996 18:11:51 +0000 (18:11 +0000)
committerChristos Zoulas <christos@zoulas.com>
Fri, 25 Oct 1996 18:11:51 +0000 (18:11 +0000)
src/readelf.c
src/readelf.h

index 0d85ff073f888b9a19586608db9ead83ccaa62e7..dc4a3ac01e1bb7fd699748984e1ae93378589414 100644 (file)
@@ -5,6 +5,9 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <errno.h>
+#ifdef __SVR4
+#include <sys/procfs.h>
+#endif
 
 #include "readelf.h"
 #include "file.h"
@@ -32,7 +35,9 @@ doshn(fd, off, num, size, buf)
        (void) printf (", stripped");
 }
 
-#ifdef notyet
+/*
+ * From: Ken Pizzini <ken@spry.com>
+ */
 static void
 dophn(fd, off, num, size, buf)
        int fd;
@@ -41,30 +46,48 @@ dophn(fd, off, num, size, buf)
        size_t size;
        char *buf;
 {
-       Elf32_Phdr *ph = (Elf32_Phdr *) buf;
+       /* I am not sure if this works for 64 bit elf formats */
+       Elf32_Phdr ph;
+       Elf32_Nhdr nh;
+       off_t off_sv;
+       off_t fname_off;
 
        if (lseek(fd, off, SEEK_SET) == -1)
                error("lseek failed (%s).\n", strerror(errno));
 
        for ( ; num; num--) {
-               if (read(fd, buf, size) == -1)
+               if (read(fd, &ph, sizeof ph) != sizeof ph)
                        error("read failed (%s).\n", strerror(errno));
-               printf("type:%d\n", ph->p_type);
-               if (ph->p_type != PT_NOTE)
+               if (ph.p_type != PT_NOTE)
                        continue;
-               if (lseek(fd, ph->p_offset, SEEK_SET) == -1)
+               off_sv = lseek(fd, ph.p_offset, SEEK_SET);
+               if (off_sv == -1)
+                       error("lseek failed (%s).\n", strerror(errno));
+               if (read(fd, &nh, sizeof nh) != sizeof nh)
+                       error("read failed (%s).\n", strerror(errno));
+               if (nh.n_type != NT_PRPSINFO) {
+                       if (lseek(fd, off_sv, SEEK_SET) == -1)
+                               error("lseek failed (%s).\n", strerror(errno));
+                       continue;
+               }
+
+#ifdef __SVR4
+
+#define ALIGN(n)       (((n)+3) & ~3)  /* round up to nearest multiple of 4 */
+#define offsetof(a, b) (int) &((a *) 0)->b
+
+               fname_off = offsetof(struct prpsinfo, pr_fname) +
+                       ALIGN(nh.n_namesz);
+               if (lseek(fd, fname_off, SEEK_CUR) == -1)
                        error("lseek failed (%s).\n", strerror(errno));
-               if (size > BUFSIZ)
-                       size = BUFSIZ;
                if (read(fd, buf, size) == -1)
                        error("read failed (%s).\n", strerror(errno));
-               for (size = 0; size < BUFSIZ; size++)
-                       if (isalnum(buf[size]))
-                               printf("%d %c\n", size, buf[size]);
+               (void) printf ("; from `%s'", buf);
+#endif
                return;
        }
 }
-#endif
+
 
 void
 tryelf(fd, buf, nbytes)
@@ -97,12 +120,10 @@ tryelf(fd, buf, nbytes)
                u.l = 1;
                (void) memcpy(&elfhdr, buf, sizeof elfhdr);
 
-#ifdef notyet
                if (elfhdr.e_type == ET_CORE) 
                        dophn(fd, elfhdr.e_phoff, elfhdr.e_phnum, 
                              elfhdr.e_phentsize, buf);
                else 
-#endif
                {
                        /*
                         * If the system byteorder does not equal the
@@ -125,12 +146,10 @@ tryelf(fd, buf, nbytes)
                u.l = 1;
                (void) memcpy(&elfhdr, buf, sizeof elfhdr);
 
-#ifdef notyet
                if (elfhdr.e_type == ET_CORE) 
                        dophn(fd, elfhdr.e_phoff, elfhdr.e_phnum, 
                              elfhdr.e_phentsize, buf);
                else
-#endif
                {
                        /*
                         * If the system byteorder does not equal the
index 08f9ccc32bcfb7290607bdcb23c51fd271baa5e5..15fb8573a152a853a34bdc04d2c639f5817b7d22 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * readelf.h 
- * @(#)$Id: readelf.h,v 1.2 1996/10/05 18:13:09 christos Exp $
+ * @(#)$Id: readelf.h,v 1.3 1996/10/25 18:11:51 christos Exp $
  *
  * Provide elf data structures for non-elf machines, allowing file
  * non-elf hosts to determine if an elf binary is stripped.
@@ -137,4 +137,24 @@ typedef struct {
     Elf64_Off  sh_entsize;
 } Elf64_Shdr;
 
+
+typedef struct {
+    Elf32_Word n_namesz;
+    Elf32_Word n_descsz;
+    Elf32_Word n_type;
+} Elf32_Nhdr;
+
+typedef struct {
+    Elf64_Word n_namesz;
+    Elf64_Word n_descsz;
+    Elf64_Word n_type;
+} Elf64_Nhdr;
+
+#define        NT_PRSTATUS     1
+#define        NT_PRFPREG      2
+#define        NT_PRPSINFO     3
+#define        NT_PRXREG       4
+#define        NT_PLATFORM     5
+#define        NT_AUXV         6
+
 #endif