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"
32 "High-level insertion:\n"
33 " --reladd obj.o Automatically insert object file contents\n"
39 void parseOptions(CLIOpts *opts, int argc, char **argv)
41 char *progname = argv[0];
46 static struct option long_options[] = {
48 {"output", 1, 0, 'o'},
49 {"print-header", 0, 0, 10001},
50 {"print-segments", 0, 0, 10002},
51 {"print-sections", 0, 0, 10003},
52 {"insert-before", 1, 0, 10004},
53 {"insert-after", 1, 0, 10005},
54 {"expand-nobits", 1, 0, 10006},
55 {"reladd", 1, 0, 10007},
59 while ((c = getopt_long(argc, argv, "e:ho:",
60 long_options, &option_index)) != -1) {
66 opts->fnOutput = optarg;
69 opts->printHeader = 1;
72 opts->printSegments = 1;
75 opts->printSections = 1;
78 opts->insertBeforeOffs = strtoul(optarg, &endptr, 0);
79 if (endptr[0] != ',') {
82 opts->insertBeforeSz = strtoul(endptr + 1, &endptr, 0);
83 if (endptr[0] != '\0' || opts->insertBeforeSz == 0) {
88 opts->insertAfterOffs = strtoul(optarg, &endptr, 0);
89 if (endptr[0] != ',') {
92 opts->insertAfterSz = strtoul(endptr + 1, &endptr, 0);
93 if (endptr[0] != '\0' || opts->insertAfterSz == 0) {
98 opts->expandNobitsOffs = strtoul(optarg, &endptr, 0);
99 if (endptr[0] != '\0' || opts->expandNobitsOffs < 1) {
104 opts->fnReladd = optarg;
112 while (optind < argc) {
113 if (!opts->fnInput) {
114 opts->fnInput = argv[optind];
119 if (!opts->fnInput) {
120 fprintf(stderr, "Error: No input file specified.\n\n");
127 printUsage(progname);