]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/mifarehost.c
chg: too many \ slashes
[proxmark3-svn] / client / mifarehost.c
index 97e53f1e97820d241c1fe67157324b5621afe3a4..5d39221f161f423ee6bd39cfb96f836d7ab69df0 100644 (file)
@@ -125,8 +125,8 @@ int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t * key, uint8_t trgBlockNo
        p4->even = 0; p4->odd = 0;\r
        statelists[0].len = p3 - statelists[0].head.slhead;\r
        statelists[1].len = p4 - statelists[1].head.slhead;\r
        p4->even = 0; p4->odd = 0;\r
        statelists[0].len = p3 - statelists[0].head.slhead;\r
        statelists[1].len = p4 - statelists[1].head.slhead;\r
-       statelists[0].tail.sltail=--p3;\r
-       statelists[1].tail.sltail=--p4;\r
+       statelists[0].tail.sltail = --p3;\r
+       statelists[1].tail.sltail = --p4;\r
 \r
        // the statelists now contain possible keys. The key we are searching for must be in the\r
        // intersection of both lists. Create the intersection:\r
 \r
        // the statelists now contain possible keys. The key we are searching for must be in the\r
        // intersection of both lists. Create the intersection:\r
@@ -170,7 +170,7 @@ int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t * key, uint8_t trgBlockNo
                free(statelists[1].head.slhead);\r
                num_to_bytes(key64, 6, resultKey);\r
 \r
                free(statelists[1].head.slhead);\r
                num_to_bytes(key64, 6, resultKey);\r
 \r
-               PrintAndLog("UID: %08x target block:%3u key type: %c  -- Found key [%012"llx"]",\r
+               PrintAndLog("UID: %08x target block:%3u key type: %c  -- Found key [%012" PRIx64 "]",\r
                        uid,\r
                        (uint16_t)resp.arg[2] & 0xff,\r
                        (resp.arg[2] >> 8) ? 'B' : 'A',\r
                        uid,\r
                        (uint16_t)resp.arg[2] & 0xff,\r
                        (resp.arg[2] >> 8) ? 'B' : 'A',\r
@@ -192,8 +192,10 @@ out:
 }\r
 \r
 int mfCheckKeys (uint8_t blockNo, uint8_t keyType, bool clear_trace, uint8_t keycnt, uint8_t * keyBlock, uint64_t * key){\r
 }\r
 \r
 int mfCheckKeys (uint8_t blockNo, uint8_t keyType, bool clear_trace, uint8_t keycnt, uint8_t * keyBlock, uint64_t * key){\r
-       *key = 0;\r
-       UsbCommand c = {CMD_MIFARE_CHKKEYS, { (blockNo | (keyType<<8)), clear_trace, keycnt}};\r
+#define STD_SEARCH 1\r
+#define EXT_SEARCH 2\r
+       *key = 0;       \r
+       UsbCommand c = {CMD_MIFARE_CHKKEYS, { (blockNo | (keyType << 8)), ((EXT_SEARCH << 8) | clear_trace), keycnt}};\r
        memcpy(c.d.asBytes, keyBlock, 6 * keycnt);\r
        clearCommandBuffer();\r
        SendCommand(&c);\r
        memcpy(c.d.asBytes, keyBlock, 6 * keycnt);\r
        clearCommandBuffer();\r
        SendCommand(&c);\r
@@ -250,15 +252,13 @@ int mfKeyBrute(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint64_t *resultk
        return found;\r
 }\r
 \r
        return found;\r
 }\r
 \r
-\r
 // EMULATOR\r
 // EMULATOR\r
-\r
 int mfEmlGetMem(uint8_t *data, int blockNum, int blocksCount) {\r
        UsbCommand c = {CMD_MIFARE_EML_MEMGET, {blockNum, blocksCount, 0}};\r
        clearCommandBuffer();\r
        SendCommand(&c);\r
        UsbCommand resp;\r
 int mfEmlGetMem(uint8_t *data, int blockNum, int blocksCount) {\r
        UsbCommand c = {CMD_MIFARE_EML_MEMGET, {blockNum, blocksCount, 0}};\r
        clearCommandBuffer();\r
        SendCommand(&c);\r
        UsbCommand resp;\r
-       if (!WaitForResponseTimeout(CMD_ACK,&resp,1500)) return 1;\r
+       if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) return 1;\r
        memcpy(data, resp.d.asBytes, blocksCount * 16);\r
        return 0;\r
 }\r
        memcpy(data, resp.d.asBytes, blocksCount * 16);\r
        return 0;\r
 }\r
