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"
17 " --print-header Print ELF header\n"
18 " --print-segments Print program headers\n"
19 " --print-sections Print sections\n"
21 " --insert-before off,sz Insert spacing at given offset\n"
27 void parseOptions(CLIOpts *opts, int argc, char **argv)
29 char *progname = argv[0];
34 static struct option long_options[] = {
36 {"output", 1, 0, 'o'},
37 {"print-header", 0, 0, 10001},
38 {"print-segments", 0, 0, 10002},
39 {"print-sections", 0, 0, 10003},
40 {"insert-before", 1, 0, 10004},
44 while ((c = getopt_long(argc, argv, "e:ho:",
45 long_options, &option_index)) != -1) {
51 opts->fnOutput = optarg;
54 opts->printHeader = 1;
57 opts->printSegments = 1;
60 opts->printSections = 1;
63 opts->insertBeforeOffs = strtoul(optarg, &endptr, 0);
64 if (endptr[0] != ',') {
67 opts->insertBeforeSz = strtoul(endptr + 1, &endptr, 0);
68 if (endptr[0] != '\0' || opts->insertBeforeSz == 0) {
78 while (optind < argc) {
80 opts->fnInput = argv[optind];
86 fprintf(stderr, "Error: No input file specified.\n\n");