Remove old and ugly printing functions
authornorly <ny-git@enpas.org>
Tue, 28 May 2013 17:22:31 +0000 (18:22 +0100)
committernorly <ny-git@enpas.org>
Tue, 28 May 2013 17:22:31 +0000 (18:22 +0100)
src/main.c
src/options.c
src/printing/header.c [deleted file]
src/printing/sections.c [deleted file]
src/printing/segments.c [deleted file]

index 1672ab41ade4bbbdaaca1766f04f82e3d57b26e7..0eb6e00b3aee7468f12f851a9b0597a4ce4e6ffc 100644 (file)
@@ -38,22 +38,7 @@ int main(int argc, char **argv)
   }
 
 
-  /* Now that we have a (hopefully) sane environment, execute commands.
-   * Printing will have to be reimplemented based on the memory model.
-   */
-  if (opts.printHeader) {
-    printHeader(hIn.e);
-  }
-
-  if (opts.printSegments) {
-    printSegments(hIn.e);
-  }
-
-  if (opts.printSections) {
-    printSections(hIn.e);
-  }
-
-
+  /* Now that we have a (hopefully) sane environment, execute commands. */
   me = elfu_mFromElf(hIn.e);
   if (me) {
     closeElf(&hIn);
index 928d080d60703aeb4ce9461010d5b1976dc0dde3..198f01baa5bd6cbfd8037179d4f21caa1345b38b 100644 (file)
@@ -14,11 +14,11 @@ static void printUsage(char *progname)
           "  -h, --help                     Print this help message\n"
           "  -o, --output                   Where to write the modified ELF file to\n"
           "\n"
-          "ELF dump:\n"
-          "      --print-header             Print ELF header\n"
-          "      --print-segments           Print program headers\n"
-          "      --print-sections           Print sections\n"
-          "\n"
+//          "ELF dump:\n"
+//          "      --print-header             Print ELF header\n"
+//          "      --print-segments           Print program headers\n"
+//          "      --print-sections           Print sections\n"
+//          "\n"
           "Space insertion:\n"
           "    off: File offset, not within any structure (headers or sections).\n"
           "    sz:  A multiple of the maximum alignment of all PHDRs.\n"
diff --git a/src/printing/header.c b/src/printing/header.c
deleted file mode 100644 (file)
index 0be2536..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-#include <stdio.h>
-
-#include <libelf/libelf.h>
-#include <libelf/gelf.h>
-
-
-void printHeader(Elf *e)
-{
-  GElf_Ehdr ehdr;
-  int elfclass;
-  size_t shdrnum, shdrstrndx, phdrnum;
-
-
-  printf("ELF header:\n");
-
-
-  elfclass = gelf_getclass(e);
-  if (elfclass == ELFCLASSNONE) {
-    fprintf(stderr, "getclass() failed: %s\n", elf_errmsg(-1));
-  }
-  printf(" * %d-bit ELF object\n", elfclass == ELFCLASS32 ? 32 : 64);
-
-
-  if (!gelf_getehdr(e, &ehdr)) {
-    fprintf(stderr, "getehdr() failed: %s.", elf_errmsg(-1));
-    return;
-  }
-
-  printf(" *     type  machine  version    entry    phoff    shoff    flags   ehsize phentsize shentsize\n");
-  printf("   %8jx %8jx %8jx %8jx %8jx %8jx %8jx %8jx %9jx %9jx\n",
-          (uintmax_t) ehdr.e_type,
-          (uintmax_t) ehdr.e_machine,
-          (uintmax_t) ehdr.e_version,
-          (uintmax_t) ehdr.e_entry,
-          (uintmax_t) ehdr.e_phoff,
-          (uintmax_t) ehdr.e_shoff,
-          (uintmax_t) ehdr.e_flags,
-          (uintmax_t) ehdr.e_ehsize,
-          (uintmax_t) ehdr.e_phentsize,
-          (uintmax_t) ehdr.e_shentsize);
-
-
-  if (elf_getshdrnum(e, &shdrnum) != 0) {
-    fprintf(stderr, "getshdrnum() failed: %s\n", elf_errmsg(-1));
-  } else {
-    printf(" * (shnum):    %u\n", shdrnum);
-  }
-
-  if (elf_getshdrstrndx(e, &shdrstrndx) != 0) {
-    fprintf(stderr, "getshdrstrndx() failed: %s\n", elf_errmsg(-1));
-  } else {
-    printf(" * (shstrndx): %u\n", shdrstrndx);
-  }
-
-  if (elf_getphdrnum(e, &phdrnum) != 0) {
-    fprintf(stderr, "getphdrnum() failed: %s\n", elf_errmsg(-1));
-  } else {
-    printf(" * (phnum):    %u\n", phdrnum);
-  }
-
-  printf("\n");
-}
diff --git a/src/printing/sections.c b/src/printing/sections.c
deleted file mode 100644 (file)
index ec0ff43..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-#include <stdio.h>
-
-#include <libelf/libelf.h>
-#include <libelf/gelf.h>
-
-#include <libelfu/libelfu.h>
-#include "printing.h"
-
-
-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++) {
-    if (gelf_getphdr(e, i, &phdr) != &phdr) {
-      fprintf(stderr, "getphdr() failed for #%d: %s\n", i, elf_errmsg(-1));
-      continue;
-    }
-
-    if (PHDR_CONTAINS_SCN_IN_MEMORY(&phdr, &shdr)) {
-      printf("     %d %s\n", i, segmentTypeStr(phdr.p_type));
-    }
-  }
-}
-
-
-void printSection(Elf *e, Elf_Scn *scn)
-{
-  printf("  %jd: %s\n",
-          (uintmax_t) elf_ndxscn(scn),
-          elfu_eScnName(e, scn));
-}
-
-
-void printSections(Elf *e)
-{
-  Elf_Scn *scn;
-
-  printf("Sections:\n");
-
-  scn = elf_getscn(e, 0);
-
-  while (scn) {
-    printSection(e, scn);
-    //printSegmentsWithSection(e, scn);
-
-    scn = elf_nextscn(e, scn);
-  }
-}
diff --git a/src/printing/segments.c b/src/printing/segments.c
deleted file mode 100644 (file)
index c7b5cb2..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-#include <stdio.h>
-
-#include <libelf/libelf.h>
-#include <libelf/gelf.h>
-
-#include <libelfu/libelfu.h>
-
-
-static char *ptstr[] = {"NULL", "LOAD", "DYNAMIC", "INTERP", "NOTE", "SHLIB", "PHDR", "TLS", "NUM"};
-
-
-char* segmentTypeStr(size_t pt)
-{
-  if (pt >= 0 && pt <= PT_NUM) {
-    return ptstr[pt];
-  }
-
-  return "-?-";
-}
-
-
-void printSectionsInSegment(Elf *e, GElf_Phdr *phdr)
-{
-  Elf_Scn *scn;
-
-  scn = elf_getscn(e, 0);
-
-  while (scn) {
-    GElf_Shdr shdr;
-
-    if (gelf_getshdr(scn, &shdr) != &shdr) {
-      fprintf(stderr, "gelf_getshdr() failed: %s\n", elf_errmsg(-1));
-      continue;
-    }
-
-    if (PHDR_CONTAINS_SCN_IN_MEMORY(phdr, &shdr)) {
-      printf("       %10u %s\n", elf_ndxscn(scn), elfu_eScnName(e, scn));
-    }
-
-    scn = elf_nextscn(e, scn);
-  }
-}
-
-
-void printSegments(Elf *e)
-{
-  size_t i, n;
-
-  if (elf_getphdrnum(e, &n)) {
-    fprintf(stderr, "elf_getphdrnum() failed: %s.", elf_errmsg(-1));
-  }
-
-  printf("Segments:\n");
-  printf("      #   typeStr     type   offset    vaddr    paddr   filesz    memsz    flags    align\n");
-
-  for (i = 0; i < n; i++) {
-    GElf_Phdr phdr;
-
-    if (gelf_getphdr(e, i, &phdr) != &phdr) {
-      fprintf(stderr, "getphdr() failed for #%d: %s.", i, elf_errmsg(-1));
-      continue;
-    }
-
-    printf(" * %4d: %8s ", i, segmentTypeStr(phdr.p_type));
-
-    printf("%8jx %8jx %8jx %8jx %8jx %8jx %8jx %8jx\n",
-            (uintmax_t) phdr.p_type,
-            (uintmax_t) phdr.p_offset,
-            (uintmax_t) phdr.p_vaddr,
-            (uintmax_t) phdr.p_paddr,
-            (uintmax_t) phdr.p_filesz,
-            (uintmax_t) phdr.p_memsz,
-            (uintmax_t) phdr.p_flags,
-            (uintmax_t) phdr.p_align);
-
-    printSectionsInSegment(e, &phdr);
-  }
-
-  printf("\n");
-}