如何计算java卡小程序CAP文件的NVM大小

问题描述 投票:0回答:3

有谁知道如何获取java卡小程序文件的NVM(非易失性存储器)吗?

在互联网上进行研究后,我找不到任何工具或指南。

applet javacard
3个回答
0
投票

您可以发送 P1=FF 和 P2=21 的 GET DATA APDU 命令,请参阅 ETSI 102.226

APDU 命令: 尝试这个 80 加拿大 FF 21 10

谢谢


0
投票

将带有标签 DF55 的 GET DATA 命令发送到卡管理器(而不是小程序)


0
投票

您可以在小程序中编写一个函数,使用 JCSystem API 返回与 NVM 或 RAM 相关的数据。

public static final byte INS_GET_MEMORY = (byte) 0xCB;
public static final short TAG_PERSISTANT_MEM = (short) 0xC602;
public static final short TAG_TRANSIENT_RESET = (short) 0xC702;
public static final short TAG_TRANSIENT_DESELECT = (short) 0xC802;
public static final short TAG_BUFFER_SIZE = (short) 0xC902;
        
private short GetMemory(byte[] apduBuffer) {
    short outDataOffset = ISO7816.OFFSET_CDATA;
        
    outDataOffset = Util.setShort(apduBuffer, outDataOffset, TAG_PERSISTANT_MEM);
        
    // Size is bounded by short limit for Persistent MEMORY_TYPE_PERSISTENT
    // Can use getAvailableMemory(short[] buffer,short offset,byte memoryType)
    // If the size is more than short range
    outDataOffset = Util.setShort(apduBuffer, outDataOffset,
                JCSystem.getAvailableMemory(JCSystem.MEMORY_TYPE_PERSISTENT));
        
    outDataOffset = Util.setShort(apduBuffer, outDataOffset,TAG_TRANSIENT_RESET);
        
    outDataOffset = Util.setShort(apduBuffer, outDataOffset,
                JCSystem.getAvailableMemory(JCSystem.MEMORY_TYPE_TRANSIENT_RESET));
        
    outDataOffset = Util.setShort(apduBuffer, outDataOffset,TAG_TRANSIENT_DESELECT);
        
    outDataOffset = Util.setShort(apduBuffer, outDataOffset,
                JCSystem.getAvailableMemory(JCSystem.MEMORY_TYPE_TRANSIENT_DESELECT));
        
    outDataOffset = Util.setShort(apduBuffer, outDataOffset,TAG_BUFFER_SIZE);
        
    outDataOffset = Util.setShort(apduBuffer, outDataOffset, (short) apduBuffer.length);

    return (short) (outDataOffset - ISO7816.OFFSET_CDATA);


  }

此函数返回输出数据长度

© www.soinside.com 2019 - 2024. All rights reserved.