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 " --expand-nobits off Expand virtual areas (NOBITS sections and similar PHDRs).\n"
27 " --insert-before off,sz Insert spacing at given offset,\n"
28 " mapping everything before it to lower mem addresses.\n"
29 " --insert-after off,sz Insert spacing at given offset,\n"
30 " mapping everything after it to higher mem addresses.\n"
36 void parseOptions(CLIOpts *opts, int argc, char **argv)
38 char *progname = argv[0];
43 static struct option long_options[] = {
45 {"output", 1, 0, 'o'},
46 {"print-header", 0, 0, 10001},
47 {"print-segments", 0, 0, 10002},
48 {"print-sections", 0, 0, 10003},
49 {"insert-before", 1, 0, 10004},
50 {"insert-after", 1, 0, 10005},
51 {"expand-nobits", 1, 0, 10006},
55 while ((c = getopt_long(argc, argv, "e:ho:",
56 long_options, &option_index)) != -1) {
62 opts->fnOutput = optarg;
65 opts->printHeader = 1;
68 opts->printSegments = 1;
71 opts->printSections = 1;
74 opts->insertBeforeOffs = strtoul(optarg, &endptr, 0);
75 if (endptr[0] != ',') {
78 opts->insertBeforeSz = strtoul(endptr + 1, &endptr, 0);
79 if (endptr[0] != '\0' || opts->insertBeforeSz == 0) {
84 opts->insertAfterOffs = strtoul(optarg, &endptr, 0);
85 if (endptr[0] != ',') {
88 opts->insertAfterSz = strtoul(endptr + 1, &endptr, 0);
89 if (endptr[0] != '\0' || opts->insertAfterSz == 0) {
94 opts->expandNobitsOffs = strtoul(optarg, &endptr, 0);
95 if (endptr[0] != '\0' || opts->expandNobitsOffs < 1) {
105 while (optind < argc) {
106 if (!opts->fnInput) {
107 opts->fnInput = argv[optind];
112 if (!opts->fnInput) {
113 fprintf(stderr, "Error: No input file specified.\n\n");
120 printUsage(progname);