From 7fe02233d82cc8fb49d2ca144348924d2016b595 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 23 Jun 2023 13:56:59 +0200 Subject: [PATCH] textual changes to MAD output --- client/src/mifare/mad.c | 47 +++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/client/src/mifare/mad.c b/client/src/mifare/mad.c index c870dbb28..42a05c5a2 100644 --- a/client/src/mifare/mad.c +++ b/client/src/mifare/mad.c @@ -190,7 +190,7 @@ int MADCheck(uint8_t *sector0, uint8_t *sector10, bool verbose, bool *haveMAD2) uint8_t GPB = sector0[(3 * 16) + 9]; if (verbose) - PrintAndLogEx(SUCCESS, "%14s " _GREEN_("0x%02x"), "GPB", GPB); + PrintAndLogEx(SUCCESS, "GPB....... " _GREEN_("0x%02X"), GPB); // DA (MAD available) if (!(GPB & 0x80)) { @@ -200,21 +200,22 @@ int MADCheck(uint8_t *sector0, uint8_t *sector10, bool verbose, bool *haveMAD2) uint8_t mad_ver = GPB & 0x03; if (verbose) - PrintAndLogEx(SUCCESS, "%14s " _GREEN_("%d"), "MAD version", mad_ver); + PrintAndLogEx(SUCCESS, "Version... " _GREEN_("%d"), mad_ver); // MAD version if ((mad_ver != 0x01) && (mad_ver != 0x02)) { - PrintAndLogEx(ERR, "Wrong MAD version " _RED_("0x%02x"), mad_ver); + PrintAndLogEx(ERR, "Wrong MAD version " _RED_("0x%02X"), mad_ver); return PM3_ESOFT; }; - if (haveMAD2) + if (haveMAD2) { *haveMAD2 = (mad_ver == 2); + } int res = madCRCCheck(sector0, true, 1); - - if (verbose && res == PM3_SUCCESS) - PrintAndLogEx(SUCCESS, "%14s " _GREEN_("0x%02x") " ( %s )", "CRC8", sector0[16], _GREEN_("ok")); + if (verbose && res == PM3_SUCCESS) { + PrintAndLogEx(SUCCESS, "CRC8...... 0x%02X ( %s )", sector0[16], _GREEN_("ok")); + } if (mad_ver == 2 && sector10) { int res2 = madCRCCheck(sector10, true, 2); @@ -222,7 +223,7 @@ int MADCheck(uint8_t *sector0, uint8_t *sector10, bool verbose, bool *haveMAD2) res = res2; if (verbose && !res2) - PrintAndLogEx(SUCCESS, "%14s " _GREEN_("0x%02x") " ( %s )", "CRC8", sector10[0], _GREEN_("ok")); + PrintAndLogEx(SUCCESS, "CRC8...... 0x%02X ( %s )", sector10[0], _GREEN_("ok")); } // MA (multi-application card) @@ -284,9 +285,10 @@ static int MADInfoByteDecode(const uint8_t *sector, bool swapmad, int mad_ver, b info = sector[16 + 1] & 0x3f; if (info >= 0xF) { PrintAndLogEx(WARNING, "Invalid Info byte (MAD1) value " _YELLOW_("0x%02x"), info); - if (verbose) + if (verbose) { // I understand the spec in a way that MAD1 InfoByte should not point into MAD2 sectors, @lukaskuzmiak PrintAndLogEx(WARNING, "MAD1 Info byte points outside of MAD1 sector space (0x%02x), report a bug?", info); + } return PM3_ESOFT; } } else { @@ -318,7 +320,7 @@ int MAD1DecodeAndPrint(uint8_t *sector, bool swapmad, bool verbose, bool *haveMA int ibs = MADInfoByteDecode(sector, swapmad, 1, verbose); if (ibs > 0) { - PrintAndLogEx(SUCCESS, "Card publisher sector " _MAGENTA_("0x%02x"), ibs); + PrintAndLogEx(SUCCESS, "Card publisher sector " _MAGENTA_("0x%02X"), ibs); } else { PrintAndLogEx(WARNING, "Card publisher " _RED_("not") " present " _YELLOW_("0x%02x"), ibs); } @@ -356,7 +358,7 @@ int MAD1DecodeAndPrint(uint8_t *sector, bool swapmad, bool verbose, bool *haveMA } int MAD2DecodeAndPrint(uint8_t *sector, bool swapmad, bool verbose) { - open_mad_file(&mad_known_aids, verbose); + open_mad_file(&mad_known_aids, false); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(INFO, "------------ " _CYAN_("MAD v2 details") " -------------"); @@ -364,14 +366,14 @@ int MAD2DecodeAndPrint(uint8_t *sector, bool swapmad, bool verbose) { int res = madCRCCheck(sector, true, 2); if (verbose) { if (res == PM3_SUCCESS) - PrintAndLogEx(SUCCESS, "CRC8 ( %s )", _GREEN_("ok")); + PrintAndLogEx(SUCCESS, "CRC8...... 0x%02X ( " _GREEN_("%s") " )", sector[0], "ok"); else - PrintAndLogEx(WARNING, "CRC8 ( %s )", _RED_("fail")); + PrintAndLogEx(SUCCESS, "CRC8...... 0x%02X ( " _RED_("%s") " )", sector[0], "fail"); } int ibs = MADInfoByteDecode(sector, swapmad, 2, verbose); if (ibs > 0) { - PrintAndLogEx(SUCCESS, "Card publisher sector " _MAGENTA_("0x%02x"), ibs); + PrintAndLogEx(SUCCESS, "Card publisher sector " _MAGENTA_("0x%02X"), ibs); } else { PrintAndLogEx(WARNING, "Card publisher " _RED_("not") " present " _YELLOW_("0x%02x"), ibs); } @@ -385,12 +387,21 @@ int MAD2DecodeAndPrint(uint8_t *sector, bool swapmad, bool verbose) { for (int i = 1; i < 8 + 8 + 7 + 1; i++) { uint16_t aid = madGetAID(sector, swapmad, 2, i); if (aid < 6) { - PrintAndLogEx(INFO, (ibs == i) ? _MAGENTA_(" %02d [%04X] (%s)") : " %02d [%04X] (%s)", i + 16, aid, aid_admin[aid]); + PrintAndLogEx(INFO, + (ibs == i) ? _MAGENTA_(" %02d [%04X] %s") : " %02d [" _GREEN_("%04X") "] %s", + i + 16, + aid, + aid_admin[aid] + ); } else if (prev_aid == aid) { - PrintAndLogEx(INFO, (ibs == i) ? _MAGENTA_(" %02d [%04X] (continuation)") : " %02d [%04X] (continuation)", i + 16, aid); + PrintAndLogEx(INFO, + (ibs == i) ? _MAGENTA_(" %02d [%04X] continuation") : " %02d [" _YELLOW_("%04X") "] continuation", + i + 16, + aid + ); } else { - char fmt[30]; - snprintf(fmt, sizeof(fmt), (ibs == i) ? _MAGENTA_(" %02d [%04X]%s") : " %02d [%04X]%s", i + 16, aid, "%s"); + char fmt[60]; + snprintf(fmt, sizeof(fmt), (ibs == i) ? _MAGENTA_(" %02d [%04X]%s") : " %02d [" _GREEN_("%04X") "]%s", i + 16, aid, "%s"); print_aid_description(mad_known_aids, aid, fmt, verbose); prev_aid = aid; }