no printf

This commit is contained in:
iceman1001 2020-08-29 16:06:08 +02:00
commit 941c6f5d25

View file

@ -11,16 +11,15 @@
// //
#include "cbortools.h" #include "cbortools.h"
#include <inttypes.h> #include <inttypes.h>
#include "emv/emvjson.h" #include "emv/emvjson.h"
#include "util.h" #include "util.h"
#include "ui.h" // PrintAndLogEx(
#include "fidocore.h" #include "fidocore.h"
static void indent(int nestingLevel) { static void indent(int nestingLevel) {
while (nestingLevel--) while (nestingLevel--)
printf(" "); PrintAndLogEx(NORMAL, " " NOLF);
} }
static CborError dumpelm(CborValue *it, bool *got_next, int nestingLevel) { static CborError dumpelm(CborValue *it, bool *got_next, int nestingLevel) {
@ -32,14 +31,14 @@ static CborError dumpelm(CborValue *it, bool *got_next, int nestingLevel) {
switch (type) { switch (type) {
case CborMapType: case CborMapType:
case CborArrayType: { case CborArrayType: {
printf(type == CborArrayType ? "Array[" : "Map["); PrintAndLogEx(NORMAL, "%s" NOLF, (type == CborArrayType) ? "Array[" : "Map[");
break; break;
} }
case CborIntegerType: { case CborIntegerType: {
int64_t val; int64_t val;
cbor_value_get_int64(it, &val); // can't fail cbor_value_get_int64(it, &val); // can't fail
printf("%lld", (long long)val); PrintAndLogEx(NORMAL, "%lld" NOLF, (long long)val);
break; break;
} }
@ -50,7 +49,8 @@ static CborError dumpelm(CborValue *it, bool *got_next, int nestingLevel) {
*got_next = true; *got_next = true;
if (err) if (err)
return err; // parse error return err; // parse error
printf("%s", sprint_hex(buf, n));
PrintAndLogEx(NORMAL, "%s" NOLF, sprint_hex(buf, n));
free(buf); free(buf);
break; break;
} }
@ -62,7 +62,8 @@ static CborError dumpelm(CborValue *it, bool *got_next, int nestingLevel) {
*got_next = true; *got_next = true;
if (err) if (err)
return err; // parse error return err; // parse error
printf("%s", buf);
PrintAndLogEx(NORMAL, "%s" NOLF, buf);
free(buf); free(buf);
break; break;
} }
@ -70,29 +71,29 @@ static CborError dumpelm(CborValue *it, bool *got_next, int nestingLevel) {
case CborTagType: { case CborTagType: {
CborTag tag; CborTag tag;
cbor_value_get_tag(it, &tag); cbor_value_get_tag(it, &tag);
printf("Tag(%lld)", (long long)tag); PrintAndLogEx(NORMAL, "Tag(%lld)" NOLF, (long long)tag);
break; break;
} }
case CborSimpleType: { case CborSimpleType: {
uint8_t t; uint8_t t;
cbor_value_get_simple_type(it, &t); cbor_value_get_simple_type(it, &t);
printf("simple(%u)", t); PrintAndLogEx(NORMAL, "simple(%u)" NOLF, t);
break; break;
} }
case CborNullType: case CborNullType:
printf("null"); PrintAndLogEx(NORMAL, "null" NOLF);
break; break;
case CborUndefinedType: case CborUndefinedType:
printf("undefined"); PrintAndLogEx(NORMAL, "undefined" NOLF);
break; break;
case CborBooleanType: { case CborBooleanType: {
bool val; bool val;
cbor_value_get_boolean(it, &val); // can't fail cbor_value_get_boolean(it, &val); // can't fail
printf("%s", val ? "true" : "false"); PrintAndLogEx(NORMAL, "%s" NOLF, (val) ? "true" : "false");
break; break;
} }
@ -106,18 +107,18 @@ static CborError dumpelm(CborValue *it, bool *got_next, int nestingLevel) {
} else { } else {
cbor_value_get_double(it, &val); cbor_value_get_double(it, &val);
} }
printf("%g", val); PrintAndLogEx(NORMAL, "%g" NOLF, val);
break; break;
} }
case CborHalfFloatType: { case CborHalfFloatType: {
uint16_t val; uint16_t val;
cbor_value_get_half_float(it, &val); cbor_value_get_half_float(it, &val);
printf("__f16(%04x)", val); PrintAndLogEx(NORMAL, "__f16(%04x)" NOLF, val);
break; break;
} }
case CborInvalidType: case CborInvalidType:
printf("CborInvalidType!!!"); PrintAndLogEx(NORMAL, _RED_("CborInvalidType!!!") NOLF);
break; break;
} }
@ -129,7 +130,7 @@ static CborError dumprecursive(uint8_t cmdCode, bool isResponse, CborValue *it,
while (!cbor_value_at_end(it)) { while (!cbor_value_at_end(it)) {
CborError err; CborError err;
CborType type = cbor_value_get_type(it); CborType type = cbor_value_get_type(it);
//printf("^%x^", type);
bool got_next = false; bool got_next = false;
switch (type) { switch (type) {
@ -140,18 +141,23 @@ static CborError dumprecursive(uint8_t cmdCode, bool isResponse, CborValue *it,
assert(cbor_value_is_container(it)); assert(cbor_value_is_container(it));
if (!(isMapType && (elmCount % 2))) if (!(isMapType && (elmCount % 2)))
indent(nestingLevel); indent(nestingLevel);
printf(type == CborArrayType ? "Array[\n" : "Map[\n");
PrintAndLogEx(NORMAL, "%s" NOLF, (type == CborArrayType) ? "Array[\n" : "Map[\n");
err = cbor_value_enter_container(it, &recursed); err = cbor_value_enter_container(it, &recursed);
if (err) if (err)
return err; // parse error return err; // parse error
err = dumprecursive(cmdCode, isResponse, &recursed, (type == CborMapType), nestingLevel + 1); err = dumprecursive(cmdCode, isResponse, &recursed, (type == CborMapType), nestingLevel + 1);
if (err) if (err)
return err; // parse error return err; // parse error
err = cbor_value_leave_container(it, &recursed); err = cbor_value_leave_container(it, &recursed);
if (err) if (err)
return err; // parse error return err; // parse error
indent(nestingLevel); indent(nestingLevel);
printf("]"); PrintAndLogEx(NORMAL, "]" NOLF);
got_next = true; got_next = true;
break; break;
} }
@ -170,12 +176,13 @@ static CborError dumprecursive(uint8_t cmdCode, bool isResponse, CborValue *it,
err = dumpelm(it, &got_next, (isMapType && (elmCount % 2)) ? 0 : nestingLevel); err = dumpelm(it, &got_next, (isMapType && (elmCount % 2)) ? 0 : nestingLevel);
if (err) if (err)
return err; return err;
if (cmdCode > 0 && nestingLevel == 1 && isMapType && !(elmCount % 2)) { if (cmdCode > 0 && nestingLevel == 1 && isMapType && !(elmCount % 2)) {
int64_t val; int64_t val;
cbor_value_get_int64(it, &val); cbor_value_get_int64(it, &val);
const char *desc = fido2GetCmdMemberDescription(cmdCode, isResponse, val); const char *desc = fido2GetCmdMemberDescription(cmdCode, isResponse, val);
if (desc) if (desc)
printf(" (%s)", desc); PrintAndLogEx(NORMAL, " (%s)" NOLF, desc);
} }
break; break;
} }
@ -187,9 +194,9 @@ static CborError dumprecursive(uint8_t cmdCode, bool isResponse, CborValue *it,
return err; return err;
} }
if (isMapType && !(elmCount % 2)) { if (isMapType && !(elmCount % 2)) {
printf(": "); PrintAndLogEx(NORMAL, ": " NOLF);
} else { } else {
printf("\n"); PrintAndLogEx(NORMAL, "");
} }
elmCount++; elmCount++;
} }