couple bug fixes - clean up

This commit is contained in:
marshmellow42 2016-06-28 21:02:26 -04:00
commit 91f4d53123
2 changed files with 13 additions and 15 deletions

View file

@ -2375,15 +2375,15 @@ void Mifare1ksim(uint8_t flags, uint8_t exitAfterNReads, uint8_t arg2, uint8_t *
//allow collecting up to 8 sets of nonces to allow recovery of up to 8 keys //allow collecting up to 8 sets of nonces to allow recovery of up to 8 keys
#define ATTACK_KEY_COUNT 8 // keep same as define in cmdhfmf.c -> readerAttack() #define ATTACK_KEY_COUNT 8 // keep same as define in cmdhfmf.c -> readerAttack()
nonces_t ar_nr_resp[ATTACK_KEY_COUNT*2]; //*2 for 2 separate attack types nonces_t ar_nr_resp[ATTACK_KEY_COUNT*2]; //*2 for 2 separate attack types (nml, moebius)
memset(ar_nr_resp, 0x00, sizeof(ar_nr_resp)); memset(ar_nr_resp, 0x00, sizeof(ar_nr_resp));
uint8_t ar_nr_collected[ATTACK_KEY_COUNT*2]; uint8_t ar_nr_collected[ATTACK_KEY_COUNT*2]; //*2 for 2nd attack type (moebius)
memset(ar_nr_collected, 0x00, sizeof(ar_nr_collected)); memset(ar_nr_collected, 0x00, sizeof(ar_nr_collected));
bool gettingMoebius = false;
uint8_t nonce1_count = 0; uint8_t nonce1_count = 0;
uint8_t nonce2_count = 0; uint8_t nonce2_count = 0;
uint8_t moebius_n_count = 0; uint8_t moebius_n_count = 0;
bool gettingMoebius = false;
uint8_t mM = 0; //moebius_modifier for collection storage uint8_t mM = 0; //moebius_modifier for collection storage
// Authenticate response - nonce // Authenticate response - nonce
@ -2511,7 +2511,7 @@ void Mifare1ksim(uint8_t flags, uint8_t exitAfterNReads, uint8_t arg2, uint8_t *
cardSTATE_TO_IDLE(); cardSTATE_TO_IDLE();
LED_A_ON(); LED_A_ON();
} }
} }
if (cardSTATE == MFEMUL_NOFIELD) continue; if (cardSTATE == MFEMUL_NOFIELD) continue;
//Now, get data //Now, get data
@ -2523,7 +2523,7 @@ void Mifare1ksim(uint8_t flags, uint8_t exitAfterNReads, uint8_t arg2, uint8_t *
} else if (res == 1) { } else if (res == 1) {
break; //return value 1 means button press break; //return value 1 means button press
} }
// REQ or WUP request in ANY state and WUP in HALTED state // REQ or WUP request in ANY state and WUP in HALTED state
if (len == 1 && ((receivedCmd[0] == ISO14443A_CMD_REQA && cardSTATE != MFEMUL_HALTED) || receivedCmd[0] == ISO14443A_CMD_WUPA)) { if (len == 1 && ((receivedCmd[0] == ISO14443A_CMD_REQA && cardSTATE != MFEMUL_HALTED) || receivedCmd[0] == ISO14443A_CMD_WUPA)) {
selTimer = GetTickCount(); selTimer = GetTickCount();
@ -2992,7 +2992,6 @@ void Mifare1ksim(uint8_t flags, uint8_t exitAfterNReads, uint8_t arg2, uint8_t *
//Send the collected ar_nr in the response //Send the collected ar_nr in the response
cmd_send(CMD_ACK,CMD_SIMULATE_MIFARE_CARD,button_pushed,0,&ar_nr_resp,sizeof(ar_nr_resp)); cmd_send(CMD_ACK,CMD_SIMULATE_MIFARE_CARD,button_pushed,0,&ar_nr_resp,sizeof(ar_nr_resp));
} }
} }

View file

@ -1123,7 +1123,6 @@ int CmdHF14AMf1kSim(const char *Cmd) {
memset(filename, 0x00, sizeof(filename)); memset(filename, 0x00, sizeof(filename));
int len = 0; int len = 0;
char buf[64]; char buf[64];
uint8_t uidBuffer[64];
uint8_t cmdp = 0; uint8_t cmdp = 0;
bool errors = false; bool errors = false;
@ -1202,7 +1201,7 @@ int CmdHF14AMf1kSim(const char *Cmd) {
PrintAndLog("Loading file and simulating. Press keyboard to abort"); PrintAndLog("Loading file and simulating. Press keyboard to abort");
while(!feof(f) && !ukbhit()){ while(!feof(f) && !ukbhit()){
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
memset(uidBuffer, 0, sizeof(uidBuffer)); memset(uid, 0, sizeof(uid));
if (fgets(buf, sizeof(buf), f) == NULL) { if (fgets(buf, sizeof(buf), f) == NULL) {
if (count > 0) break; if (count > 0) break;
@ -1211,21 +1210,21 @@ int CmdHF14AMf1kSim(const char *Cmd) {
fclose(f); fclose(f);
return 2; return 2;
} }
if(strlen(buf) && feof(f)) break; if(!strlen(buf) && feof(f)) break;
uidlen = strlen(buf); uidlen = strlen(buf)-1;
switch(uidlen) { switch(uidlen) {
case 20: flags = FLAG_10B_UID_IN_DATA; break; //not complete case 20: flags |= FLAG_10B_UID_IN_DATA; break; //not complete
case 14: flags = FLAG_7B_UID_IN_DATA; break; case 14: flags |= FLAG_7B_UID_IN_DATA; break;
case 8: flags = FLAG_4B_UID_IN_DATA; break; case 8: flags |= FLAG_4B_UID_IN_DATA; break;
default: default:
PrintAndLog("uid in file wrong length at %d",count); PrintAndLog("uid in file wrong length at %d (length: %d) [%s]",count, uidlen, buf);
fclose(f); fclose(f);
return 2; return 2;
} }
for (uint8_t i = 0; i < uidlen; i += 2) { for (uint8_t i = 0; i < uidlen; i += 2) {
sscanf(&buf[i], "%02x", (unsigned int *)&uidBuffer[i / 2]); sscanf(&buf[i], "%02x", (unsigned int *)&uid[i / 2]);
} }
PrintAndLog("mf 1k sim uid: %s, numreads:%d, flags:%d (0x%02x) - press button to abort", PrintAndLog("mf 1k sim uid: %s, numreads:%d, flags:%d (0x%02x) - press button to abort",