8 #include <libelfu/libelfu.h>
10 #include "elfhandle.h"
15 int main(int argc, char **argv)
18 ELFHandles hIn = { 0 };
19 ELFHandles hOut = { 0 };
20 int exitval = EXIT_SUCCESS;
22 /* Is libelf alive and well? */
23 if (elf_version(EV_CURRENT) == EV_NONE) {
24 fprintf(stderr, "libelf init error: %s\n", elf_errmsg(-1));
28 /* Parse and validate user input */
29 parseOptions(&opts, argc, argv);
32 /* Open input/output files */
33 openElf(&hIn, opts.fnInput, ELF_C_READ);
35 exitval = EXIT_FAILURE;
40 openElf(&hOut, opts.fnOutput, ELF_C_WRITE);
42 exitval = EXIT_FAILURE;
48 /* Now that we have a (hopefully) sane environment, execute commands */
49 if (opts.printHeader) {
53 if (opts.printSegments) {
57 if (opts.printSections) {
62 /* Copy the input ELF to the output file if the latter is specified */
66 me = elfu_modelFromElf(hIn.e);
69 printf("Model successfully loaded.\n");
72 printf("Model checked.\n");
74 elfu_modelToElf(me, hOut.e);
76 printf("Model converted to ELF, ready to be written.\n");
78 printf("Failed to load model.\n");
86 if (elf_update(hOut.e, ELF_C_WRITE) < 0) {
87 fprintf(stderr, "elf_update() failed: %s\n", elf_errmsg(-1));