Page 1 of 1

get the ram and eeprom using applet

Posted: Wed Jun 08, 2016 5:11 am
by morva14
i write applet to get amount of eeprom but i am not sure whether or not it is right

i multiplicate counter and 1024 to get amount of eeprom , when exception throw

1.sample of EEPROM:

package memoryPack;

import javacard.framework.*;
import java.lang.Exception;

public class memoryApp extends Applet
{

public static void install(byte[] bArray, short bOffset, byte bLength)
{
new memoryApp().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
}

public void process(APDU apdu)
{
short counter = (short) 0x0000;
if (selectingApplet())
{
return;
}

byte[] buf = apdu.getBuffer();
switch (buf[ISO7816.OFFSET_INS])
{
case (byte)0x00:
try{
while(true){
byte[] temp = new byte[1024];
counter++;
}
}catch(Exception e){
ISOException.throwIt(counter);
}
break;
default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
}

}

Re: get the ram and eeprom using applet

Posted: Wed Jun 08, 2016 5:04 pm
by rena2019
Why you do not use javacard.framework.JCSystem.getAvailableMemory?
http://www.win.tue.nl/pinpasjc/docs/api ... ystem.html

Re: get the ram and eeprom using applet

Posted: Sun Jun 12, 2016 1:18 am
by Harten
You can use the following code to get the size of EEPROM.

Code: Select all

    short memSize_persistent = 0;
    short memSize = 0;
    try{
         while(true){
                        byte[] temp = new byte[1024];
                        memSize += (short)1024;
                    }
         }catch(Exception e)
         {
                memSize_persistent = JCSystem.getAvailableMemory(JCSystem.MEMORY_TYPE_PERSISTENT);   
         }

         memSize += memSize_persistent;
         Util.setShort(buf, (short)0, memSize);

Re: get the ram and eeprom using applet

Posted: Sun Jun 12, 2016 12:53 pm
by morva14
thanks