diff options
author | hploetz <hploetz@f711b948-2313-0410-aaa9-d29f33439f0b> | 2006-07-18 12:05:39 +0000 |
---|---|---|
committer | hploetz <hploetz@f711b948-2313-0410-aaa9-d29f33439f0b> | 2006-07-18 12:05:39 +0000 |
commit | c2c2457c793adf982d95853060379562d0346205 (patch) | |
tree | c34992cdc84f39f4fae02a88b725229916c06642 | |
parent | 63cded4f7d434dcdd8235dacc3bd265df336886e (diff) |
Some CardOS support
git-svn-id: svn+ssh://localhost/home/henryk/svn/cyberflex-shell/trunk@102 f711b948-2313-0410-aaa9-d29f33439f0b
-rw-r--r-- | cards/building_blocks.py | 60 | ||||
-rw-r--r-- | cyberflex-shell.e3p | 6 |
2 files changed, 37 insertions, 29 deletions
diff --git a/cards/building_blocks.py b/cards/building_blocks.py index 9fa3efe..6f765b1 100644 --- a/cards/building_blocks.py +++ b/cards/building_blocks.py @@ -3,30 +3,7 @@ from utils import C_APDU, R_APDU import utils, TLV_utils -class Card_with_80_aa: - APDU_LIST_X = C_APDU("\x80\xaa\x01\x00\x00") - - def list_x(self, x): - "Get a list of x objects, where x is one of 1 (DFs) or 2 (EFs) or 3 (DFs and EFs)" - result = self.send_apdu(C_APDU(self.APDU_LIST_X, p1=x)) - - tail = result.data - result_list = [] - while len(tail) > 0: - head, tail = tail[:2], tail[2:] - result_list.append(head) - return result_list - - def cmd_listdirs(self): - "List DFs in current DF" - result = self.list_x(1) - print "DFs: " + ", ".join([utils.hexdump(a, short=True) for a in result]) - - def cmd_listfiles(self): - "List EFs in current DF" - result = self.list_x(2) - print "EFs: " + ", ".join([utils.hexdump(a, short=True) for a in result]) - +class Card_with_ls: def _str_to_long(value): num = 0 for i in value: @@ -46,7 +23,7 @@ class Card_with_80_aa: if tag == search_tag: return value else: - ret = Card_with_80_aa._find_recursive(search_tag, value) + ret = Card_with_ls._find_recursive(search_tag, value) if ret is not None: return ret return None _find_recursive = staticmethod(_find_recursive) @@ -54,8 +31,8 @@ class Card_with_80_aa: _ls_l_template = "%(name)-12s\t%(type)3s\t%(size)4s" def cmd_list(self, *options): """List all EFs and DFs in current DF. Call with -l for verbose information (caution: deselects current file)""" - dirs = self.list_x(1) - files = self.list_x(2) + dirs = self.list_x(self.LIST_X_DF) + files = self.list_x(self.LIST_X_EF) if "-l" in options: response_DF = {} @@ -80,8 +57,35 @@ class Card_with_80_aa: for FID in files: name = " " + utils.hexdump(FID, short=True) + " " type = "EF" - size = self._str_to_long(self._find_recursive(0x81, response_EF[FID].data)) + size = self._str_to_long(self._find_recursive(self.LS_L_SIZE_TAG, response_EF[FID].data)) print self._ls_l_template % locals() else: print "\n".join( ["[%s]" % utils.hexdump(a, short=True) for a in dirs] + [" %s " % utils.hexdump(a, short=True) for a in files] ) + +class Card_with_80_aa(Card_with_ls): + APDU_LIST_X = C_APDU("\x80\xaa\x01\x00\x00") + LIST_X_DF = 1 + LIST_X_EF = 2 + LS_L_SIZE_TAG = 0x81 + + def list_x(self, x): + "Get a list of x objects, where x is one of 1 (DFs) or 2 (EFs) or 3 (DFs and EFs)" + result = self.send_apdu(C_APDU(self.APDU_LIST_X, p1=x)) + + tail = result.data + result_list = [] + while len(tail) > 0: + head, tail = tail[:2], tail[2:] + result_list.append(head) + return result_list + + def cmd_listdirs(self): + "List DFs in current DF" + result = self.list_x(1) + print "DFs: " + ", ".join([utils.hexdump(a, short=True) for a in result]) + + def cmd_listfiles(self): + "List EFs in current DF" + result = self.list_x(2) + print "EFs: " + ", ".join([utils.hexdump(a, short=True) for a in result]) diff --git a/cyberflex-shell.e3p b/cyberflex-shell.e3p index 615dfd7..92bf4dd 100644 --- a/cyberflex-shell.e3p +++ b/cyberflex-shell.e3p @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE Project SYSTEM "Project-3.7.dtd"> <!-- Project file for project cyberflex-shell --> -<!-- Saved: 2006-06-18, 14:02:00 --> +<!-- Saved: 2006-07-18, 13:42:27 --> <!-- Copyright (C) 2006 Henryk Plötz, henryk@ploetzli.ch --> <Project version="3.7"> <ProgLanguage mixed="0">Python</ProgLanguage> @@ -72,6 +72,10 @@ <Dir>cards</Dir> <Name>mtcos_card.py</Name> </Source> + <Source> + <Dir>cards</Dir> + <Name>cardos_card.py</Name> + </Source> </Sources> <Forms> </Forms> |