New ShowDataPrompt() input prompt

This commit is contained in:
d0k3 2016-07-12 18:15:45 +02:00
parent f998975d05
commit 0cf31eb547
2 changed files with 28 additions and 0 deletions

View File

@ -469,6 +469,33 @@ u64 ShowHexPrompt(u64 start_val, u32 n_digits, const char *format, ...) {
return ret; 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) bool ShowProgress(u64 current, u64 total, const char* opstr)
{ {
static u32 last_prog_width = 0; static u32 last_prog_width = 0;

View File

@ -73,4 +73,5 @@ bool ShowUnlockSequence(u32 seqlvl, const char *format, ...);
u32 ShowSelectPrompt(u32 n, const char** options, const char *format, ...); u32 ShowSelectPrompt(u32 n, const char** options, const char *format, ...);
bool ShowStringPrompt(char* inputstr, u32 max_size, const char *format, ...); bool ShowStringPrompt(char* inputstr, u32 max_size, const char *format, ...);
u64 ShowHexPrompt(u64 start_val, u32 n_digits, 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); bool ShowProgress(u64 current, u64 total, const char* opstr);