test eewayinfo.cap

来源:互联网 发布:steam上mac游戏推荐 编辑:程序博客网 时间:2024/05/01 19:42

cm>  send 00a404000f4150504c45544545574159494e464f
 => 00 A4 04 00 0F 41 50 50 4C 45 54 45 45 57 41 59    .....APPLETEEWAY
    49 4E 46 4F                                        INFO
 (230197 nsec)
 <= 90 00                                              ..
Status: No Error
cm>  send 00200000024142
 => 00 20 00 00 02 41 42                               . ...AB
 (282158 nsec)
 <= 90 00                                              ..
Status: No Error
cm>  send 0030000002
 => 00 30 00 00 02                                     .0...
 (257575 nsec)
 <= 41 42 00 00 00 00 00 00 00 00 00 00 00 00 00 00    AB..............
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    00 00 00 00 00 00 00 00 90 00                      ..........
Status: No Error

cm>  send 0030000000
 => 00 30 00 00 00                                     .0...
 (47645 usec)
 <= 41 42 00 00 00 00 00 00 00 00 00 00 00 00 00 00    AB..............
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    00 00 00 00 00 00 00 00 90 00                      ..........
Status: No Error


/**
 * File:AppletMain.java Package:com.pervcom.eeway.eewayinfo Project:EEWayInfo
 * Date:2010-12-1 Author:Peter.Feng
 * Copyright (c) 2010 Pervcom, Inc. All Rights Reserved.
 */
package com.pervcom.eeway.eewayinfo;

import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISO7816;
import javacard.framework.ISOException;
import javacard.framework.Util;

/**
 * <pre>
 * Author: Peter.Feng
 * Date&Time: 2010-12-1 下午02:16:07
 * AppletMain
 * 在易惠通手机客户端推荐优惠券给指定的好友之前,必须先确定自己的身份,也就是推荐人的在软件使用时对外的信息。
 * </pre>
 */
public class AppletMain extends Applet {
 
 private byte[] data = new byte[200];
 private short length = 200;
 
 final static short INS_WRITE = (byte)0x20;
 final static short INS_READ = (byte)0x30;
 
 final static short SW_WRONG_LC_LENGTH = 0x0011;
 final static short SW_WRONG_LE_LENGTH = 0x0012;
 
 private AppletMain(byte[] data, short offset, byte length)
 {  
  super.register();
 }

 public static void install(byte[] data, short offset, byte length) {
  new AppletMain(data, offset, length);
 }

 public void process(APDU apdu) {
  byte[] buffer = apdu.getBuffer();
  switch(buffer[ISO7816.OFFSET_INS])
  {
  case INS_WRITE:
   writeData(apdu);
   return;
  case INS_READ:
   readData(apdu);
   return;
  }
 }
 
 private void readData(APDU apdu)
 {
  byte[] buffer = apdu.getBuffer();
  Util.arrayCopy(data,(short)0,buffer,(short)0, length);
  apdu.setOutgoingAndSend((short)0, length);
 }
 
 private void writeData(APDU apdu)
 {
  byte[] buffer = apdu.getBuffer();
  byte lc = buffer[ISO7816.OFFSET_LC];
  byte lengthReceive = (byte)(apdu.setIncomingAndReceive());
  if(lc!=lengthReceive)
   ISOException.throwIt(SW_WRONG_LC_LENGTH);
  Util.arrayCopy(buffer,(short)(ISO7816.OFFSET_LC+1),data,(short)0,(short)lengthReceive);
 }

}

原创粉丝点击