Skip to content

Commit

Permalink
Merge pull request #481 from alecor450/fix_read_cancel
Browse files Browse the repository at this point in the history
fix Cancel Create Key Map in MCReader
  • Loading branch information
ikarus23 authored May 13, 2024
2 parents 19dca31 + 7264680 commit f33c69f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -395,6 +399,7 @@ public void onCreateKeyMap(View view) {

// Create reader.
MCReader reader = Common.checkForTagAndCreateReader(this);
currentReader = reader;
if (reader == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class MCReader {
private int mFirstSector = 0;
private ArrayList<String> mKeysWithOrder;
private boolean mHasAllZeroKey = false;
private boolean cancelCreateKeyMap = false;

/**
* Initialize a MIFARE Classic reader for the given tag.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f33c69f

Please sign in to comment.