X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/7d0efb37d87a2d87d675827b2fa5018677226c4f..e1778858ddc53a6a82e8ee24f02e6b673687f69a:/client/mifarehost.c diff --git a/client/mifarehost.c b/client/mifarehost.c index b41c3687..5d39221f 100644 --- a/client/mifarehost.c +++ b/client/mifarehost.c @@ -170,7 +170,7 @@ int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t * key, uint8_t trgBlockNo free(statelists[1].head.slhead); num_to_bytes(key64, 6, resultKey); - PrintAndLog("UID: %08x target block:%3u key type: %c -- Found key [%012"llx"]", + PrintAndLog("UID: %08x target block:%3u key type: %c -- Found key [%012" PRIx64 "]", uid, (uint16_t)resp.arg[2] & 0xff, (resp.arg[2] >> 8) ? 'B' : 'A', @@ -192,8 +192,10 @@ out: } int mfCheckKeys (uint8_t blockNo, uint8_t keyType, bool clear_trace, uint8_t keycnt, uint8_t * keyBlock, uint64_t * key){ - *key = 0; - UsbCommand c = {CMD_MIFARE_CHKKEYS, { (blockNo | (keyType<<8)), clear_trace, keycnt}}; +#define STD_SEARCH 1 +#define EXT_SEARCH 2 + *key = 0; + UsbCommand c = {CMD_MIFARE_CHKKEYS, { (blockNo | (keyType << 8)), ((EXT_SEARCH << 8) | clear_trace), keycnt}}; memcpy(c.d.asBytes, keyBlock, 6 * keycnt); clearCommandBuffer(); SendCommand(&c); @@ -250,15 +252,13 @@ int mfKeyBrute(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint64_t *resultk return found; } - // EMULATOR - int mfEmlGetMem(uint8_t *data, int blockNum, int blocksCount) { UsbCommand c = {CMD_MIFARE_EML_MEMGET, {blockNum, blocksCount, 0}}; clearCommandBuffer(); SendCommand(&c); UsbCommand resp; - if (!WaitForResponseTimeout(CMD_ACK,&resp,1500)) return 1; + if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) return 1; memcpy(data, resp.d.asBytes, blocksCount * 16); return 0; } @@ -412,14 +412,20 @@ int loadTraceCard(uint8_t *tuid, uint8_t uidlen) { memset(buf, 0, sizeof(buf)); if (fgets(buf, sizeof(buf), f) == NULL) { PrintAndLog("No trace file found or reading error."); - fclose(f); + if (f) { + fclose(f); + f = NULL; + } return 2; } if (strlen(buf) < 32){ if (feof(f)) break; PrintAndLog("File content error. Block data must include 32 HEX symbols"); - fclose(f); + if (f) { + fclose(f); + f = NULL; + } return 2; } for (i = 0; i < 32; i += 2) @@ -429,7 +435,10 @@ int loadTraceCard(uint8_t *tuid, uint8_t uidlen) { blockNum++; } - fclose(f); + if (f) { + fclose(f); + f = NULL; + } return 0; } @@ -447,7 +456,10 @@ int saveTraceCard(void) { fprintf(f,"\n"); } fflush(f); - fclose(f); + if (f) { + fclose(f); + f = NULL; + } return 0; } @@ -617,7 +629,7 @@ int mfTraceDecode(uint8_t *data_src, int len, bool wantSaveToEmlFile) { lfsr_rollback_word(revstate, nr_enc, 1); lfsr_rollback_word(revstate, cuid ^ nt, 0); crypto1_get_lfsr(revstate, &key); - PrintAndLog("Found Key: [%012"llx"]", key); + PrintAndLog("Found Key: [%012" PRIx64 "]", key); //if ( tryMfk64(cuid, nt, nr_enc, ar_enc, at_enc, &key) ) AddLogUint64(logHexFileName, "Found Key: ", key);