#include #include #include #include #include #include #include #include struct entry { const char *cmd; int (* main)(int argc, char *argv[]); char *desc; }; struct entry entries[] = { { "get-offset", do_get_offset, "print the offset of the payload within an image" }, { "get-size", do_get_size, "print the size of the payload within an image" }, { "pack", do_pack, "pack the payload within an image" }, { "sign", do_sign, "sign an image" }, { "unpack", do_unpack, "unpack the payload of an image" }, { "verify", do_verify, "verify the signatures of an image" }, { NULL, NULL, NULL }, }; static void show_usage(const char *prog_name) { struct entry *entry; fprintf(stderr, "usage: %s ...\n\n" "ROTS utilities to work with signed images\n\n" "Available commands:\n", prog_name); for (entry = entries; entry->cmd; ++entry) { fprintf(stderr, "\t%-16s %-80s\n", entry->cmd, entry->desc); } } int main(int argc, char *argv[]) { struct entry *entry; if (argc < 2) { show_usage(argv[0]); return -1; } for (entry = entries; entry->cmd; ++entry) { if (strcmp(entry->cmd, argv[1]) == 0) return entry->main(argc, argv); } show_usage(argv[0]); return -1; }