private MfCardListener cardListener;
public MfCard loadCardFromFile(String fileName) throws IOException {
Collection<String> lines = readLinesFromFile(fileName);
MfCard mfCard = lines.size() == 256 ? new MfCard4k(null, null) : lines.size() == 64 ? new MfCard1k(null, null)
: null;
if (mfCard == null)
throw new MfException("unknown card. lines " + lines.size());
BlockResolver blockResolver = new BlockResolver();
Map<Integer, MfBlock> blockMap = new HashMap<Integer, MfBlock>();
int blockNumber = 0;
Pattern pattern = Pattern
.compile("S(.*)\\|B(.*) Key: (............).*\\[(................................)\\]");
for (String data : lines) {
Matcher matcher = pattern.matcher(data);
if (matcher.matches()) {
int sectorId = Integer.parseInt(matcher.group(1));
int blockId = Integer.parseInt(matcher.group(2));
byte[] keyA = NfcUtils.convertASCIIToBin(matcher.group(3));
byte[] blockData = NfcUtils.convertASCIIToBin(matcher.group(4));
MfBlock resolvedBlock = blockResolver.resolveBlock(mfCard, sectorId, blockId, blockData);
if (mfCard.isTrailerBlock(sectorId, blockId))
System.arraycopy(keyA, 0, blockData, 0, 6);
blockMap.put(blockNumber, resolvedBlock);
blockNumber++;
}
}