Below, you see a program that is written to return the EEPROM available memory on reception of any APDU command :
public class HelloWorld extends Applet {
public static void install(byte[] bArray, short bOffset, byte bLength) {
new helloWorld.HelloWorld().register(bArray, (short) (bOffset + 1),
bArray[bOffset]);
}
public void process(APDU apdu) {
if (selectingApplet()) {
return;
}
getAvailableMem(apdu);
}
public void getAvailableMem(APDU apdu){
byte[] buffer = apdu.getBuffer();
short[] AvailableMem = {};
UtilX.getAvailableMemoryInfo(AvailableMem, (short) 0,
UtilX.MEMORY_TYPE_PERSISTENT);
for(short i=0;i<(short)AvailableMem.length;i++){
buffer[i]=(byte)AvailableMem[i];
}
apdu.setOutgoingAndSend((short)0, (short)(2*AvailableMem.length));
}
}
But when I send an APDU command to the applet, it returns 0x6F00
:
OSC: opensc-tool -s 00a4040006010203040506 -s 00000000
Using reader with a card: ACS CCID USB Reader 0
Sending: 00 A4 04 00 06 01 02 03 04 05 06
Received (SW1=0x90, SW2=0x00)
Sending: 00 00 00 00
Received (SW1=0x6F, SW2=0x00)
Note that I tried the above program with the below loop also :
for(byte i=0;i<(byte)AvailableMem.length;i++){
buffer[i]=(byte)AvailableMem[i];
}
It compiled successfully also! Shouldn't the compiler restrict the type of array indexes to byte
only or short
only? Why it accepts both types for indexes?
-This second program has the same output in OpenSCTool. What's wrong?