mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 05:43:48 -07:00
dump/info readblock loops rework
This commit is contained in:
parent
5de626992f
commit
cedc593528
1 changed files with 13 additions and 70 deletions
|
@ -626,6 +626,8 @@ static void xerox_print_info(uint8_t *d) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// Assumes the card is already selected.
|
||||
static int read_xerox_block(iso14b_card_select_t *card, uint8_t blockno, uint8_t *out) {
|
||||
|
||||
if (card == NULL || out == NULL) {
|
||||
|
@ -640,9 +642,9 @@ static int read_xerox_block(iso14b_card_select_t *card, uint8_t blockno, uint8_t
|
|||
}
|
||||
|
||||
// set up the read command
|
||||
packet->flags = (ISO14B_CONNECT | ISO14B_APPEND_CRC | ISO14B_RAW);
|
||||
packet->flags = (ISO14B_APPEND_CRC | ISO14B_RAW);
|
||||
packet->raw[packet->rawlen++] = 0x02;
|
||||
packet->raw[packet->rawlen++] = ISO14443B_XEROX_READ_BLK;
|
||||
packet->raw[packet->rawlen++] = (blockno < 12) ? ISO14443B_XEROX_READ_BLK : ISO14443B_XEROX_EXT_READ_BLK;
|
||||
|
||||
// uid
|
||||
memcpy(packet->raw + packet->rawlen, card->uid, card->uidlen);
|
||||
|
@ -651,14 +653,10 @@ static int read_xerox_block(iso14b_card_select_t *card, uint8_t blockno, uint8_t
|
|||
// block to read
|
||||
packet->raw[packet->rawlen++] = blockno;
|
||||
|
||||
|
||||
int res = PM3_ESOFT;
|
||||
// read loop
|
||||
for (int retry = 0; retry < 2; retry++) {
|
||||
|
||||
if (retry) {
|
||||
packet->flags = (ISO14B_APPEND_CRC | ISO14B_RAW);
|
||||
}
|
||||
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_HF_ISO14443B_COMMAND, (uint8_t *)packet, sizeof(iso14b_raw_cmd_t) + packet->rawlen);
|
||||
PacketResponseNG resp;
|
||||
|
@ -693,8 +691,6 @@ static int read_xerox_block(iso14b_card_select_t *card, uint8_t blockno, uint8_t
|
|||
res = PM3_SUCCESS;
|
||||
break;
|
||||
}
|
||||
|
||||
switch_off_field();
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -758,6 +754,7 @@ static int CmdHFXeroxInfo(const char *Cmd) {
|
|||
|
||||
uint8_t data[sizeof(info_blocks) * XEROX_BLOCK_SIZE] = {0};
|
||||
|
||||
// special blocks to read.
|
||||
for (int i = 0; i < sizeof(i); i++) {
|
||||
|
||||
int res = read_xerox_block(&card, info_blocks[i], data + (i * XEROX_BLOCK_SIZE));
|
||||
|
@ -810,78 +807,24 @@ static int CmdHFXeroxDump(const char *Cmd) {
|
|||
}
|
||||
|
||||
PrintAndLogEx(INFO, "Reading memory from tag UID " _GREEN_("%s"), sprint_hex(card.uid, card.uidlen));
|
||||
PrintAndLogEx(INFO, "" NOLF);
|
||||
|
||||
uint8_t approx_len = (2 + 8 + 1);
|
||||
iso14b_raw_cmd_t *packet = (iso14b_raw_cmd_t *)calloc(1, sizeof(iso14b_raw_cmd_t) + approx_len);
|
||||
if (packet == NULL) {
|
||||
PrintAndLogEx(FAILED, "failed to allocate memory");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
|
||||
int blockno = 1; // block 0 all zeros
|
||||
uint8_t data[256 * XEROX_BLOCK_SIZE] = {0};
|
||||
|
||||
// set up the read command
|
||||
packet->flags = (ISO14B_CONNECT | ISO14B_APPEND_CRC | ISO14B_RAW);
|
||||
packet->raw[packet->rawlen++] = 0x02;
|
||||
uint16_t blockno = 0;
|
||||
for (; blockno < 0x100; blockno++) {
|
||||
|
||||
// add one for command byte
|
||||
packet->rawlen++;
|
||||
|
||||
// store uid
|
||||
memcpy(packet->raw + packet->rawlen, card.uid, 8);
|
||||
packet->rawlen += 8;
|
||||
|
||||
PrintAndLogEx(INFO, "." NOLF);
|
||||
|
||||
for (int retry = 0; (retry < 2 && blockno < 0x100); retry++) {
|
||||
|
||||
// set command: read ext mem or read mem
|
||||
packet->raw[1] = (blockno < 12) ? ISO14443B_XEROX_READ_BLK : ISO14443B_XEROX_EXT_READ_BLK;
|
||||
packet->raw[10] = blockno & 0xFF;
|
||||
|
||||
PacketResponseNG resp;
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_HF_ISO14443B_COMMAND, (uint8_t *)packet, sizeof(iso14b_raw_cmd_t) + packet->rawlen);
|
||||
if (WaitForResponseTimeout(CMD_HF_ISO14443B_COMMAND, &resp, 2000) == false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (resp.status != PM3_SUCCESS) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (resp.length < 7) {
|
||||
PrintAndLogEx(FAILED, "retrying one more time");
|
||||
continue;
|
||||
}
|
||||
|
||||
uint8_t *d = resp.data.asBytes;
|
||||
|
||||
if (check_crc(CRC_14443_B, d, 7) == false) {
|
||||
PrintAndLogEx(FAILED, "retrying one more time, CRC ( " _RED_("fail") " )");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (d[0] != 0x02) {
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(FAILED, "Tag returned Error %x %x", d[0], d[1]);
|
||||
int res = read_xerox_block(&card, blockno, data + (blockno * XEROX_BLOCK_SIZE));
|
||||
if (res != PM3_SUCCESS) {
|
||||
PrintAndLogEx(FAILED, "Fuji/Xerox tag read failed");
|
||||
break;
|
||||
}
|
||||
|
||||
memcpy(data + (blockno * XEROX_BLOCK_SIZE), resp.data.asBytes + 1, XEROX_BLOCK_SIZE);
|
||||
|
||||
retry = 0;
|
||||
blockno++;
|
||||
|
||||
PrintAndLogEx(NORMAL, "." NOLF);
|
||||
fflush(stdout);
|
||||
PrintAndLogEx(INPLACE, "blk %3d", blockno);
|
||||
}
|
||||
|
||||
switch_off_field();
|
||||
|
||||
free(packet);
|
||||
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
|
||||
if (blockno != 0x100) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue