Skip to content

Commit

Permalink
Merge pull request codebutler#120 from phcoder/empty
Browse files Browse the repository at this point in the history
Mark empty sector on Mifare Classic as such
  • Loading branch information
micolous authored Aug 18, 2018
2 parents 063f894 + cf60f1b commit 6fe6433
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,13 @@ public String getType() {
public byte[] getData() {
return mData.getData();
}

private static final String ZERO = "AAAAAAAAAAAAAAAAAAAAAA==";
private static final String FF = "/////////////////////w==";
private static final String ZERO_VB = "AAAAAP////8AAAAAAP8A/w==";

public boolean isEmpty() {
String actual = mData.toBase64();
return actual.equals(ZERO) || actual.equals(FF) || actual.equals(ZERO_VB);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,21 @@ public byte[] readBlocks(int startBlock, int blockCount) throws IndexOutOfBounds
}
return data;
}

public boolean isEmpty() {
try {
List<ClassicBlock> blocks = getBlocks();
for (ClassicBlock block : blocks) {
if (getIndex() == 0 && block.getIndex() == 0)
continue;
if (block.getIndex() == blocks.size() - 1)
continue;
if (!block.isEmpty())
return false;
}
} catch (Exception e) {
return true;
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ public View getGroupView(int groupPosition, boolean isExpanded, View convertView
textView.setText(mActivity.getString(R.string.unauthorized_sector_title_format, sectorIndexString));
} else if (sector instanceof InvalidClassicSector) {
textView.setText(mActivity.getString(R.string.invalid_sector_title_format, sectorIndexString, ((InvalidClassicSector) sector).getError()));
} else if (sector.isEmpty()) {
textView.setText(mActivity.getString(R.string.sector_title_format_empty, sectorIndexString));
} else {
textView.setText(mActivity.getString(R.string.sector_title_format, sectorIndexString));
}
Expand Down
1 change: 1 addition & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
<string name="unauthorized_page_title_format">Page: 0x%s (unauthorized)</string>
<string name="sector_title_format">Sector: 0x%s</string>
<string name="unauthorized_sector_title_format">Sector: 0x%s (unauthorized)</string>
<string name="sector_title_format_empty">Sector: 0x%s (empty)</string>
<string name="invalid_sector_title_format">Sector: 0x%1$s (invalid: %2$s)</string>
<!-- Translators: the first parameter is a hexadecimal number, the second parameter is a string
describing a "well known" system code. eg: "System: 0x3 (Suica)" -->
Expand Down

0 comments on commit 6fe6433

Please sign in to comment.