]> cvs.zerfleddert.de Git - proxmark3-svn/blobdiff - client/mifarehost.c
fix 14b raw -s option, + get rid of...
[proxmark3-svn] / client / mifarehost.c
index 35499b83677e18129e2278221ed865edbc52f32a..95453ebfd9b5e6ab270df7696985a32232ce7e40 100644 (file)
@@ -69,7 +69,7 @@ void* nested_worker_thread(void *arg)
 \r
 int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t * key, uint8_t trgBlockNo, uint8_t trgKeyType, uint8_t * resultKey, bool calibrate) \r
 {\r
 \r
 int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t * key, uint8_t trgBlockNo, uint8_t trgKeyType, uint8_t * resultKey, bool calibrate) \r
 {\r
-       uint16_t i, len;\r
+       uint16_t i;\r
        uint32_t uid;\r
        UsbCommand resp;\r
 \r
        uint32_t uid;\r
        UsbCommand resp;\r
 \r
@@ -77,31 +77,29 @@ int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t * key, uint8_t trgBlockNo
        struct Crypto1State *p1, *p2, *p3, *p4;\r
        \r
        // flush queue\r
        struct Crypto1State *p1, *p2, *p3, *p4;\r
        \r
        // flush queue\r
-       WaitForResponseTimeout(CMD_ACK,NULL,100);\r
+       WaitForResponseTimeout(CMD_ACK, NULL, 100);\r
        \r
        UsbCommand c = {CMD_MIFARE_NESTED, {blockNo + keyType * 0x100, trgBlockNo + trgKeyType * 0x100, calibrate}};\r
        memcpy(c.d.asBytes, key, 6);\r
        SendCommand(&c);\r
 \r
        \r
        UsbCommand c = {CMD_MIFARE_NESTED, {blockNo + keyType * 0x100, trgBlockNo + trgKeyType * 0x100, calibrate}};\r
        memcpy(c.d.asBytes, key, 6);\r
        SendCommand(&c);\r
 \r
-       if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {\r
-               len = resp.arg[1];\r
-               if (len == 2) { \r
-                       memcpy(&uid, resp.d.asBytes, 4);\r
-                       PrintAndLog("uid:%08x len=%d trgbl=%d trgkey=%x", uid, len, (uint16_t)resp.arg[2] & 0xff, (uint16_t)resp.arg[2] >> 8);\r
-                       \r
-                       for (i = 0; i < 2; i++) {\r
-                               statelists[i].blockNo = resp.arg[2] & 0xff;\r
-                               statelists[i].keyType = (resp.arg[2] >> 8) & 0xff;\r
-                               statelists[i].uid = uid;\r
+       if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {\r
+               return -1;\r
+       }\r
 \r
 \r
-                               memcpy(&statelists[i].nt,  (void *)(resp.d.asBytes + 4 + i * 8 + 0), 4);\r
-                               memcpy(&statelists[i].ks1, (void *)(resp.d.asBytes + 4 + i * 8 + 4), 4);\r
-                       }\r
-               }\r
-               else {\r
-                       PrintAndLog("Got 0 keys from proxmark."); \r
-                       return 1;\r
-               }\r
+       if (resp.arg[0]) {\r
+               return resp.arg[0];  // error during nested\r
+       }\r
+               \r
+       memcpy(&uid, resp.d.asBytes, 4);\r
+       PrintAndLog("uid:%08x trgbl=%d trgkey=%x", uid, (uint16_t)resp.arg[2] & 0xff, (uint16_t)resp.arg[2] >> 8);\r
+       \r
+       for (i = 0; i < 2; i++) {\r
+               statelists[i].blockNo = resp.arg[2] & 0xff;\r
+               statelists[i].keyType = (resp.arg[2] >> 8) & 0xff;\r
+               statelists[i].uid = uid;\r
+               memcpy(&statelists[i].nt,  (void *)(resp.d.asBytes + 4 + i * 8 + 0), 4);\r
+               memcpy(&statelists[i].ks1, (void *)(resp.d.asBytes + 4 + i * 8 + 4), 4);\r
        }\r
        \r
        // calc keys\r
        }\r
        \r
        // calc keys\r
@@ -354,10 +352,7 @@ int loadTraceCard(uint8_t *tuid) {
        FillFileNameByUID(traceFileName, tuid, ".eml", 7);\r
 \r
        f = fopen(traceFileName, "r");\r
        FillFileNameByUID(traceFileName, tuid, ".eml", 7);\r
 \r
        f = fopen(traceFileName, "r");\r
-       if (!f) {\r
-               fclose(f);\r
-               return 1;\r
-       }\r
+       if (!f) return 1;\r
        \r
        blockNum = 0;\r
                \r
        \r
        blockNum = 0;\r
                \r
@@ -394,10 +389,7 @@ int saveTraceCard(void) {
        if ((!strlen(traceFileName)) || (isTraceCardEmpty())) return 0;\r
        \r
        f = fopen(traceFileName, "w+");\r
        if ((!strlen(traceFileName)) || (isTraceCardEmpty())) return 0;\r
        \r
        f = fopen(traceFileName, "w+");\r
-       if ( !f ) {\r
-               fclose(f);\r
-               return 1;\r
-       }\r
+       if ( !f ) return 1;\r
        \r
        for (int i = 0; i < 64; i++) {  // blocks\r
                for (int j = 0; j < 16; j++)  // bytes\r
        \r
        for (int i = 0; i < 64; i++) {  // blocks\r
                for (int j = 0; j < 16; j++)  // bytes\r
Impressum, Datenschutz