Simplify includes
[centaur.git] / src / main.c
index 06de642171fb2df3516719c7cc119e32a56068e5..5aec1a2bc2c5e50312dc32b5ddb8c932e7127534 100644 (file)
@@ -1,10 +1,6 @@
 #include <stdio.h>
 #include <stdlib.h>
-
 #include <getopt.h>
-#include <libelf.h>
-#include <gelf.h>
-
 #include <libelfu/libelfu.h>
 
 #include "elfhandle.h"
@@ -38,26 +34,14 @@ 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);
     printf("Model successfully loaded.\n");
+
+    elfu_mDumpElf(me);
+
     elfu_mCheck(me);
     printf("Input model checked.\n");
   } else {
@@ -71,21 +55,31 @@ int main(int argc, char **argv)
   if (!opts.fnOutput) {
     printf("No output file specified - no further operations performed.\n");
   } else {
-    if (opts.expandNobitsOffs) {
-      elfu_mExpandNobits(me, opts.expandNobitsOffs);
-    }
-
-    if (opts.insertBeforeSz) {
-      elfu_mInsertBefore(me, opts.insertBeforeOffs, opts.insertBeforeSz);
-    }
-
-    if (opts.insertAfterSz) {
-      elfu_mInsertAfter(me, opts.insertAfterOffs, opts.insertAfterSz);
+    if (opts.fnReladd) {
+      ELFHandles hRel = { 0 };
+      ElfuElf *mrel = NULL;
+
+      openElf(&hRel, opts.fnReladd, ELF_C_READ);
+      if (!hRel.e) {
+        printf("--reladd: Failed to open file for --reladd, skipping operation.\n");
+      } else {
+        mrel = elfu_mFromElf(hRel.e);
+        closeElf(&hRel);
+        if (!me) {
+          printf("--reladd: Failed to load model for --reladd, skipping operation.\n");
+        } else {
+          printf("--reladd: Model successfully loaded.\n");
+          elfu_mCheck(mrel);
+          printf("--reladd: Input model checked.\n");
+          elfu_mReladd(me, mrel);
+        }
+      }
     }
 
     elfu_mCheck(me);
     printf("Output model checked.\n");
 
+    elfu_mDumpElf(me);
 
     openElf(&hOut, opts.fnOutput, ELF_C_WRITE);
     if (!hOut.e) {