diff --git a/Mifare Classic Tool/app/src/main/java/de/syss/MifareClassicTool/Activities/KeyMapCreator.java b/Mifare Classic Tool/app/src/main/java/de/syss/MifareClassicTool/Activities/KeyMapCreator.java index ffa3272d..45ff7621 100644 --- a/Mifare Classic Tool/app/src/main/java/de/syss/MifareClassicTool/Activities/KeyMapCreator.java +++ b/Mifare Classic Tool/app/src/main/java/de/syss/MifareClassicTool/Activities/KeyMapCreator.java @@ -142,6 +142,7 @@ public class KeyMapCreator extends BasicActivity { private File mKeyDirPath; private int mFirstSector; private int mLastSector; + private MCReader currentReader; /** * Set layout, set the mapping range @@ -331,6 +332,9 @@ private void selectKeyFiles(boolean allOrNone) { public void onCancelCreateKeyMap(View view) { if (mIsCreatingKeyMap) { mIsCreatingKeyMap = false; + if (currentReader != null) { + currentReader.cancelCreateKeyMap(); + } mCancel.setEnabled(false); } else { finish(); @@ -395,6 +399,7 @@ public void onCreateKeyMap(View view) { // Create reader. MCReader reader = Common.checkForTagAndCreateReader(this); + currentReader = reader; if (reader == null) { return; } 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 df8ab708..5adf94cc 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 @@ -65,6 +65,7 @@ public class MCReader { private int mFirstSector = 0; private ArrayList mKeysWithOrder; private boolean mHasAllZeroKey = false; + private boolean cancelCreateKeyMap = false; /** * Initialize a MIFARE Classic reader for the given tag. @@ -107,6 +108,10 @@ public static MCReader get(Tag tag) { return mcr; } + public void cancelCreateKeyMap() { + cancelCreateKeyMap = true; + } + /** * Read as much as possible from the tag with the given key information. * @param keyMap Keys (A and B) mapped to a sector. @@ -460,6 +465,7 @@ public int writeValueBlock(int sectorIndex, int blockIndex, int value, public int buildNextKeyMapPart() { // Clear status and key map before new walk through sectors. boolean error = false; + cancelCreateKeyMap = false; if (mKeysWithOrder != null && mLastSector != -1) { if (mKeyMapStatus == mLastSector+1) { mKeyMapStatus = mFirstSector; @@ -487,6 +493,9 @@ public int buildNextKeyMapPart() { byte[] bytesKey = Common.hex2Bytes(key); for (int j = 0; j < retryAuthCount+1;) { try { + if (cancelCreateKeyMap) { + return -1; + } if (!foundKeys[0]) { auth = mMFC.authenticateSectorWithKeyA( mKeyMapStatus, bytesKey);