X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/d9ed4e191445d342d11e35fbe4886980e40771a8..aa9b584f5c3050e4f186f12c097219814422b19b:/client/mifarehost.c?ds=sidebyside diff --git a/client/mifarehost.c b/client/mifarehost.c index 97e53f1e..d1bfa69a 100644 --- a/client/mifarehost.c +++ b/client/mifarehost.c @@ -125,8 +125,8 @@ int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t * key, uint8_t trgBlockNo p4->even = 0; p4->odd = 0; statelists[0].len = p3 - statelists[0].head.slhead; statelists[1].len = p4 - statelists[1].head.slhead; - statelists[0].tail.sltail=--p3; - statelists[1].tail.sltail=--p4; + statelists[0].tail.sltail = --p3; + statelists[1].tail.sltail = --p4; // the statelists now contain possible keys. The key we are searching for must be in the // intersection of both lists. Create the intersection: @@ -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', @@ -250,15 +250,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 +410,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 +433,10 @@ int loadTraceCard(uint8_t *tuid, uint8_t uidlen) { blockNum++; } - fclose(f); + if (f) { + fclose(f); + f = NULL; + } return 0; } @@ -447,7 +454,10 @@ int saveTraceCard(void) { fprintf(f,"\n"); } fflush(f); - fclose(f); + if (f) { + fclose(f); + f = NULL; + } return 0; } @@ -617,7 +627,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); @@ -654,12 +664,12 @@ int mfTraceDecode(uint8_t *data_src, int len, bool wantSaveToEmlFile) { int tryDecryptWord(uint32_t nt, uint32_t ar_enc, uint32_t at_enc, uint8_t *data, int len){ PrintAndLog("\nEncrypted data: [%s]", sprint_hex(data, len) ); - struct Crypto1State *pcs = NULL; + struct Crypto1State *s; ks2 = ar_enc ^ prng_successor(nt, 64); ks3 = at_enc ^ prng_successor(nt, 96); - pcs = lfsr_recovery64(ks2, ks3); - mf_crypto1_decrypt(pcs, data, len, FALSE); + s = lfsr_recovery64(ks2, ks3); + mf_crypto1_decrypt(s, data, len, FALSE); PrintAndLog("Decrypted data: [%s]", sprint_hex(data, len) ); - crypto1_destroy(pcs); + crypto1_destroy(s); return 0; }