Fix: 'hf mf fchk' - now reports back correct found keys.

This commit is contained in:
iceman1001 2019-02-17 15:56:45 +01:00
commit 4ea05fc026
3 changed files with 25 additions and 18 deletions

View file

@ -3,6 +3,8 @@ All notable changes to this project will be documented in this file.
This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log...
## [unreleased][unreleased] ## [unreleased][unreleased]
- Fix 'hf mf fchk' (@iceman)
- Fix 'usb slow on posix based systems' (@fl0-0)
- Change 'lf pcf7931' - improved read code (@sguerrini97) - Change 'lf pcf7931' - improved read code (@sguerrini97)
- Change 'hf felica list' - started with some FeliCa annotations (@iceman) - Change 'hf felica list' - started with some FeliCa annotations (@iceman)
- Fix 'hf tune' - now works as expected (@iceman) - Fix 'hf tune' - now works as expected (@iceman)

View file

@ -1259,7 +1259,6 @@ void MifareChkKeys_fast(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *da
LED_A_ON(); LED_A_ON();
if ( firstchunk ) { if ( firstchunk ) {
clear_trace(); clear_trace();
set_tracing(false); set_tracing(false);
@ -1458,26 +1457,31 @@ void MifareChkKeys_fast(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *da
} // end loop sectors } // end loop sectors
} // end loop keys } // end loop keys
} // end loop strategy 2 } // end loop strategy 2
OUT: OUT:
LEDsoff(); LEDsoff();
crypto1_destroy(pcs); crypto1_destroy(pcs);
// All keys found, send to client, or last keychunk from client // All keys found, send to client, or last keychunk from client
if (foundkeys == allkeys || lastchunk ) { if (foundkeys == allkeys || lastchunk ) {
uint64_t foo = 0; uint64_t foo = 0;
for (uint8_t m = 0; m < 64; m++) {
foo |= ((uint64_t)(found[m] & 1) << m);
}
uint16_t bar = 0; uint16_t bar = 0;
for (uint8_t m = 0; m < 64; ++m) uint8_t j = 0;
foo |= (found[m] << m); for (uint8_t m=64; m < sizeof(found); m++) {
for (uint8_t m=64; m < sizeof(found); ++m) bar |= ((uint16_t)(found[m] & 1) << j++);
bar |= (found[m] << (m-64)); }
uint8_t *tmp = BigBuf_malloc(480+10); uint8_t *tmp = BigBuf_malloc(480+10);
memcpy(tmp, k_sector, sectorcnt * sizeof(sector_t) ); memcpy(tmp, k_sector, sectorcnt * sizeof(sector_t) );
num_to_bytes(foo, 8, tmp+480); num_to_bytes(foo, 8, tmp+480);
tmp[488] = bar & 0xFF; tmp[488] = bar & 0xFF;
tmp[489] = bar >> 8 & 0xFF; tmp[489] = bar >> 8 & 0xFF;
cmd_send(CMD_ACK, foundkeys, 0, 0, tmp, 480+10); cmd_send(CMD_ACK, foundkeys, 0, 0, tmp, 480+10);
set_tracing(false); set_tracing(false);

View file

@ -173,18 +173,19 @@ int mfCheckKeys_fast( uint8_t sectorsCnt, uint8_t firstChunk, uint8_t lastChunk,
// success array. each byte is status of key // success array. each byte is status of key
uint8_t arr[80]; uint8_t arr[80];
uint64_t foo = bytes_to_num(resp.d.asBytes+480, 8); uint64_t foo = 0;
for (uint8_t i = 0; i < 64; ++i) { uint16_t bar = 0;
arr[i] = (foo >> i) & 0x1; foo = bytes_to_num(resp.d.asBytes+480, 8);
} bar = (resp.d.asBytes[489] << 8 | resp.d.asBytes[488]);
foo = bytes_to_num(resp.d.asBytes+488, 2);
for (uint8_t i = 0; i < 16; ++i) {
arr[i+64] = (foo >> i) & 0x1;
}
for (uint8_t i = 0; i < 64; i++)
arr[i] = (foo >> i) & 0x1;
for (uint8_t i = 0; i < 16; i++)
arr[i+64] = (bar >> i) & 0x1;
// initialize storage for found keys // initialize storage for found keys
icesector_t *tmp = NULL; icesector_t *tmp = calloc(sectorsCnt, sizeof(icesector_t));
tmp = calloc(sectorsCnt, sizeof(icesector_t));
if (tmp == NULL) if (tmp == NULL)
return 1; return 1;
memcpy(tmp, resp.d.asBytes, sectorsCnt * sizeof(icesector_t) ); memcpy(tmp, resp.d.asBytes, sectorsCnt * sizeof(icesector_t) );