mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 05:43:48 -07:00
Improved sam response processing
Improved sam response processing on client side, it detects when the response contains an error and highlights the error number, detects when the response is an snmp messages and does the asn.1 decoding of the snmp message.
This commit is contained in:
parent
b74b52f01a
commit
37166d6c73
1 changed files with 28 additions and 1 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue