9 static void printUsage(char *progname)
11 printf("Usage: %s [OPTIONS] <elf-file>\n", progname);
14 " -h, --help Print this help message\n"
15 " -o, --output Where to write the modified ELF file to\n"
18 " --print-header Print ELF header\n"
19 " --print-segments Print program headers\n"
20 " --print-sections Print sections\n"
23 " off: File offset, not within any structure (headers or sections).\n"
24 " sz: A multiple of the maximum alignment of all PHDRs.\n"
26 " --insert-before off,sz Insert spacing at given offset,\n"
27 " mapping everything before it to lower mem addresses.\n"
28 " --insert-after off,sz Insert spacing at given offset,\n"
29 " mapping everything after it to higher mem addresses.\n"
35 void parseOptions(CLIOpts *opts, int argc, char **argv)
37 char *progname = argv[0];
42 static struct option long_options[] = {
44 {"output", 1, 0, 'o'},
45 {"print-header", 0, 0, 10001},
46 {"print-segments", 0, 0, 10002},
47 {"print-sections", 0, 0, 10003},
48 {"insert-before", 1, 0, 10004},
49 {"insert-after", 1, 0, 10005},
53 while ((c = getopt_long(argc, argv, "e:ho:",
54 long_options, &option_index)) != -1) {
60 opts->fnOutput = optarg;
63 opts->printHeader = 1;
66 opts->printSegments = 1;
69 opts->printSections = 1;
72 opts->insertBeforeOffs = strtoul(optarg, &endptr, 0);
73 if (endptr[0] != ',') {
76 opts->insertBeforeSz = strtoul(endptr + 1, &endptr, 0);
77 if (endptr[0] != '\0' || opts->insertBeforeSz == 0) {
82 opts->insertAfterOffs = strtoul(optarg, &endptr, 0);
83 if (endptr[0] != ',') {
86 opts->insertAfterSz = strtoul(endptr + 1, &endptr, 0);
87 if (endptr[0] != '\0' || opts->insertAfterSz == 0) {
97 while (optind < argc) {
99 opts->fnInput = argv[optind];
104 if (!opts->fnInput) {
105 fprintf(stderr, "Error: No input file specified.\n\n");
112 printUsage(progname);