@@ -412,14 +412,20 @@ int loadTraceCard(uint8_t *tuid, uint8_t uidlen) {
                memset(buf, 0, sizeof(buf));\r
                if (fgets(buf, sizeof(buf), f) == NULL) {\r
                        PrintAndLog("No trace file found or reading error.");\r
                memset(buf, 0, sizeof(buf));\r
                if (fgets(buf, sizeof(buf), f) == NULL) {\r
                        PrintAndLog("No trace file found or reading error.");\r
-                       fclose(f);\r
+                       if (f) {\r
+                               fclose(f);\r
+                               f = NULL;\r
+                       }\r
                        return 2;\r
                }\r
 \r
                if (strlen(buf) < 32){\r
                        if (feof(f)) break;\r
                        PrintAndLog("File content error. Block data must include 32 HEX symbols");\r
                        return 2;\r
                }\r
 \r
                if (strlen(buf) < 32){\r
                        if (feof(f)) break;\r
                        PrintAndLog("File content error. Block data must include 32 HEX symbols");\r
-                       fclose(f);\r
+                       if (f) {\r
+                               fclose(f);\r
+                               f = NULL;\r
+                       }\r
                        return 2;\r
                }\r
                for (i = 0; i < 32; i += 2)\r
                        return 2;\r
                }\r
                for (i = 0; i < 32; i += 2)\r
@@ -429,7 +435,10 @@ int loadTraceCard(uint8_t *tuid, uint8_t uidlen) {
 \r
                blockNum++;\r
        }\r
 \r
                blockNum++;\r
        }\r
-       fclose(f);\r
+       if (f) {\r
+               fclose(f);\r
+               f = NULL;\r
+       }\r
        return 0;\r
 }\r
 \r
        return 0;\r
 }\r
 \r
@@ -447,7 +456,10 @@ int saveTraceCard(void) {
                fprintf(f,"\n");\r
        }\r
        fflush(f);\r
                fprintf(f,"\n");\r
        }\r
        fflush(f);\r
-       fclose(f);\r
+       if (f) {\r
+               fclose(f);\r
+               f = NULL;\r
+       }\r
        return 0;\r
 }\r
 \r
        return 0;\r
 }\r
 \r
@@ -617,7 +629,7 @@ int mfTraceDecode(uint8_t *data_src, int len, bool wantSaveToEmlFile) {
                        lfsr_rollback_word(revstate, nr_enc, 1);\r
                        lfsr_rollback_word(revstate, cuid ^ nt, 0);\r
                        crypto1_get_lfsr(revstate, &key);\r
                        lfsr_rollback_word(revstate, nr_enc, 1);\r
                        lfsr_rollback_word(revstate, cuid ^ nt, 0);\r
                        crypto1_get_lfsr(revstate, &key);\r
-                       PrintAndLog("Found Key: [%012"llx"]", key);\r
+                       PrintAndLog("Found Key: [%012" PRIx64 "]", key);\r
                        \r
                        //if ( tryMfk64(cuid, nt, nr_enc, ar_enc, at_enc, &key) )\r
                        AddLogUint64(logHexFileName, "Found Key: ", key); \r
                        \r
                        //if ( tryMfk64(cuid, nt, nr_enc, ar_enc, at_enc, &key) )\r
                        AddLogUint64(logHexFileName, "Found Key: ", key); \r
@@ -654,12 +666,12 @@ int mfTraceDecode(uint8_t *data_src, int len, bool wantSaveToEmlFile) {
 \r
 int tryDecryptWord(uint32_t nt, uint32_t ar_enc, uint32_t at_enc, uint8_t *data, int len){\r
        PrintAndLog("\nEncrypted data: [%s]", sprint_hex(data, len) );\r
 \r
 int tryDecryptWord(uint32_t nt, uint32_t ar_enc, uint32_t at_enc, uint8_t *data, int len){\r
        PrintAndLog("\nEncrypted data: [%s]", sprint_hex(data, len) );\r
-       struct Crypto1State *pcs = NULL;\r
+       struct Crypto1State *s;\r
        ks2 = ar_enc ^ prng_successor(nt, 64);\r
        ks3 = at_enc ^ prng_successor(nt, 96);\r
        ks2 = ar_enc ^ prng_successor(nt, 64);\r
        ks3 = at_enc ^ prng_successor(nt, 96);\r
-       pcs = lfsr_recovery64(ks2, ks3);\r
-       mf_crypto1_decrypt(pcs, data, len, FALSE);\r
+       s = lfsr_recovery64(ks2, ks3);\r
+       mf_crypto1_decrypt(s, data, len, FALSE);\r
        PrintAndLog("Decrypted data: [%s]", sprint_hex(data, len) );\r
        PrintAndLog("Decrypted data: [%s]", sprint_hex(data, len) );\r
-       crypto1_destroy(pcs);\r
+       crypto1_destroy(s);\r
        return 0;\r
 }\r
        return 0;\r
 }\r
Impressum, Datenschutz