int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t * key, uint8_t trgBlockNo, uint8_t trgKeyType, uint8_t * resultKeys) { int i, m, len; uint8_t isEOF; uint32_t uid; fnVector * vector = NULL; countKeys *ck; int lenVector = 0; UsbCommand * resp = NULL; memset(resultKeys, 0x00, 16 * 6); // flush queue while (WaitForResponseTimeout(CMD_ACK, 500) != NULL) ; UsbCommand c = {CMD_MIFARE_NESTED, {blockNo, keyType, trgBlockNo + trgKeyType * 0x100}}; memcpy(c.d.asBytes, key, 6); SendCommand(&c); PrintAndLog("\n"); // wait cycle while (true) { printf("."); if (ukbhit()) { getchar(); printf("\naborted via keyboard!\n"); break; } resp = WaitForResponseTimeout(CMD_ACK, 1500); if (resp != NULL) { isEOF = resp->arg[0] & 0xff; if (isEOF) break; len = resp->arg[1] & 0xff; if (len == 0) continue; memcpy(&uid, resp->d.asBytes, 4); PrintAndLog("uid:%08x len=%d trgbl=%d trgkey=%x", uid, len, resp->arg[2] & 0xff, (resp->arg[2] >> 8) & 0xff); vector = (fnVector *) realloc((void *)vector, (lenVector + len) * sizeof(fnVector) + 200); if (vector == NULL) { PrintAndLog("Memory allocation error for fnVector. len: %d bytes: %d", lenVector + len, (lenVector + len) * sizeof(fnVector)); break; } for (i = 0; i < len; i++) { vector[lenVector + i].blockNo = resp->arg[2] & 0xff; vector[lenVector + i].keyType = (resp->arg[2] >> 8) & 0xff; vector[lenVector + i].uid = uid; memcpy(&vector[lenVector + i].nt, (void *)(resp->d.asBytes + 8 + i * 8 + 0), 4); memcpy(&vector[lenVector + i].ks1, (void *)(resp->d.asBytes + 8 + i * 8 + 4), 4); } lenVector += len; } }
/* * The debug_wait was used to wait for the "KEY" to enter debug mode. * */ void debug_wait() { int i; char ch; // Waiting 3 sec to enter debug mode. uprintf("Press ESC to enter debug mode "); for( i=0;i < 6;i++) { sleep(500); // 0.5 sec if( ukbhit() ) { ch=ugetchar(); /* Enter the debug mode if the key "ESC" or "B" was pressed */ if( (ch == 27) || (ch == 'B') )sh(0,0); } uputchar('.'); } uputchar('\n'); }
/** * @brief Utility to check if a key has been pressed by the user. This method does not block. * @param L * @return boolean, true if kbhit, false otherwise. */ static int l_ukbhit(lua_State *L) { lua_pushboolean(L,ukbhit() ? true : false); return 1; }