JavacardOS will not accept order any more, please contact our partner Feitian online Store:
https://ftsafe.en.alibaba.com/index.html
https://ftsafe.en.alibaba.com/index.html
Applet's own space
Applet's own space
This problem may be a little strange, but it is indeed an application developer proposed to me.
How can an Applet know how much NVM space it occupies?
I don't want to use JCSystem.getAvailableMemory() to achieve this because its return value is too small, but my card space can be quite large.
How can an Applet know how much NVM space it occupies?
I don't want to use JCSystem.getAvailableMemory() to achieve this because its return value is too small, but my card space can be quite large.
-
- Posts: 55
- Joined: Thu Sep 22, 2016 5:05 am
- Points :784
- Contact:
Re: Applet's own space
You can keep new space until SystemException.NO_RESOURCE == ex.getReason()
-
- Posts: 39
- Joined: Wed Aug 31, 2016 9:55 pm
- Points :372
- Contact:
Re: Applet's own space
Maybe you can do it like this:
Code: Select all
byte[] buf = apdu.getBuffer();
byte p1 = buf[ISO7816.OFFSET_P1];
switch (buf[ISO7816.OFFSET_INS]) {
case (byte) 0x00:
byte type=0;
if(0==p1)
type=JCSystem.MEMORY_TYPE_PERSISTENT;
else if(1==p1)
type=JCSystem.MEMORY_TYPE_TRANSIENT_RESET;
else if(2==p1)
type=JCSystem.MEMORY_TYPE_TRANSIENT_DESELECT;
else
ISOException.throwIt(ISO7816.SW_WRONG_P1P2);
memsize=JCSystem.getAvailableMemory(type);
allmemsize=memsize;
while(memsize==(short)32767){
if(type==JCSystem.MEMORY_TYPE_PERSISTENT)
bbb=new byte[memsize];
else
bbb=JCSystem.makeTransientByteArray(memsize,type);
memsize=JCSystem.getAvailableMemory(type);
allmemsize+=memsize;
}
bbb=null;
JCSystem.requestObjectDeletion();
buf[3]=(byte)(allmemsize);
buf[2]=(byte)(allmemsize>>8);
buf[1]=(byte)(allmemsize>>16);
buf[0]=(byte)(allmemsize>>24);
//buf[1]=(byte)(memsize>>8);
apdu.setOutgoingAndSend((short)0, (short)4);
break;
default:
// good practice: If you don't know the INStruction, say so:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
-
- Posts: 11
- Joined: Tue May 22, 2018 9:43 pm
- Points :130
- Contact:
Re: Applet's own space
you can use a new API(since jck3.0.4) to get the size:
public static void getAvailableMemory(short[] buffer,
short offset,
byte memoryType)
throws SystemException
Obtains the amount of memory of the specified type that is available to the applet. Note that implementation-dependent memory overhead structures may also use the same memory pool. The requested memory information is returned as a 32 bit number stored in the specified short array - buffer. The 32 bit number number is the concatenation of buffer[offset] and buffer[offset+1].
Notes:
•The number of bytes returned is only an upper bound on the amount of memory available due to overhead requirements.
•Allocation of CLEAR_ON_RESET transient objects may affect the amount of CLEAR_ON_DESELECT transient memory available.
•Allocation of CLEAR_ON_DESELECT transient objects may affect the amount of CLEAR_ON_RESET transient memory available.
•The 32 bit number is not an indicator of the size of object which may be created since memory fragmentation is possible.
Parameters:memoryType - the type of memory being queried. One of the MEMORY_TYPE_* constants defined above, for example MEMORY_TYPE_PERSISTENT.buffer - the output buffer for storing memory size informationoffset - the offset within the buffer where memory size information beginsThrows:ArrayIndexOutOfBoundsException - if buffer[offset] or buffer[offset+1] outside array boundsNullPointerException - if buffer is nullSystemException - with the following reason codes: •SystemException.ILLEGAL_VALUE if memoryType is not a valid memory type.
Since:3.0.4
public static void getAvailableMemory(short[] buffer,
short offset,
byte memoryType)
throws SystemException
Obtains the amount of memory of the specified type that is available to the applet. Note that implementation-dependent memory overhead structures may also use the same memory pool. The requested memory information is returned as a 32 bit number stored in the specified short array - buffer. The 32 bit number number is the concatenation of buffer[offset] and buffer[offset+1].
Notes:
•The number of bytes returned is only an upper bound on the amount of memory available due to overhead requirements.
•Allocation of CLEAR_ON_RESET transient objects may affect the amount of CLEAR_ON_DESELECT transient memory available.
•Allocation of CLEAR_ON_DESELECT transient objects may affect the amount of CLEAR_ON_RESET transient memory available.
•The 32 bit number is not an indicator of the size of object which may be created since memory fragmentation is possible.
Parameters:memoryType - the type of memory being queried. One of the MEMORY_TYPE_* constants defined above, for example MEMORY_TYPE_PERSISTENT.buffer - the output buffer for storing memory size informationoffset - the offset within the buffer where memory size information beginsThrows:ArrayIndexOutOfBoundsException - if buffer[offset] or buffer[offset+1] outside array boundsNullPointerException - if buffer is nullSystemException - with the following reason codes: •SystemException.ILLEGAL_VALUE if memoryType is not a valid memory type.
Since:3.0.4
Who is online
Users browsing this forum: No registered users and 54 guests