Skip to content

Commit f33c69f

Browse files
authored
Merge pull request #481 from alecor450/fix_read_cancel
fix Cancel Create Key Map in MCReader
2 parents 19dca31 + 7264680 commit f33c69f

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

Mifare Classic Tool/app/src/main/java/de/syss/MifareClassicTool/Activities/KeyMapCreator.java

+5
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public class KeyMapCreator extends BasicActivity {
142142
private File mKeyDirPath;
143143
private int mFirstSector;
144144
private int mLastSector;
145+
private MCReader currentReader;
145146

146147
/**
147148
* Set layout, set the mapping range
@@ -331,6 +332,9 @@ private void selectKeyFiles(boolean allOrNone) {
331332
public void onCancelCreateKeyMap(View view) {
332333
if (mIsCreatingKeyMap) {
333334
mIsCreatingKeyMap = false;
335+
if (currentReader != null) {
336+
currentReader.cancelCreateKeyMap();
337+
}
334338
mCancel.setEnabled(false);
335339
} else {
336340
finish();
@@ -395,6 +399,7 @@ public void onCreateKeyMap(View view) {
395399

396400
// Create reader.
397401
MCReader reader = Common.checkForTagAndCreateReader(this);
402+
currentReader = reader;
398403
if (reader == null) {
399404
return;
400405
}

Mifare Classic Tool/app/src/main/java/de/syss/MifareClassicTool/MCReader.java

+9
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public class MCReader {
6565
private int mFirstSector = 0;
6666
private ArrayList<String> mKeysWithOrder;
6767
private boolean mHasAllZeroKey = false;
68+
private boolean cancelCreateKeyMap = false;
6869

6970
/**
7071
* Initialize a MIFARE Classic reader for the given tag.
@@ -107,6 +108,10 @@ public static MCReader get(Tag tag) {
107108
return mcr;
108109
}
109110

111+
public void cancelCreateKeyMap() {
112+
cancelCreateKeyMap = true;
113+
}
114+
110115
/**
111116
* Read as much as possible from the tag with the given key information.
112117
* @param keyMap Keys (A and B) mapped to a sector.
@@ -460,6 +465,7 @@ public int writeValueBlock(int sectorIndex, int blockIndex, int value,
460465
public int buildNextKeyMapPart() {
461466
// Clear status and key map before new walk through sectors.
462467
boolean error = false;
468+
cancelCreateKeyMap = false;
463469
if (mKeysWithOrder != null && mLastSector != -1) {
464470
if (mKeyMapStatus == mLastSector+1) {
465471
mKeyMapStatus = mFirstSector;
@@ -487,6 +493,9 @@ public int buildNextKeyMapPart() {
487493
byte[] bytesKey = Common.hex2Bytes(key);
488494
for (int j = 0; j < retryAuthCount+1;) {
489495
try {
496+
if (cancelCreateKeyMap) {
497+
return -1;
498+
}
490499
if (!foundKeys[0]) {
491500
auth = mMFC.authenticateSectorWithKeyA(
492501
mKeyMapStatus, bytesKey);

0 commit comments

Comments
 (0)