diff --git a/source/ui.c b/source/ui.c index 8c6eedb..5a50582 100644 --- a/source/ui.c +++ b/source/ui.c @@ -469,6 +469,33 @@ u64 ShowHexPrompt(u64 start_val, u32 n_digits, const char *format, ...) { return ret; } +bool ShowDataPrompt(u8* data, u32* size, const char *format, ...) { + const char* alphabet = "0123456789ABCDEF"; + char inputstr[128 + 1] = { 0 }; // maximum size of data: 64 byte + bool ret = false; + va_list va; + + if (*size > 64) *size = 64; + for (u32 i = 0; i < *size; i++) + snprintf(inputstr + (2*i), 128 + 1 - (2*i), "%02X", (unsigned int) data[i]); + + va_start(va, format); + if (ShowInputPrompt(inputstr, 128 + 1, 2, alphabet, format, va)) { + *size = strnlen(inputstr, 128) / 2; + for (u32 i = 0; i < *size; i++) { + char bytestr[2 + 1] = { 0 }; + unsigned int byte; + strncpy(bytestr, inputstr + (2*i), 2); + sscanf(bytestr, "%02X", &byte); + data[i] = (u8) byte; + } + ret = true; + } + va_end(va); + + return ret; +} + bool ShowProgress(u64 current, u64 total, const char* opstr) { static u32 last_prog_width = 0; diff --git a/source/ui.h b/source/ui.h index 25fa82b..21f2e2b 100644 --- a/source/ui.h +++ b/source/ui.h @@ -73,4 +73,5 @@ bool ShowUnlockSequence(u32 seqlvl, const char *format, ...); u32 ShowSelectPrompt(u32 n, const char** options, const char *format, ...); bool ShowStringPrompt(char* inputstr, u32 max_size, const char *format, ...); u64 ShowHexPrompt(u64 start_val, u32 n_digits, const char *format, ...); +bool ShowDataPrompt(u8* data, u32* size, const char *format, ...); bool ShowProgress(u64 current, u64 total, const char* opstr);