mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-07-30 11:39:14 -07:00
Merge pull request #2912 from Antiklesys/master
Improved sam response parsing
This commit is contained in:
commit
cfe9c39b89
1 changed files with 30 additions and 2 deletions
|
@ -5886,6 +5886,15 @@ static int CmdHFiClassConfigCard(const char *Cmd) {
|
||||||
return PM3_SUCCESS;
|
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) {
|
static int CmdHFiClassSAM(const char *Cmd) {
|
||||||
CLIParserContext *ctx;
|
CLIParserContext *ctx;
|
||||||
CLIParserInit(&ctx, "hf iclass sam",
|
CLIParserInit(&ctx, "hf iclass sam",
|
||||||
|
@ -5964,6 +5973,12 @@ static int CmdHFiClassSAM(const char *Cmd) {
|
||||||
PacketResponseNG resp;
|
PacketResponseNG resp;
|
||||||
WaitForResponse(CMD_HF_SAM_PICOPASS, &resp);
|
WaitForResponse(CMD_HF_SAM_PICOPASS, &resp);
|
||||||
|
|
||||||
|
bool is_snmp = false;
|
||||||
|
uint8_t snmp_pattern[] = {0xBD, 0x81, 0xFF, 0x8A, 0x81, 0xFF}; // SNMP Response header pattern, 0xFF is a wildcard value for message length
|
||||||
|
bool snmp_mask[] = {true, true, false, true, true, false}; // false means wildcard value in that position
|
||||||
|
uint8_t ack_pattern[] = {0xBD, 0xFF, 0x8A}; // Acknowledge Response header pattern, 0xFF is a wildcard value for message length
|
||||||
|
bool ack_mask[] = {true, false, true}; // false means wildcard value in that position
|
||||||
|
|
||||||
switch (resp.status) {
|
switch (resp.status) {
|
||||||
case PM3_SUCCESS:
|
case PM3_SUCCESS:
|
||||||
break;
|
break;
|
||||||
|
@ -6022,11 +6037,24 @@ static int CmdHFiClassSAM(const char *Cmd) {
|
||||||
PrintAndLogEx(SUCCESS, " hf iclass dump --nr -k %s", sprint_hex_inrow(d + 1, 8));
|
PrintAndLogEx(SUCCESS, " hf iclass dump --nr -k %s", sprint_hex_inrow(d + 1, 8));
|
||||||
}
|
}
|
||||||
} else {
|
} 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: %02x"), d[4]);
|
||||||
|
print_hex(d, resp.length);
|
||||||
|
}else if (match_with_wildcard(d, snmp_pattern, snmp_mask, 6)){
|
||||||
|
is_snmp = true;
|
||||||
|
PrintAndLogEx(SUCCESS, _YELLOW_("[samSNMPMessageResponse] ")"%s", sprint_hex(d + 6, resp.length - 6));
|
||||||
|
}else if (match_with_wildcard(d,ack_pattern, ack_mask, 3)){
|
||||||
|
PrintAndLogEx(SUCCESS, _YELLOW_("[samResponseAcknowledge] ")"%s", sprint_hex(d + 4, resp.length - 4));
|
||||||
|
}else{
|
||||||
print_hex(d, resp.length);
|
print_hex(d, resp.length);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (decodeTLV) {
|
if (decodeTLV && is_snmp == false) {
|
||||||
asn1_print(d, d[1] + 2, " ");
|
asn1_print(d, d[1] + 2, " ");
|
||||||
|
} else if (decodeTLV && is_snmp){
|
||||||
|
asn1_print(d + 6, resp.length - 6, " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue