mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-08-14 02:26:59 -07:00
fix 'hf iclass writebl' and 'hf iclass clone' (#896)
* check for correct responses after block updates * reduce number of tries from 10 to 3 * Allow to override warning on attempt to clone blocks < 5 * add same warning and override option to 'hf iclass writebl' * some reformatting and minor refactoring * Drop field after dump and clone functions * If dumping AA1 with Credit Key, authenticate as Debit Key * Initialize reader when beginning to clone
This commit is contained in:
parent
1d4b67cb3d
commit
a4ff62be63
2 changed files with 102 additions and 63 deletions
|
@ -848,6 +848,9 @@ void iClass_Dump(uint8_t startblock, uint8_t numblks) {
|
|||
}
|
||||
}
|
||||
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
LED_D_OFF();
|
||||
|
||||
cmd_send(CMD_ACK, isOK, blkCnt, 0, readblockdata, blkCnt*8);
|
||||
|
||||
LED_A_OFF();
|
||||
|
@ -863,12 +866,27 @@ static bool iClass_WriteBlock_ext(uint8_t blockNo, uint8_t *data) {
|
|||
bool isOK = false;
|
||||
uint32_t eof_time = 0;
|
||||
|
||||
isOK = sendCmdGetResponseWithRetries(write, sizeof(write), resp, sizeof(resp), 10, 10, 0, ICLASS_READER_TIMEOUT_UPDATE, &eof_time);
|
||||
if (isOK && blockNo != 3 && blockNo != 4 && memcmp(write+2, resp, 8)) { // check response
|
||||
isOK = false;
|
||||
isOK = sendCmdGetResponseWithRetries(write, sizeof(write), resp, sizeof(resp), 10, 3, 0, ICLASS_READER_TIMEOUT_UPDATE, &eof_time);
|
||||
if (!isOK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t all_ff[8] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
|
||||
if (blockNo == 2) {
|
||||
if (memcmp(data+4, resp, 4) || memcmp(data, resp+4, 4)) { // check response. e-purse update swaps first and second half
|
||||
return false;
|
||||
}
|
||||
} else if (blockNo == 3 || blockNo == 4) {
|
||||
if (memcmp(all_ff, resp, 8)) { // check response. Key updates always return 0xffffffffffffffff
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (memcmp(data, resp, 8)) { // check response. All other updates return unchanged data
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return isOK;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -895,17 +913,16 @@ void iClass_Clone(uint8_t startblock, uint8_t endblock, uint8_t *data) {
|
|||
|
||||
LED_A_ON();
|
||||
|
||||
int i;
|
||||
int written = 0;
|
||||
int total_blocks = (endblock - startblock) + 1;
|
||||
|
||||
for (i = 0; i < total_blocks; i++) {
|
||||
for (uint8_t block = startblock; block <= endblock; block++) {
|
||||
// block number
|
||||
if (iClass_WriteBlock_ext(i+startblock, data + (i*12))){
|
||||
Dbprintf("Write block [%02x] successful", i + startblock);
|
||||
if (iClass_WriteBlock_ext(block, data + (block-startblock)*12)) {
|
||||
Dbprintf("Write block [%02x] successful", block);
|
||||
written++;
|
||||
} else {
|
||||
Dbprintf("Write block [%02x] failed", i + startblock);
|
||||
Dbprintf("Write block [%02x] failed", block);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -914,9 +931,10 @@ void iClass_Clone(uint8_t startblock, uint8_t endblock, uint8_t *data) {
|
|||
else
|
||||
Dbprintf("Clone incomplete");
|
||||
|
||||
cmd_send(CMD_ACK, 1, 0, 0, 0, 0);
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
LED_D_OFF();
|
||||
|
||||
cmd_send(CMD_ACK, 1, 0, 0, 0, 0);
|
||||
|
||||
LED_A_OFF();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue