preparing for better output of configuration data

This commit is contained in:
iceman1001 2024-01-18 13:44:03 +01:00
commit 0e937e8cc6
2 changed files with 67 additions and 0 deletions

View file

@ -558,6 +558,64 @@ char *sprint_ascii(const uint8_t *data, const size_t len) {
return sprint_ascii_ex(data, len, 0);
}
char *sprint_breakdown_bin(color_t color, const char* bs, int width, int padn, int bits, const char* msg) {
if (bs == NULL || width > 32) {
return NULL;
}
const char *prepad = " ";
const char *postmarker = "................................";
static char buf[32 + 120] = {0};
memset(buf, 0, sizeof(buf));
int8_t end = (width - padn - 1 - bits);
if (end < 0) {
end = 0;
}
switch (color) {
case C_GREEN: {
snprintf(buf, sizeof(buf), "%.*s" _GREEN_("%.*s") " %.*s - " _GREEN_("%s")
, padn, prepad
, bits, bs + padn
, end, postmarker
, msg
);
break;
}
case C_RED: {
snprintf(buf, sizeof(buf), "%.*s" _RED_("%.*s") " %.*s - " _RED_("%s")
, padn, prepad
, bits, bs + padn
, end, postmarker
, msg
);
break;
}
case C_YELLOW: {
snprintf(buf, sizeof(buf), "%.*s" _YELLOW_("%.*s") " %.*s - " _YELLOW_("%s")
, padn, prepad
, bits, bs + padn
, end, postmarker
, msg
);
break;
}
case C_NONE:
default: {
snprintf(buf, sizeof(buf), "%.*s%.*s %.*s - %s"
, padn, prepad
, bits, bs + padn
, end, postmarker
, msg
);
break;
}
}
return buf;
}
int hex_to_bytes(const char *hexValue, uint8_t *bytesValue, size_t maxBytesValueLen) {
char buf[4] = {0};
int indx = 0;

View file

@ -54,6 +54,13 @@ extern int g_numCPUs;
#define PM3_RET_IF_ERR_WITH_MSG(res, ...) if (res != PM3_SUCCESS) { PrintAndLogEx(ERR, __VA_ARGS__); return res; }
#define PM3_RET_IF_ERR_MAYBE_MSG(res, verbose, ...) if (res != PM3_SUCCESS) { if (verbose) PrintAndLogEx(ERR, __VA_ARGS__); return res; }
typedef enum {
C_NONE,
C_GREEN,
C_RED,
C_YELLOW,
} color_t;
int kbd_enter_pressed(void);
void FillFileNameByUID(char *filenamePrefix, const uint8_t *uid, const char *ext, const int uidlen);
// fill buffer from structure [{uint8_t data, size_t length},...]
@ -81,6 +88,8 @@ char *sprint_hex_ascii(const uint8_t *data, const size_t len);
char *sprint_ascii(const uint8_t *data, const size_t len);
char *sprint_ascii_ex(const uint8_t *data, const size_t len, const size_t min_str_len);
char *sprint_breakdown_bin(color_t color, const char* bs, int width, int padn, int bits, const char* msg);
void print_buffer_with_offset(const uint8_t *data, const size_t len, int offset, bool print_header);
void print_buffer(const uint8_t *data, const size_t len, int level);
void print_blocks(uint32_t *data, size_t len);