def _format_management_information(self, indent): result = [] if self._management_information is None: return result try: if self._card_object is not None: c = TLV_utils.decode(self._management_information, tags=self._card_object.TLV_OBJECTS, context=self._card_object.DEFAULT_CONTEXT) else: c = TLV_utils.decode(self._management_information) result.append( self.get_indent(indent + 1) + "Management information:") result.extend( map(lambda a: self.get_indent(indent + 2) + a, c.splitlines(False))) except (SystemExit, KeyboardInterrupt): raise except: result.append( self.get_indent(indent + 1) + "Raw dump of unparseable management information following:") result.extend( self._dump_internal(self._management_information, indent=indent + 2, do_tlv=False)) return result
def cmd_open(self, file): "Open a file" fid = binascii.a2b_hex("".join(file.split())) result = self.open_file(fid) if len(result.data) > 0: print utils.hexdump(result.data) print TLV_utils.decode(result.data,tags=self.TLV_OBJECTS)
def cmd_open(self, file): "Open a file" fid = binascii.a2b_hex("".join(file.split())) result = self.open_file(fid) if len(result.data) > 0: print utils.hexdump(result.data) print TLV_utils.decode(result.data, tags=self.TLV_OBJECTS)
def cmd_selectapplication(self, application): """Select an application on the card. application can be given either as hexadecimal aid or by symbolic name (if known).""" aid = self.resolve_symbolic_aid(application) result = self.select_application(aid) if len(result.data) > 0: print utils.hexdump(result.data) print TLV_utils.decode(result.data,tags=self.TLV_OBJECTS)
def cmd_selectapplication(self, application): """Select an application on the card. application can be given either as hexadecimal aid or by symbolic name (if known).""" aid = self.resolve_symbolic_aid(application) result = self.select_application(aid) if len(result.data) > 0: print utils.hexdump(result.data) print TLV_utils.decode(result.data, tags=self.TLV_OBJECTS)
def cmd_selectfile(self, p1, p2, fid): """Select a file on the card.""" p1 = binascii.a2b_hex("".join(p1.split())) p2 = binascii.a2b_hex("".join(p2.split())) fid = binascii.a2b_hex("".join(fid.split())) result = self.select_file(p1, p2, fid) if len(result.data) > 0: print utils.hexdump(result.data) print TLV_utils.decode(result.data,tags=self.TLV_OBJECTS)
def cmd_selectfile(self, p1, p2, fid): """Select a file on the card.""" p1 = binascii.a2b_hex("".join(p1.split())) p2 = binascii.a2b_hex("".join(p2.split())) fid = binascii.a2b_hex("".join(fid.split())) result = self.select_file(p1, p2, fid) if len(result.data) > 0: print utils.hexdump(result.data) print TLV_utils.decode(result.data, tags=self.TLV_OBJECTS)
def dump(data): print "Dump following (%i bytes)" % (len(data)) print utils.hexdump(data) try: print "Trying TLV parse:" print TLV_utils.decode(data, tags=card.TLV_OBJECTS, context = card.DEFAULT_CONTEXT) print "TLV parsed successfully" except (SystemExit, KeyboardInterrupt): raise except: print "TLV error" pass
def cmd_cd(self, dir = None): "Change into a DF, or into the MF if no dir is given" if dir is None: result = self.change_dir() else: fid = binascii.a2b_hex("".join(dir.split())) result = self.change_dir(fid) if len(result.data) > 0: print utils.hexdump(result.data) print TLV_utils.decode(result.data,tags=self.TLV_OBJECTS)
def cmd_parsetlv(self, start = None, end = None): "Decode the TLV data in the last response, start and end are optional" lastlen = len(self.last_result.data) if start is not None: start = (lastlen + (int(start,0) % lastlen) ) % lastlen else: start = 0 if end is not None: end = (lastlen + (int(end,0) % lastlen) ) % lastlen else: end = lastlen print TLV_utils.decode(self.last_result.data[start:end], tags=self.TLV_OBJECTS, context = self.DEFAULT_CONTEXT)
def cmd_cd(self, dir=None): "Change into a DF, or into the MF if no dir is given" if dir is None: result = self.change_dir() else: fid = binascii.a2b_hex("".join(dir.split())) result = self.change_dir(fid) if len(result.data) > 0: print utils.hexdump(result.data) print TLV_utils.decode(result.data, tags=self.TLV_OBJECTS)
def cmd_parsetlv(self, start=None, end=None): "Decode the TLV data in the last response, start and end are optional" lastlen = len(self.last_result.data) if start is not None: start = (lastlen + (int(start, 0) % lastlen)) % lastlen else: start = 0 if end is not None: end = (lastlen + (int(end, 0) % lastlen)) % lastlen else: end = lastlen print TLV_utils.decode(self.last_result.data[start:end], tags=self.TLV_OBJECTS, context=self.DEFAULT_CONTEXT)
def _dump_internal(self, data, indent, do_tlv=True): c = utils.hexdump(data) r = map(lambda a: self.get_indent(indent)+a, c.splitlines(False)) if do_tlv: try: if self._card_object is not None: c = TLV_utils.decode(data, tags=self._card_object.TLV_OBJECTS, context = self._card_object.DEFAULT_CONTEXT) else: c = TLV_utils.decode(data) r.append( self.get_indent(indent) + "Trying TLV parse:" ) r.extend( map(lambda a: self.get_indent(indent)+a, c.splitlines(False)) ) except (SystemExit, KeyboardInterrupt): raise except: pass return r
def _format_management_information(self, indent): result = [] if self._management_information is None: return result try: if self._card_object is not None: c = TLV_utils.decode(self._management_information, tags=self._card_object.TLV_OBJECTS, context = self._card_object.DEFAULT_CONTEXT) else: c = TLV_utils.decode(self._management_information) result.append(self.get_indent(indent+1) + "Management information:") result.extend( map(lambda a: self.get_indent(indent+2)+a, c.splitlines(False)) ) except (SystemExit, KeyboardInterrupt): raise except: result.append(self.get_indent(indent+1) + "Raw dump of unparseable management information following:") result.extend(self._dump_internal(self._management_information, indent=indent+2, do_tlv=False)) return result
def _dump_internal(self, data, indent, do_tlv=True): c = utils.hexdump(data) r = map(lambda a: self.get_indent(indent) + a, c.splitlines(False)) if do_tlv: try: if self._card_object is not None: c = TLV_utils.decode( data, tags=self._card_object.TLV_OBJECTS, context=self._card_object.DEFAULT_CONTEXT) else: c = TLV_utils.decode(data) r.append(self.get_indent(indent) + "Trying TLV parse:") r.extend( map(lambda a: self.get_indent(indent) + a, c.splitlines(False))) except (SystemExit, KeyboardInterrupt): raise except: pass return r
traceback.print_exc() print >>sys.stderr print "="*80 print "Results:" for fid, result in sorted(results_dir.items()): if results_file.has_key(fid): continue print "-"*80 print "Dir\t%04X" % fid if len(result.data) > 0: print utils.hexdump(result.data) try: print TLV_utils.decode(result.data,tags=card.TLV_OBJECTS) except: print "Exception during TLV parse" for fid, result in sorted(results_file.items()): print "-"*80 print "File\t%04X" % fid if len(result.data) > 0: print utils.hexdump(result.data) try: print TLV_utils.decode(result.data,tags=card.TLV_OBJECTS) except: print "Exception during TLV parse" if contents_file.has_key( fid ): contents_result = contents_file[fid] if contents_result[0] == '\x69\x81': print "Record-oriented file" elif contents_result[0] == '\x69\x82':