diff --git a/client/src/cmdhficlass.c b/client/src/cmdhficlass.c index 035031cf2..b7e1fedc7 100644 --- a/client/src/cmdhficlass.c +++ b/client/src/cmdhficlass.c @@ -5886,6 +5886,15 @@ static int CmdHFiClassConfigCard(const char *Cmd) { return PM3_SUCCESS; } +static bool match_with_wildcard(const uint8_t *data, const uint8_t *pattern, const bool *mask, size_t length) { + for (size_t i = 0; i < length; ++i) { + if (mask[i] && data[i] != pattern[i]) { + return false; + } + } + return true; +} + static int CmdHFiClassSAM(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf iclass sam", @@ -5964,6 +5973,8 @@ static int CmdHFiClassSAM(const char *Cmd) { PacketResponseNG resp; WaitForResponse(CMD_HF_SAM_PICOPASS, &resp); + bool is_snmp = false; + switch (resp.status) { case PM3_SUCCESS: break; @@ -6022,11 +6033,27 @@ static int CmdHFiClassSAM(const char *Cmd) { PrintAndLogEx(SUCCESS, " hf iclass dump --nr -k %s", sprint_hex_inrow(d + 1, 8)); } } else { + //if it is an error decode it + if (memcmp(d, "\xBE\x07\x80\x01", 4) == 0) { //if it the string is 0xbe 0x07 0x80 0x01 the next byte will indicate the error code + PrintAndLogEx(ERR,_RED_("Sam Error Code: %s"), d[4]); print_hex(d, resp.length); + + }else{ + uint8_t pattern[] = {0xBD, 0x81, 0xFF, 0x8A, 0x81, 0xFF}; // 0xFF is a placeholder for the length message + bool mask[] = {true, true, false, true, true, false}; // false means wildcard + if (match_with_wildcard(d, pattern, mask, 4)) { // Pattern matched with wildcard support + is_snmp = true; + PrintAndLogEx(SUCCESS, _YELLOW_("samSNMPMessageResponse: ")"%s", sprint_hex(d + 6, resp.length - 6)); + }else{ + print_hex(d, resp.length); + } + } } - if (decodeTLV) { + if (decodeTLV && is_snmp == false) { asn1_print(d, d[1] + 2, " "); + } else{ + asn1_print(d + 6, resp.length - 6, " "); } return PM3_SUCCESS;