hf mf gview, gload : 2x speed

on Gen4 GTU cards, a select was made before each read or write command.
This commit adds a flag parameter to the read and write commands,
and gload and gview commands use this flag to tell when to select and end.

The trace buffer also contains the complete operation instead of the last
blokc read/write.

Speed gain:
`time ./proxmark3 -p /dev/ttyACM0 -c 'hf mf gview --4k'`
before: about 20s, now: about 7s

`time ./proxmark3 -p /dev/ttyACM0 -c 'hf mf gload --4k -f ../../../dumps/4k.bin'`
before: about 23s, now: about 10s
This commit is contained in:
DidierA 2022-11-13 01:37:52 +01:00
commit da1ce30533

View file

@ -7022,8 +7022,13 @@ static int CmdHF14AGen4Load(const char *cmd) {
fflush(stdout); fflush(stdout);
// write block // write block
if (mfG4SetBlock(pwd, blockno, data + (blockno * MFBLOCK_SIZE), MAGIC_INIT | MAGIC_OFF) != PM3_SUCCESS) { uint8_t flags = 0 ;
PrintAndLogEx(WARNING, "Can't set magic card block: %d", blockno); if (blockno == start) flags |= MAGIC_INIT ;
if (blockno == end) flags |= MAGIC_OFF ;
int res=mfG4SetBlock(pwd, blockno, data + (blockno * MFBLOCK_SIZE), flags);
if ( res != PM3_SUCCESS) {
PrintAndLogEx(WARNING, "Can't set magic card block: %d. error=%d", blockno, res);
PrintAndLogEx(HINT, "Verify your card size, and try again or try another tag position"); PrintAndLogEx(HINT, "Verify your card size, and try again or try another tag position");
free(data); free(data);
return PM3_ESOFT; return PM3_ESOFT;
@ -7163,31 +7168,6 @@ static int CmdHF14AGen4View(const char *Cmd) {
} }
PrintAndLogEx(SUCCESS, "View magic gen4 GTU MIFARE Classic " _GREEN_("%s"), s); PrintAndLogEx(SUCCESS, "View magic gen4 GTU MIFARE Classic " _GREEN_("%s"), s);
// Select card to get UID/UIDLEN information
clearCommandBuffer();
SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT, 0, 0, NULL, 0);
PacketResponseNG resp;
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) {
PrintAndLogEx(WARNING, "iso14443a card select timeout");
return PM3_ETIMEOUT;
}
/*
0: couldn't read
1: OK, with ATS
2: OK, no ATS
3: proprietary Anticollision
*/
uint64_t select_status = resp.oldarg[0];
if (select_status == 0) {
PrintAndLogEx(WARNING, "iso14443a card select failed");
return PM3_SUCCESS;
}
iso14a_card_select_t card;
memcpy(&card, (iso14a_card_select_t *)resp.data.asBytes, sizeof(iso14a_card_select_t));
// reserve memory // reserve memory
uint16_t bytes = block_cnt * MFBLOCK_SIZE; uint16_t bytes = block_cnt * MFBLOCK_SIZE;
uint8_t *dump = calloc(bytes, sizeof(uint8_t)); uint8_t *dump = calloc(bytes, sizeof(uint8_t));
@ -7206,8 +7186,13 @@ static int CmdHF14AGen4View(const char *Cmd) {
PrintAndLogEx(NORMAL, "." NOLF); PrintAndLogEx(NORMAL, "." NOLF);
fflush(stdout); fflush(stdout);
if (mfG4GetBlock(pwd, i, dump + (i * MFBLOCK_SIZE), MAGIC_INIT | MAGIC_OFF) != PM3_SUCCESS) { uint8_t flags = 0 ;
PrintAndLogEx(WARNING, "Can't get magic card block: %u", i); if (i == 0) flags |= MAGIC_INIT ;
if (i+1 == block_cnt) flags |= MAGIC_OFF ;
int res = mfG4GetBlock(pwd, i, dump + (i * MFBLOCK_SIZE), flags);
if ( res != PM3_SUCCESS) {
PrintAndLogEx(WARNING, "Can't get magic card block: %u. error=%d", i, res);
PrintAndLogEx(HINT, "Verify your card size, and try again or try another tag position"); PrintAndLogEx(HINT, "Verify your card size, and try again or try another tag position");
free(dump); free(dump);
return PM3_ESOFT; return PM3_ESOFT;