示例#1
0
 def run(self):
     send = []
     receive = []
     for line in sys.stdin:
         line = line.rstrip()
         if len(line) == 0 and len(send) != 0 and len(receive) != 0:
             print "==> %s" % a2s(send)
             try:
                 got = self.transmit(send)
             except:
                 print self.vm.log
                 raise
             self.checkreceive(receive, got)
             send = []
             receive = []
         if line[:4] == "==> ":
             send.extend(s2a(line[4:]))
         elif line[:4] == "<== ":
             receive.extend(s2a(line[4:]))
         elif line.startswith('install:'):
             sep1 = 8
             sep2 = line.find(':', sep1+1)
             data = s2a(line[sep1:sep2])
             offset = s2a(line[sep2 + 1:])[0]
             self.install(data, offset)
         elif line.startswith('load:'):
             self.vm.load(capfile.CAPFile(line[5:].strip()))
         elif line.startswith('log;'):
             print self.vm.log
         else:
             print line
示例#2
0
 def run(self):
     send = []
     receive = []
     for line in sys.stdin:
         line = line.rstrip()
         if len(line) == 0 and len(send) != 0 and len(receive) != 0:
             print "==> %s" % a2s(send)
             try:
                 got = self.transmit(send)
             except:
                 print self.vm.log
                 raise
             self.checkreceive(receive, got)
             send = []
             receive = []
         if line[:4] == "==> ":
             send.extend(s2a(line[4:]))
         elif line[:4] == "<== ":
             receive.extend(s2a(line[4:]))
         elif line.startswith('install:'):
             sep1 = 8
             sep2 = line.find(':', sep1 + 1)
             data = s2a(line[sep1:sep2])
             offset = s2a(line[sep2 + 1:])[0]
             self.install(data, offset)
         elif line.startswith('load:'):
             self.vm.load(capfile.CAPFile(line[5:].strip()))
         elif line.startswith('log;'):
             print self.vm.log
         else:
             print line
示例#3
0
 def myregister(applet, bArray=[], bOffset=0, bLength=0):
     if bLength != 0:
         aid = bArray[bOffset:bOffset + bLength]
         # also update the current one
         self.current_applet_aid = aid
     else:
         aid = self.current_applet_aid
     self.applets[a2d(aid)] = applet
     self.echo("registered %s as %s" % (a2s(aid), applet))
示例#4
0
 def myregister(applet, bArray = [], bOffset=0, bLength=0):
     if bLength != 0:
         aid = bArray[bOffset:bOffset + bLength]
         # also update the current one
         self.current_applet_aid = aid
     else:
         aid = self.current_applet_aid
     self.applets[a2d(aid)] = applet
     self.echo("registered %s as %s" % (a2s(aid), applet))
示例#5
0
 def install(self, data, offset):
     """ 
     data[offset:] is len||appletaid||len||installdata
     where installdata is the data given to the install method
     """
     aidlen = data[offset]
     offset += 1
     aid = data[offset: offset + aidlen]
     offset += aidlen
     length = data[offset]
     offset += 1
     # data[offset:offset+length] is what is given to the install JavaCard 
     # method which means: len-instanceaid-len-stuff-len-customparams
     # where instance AID might be empty
     self.vm.frame.push(data)
     self.vm.frame.push(offset)
     self.vm.frame.push(length)
     applet = None
     self.echo(len(self.vm.cap_file.Applet.applets))
     for apl in self.vm.cap_file.Applet.applets:
         if a2d(aid) == a2d(apl.aid):
             applet = apl
             break
     if applet is None:
         self.echo("Applet %s not found in the CAP file" % a2s(aid))
         return
     self.current_applet_aid = aid
     self.vm._invokestaticjava(JavaCardStaticMethod(
             applet.install_method_offset,
             self.vm.cap_file,
             self.vm.resolver))
     try:
         while self.vm.step():
             pass
     except ISOException, ie:
         sw = isoe.getReason()
         return [signed1((sw & 0xff00) >> 8), signed1(sw & 0x00ff)]
示例#6
0
 def install(self, data, offset):
     """ 
     data[offset:] is len||appletaid||len||installdata
     where installdata is the data given to the install method
     """
     aidlen = data[offset]
     offset += 1
     aid = data[offset:offset + aidlen]
     offset += aidlen
     length = data[offset]
     offset += 1
     # data[offset:offset+length] is what is given to the install JavaCard
     # method which means: len-instanceaid-len-stuff-len-customparams
     # where instance AID might be empty
     self.vm.frame.push(data)
     self.vm.frame.push(offset)
     self.vm.frame.push(length)
     applet = None
     self.echo(len(self.vm.cap_file.Applet.applets))
     for apl in self.vm.cap_file.Applet.applets:
         if a2d(aid) == a2d(apl.aid):
             applet = apl
             break
     if applet is None:
         self.echo("Applet %s not found in the CAP file" % a2s(aid))
         return
     self.current_applet_aid = aid
     self.vm._invokestaticjava(
         JavaCardStaticMethod(applet.install_method_offset,
                              self.vm.cap_file, self.vm.resolver))
     try:
         while self.vm.step():
             pass
     except ISOException, ie:
         sw = isoe.getReason()
         return [signed1((sw & 0xff00) >> 8), signed1(sw & 0x00ff)]
示例#7
0
 def checkreceive(self, expected, received):
     print "<== %s" % a2s(received)
     if expected != received:
         print "<== %s was expected" % a2s(expected)
         print self.vm.log
         sys.exit(1)
示例#8
0
 def checkreceive(self, expected, received):
     print "<== %s" % a2s(received)
     if expected != received:
         print "<== %s was expected" % a2s(expected)
         print self.vm.log
         sys.exit(1)