Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Cancel Create Key Map in MCReader #481

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading