added mifare trailer block decoding (#726)

This commit is contained in:
Oleg Moiseenko 2018-12-03 09:29:13 +02:00 committed by pwpiwi
parent 383f4e2479
commit ac4ecfe353
3 changed files with 83 additions and 2 deletions

View file

@ -141,12 +141,26 @@ int CmdHF14AMfRdBl(const char *Cmd)
uint8_t isOK = resp.arg[0] & 0xff;
uint8_t *data = resp.d.asBytes;
if (isOK)
if (isOK) {
PrintAndLog("isOk:%02x data:%s", isOK, sprint_hex(data, 16));
else
} else {
PrintAndLog("isOk:%02x", isOK);
return 1;
}
if (mfIsSectorTrailer(blockNo) && (data[6] || data[7] || data[8])) {
PrintAndLogEx(NORMAL, "Trailer decoded:");
int bln = mfFirstBlockOfSector(mfSectorNum(blockNo));
int blinc = (mfNumBlocksPerSector(mfSectorNum(blockNo)) > 4) ? 5 : 1;
for (int i = 0; i < 4; i++) {
PrintAndLogEx(NORMAL, "Access block %d%s: %s", bln, ((blinc > 1) && (i < 3) ? "+" : "") , mfGetAccessConditionsDesc(i, &data[6]));
bln += blinc;
}
PrintAndLogEx(NORMAL, "UserData: %s", sprint_hex_inrow(&data[9], 1));
}
} else {
PrintAndLog("Command execute timeout");
return 2;
}
return 0;
@ -2272,6 +2286,20 @@ int CmdHF14AMfCGetBlk(const char *Cmd) {
}
PrintAndLog("block data:%s", sprint_hex(memBlock, 16));
if (mfIsSectorTrailer(blockNo)) {
PrintAndLogEx(NORMAL, "Trailer decoded:");
PrintAndLogEx(NORMAL, "Key A: %s", sprint_hex_inrow(memBlock, 6));
PrintAndLogEx(NORMAL, "Key B: %s", sprint_hex_inrow(&memBlock[10], 6));
int bln = mfFirstBlockOfSector(mfSectorNum(blockNo));
int blinc = (mfNumBlocksPerSector(mfSectorNum(blockNo)) > 4) ? 5 : 1;
for (int i = 0; i < 4; i++) {
PrintAndLogEx(NORMAL, "Access block %d%s: %s", bln, ((blinc > 1) && (i < 3) ? "+" : "") , mfGetAccessConditionsDesc(i, &memBlock[6]));
bln += blinc;
}
PrintAndLogEx(NORMAL, "UserData: %s", sprint_hex_inrow(&memBlock[9], 1));
}
return 0;
}