fixing padding @anon

This commit is contained in:
iceman1001 2021-04-07 09:13:45 +02:00
commit 871820f8f7

View file

@ -652,8 +652,7 @@ void *mifare_cryto_postprocess_data(desfiretag_t tag, void *data, size_t *nbytes
free(edata); free(edata);
break; break;
case MDCM_ENCIPHERED: case MDCM_ENCIPHERED: {
(*nbytes)--;
bool verified = false; bool verified = false;
int crc_pos = 0x00; int crc_pos = 0x00;
int end_crc_pos = 0x00; int end_crc_pos = 0x00;
@ -702,11 +701,13 @@ void *mifare_cryto_postprocess_data(desfiretag_t tag, void *data, size_t *nbytes
if (res != NULL) { if (res != NULL) {
memcpy(res, data, *nbytes); memcpy(res, data, *nbytes);
crc_pos = (*nbytes) - 16 - 3; size_t padding_start_pos = *nbytes - 1;
if (crc_pos < 0) { while (padding_start_pos > 0 && ((uint8_t *) res)[padding_start_pos] == 0x00) {
/* Single block */ padding_start_pos--;
crc_pos = 0;
} }
//TODO: Add support for cases where there is no padding. Uncommon but possible.
crc_pos = padding_start_pos - 4;
memcpy((uint8_t *) res + crc_pos + 1, (uint8_t *) res + crc_pos, *nbytes - crc_pos); memcpy((uint8_t *) res + crc_pos + 1, (uint8_t *) res + crc_pos, *nbytes - crc_pos);
((uint8_t *) res)[crc_pos] = 0x00; ((uint8_t *) res)[crc_pos] = 0x00;
crc_pos++; crc_pos++;
@ -747,6 +748,7 @@ void *mifare_cryto_postprocess_data(desfiretag_t tag, void *data, size_t *nbytes
((uint8_t *)data)[(*nbytes)++] = 0x00; ((uint8_t *)data)[(*nbytes)++] = 0x00;
break; break;
case AS_NEW: case AS_NEW:
*nbytes = crc_pos - 1;
/* The status byte was already before the CRC */ /* The status byte was already before the CRC */
break; break;
} }
@ -775,6 +777,7 @@ void *mifare_cryto_postprocess_data(desfiretag_t tag, void *data, size_t *nbytes
} }
break; break;
}
default: default:
PrintAndLogEx(ERR, "Unknown communication settings"); PrintAndLogEx(ERR, "Unknown communication settings");
*nbytes = -1; *nbytes = -1;