Skip to content

Commit

Permalink
Try to write dump block a second time if the first fails.
Browse files Browse the repository at this point in the history
For more informaiton see: #412
  • Loading branch information
ikarus23 committed Aug 17, 2023
1 parent 085520b commit ec3f047
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1267,9 +1267,21 @@ private void writeDump(
}

// Write block.
int result = reader.writeBlock(sector, block,
// Writing multiple blocks consecutively sometimes fails. I have no idea why.
// It also depends on the data (see: https://github.com/ikarus23/MifareClassicTool/issues/412).
// This makes no sense. This error does not occurs while debugging which
// might indicate a timing issue. When adding a delay of 200 ms, the error
// does not occur. Retrying to write also works. This why the ugly workaround
// of trying to write at least two times was added.
int result = 0;
for (int i = 0; i < 2; i++) {
result = reader.writeBlock(sector, block,
mDumpWithPos.get(sector).get(block),
writeKey, useAsKeyB);
if (result == 0) {
break;
}
}

if (result != 0) {
// Error. Some error while writing.
Expand Down

0 comments on commit ec3f047

Please sign in to comment.