4 #include <libelfu/libelfu.h>
11 int main(int argc, char **argv)
14 ELFHandles hIn = { 0 };
15 ELFHandles hOut = { 0 };
16 int exitval = EXIT_SUCCESS;
19 /* Is libelf alive and well? */
20 if (elf_version(EV_CURRENT) == EV_NONE) {
21 fprintf(stderr, "libelf init error: %s\n", elf_errmsg(-1));
25 /* Parse and validate user input */
26 parseOptions(&opts, argc, argv);
29 /* Open input/output files */
30 openElf(&hIn, opts.fnInput, ELF_C_READ);
32 exitval = EXIT_FAILURE;
37 /* Now that we have a (hopefully) sane environment, execute commands. */
38 me = elfu_mFromElf(hIn.e);
41 printf("Model successfully loaded.\n");
46 printf("Input model checked.\n");
48 printf("Failed to load model, aborting.\n");
53 /* Copy the input ELF to the output file if the latter is specified.
54 * Perform requested transformations on the memory model on-the-fly. */
56 printf("No output file specified - no further operations performed.\n");
59 ELFHandles hRel = { 0 };
62 openElf(&hRel, opts.fnReladd, ELF_C_READ);
64 printf("--reladd: Failed to open file for --reladd, skipping operation.\n");
66 mrel = elfu_mFromElf(hRel.e);
69 printf("--reladd: Failed to load model for --reladd, skipping operation.\n");
71 printf("--reladd: Model successfully loaded.\n");
73 printf("--reladd: Input model checked.\n");
74 elfu_mReladd(me, mrel);
80 printf("Output model checked.\n");
84 openElf(&hOut, opts.fnOutput, ELF_C_WRITE);
86 printf("Failed to open output file. Aborting.\n");
87 exitval = EXIT_FAILURE;
91 elfu_mToElf(me, hOut.e);
92 printf("Model converted to ELF, ready to be written.\n");
99 if (elf_update(hOut.e, ELF_C_WRITE) < 0) {
100 fprintf(stderr, "elf_update() failed: %s\n", elf_errmsg(-1));