Changeset View
Changeset View
Standalone View
Standalone View
usr.bin/elfctl/elfctl.c
Show First 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | static struct option long_opts[] = { | ||||
{ NULL, 0, NULL, 0 } | { NULL, 0, NULL, 0 } | ||||
}; | }; | ||||
#if BYTE_ORDER == LITTLE_ENDIAN | #if BYTE_ORDER == LITTLE_ENDIAN | ||||
#define SUPPORTED_ENDIAN ELFDATA2LSB | #define SUPPORTED_ENDIAN ELFDATA2LSB | ||||
#else | #else | ||||
#define SUPPORTED_ENDIAN ELFDATA2MSB | #define SUPPORTED_ENDIAN ELFDATA2MSB | ||||
#endif | #endif | ||||
static bool iflag; | |||||
int | int | ||||
main(int argc, char **argv) | main(int argc, char **argv) | ||||
{ | { | ||||
GElf_Ehdr ehdr; | GElf_Ehdr ehdr; | ||||
Elf *elf; | Elf *elf; | ||||
Elf_Kind kind; | Elf_Kind kind; | ||||
int ch, fd, retval; | int ch, fd, retval; | ||||
char *features; | char *features; | ||||
bool editfeatures, lflag; | bool editfeatures, lflag; | ||||
lflag = 0; | lflag = 0; | ||||
editfeatures = false; | editfeatures = false; | ||||
retval = 0; | retval = 0; | ||||
features = NULL; | features = NULL; | ||||
if (elf_version(EV_CURRENT) == EV_NONE) | if (elf_version(EV_CURRENT) == EV_NONE) | ||||
errx(EXIT_FAILURE, "elf_version error"); | errx(EXIT_FAILURE, "elf_version error"); | ||||
while ((ch = getopt_long(argc, argv, "hle:", long_opts, NULL)) != -1) { | while ((ch = getopt_long(argc, argv, "hile:", long_opts, NULL)) != -1) { | ||||
switch (ch) { | switch (ch) { | ||||
case 'i': | |||||
iflag = true; | |||||
break; | |||||
case 'l': | case 'l': | ||||
print_features(); | print_features(); | ||||
lflag = true; | lflag = true; | ||||
break; | break; | ||||
case 'e': | case 'e': | ||||
features = optarg; | features = optarg; | ||||
editfeatures = true; | editfeatures = true; | ||||
break; | break; | ||||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
#define USAGE_MESSAGE \ | #define USAGE_MESSAGE \ | ||||
"\ | "\ | ||||
Usage: %s [options] file...\n\ | Usage: %s [options] file...\n\ | ||||
Set or display the control features for an ELF object.\n\n\ | Set or display the control features for an ELF object.\n\n\ | ||||
Supported options are:\n\ | Supported options are:\n\ | ||||
-l List known control features.\n\ | -l List known control features.\n\ | ||||
-i Ignore unknown features.\n\ | |||||
-e [+-=]feature,list Edit features from a comma separated list.\n\ | -e [+-=]feature,list Edit features from a comma separated list.\n\ | ||||
-h | --help Print a usage message and exit.\n" | -h | --help Print a usage message and exit.\n" | ||||
static void | static void | ||||
usage(void) | usage(void) | ||||
{ | { | ||||
fprintf(stderr, USAGE_MESSAGE, ELFTC_GETPROGNAME()); | fprintf(stderr, USAGE_MESSAGE, ELFTC_GETPROGNAME()); | ||||
Show All 16 Lines | while ((feature = strsep(&feature_str, ",")) != NULL) { | ||||
for (i = 0; i < len; ++i) { | for (i = 0; i < len; ++i) { | ||||
if (strcmp(featurelist[i].alias, feature) == 0) { | if (strcmp(featurelist[i].alias, feature) == 0) { | ||||
input |= featurelist[i].value; | input |= featurelist[i].value; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
if (i == len) { | if (i == len) { | ||||
warnx("%s is not a valid feature", feature); | warnx("%s is not a valid feature", feature); | ||||
if (!iflag) | |||||
return (false); | return (false); | ||||
} | } | ||||
} | } | ||||
if (operation == '+') { | if (operation == '+') { | ||||
*feature_val |= input; | *feature_val |= input; | ||||
} else if (operation == '=') { | } else if (operation == '=') { | ||||
*feature_val = input; | *feature_val = input; | ||||
} else if (operation == '-') { | } else if (operation == '-') { | ||||
▲ Show 20 Lines • Show All 164 Lines • Show Last 20 Lines |