fixing textual output of ASN1 printing

This commit is contained in:
iceman1001 2021-05-05 12:07:36 +02:00
parent e6e58227cb
commit ea416c3694
2 changed files with 26 additions and 10 deletions

View file

@ -35,6 +35,7 @@ enum asn1_tag_t {
ASN1_TAG_UTC_TIME,
ASN1_TAG_STR_TIME,
ASN1_TAG_OBJECT_ID,
ASN1_TAG_HEX,
};
struct asn1_tag {
@ -157,8 +158,11 @@ static void asn1_tag_dump_str_time(const struct tlv *tlv, const struct asn1_tag
}
static void asn1_tag_dump_string(const struct tlv *tlv, const struct asn1_tag *tag, int level) {
PrintAndLogEx(NORMAL, " value: '" NOLF);
PrintAndLogEx(NORMAL, "%s'", sprint_hex(tlv->value, tlv->len));
PrintAndLogEx(NORMAL, " value: '%s'", sprint_hex(tlv->value, tlv->len));
}
static void asn1_tag_dump_hex(const struct tlv *tlv, const struct asn1_tag *tag, int level) {
PrintAndLogEx(NORMAL, " value: '%s'", sprint_hex_inrow(tlv->value, tlv->len));
}
static void asn1_tag_dump_octet_string(const struct tlv *tlv, const struct asn1_tag *tag, int level, bool *needdump) {
@ -170,7 +174,7 @@ static void asn1_tag_dump_octet_string(const struct tlv *tlv, const struct asn1_
}
if (*needdump) {
PrintAndLogEx(NORMAL, "'");
PrintAndLogEx(NORMAL, "");
} else {
PrintAndLogEx(NORMAL, " " NOLF);
asn1_tag_dump_string(tlv, tag, level);
@ -314,18 +318,26 @@ bool asn1_tag_dump(const struct tlv *tlv, int level, bool *candump) {
const struct asn1_tag *tag = asn1_get_tag(tlv);
/*
if ((tlv->tag & 0x20) == 0x20 ) {
} else if ((tlv->tag & 0x80) == 0x80 ) {
} else {
}
*/
PrintAndLogEx(INFO,
"%*s-- %2x [%02zx] '"_YELLOW_("%s") "' :" NOLF
, (level * 4)
, " "
, tlv->tag
, tlv->len
, tag->name
"%*s-- %2x [%02zx] '"_YELLOW_("%s") "'" NOLF
, (level * 4)
, " "
, tlv->tag
, tlv->len
, tag->name
);
switch (tag->type) {
case ASN1_TAG_GENERIC:
PrintAndLogEx(NORMAL, "");
// maybe print number of elements?
break;
case ASN1_TAG_STRING:
asn1_tag_dump_string(tlv, tag, level);
@ -352,6 +364,10 @@ bool asn1_tag_dump(const struct tlv *tlv, int level, bool *candump) {
asn1_tag_dump_object_id(tlv, tag, level);
*candump = false;
break;
case ASN1_TAG_HEX:
asn1_tag_dump_hex(tlv, tag, level);
*candump = false;
break;
};
return true;

View file

@ -65,7 +65,7 @@ static void asn1_print_cb(void *data, const struct tlv *tlv, int level, bool is_
bool candump = true;
asn1_tag_dump(tlv, level, &candump);
if (is_leaf && candump) {
print_buffer(tlv->value, tlv->len, level);
print_buffer(tlv->value, tlv->len, level + 1);
}
}