From: roel@libnfc.org <roel@libnfc.org@ef4ab9da-24cd-11de-8aaa-f3a34680c41f>
Date: Mon, 10 Dec 2012 15:12:32 +0000 (+0000)
Subject: fixed hitag2 dump if one or more blocks are locked
X-Git-Tag: v1.0.0~130^2~17
X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/commitdiff_plain/fc8c5cdd12428f39dbb67b7e744b2dfdd59b5f23

fixed hitag2 dump if one or more blocks are locked
---

diff --git a/armsrc/hitag2.c b/armsrc/hitag2.c
index 6f5557f6..05ac1f5e 100644
--- a/armsrc/hitag2.c
+++ b/armsrc/hitag2.c
@@ -524,11 +524,27 @@ bool hitag2_crypto(byte_t* rx, const size_t rxlen, byte_t* tx, size_t* txlen) {
 		case 0: {
 			// Stop if there is no answer while we are in crypto mode (after sending NrAr)
 			if (bCrypto) {
-				DbpString("Authentication failed!");
-				return false;
-			}
-			*txlen = 5;
-			memcpy(tx,"\xc0",nbytes(*txlen));
+        // Failed during authentication
+        if (bAuthenticating) {
+          DbpString("Authentication failed!");
+          return false;
+        } else {
+          // Failed reading a block, could be (read/write) locked, skip block and re-authenticate
+          if (blocknr == 1) {
+            memcpy(tag.sectors[1],key+2,4);
+          } else if (blocknr == 2) {
+            tag.sectors[2][0] = 0x00;
+            tag.sectors[2][1] = 0x00;
+            tag.sectors[2][2] = key[0];
+            tag.sectors[2][3] = key[1];
+          }
+          blocknr++;
+          bCrypto = false;
+        }
+			} else {
+        *txlen = 5;
+        memcpy(tx,"\xc0",nbytes(*txlen));
+      }
 		} break;
 			
       // Received UID, crypto tag answer