fix 'hf iclass sim'

* add simulation of multiple pages (PAGESEL by @sherhannn9)
* maintain cipher states per page
* update cipher state after UPDATE commands (@sherhannn9)
* add simulation of personalization mode
* respond with SOF on HALT
* display "<SOF>" instead of "0f" in 'hf list iclass'
* standard LED handling
This commit is contained in:
pwpiwi 2019-10-01 21:03:18 +02:00
commit ae60ceca92
2 changed files with 132 additions and 85 deletions

View file

@ -225,17 +225,18 @@ void annotateIclass(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize) {
}
break;
}
case ICLASS_CMD_SELECT: snprintf(exp,size, "SELECT"); break;
case ICLASS_CMD_PAGESEL: snprintf(exp,size, "PAGESEL(%d)", cmd[1]); break;
case ICLASS_CMD_READCHECK_KC:snprintf(exp,size, "READCHECK[Kc](%d)", cmd[1]); break;
case ICLASS_CMD_READCHECK_KD:snprintf(exp,size, "READCHECK[Kd](%d)", cmd[1]); break;
case ICLASS_CMD_CHECK: snprintf(exp,size, "CHECK"); break;
case ICLASS_CMD_DETECT: snprintf(exp,size, "DETECT"); break;
case ICLASS_CMD_HALT: snprintf(exp,size, "HALT"); break;
case ICLASS_CMD_UPDATE: snprintf(exp,size, "UPDATE(%d)",cmd[1]); break;
case ICLASS_CMD_ACT: snprintf(exp,size, "ACT"); break;
case ICLASS_CMD_READ4: snprintf(exp,size, "READ4(%d)",cmd[1]); break;
default: snprintf(exp,size, "?"); break;
case ICLASS_CMD_SELECT: snprintf(exp,size, "SELECT"); break;
case ICLASS_CMD_PAGESEL: snprintf(exp,size, "PAGESEL(%d)", cmd[1]); break;
case ICLASS_CMD_READCHECK_KC: snprintf(exp,size, "READCHECK[Kc](%d)", cmd[1]); break;
case ICLASS_CMD_READCHECK_KD: snprintf(exp,size, "READCHECK[Kd](%d)", cmd[1]); break;
case ICLASS_CMD_CHECK_KC:
case ICLASS_CMD_CHECK_KD: snprintf(exp,size, "CHECK"); break;
case ICLASS_CMD_DETECT: snprintf(exp,size, "DETECT"); break;
case ICLASS_CMD_HALT: snprintf(exp,size, "HALT"); break;
case ICLASS_CMD_UPDATE: snprintf(exp,size, "UPDATE(%d)",cmd[1]); break;
case ICLASS_CMD_ACT: snprintf(exp,size, "ACT"); break;
case ICLASS_CMD_READ4: snprintf(exp,size, "READ4(%d)",cmd[1]); break;
default: snprintf(exp,size, "?"); break;
}
return;
}
@ -336,7 +337,7 @@ void annotateIso14443_4(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize){
else {
int pos = 1;
switch (cmd[0] & 0x0c) {
case 0x08: // CID following
case 0x08: // CID following
case 0x04: // NAD following
pos = 2;
break;
@ -906,7 +907,7 @@ uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *trace, ui
timestamp *= 32;
duration *= 32;
}
//Check the CRC status
uint8_t crcStatus = 2;
@ -969,11 +970,15 @@ uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *trace, ui
if (protocol == ISO_14443A || protocol == PROTO_MIFARE) {
if (duration < 128 * (9 * data_len)) {
line[(data_len-1)/16][((data_len-1)%16) * 4 + 3] = '\'';
}
}
}
if (data_len == 0) {
sprintf(line[0]," <empty trace - possible error>");
if (protocol == ICLASS && duration == 2048) {
sprintf(line[0], " <SOF>");
} else {
sprintf(line[0], " <empty trace - possible error>");
}
}
//--- Draw the CRC column
@ -1014,7 +1019,7 @@ uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *trace, ui
(j == num_lines-1) ? explanation : "");
}
}
if (DecodeMifareData(frame, data_len, parityBytes, isResponse, mfData, &mfDataLen)) {
memset(explanation, 0x00, sizeof(explanation));
if (!isResponse) {