|
|
|
@ -11,23 +11,24 @@ |
|
|
|
|
struct entry { |
|
|
|
|
const char *cmd; |
|
|
|
|
int (* main)(int argc, char *argv[]); |
|
|
|
|
void (* show_usage)(const char *prog_name, const char *cmd); |
|
|
|
|
char *desc; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
struct entry entries[] = { |
|
|
|
|
{ "get-offset", do_get_offset, |
|
|
|
|
{ "get-offset", do_get_offset, show_get_offset_usage, |
|
|
|
|
"print the offset of the payload within an image" }, |
|
|
|
|
{ "get-size", do_get_size, |
|
|
|
|
{ "get-size", do_get_size, show_get_size_usage, |
|
|
|
|
"print the size of the payload within an image" }, |
|
|
|
|
{ "pack", do_pack, |
|
|
|
|
{ "pack", do_pack, show_pack_usage, |
|
|
|
|
"pack the payload within an image" }, |
|
|
|
|
{ "sign", do_sign, |
|
|
|
|
{ "sign", do_sign, show_sign_usage, |
|
|
|
|
"sign an image" }, |
|
|
|
|
{ "unpack", do_unpack, |
|
|
|
|
{ "unpack", do_unpack, show_unpack_usage, |
|
|
|
|
"unpack the payload of an image" }, |
|
|
|
|
{ "verify", do_verify, |
|
|
|
|
{ "verify", do_verify, show_verify_usage, |
|
|
|
|
"verify the signatures of an image" }, |
|
|
|
|
{ NULL, NULL, NULL }, |
|
|
|
|
{ NULL, NULL, NULL, NULL }, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
static void show_usage(const char *prog_name) |
|
|
|
@ -39,10 +40,28 @@ static void show_usage(const char *prog_name) |
|
|
|
|
"Available commands:\n", prog_name); |
|
|
|
|
|
|
|
|
|
for (entry = entries; entry->cmd; ++entry) { |
|
|
|
|
fprintf(stderr, "\t%-16s %-80s\n", entry->cmd, entry->desc); |
|
|
|
|
fprintf(stderr, "\t%-16s %s\n", entry->cmd, entry->desc); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void show_cmd_usage(char *prog_name, char *cmd) |
|
|
|
|
{ |
|
|
|
|
struct entry *entry; |
|
|
|
|
|
|
|
|
|
for (entry = entries; entry->cmd; ++entry) { |
|
|
|
|
if (strcmp(entry->cmd, cmd) != 0) |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
if (!entry->show_usage) |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
entry->show_usage(prog_name, cmd); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
show_usage(prog_name); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) |
|
|
|
|
{ |
|
|
|
|
struct entry *entry; |
|
|
|
@ -52,6 +71,15 @@ int main(int argc, char *argv[]) |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) { |
|
|
|
|
if (argc < 3) |
|
|
|
|
show_usage(argv[0]); |
|
|
|
|
else |
|
|
|
|
show_cmd_usage(argv[0], argv[2]); |
|
|
|
|
|
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (entry = entries; entry->cmd; ++entry) { |
|
|
|
|
if (strcmp(entry->cmd, argv[1]) == 0) |
|
|
|
|
return entry->main(argc, argv); |
|
|
|
|