Package org.nfctools.mf.ul

Examples of org.nfctools.mf.ul.MemoryMap


public class MfClassicNfcTagListenerTest {

  @Test
  public void testCreateNdefOperations() throws Exception {
    MemoryMap memoryMap = FileMfClassicReader.loadCardFromFile("mfstd1k_blank.txt");
    InMemoryTag tag = new InMemoryTag(memoryMap);

    MfClassicNfcTagListener nfcTagListener = new MfClassicNfcTagListener();

    MfClassicNdefOperations ndefOperations = nfcTagListener.createNdefOperations(tag, MemoryLayout.CLASSIC_1K);
View Full Code Here


public class FileMfUlReader {

  public static MemoryMap loadCardFromFile(String fileName) {
    Collection<String> lines = readLinesFromFile(fileName);

    MemoryMap memoryMap = new MemoryMap(lines.size(), 4);

    Pattern pattern = Pattern.compile("\\[(..)\\]...(..).(..).(..).(..).*");
    byte[] bytes = new byte[4];

    for (String data : lines) {
      Matcher matcher = pattern.matcher(data);
      if (matcher.matches()) {
        int sectorId = Integer.parseInt(matcher.group(1), 16);
        for (int x = 0; x < bytes.length; x++) {
          bytes[x] = (byte)Integer.parseInt(matcher.group(2 + x), 16);
        }
        memoryMap.setPage(sectorId, bytes);
      }
    }

    return memoryMap;
  }
View Full Code Here

  public static MemoryMap loadCardFromFile(String fileName) throws IOException {
    Collection<String> lines = readLinesFromFile(fileName);

    if (lines.size() == 256 || lines.size() == 64) {
      MemoryLayout memoryLayout = lines.size() == 64 ? MemoryLayout.CLASSIC_1K : MemoryLayout.CLASSIC_4K;
      MemoryMap memoryMap = new MemoryMap(lines.size(), 16);

      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));

          if (memoryLayout.isTrailerBlock(sectorId, blockId)) {
            byte[] key = new byte[6];
            System.arraycopy(blockData, 0, key, 0, 6);
            // copy keyA only if the read data is all 0. This is a real card scan.
            if (Arrays.equals(EMPTY_KEY, key)) {
              System.arraycopy(keyA, 0, blockData, 0, 6);
            }
          }

          memoryMap.setPage(blockNumber, blockData);
          blockNumber++;
        }
      }

      return memoryMap;
View Full Code Here

public class ReaderWriterCreator {

  public static AcrMfClassicReaderWriter createReadWriter(String fileName, MemoryLayout memoryLayout)
      throws IOException {
    MemoryMap memoryMap = FileMfClassicReader.loadCardFromFile(fileName);
    InMemoryTag tag = new InMemoryTag(memoryMap);
    AcrMfClassicReaderWriter readerWriter = new AcrMfClassicReaderWriter(tag, memoryLayout);
    return readerWriter;
  }
View Full Code Here

    }
  }

  protected MfClassicReaderWriter loadData(String fileName) {
    try {
      MemoryMap memoryMap = FileMfClassicReader.loadCardFromFile(fileName);
      InMemoryTag tag = new InMemoryTag(memoryMap);

      AcrMfClassicReaderWriter mfClassicReaderWriter = new AcrMfClassicReaderWriter(tag, memoryLayout);
      return mfClassicReaderWriter;
    }
View Full Code Here

  private static final Config[] MAKE_READ_ONLY_TEST = {
      new Config("mfstd1k_formatted.txt", MemoryLayout.CLASSIC_1K, true, true, "mfstd1k_formatted_readonly.txt"),
      new Config("mfstd4k_formatted.txt", MemoryLayout.CLASSIC_4K, true, true, "mfstd4k_formatted_readonly.txt") };

  private void init(Config config) throws IOException {
    MemoryMap memoryMap = FileMfClassicReader.loadCardFromFile(config.fileName);
    tag = new InMemoryTag(memoryMap);
    readerWriter = new AcrMfClassicReaderWriter(tag, config.memoryLayout);
    ndefOperations = new MfClassicNdefOperations(readerWriter, readerWriter.getTagInfo(), config.formatted,
        config.writeable);
    if (config.expected != null && config.expected.startsWith("mfstd")) {
View Full Code Here

TOP

Related Classes of org.nfctools.mf.ul.MemoryMap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.