From 2aace8af169a9effff321b0ffa849bdfd29a00db Mon Sep 17 00:00:00 2001 From: ikarus <ikarus4ever@web.de> Date: Wed, 27 Dec 2023 15:44:38 +0100 Subject: [PATCH] Removed "patchTag" workaround. Might break HTC One & Sony Xperia Z3. Might fix compatebility with Android 14 (mCookie issue). --- .../de/syss/MifareClassicTool/Common.java | 1 - .../de/syss/MifareClassicTool/MCReader.java | 125 ------------------ 2 files changed, 126 deletions(-) diff --git a/Mifare Classic Tool/app/src/main/java/de/syss/MifareClassicTool/Common.java b/Mifare Classic Tool/app/src/main/java/de/syss/MifareClassicTool/Common.java index 6925fdb2..6ce8a41b 100644 --- a/Mifare Classic Tool/app/src/main/java/de/syss/MifareClassicTool/Common.java +++ b/Mifare Classic Tool/app/src/main/java/de/syss/MifareClassicTool/Common.java @@ -750,7 +750,6 @@ public static int treatAsNewTag(Intent intent, Context context) { } else { tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); } - tag = MCReader.patchTag(tag); if (tag == null) { return -3; } diff --git a/Mifare Classic Tool/app/src/main/java/de/syss/MifareClassicTool/MCReader.java b/Mifare Classic Tool/app/src/main/java/de/syss/MifareClassicTool/MCReader.java index 0f17e17f..2841b051 100644 --- a/Mifare Classic Tool/app/src/main/java/de/syss/MifareClassicTool/MCReader.java +++ b/Mifare Classic Tool/app/src/main/java/de/syss/MifareClassicTool/MCReader.java @@ -86,131 +86,6 @@ private MCReader(Tag tag) { mMFC = tmpMFC; } - /** - * Patch a possibly broken Tag object of HTC One (m7/m8) or Sony - * Xperia Z3 devices (with Android 5.x.) - * - * HTC One: "It seems, the reason of this bug is TechExtras of NfcA is null. - * However, TechList contains MifareClassic." -- bildin. - * This method will fix this. For more information please refer to - * https://github.com/ikarus23/MifareClassicTool/issues/52 - * This patch was provided by bildin (https://github.com/bildin). - * - * Sony Xperia Z3 (+ emmulated MIFARE Classic tag): The buggy tag has - * two NfcA in the TechList with different SAK values and a MifareClassic - * (with the Extra of the second NfcA). Both, the second NfcA and the - * MifareClassic technique, have a SAK of 0x20. According to NXP's - * guidelines on identifying MIFARE tags (Page 11), this a MIFARE Plus or - * MIFARE DESFire tag. This method creates a new Extra with the SAK - * values of both NfcA occurrences ORed (as mentioned in NXP's - * MIFARE type identification procedure guide) and replace the Extra of - * the first NfcA with the new one. For more information please refer to - * https://github.com/ikarus23/MifareClassicTool/issues/64 - * This patch was provided by bildin (https://github.com/bildin). - * - * @param tag The possibly broken tag. - * @return The fixed tag. - */ - public static Tag patchTag(Tag tag) { - if (tag == null) { - return null; - } - - String[] techList = tag.getTechList(); - - Parcel oldParcel = Parcel.obtain(); - tag.writeToParcel(oldParcel, 0); - oldParcel.setDataPosition(0); - - int len = oldParcel.readInt(); - byte[] id = new byte[0]; - if (len >= 0) { - id = new byte[len]; - oldParcel.readByteArray(id); - } - int[] oldTechList = new int[oldParcel.readInt()]; - oldParcel.readIntArray(oldTechList); - Bundle[] oldTechExtras = oldParcel.createTypedArray(Bundle.CREATOR); - int serviceHandle = oldParcel.readInt(); - // Android 14 - long mCookie = 0; - if (android.os.Build.VERSION.SDK_INT > Build.VERSION_CODES.TIRAMISU) { - mCookie = oldParcel.readLong(); - } - int isMock = oldParcel.readInt(); - IBinder tagService; - if (isMock == 0) { - tagService = oldParcel.readStrongBinder(); - } else { - tagService = null; - } - oldParcel.recycle(); - - int nfcaIdx = -1; - int mcIdx = -1; - short sak = 0; - boolean isFirstSak = true; - - for (int i = 0; i < techList.length; i++) { - if (techList[i].equals(NfcA.class.getName())) { - if (nfcaIdx == -1) { - nfcaIdx = i; - } - if (oldTechExtras[i] != null - && oldTechExtras[i].containsKey("sak")) { - sak = (short) (sak - | oldTechExtras[i].getShort("sak")); - isFirstSak = nfcaIdx == i; - } - } else if (techList[i].equals(MifareClassic.class.getName())) { - mcIdx = i; - } - } - - boolean modified = false; - - // Patch the double NfcA issue (with different SAK) for - // Sony Z3 devices. - if (!isFirstSak) { - oldTechExtras[nfcaIdx].putShort("sak", sak); - modified = true; - } - - // Patch the wrong index issue for HTC One devices. - if (nfcaIdx != -1 && mcIdx != -1 && oldTechExtras[mcIdx] == null) { - oldTechExtras[mcIdx] = oldTechExtras[nfcaIdx]; - modified = true; - } - - if (!modified) { - // Old tag was not modivied. Return the old one. - return tag; - } - - // Old tag was modified. Create a new tag with the new data. - Parcel newParcel = Parcel.obtain(); - newParcel.writeInt(id.length); - newParcel.writeByteArray(id); - newParcel.writeInt(oldTechList.length); - newParcel.writeIntArray(oldTechList); - newParcel.writeTypedArray(oldTechExtras, 0); - newParcel.writeInt(serviceHandle); - // Android 14 - if (android.os.Build.VERSION.SDK_INT > Build.VERSION_CODES.TIRAMISU) { - newParcel.writeLong(mCookie); - } - - newParcel.writeInt(isMock); - if (isMock == 0) { - newParcel.writeStrongBinder(tagService); - } - newParcel.setDataPosition(0); - Tag newTag = Tag.CREATOR.createFromParcel(newParcel); - newParcel.recycle(); - - return newTag; - } - /** * Get new instance of {@link MCReader}. * If the tag is "null" or if it is not a MIFARE Classic tag, "null"