diff options
Diffstat (limited to 'utils/sbtools')
-rw-r--r-- | utils/sbtools/misc.c | 21 | ||||
-rw-r--r-- | utils/sbtools/misc.h | 6 | ||||
-rw-r--r-- | utils/sbtools/sbtoelf.c | 25 |
3 files changed, 34 insertions, 18 deletions
diff --git a/utils/sbtools/misc.c b/utils/sbtools/misc.c index 39934951ae..4eeda4ef33 100644 --- a/utils/sbtools/misc.c +++ b/utils/sbtools/misc.c | |||
@@ -211,3 +211,24 @@ void print_key(struct crypto_key_t *key, bool newline) | |||
211 | if(newline) | 211 | if(newline) |
212 | printf("\n"); | 212 | printf("\n"); |
213 | } | 213 | } |
214 | |||
215 | char OFF[] = { 0x1b, 0x5b, 0x31, 0x3b, '0', '0', 0x6d, '\0' }; | ||
216 | |||
217 | char GREY[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '0', 0x6d, '\0' }; | ||
218 | char RED[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '1', 0x6d, '\0' }; | ||
219 | char GREEN[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '2', 0x6d, '\0' }; | ||
220 | char YELLOW[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '3', 0x6d, '\0' }; | ||
221 | char BLUE[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '4', 0x6d, '\0' }; | ||
222 | |||
223 | static bool g_color_enable = true; | ||
224 | |||
225 | void enable_color(bool enable) | ||
226 | { | ||
227 | g_color_enable = enable; | ||
228 | } | ||
229 | |||
230 | void color(color_t c) | ||
231 | { | ||
232 | if(g_color_enable) | ||
233 | printf("%s", (char *)c); | ||
234 | } | ||
diff --git a/utils/sbtools/misc.h b/utils/sbtools/misc.h index cc0a3fb5ea..a685816047 100644 --- a/utils/sbtools/misc.h +++ b/utils/sbtools/misc.h | |||
@@ -48,4 +48,10 @@ bool parse_key(char **str, struct crypto_key_t *key); | |||
48 | void add_keys_from_file(const char *key_file); | 48 | void add_keys_from_file(const char *key_file); |
49 | void print_key(struct crypto_key_t *key, bool newline); | 49 | void print_key(struct crypto_key_t *key, bool newline); |
50 | 50 | ||
51 | typedef char color_t[]; | ||
52 | |||
53 | extern color_t OFF, GREY, RED, GREEN, YELLOW, BLUE; | ||
54 | void color(color_t c); | ||
55 | void enable_color(bool enable); | ||
56 | |||
51 | #endif /* __MISC_H__ */ | 57 | #endif /* __MISC_H__ */ |
diff --git a/utils/sbtools/sbtoelf.c b/utils/sbtools/sbtoelf.c index 47aebe7890..24417dc88e 100644 --- a/utils/sbtools/sbtoelf.c +++ b/utils/sbtools/sbtoelf.c | |||
@@ -42,22 +42,6 @@ | |||
42 | #include "sb.h" | 42 | #include "sb.h" |
43 | #include "misc.h" | 43 | #include "misc.h" |
44 | 44 | ||
45 | #if 1 /* ANSI colors */ | ||
46 | |||
47 | # define color(a) printf("%s",a) | ||
48 | char OFF[] = { 0x1b, 0x5b, 0x31, 0x3b, '0', '0', 0x6d, '\0' }; | ||
49 | |||
50 | char GREY[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '0', 0x6d, '\0' }; | ||
51 | char RED[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '1', 0x6d, '\0' }; | ||
52 | char GREEN[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '2', 0x6d, '\0' }; | ||
53 | char YELLOW[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '3', 0x6d, '\0' }; | ||
54 | char BLUE[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '4', 0x6d, '\0' }; | ||
55 | |||
56 | #else | ||
57 | /* disable colors */ | ||
58 | # define color(a) | ||
59 | #endif | ||
60 | |||
61 | /* all blocks are sized as a multiple of 0x1ff */ | 45 | /* all blocks are sized as a multiple of 0x1ff */ |
62 | #define PAD_TO_BOUNDARY(x) (((x) + 0x1ff) & ~0x1ff) | 46 | #define PAD_TO_BOUNDARY(x) (((x) + 0x1ff) & ~0x1ff) |
63 | 47 | ||
@@ -723,7 +707,8 @@ void usage(void) | |||
723 | printf(" -k <file>\tAdd key file\n"); | 707 | printf(" -k <file>\tAdd key file\n"); |
724 | printf(" -z\t\tAdd zero key\n"); | 708 | printf(" -z\t\tAdd zero key\n"); |
725 | printf(" -r\t\tUse raw command mode\n"); | 709 | printf(" -r\t\tUse raw command mode\n"); |
726 | printf(" --add-key <key>\tAdd single key (hex or usbotp)\n"); | 710 | printf(" -a/--add-key <key>\tAdd single key (hex or usbotp)\n"); |
711 | printf(" -n/--no-color\tDisable output colors\n"); | ||
727 | exit(1); | 712 | exit(1); |
728 | } | 713 | } |
729 | 714 | ||
@@ -742,16 +727,20 @@ int main(int argc, char **argv) | |||
742 | {"help", no_argument, 0, '?'}, | 727 | {"help", no_argument, 0, '?'}, |
743 | {"debug", no_argument, 0, 'd'}, | 728 | {"debug", no_argument, 0, 'd'}, |
744 | {"add-key", required_argument, 0, 'a'}, | 729 | {"add-key", required_argument, 0, 'a'}, |
730 | {"no-color", no_argument, 0, 'n'}, | ||
745 | {0, 0, 0, 0} | 731 | {0, 0, 0, 0} |
746 | }; | 732 | }; |
747 | 733 | ||
748 | int c = getopt_long(argc, argv, "?do:k:zra:", long_options, NULL); | 734 | int c = getopt_long(argc, argv, "?do:k:zra:n", long_options, NULL); |
749 | if(c == -1) | 735 | if(c == -1) |
750 | break; | 736 | break; |
751 | switch(c) | 737 | switch(c) |
752 | { | 738 | { |
753 | case -1: | 739 | case -1: |
754 | break; | 740 | break; |
741 | case 'n': | ||
742 | enable_color(false); | ||
743 | break; | ||
755 | case 'd': | 744 | case 'd': |
756 | g_debug = true; | 745 | g_debug = true; |
757 | break; | 746 | break; |