Remove ELFU_BOOL
authornorly <ny-git@enpas.org>
Sat, 23 Feb 2013 15:36:30 +0000 (15:36 +0000)
committernorly <ny-git@enpas.org>
Sat, 23 Feb 2013 15:36:30 +0000 (15:36 +0000)
include/libelfu/analysis.h
include/libelfu/types.h
src/analysis/segment-contains-section.c
src/lookup/first-section-in-segment.c
src/lookup/last-section-in-segment.c
src/printing/sections.c
src/printing/segments.c

index 80ec251e046f68ae7685a8dd364ff483b997ac2a..f3d4ddb095e102ff68ac480241ad02066031933f 100644 (file)
@@ -6,6 +6,6 @@
 
 #include <libelfu/types.h>
 
-ELFU_BOOL elfu_segmentContainsSection(GElf_Phdr *phdr, Elf_Scn *scn);
+int elfu_segmentContainsSection(GElf_Phdr *phdr, GElf_Shdr *shdr);
 
 #endif
index 6ffdd84649a152d79a97e2adef1ca74a04fe5a20..a59efca7e78ace74d7dfb139442f1d6604a262e6 100644 (file)
@@ -1,10 +1,6 @@
 #ifndef __LIBELFU_TYPES_H__
 #define __LIBELFU_TYPES_H__
 
-typedef enum {
-  ELFU_ERROR = -1,
-  ELFU_FALSE = 0,
-  ELFU_TRUE = 1
-} ELFU_BOOL;
+
 
 #endif
index dc3269dc19438aeb95b4c79c416cc2b3a07d9cac..298cf726477c25845880a5a4a0f5c3478a2507b5 100644 (file)
@@ -4,23 +4,16 @@
 #include <libelfu/libelfu.h>
 
 
-ELFU_BOOL elfu_segmentContainsSection(GElf_Phdr *phdr, Elf_Scn *scn)
+int elfu_segmentContainsSection(GElf_Phdr *phdr, GElf_Shdr *shdr)
 {
-  GElf_Shdr shdr;
-
-
-  if (gelf_getshdr(scn, &shdr) != &shdr) {
-    return ELFU_ERROR;
-  }
-
-  size_t secStart = shdr.sh_offset;
-  size_t secEnd   = shdr.sh_offset + shdr.sh_size;
+  size_t secStart = shdr->sh_offset;
+  size_t secEnd   = shdr->sh_offset + shdr->sh_size;
   size_t segStart = phdr->p_offset;
   size_t segEnd   = phdr->p_offset + phdr->p_memsz;
 
   if (secStart < segStart || secEnd > segEnd) {
-    return ELFU_FALSE;
+    return 0;
   }
 
-  return ELFU_TRUE;
+  return 1;
 }
index 833563d76964a41dbcb406f00405cb8ff5f32a61..58065a500423af43ec8dc105bcb9e1586f65da05 100644 (file)
@@ -25,7 +25,7 @@ Elf_Scn* elfu_firstSectionInSegment(Elf *e, GElf_Phdr *phdr)
     }
 
     if (shdr.sh_offset == phdr->p_offset
-        && elfu_segmentContainsSection(phdr, scn) == ELFU_TRUE) {
+        && elfu_segmentContainsSection(phdr, &shdr)) {
       return scn;
     }
 
index 964e854a678cf8db2be52b8f30eef6f46508c229..53323f66e6da9d3de64ce565c9f1e2007c6e5cd5 100644 (file)
@@ -1,3 +1,4 @@
+#include <stdio.h>
 #include <stdlib.h>
 
 #include <libelf.h>
@@ -21,22 +22,24 @@ Elf_Scn* elfu_lastSectionInSegment(Elf *e, GElf_Phdr *phdr)
 
   scn = elf_getscn(e, 1);
   while (scn) {
-    if (elfu_segmentContainsSection(phdr, scn) == ELFU_TRUE) {
+    GElf_Shdr shdr;
+
+    if (gelf_getshdr(scn, &shdr) != &shdr) {
+      fprintf(stderr, "gelf_getshdr() failed: %s\n", elf_errmsg(-1));
+      continue;
+    }
+
+    if (elfu_segmentContainsSection(phdr, &shdr)) {
       if (!last) {
         last = scn;
       } else {
         GElf_Shdr shdrOld;
-        GElf_Shdr shdrNew;
 
         if (gelf_getshdr(last, &shdrOld) != &shdrOld) {
           continue;
         }
 
-        if (gelf_getshdr(scn, &shdrNew) != &shdrNew) {
-          continue;
-        }
-
-        if (shdrNew.sh_offset + shdrNew.sh_size
+        if (shdr.sh_offset + shdr.sh_size
             > shdrOld.sh_offset + shdrOld.sh_size) {
           // TODO: Check (leftover space in memory image) < (p_align)
           last = scn;
index 6241a733a7b396240c0a6559b54b9672a052beb7..be7a9072ae05aa304cf6cb28b19b25a6e2cdfb32 100644 (file)
 void printSegmentsWithSection(Elf *e, Elf_Scn *scn)
 {
   GElf_Phdr phdr;
+  GElf_Shdr shdr;
   int i;
   size_t n;
 
 
+  if (gelf_getshdr(scn, &shdr) != &shdr) {
+    fprintf(stderr, "gelf_getshdr() failed: %s\n", elf_errmsg(-1));
+    return;
+  }
+
   if (elf_getphdrnum(e, &n)) {
     fprintf(stderr, "elf_getphdrnum() failed: %s\n", elf_errmsg(-1));
     return;
   }
 
   for (i = 0; i < n; i++) {
-    ELFU_BOOL isInSeg;
-
     if (gelf_getphdr(e, i, &phdr) != &phdr) {
       fprintf(stderr, "getphdr() failed for #%d: %s\n", i, elf_errmsg(-1));
       continue;
     }
 
-    isInSeg = elfu_segmentContainsSection(&phdr, scn);
-    if (isInSeg == ELFU_TRUE) {
+    if (elfu_segmentContainsSection(&phdr, &shdr)) {
       printf("     %d %s\n", i, segmentTypeStr(phdr.p_type));
     }
   }
index 6d8cac7223c6f003d73e845db781dc4520ea242a..1f431d673e85969d2c78eb31e7d9ce7ce79329b2 100644 (file)
@@ -26,10 +26,14 @@ void printSectionsInSegment(Elf *e, GElf_Phdr *phdr)
   scn = elf_getscn(e, 0);
 
   while (scn) {
-    ELFU_BOOL isInSeg;
+    GElf_Shdr shdr;
 
-    isInSeg = elfu_segmentContainsSection(phdr, scn);
-    if (isInSeg == ELFU_TRUE) {
+    if (gelf_getshdr(scn, &shdr) != &shdr) {
+      fprintf(stderr, "gelf_getshdr() failed: %s\n", elf_errmsg(-1));
+      continue;
+    }
+
+    if (elfu_segmentContainsSection(phdr, &shdr)) {
       printf("       %10u %s\n", elf_ndxscn(scn), elfu_sectionName(e, scn));
     }