ls -l (still ugly)
git-svn-id: svn+ssh://localhost/home/henryk/svn/cyberflex-shell/trunk@75 f711b948-2313-0410-aaa9-d29f33439f0b
This commit is contained in:
parent
c100297855
commit
b1f2a56881
16
TLV_utils.py
16
TLV_utils.py
|
@ -169,6 +169,7 @@ tags = {
|
||||||
0x62: (recurse, "File Control Parameters", context_FCP),
|
0x62: (recurse, "File Control Parameters", context_FCP),
|
||||||
0x64: (recurse, "File Management Data", context_FMD),
|
0x64: (recurse, "File Management Data", context_FMD),
|
||||||
0x6F: (recurse, "File Control Information", context_FCI),
|
0x6F: (recurse, "File Control Information", context_FCI),
|
||||||
|
|
||||||
0x80: (number, "Number of data bytes in the file, excluding structural information"),
|
0x80: (number, "Number of data bytes in the file, excluding structural information"),
|
||||||
0x81: (number, "Number of data bytes in the file, including structural information"),
|
0x81: (number, "Number of data bytes in the file, including structural information"),
|
||||||
0x82: (decode_file_descriptor_byte, "File descriptor byte"),
|
0x82: (decode_file_descriptor_byte, "File descriptor byte"),
|
||||||
|
@ -264,6 +265,21 @@ def decode(data, context = None, level = 0):
|
||||||
|
|
||||||
return "\n".join(result)
|
return "\n".join(result)
|
||||||
|
|
||||||
|
def unpack(data):
|
||||||
|
result = []
|
||||||
|
while len(data) > 0:
|
||||||
|
if ord(data[0]) in (0x00, 0xFF):
|
||||||
|
data = data[1:]
|
||||||
|
continue
|
||||||
|
|
||||||
|
ber_class, constructed, tag, length, value, data = tlv_unpack(data)
|
||||||
|
if not constructed:
|
||||||
|
result.append( (tag, length, value) )
|
||||||
|
else:
|
||||||
|
result.append( (tag, length, unpack(value)) )
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test = binascii.unhexlify("".join(("6f 2b 83 02 2f 00 81 02 01 00 82 03 05 41 26 85" \
|
test = binascii.unhexlify("".join(("6f 2b 83 02 2f 00 81 02 01 00 82 03 05 41 26 85" \
|
||||||
+"02 01 00 86 18 60 00 00 00 ff ff b2 00 00 00 ff" \
|
+"02 01 00 86 18 60 00 00 00 ff ff b2 00 00 00 ff" \
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import utils
|
import utils, TLV_utils
|
||||||
from iso_7816_4_card import *
|
from iso_7816_4_card import *
|
||||||
|
|
||||||
class TCOS_Card(ISO_7816_4_Card):
|
class TCOS_Card(ISO_7816_4_Card):
|
||||||
|
@ -26,13 +26,62 @@ class TCOS_Card(ISO_7816_4_Card):
|
||||||
result = self.list_x(2)
|
result = self.list_x(2)
|
||||||
print "EFs: " + ", ".join([utils.hexdump(a, short=True) for a in result])
|
print "EFs: " + ", ".join([utils.hexdump(a, short=True) for a in result])
|
||||||
|
|
||||||
def cmd_list(self):
|
def _str_to_long(value):
|
||||||
"List all EFs and DFs in current DF"
|
num = 0
|
||||||
|
for i in value:
|
||||||
|
num = num * 256
|
||||||
|
num = num + ord(i)
|
||||||
|
return num
|
||||||
|
_str_to_long = staticmethod(_str_to_long)
|
||||||
|
|
||||||
|
def _find_recursive(search_tag, data):
|
||||||
|
while len(data) > 0:
|
||||||
|
if ord(data[0]) in (0x00, 0xFF):
|
||||||
|
data = data[1:]
|
||||||
|
continue
|
||||||
|
|
||||||
|
ber_class, constructed, tag, length, value, data = TLV_utils.tlv_unpack(data)
|
||||||
|
if not constructed:
|
||||||
|
if tag == search_tag:
|
||||||
|
return value
|
||||||
|
else:
|
||||||
|
ret = TCOS_Card._find_recursive(search_tag, value)
|
||||||
|
if ret is not None: return ret
|
||||||
|
return None
|
||||||
|
_find_recursive = staticmethod(_find_recursive)
|
||||||
|
|
||||||
|
_ls_l_template = "%(name)10s\t%(type)s\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)
|
dirs = self.list_x(1)
|
||||||
files = self.list_x(2)
|
files = self.list_x(2)
|
||||||
|
|
||||||
|
if "-l" in options:
|
||||||
|
response_DF = {}
|
||||||
|
response_EF = {}
|
||||||
|
for DF in dirs:
|
||||||
|
response_DF[DF] = self.select_file(0x01, 0x00, DF)
|
||||||
|
self.select_file(0x03, 0x00, "")
|
||||||
|
for EF in files:
|
||||||
|
response_EF[EF] = self.select_file(0x02, 0x00, EF)
|
||||||
|
|
||||||
self.sw_changed = False
|
self.sw_changed = False
|
||||||
print "\n".join( ["[%s]" % utils.hexdump(a, short=True) for a in dirs]
|
|
||||||
+ [" %s " % utils.hexdump(a, short=True) for a in files] )
|
if "-l" in options:
|
||||||
|
print self._ls_l_template % {"name": "Name", "type": "Type", "size": "Size"}
|
||||||
|
for FID in dirs:
|
||||||
|
name = "[" + utils.hexdump(FID, short=True) + "]"
|
||||||
|
type = "DF"
|
||||||
|
size = ""
|
||||||
|
print self._ls_l_template % locals()
|
||||||
|
for FID in files:
|
||||||
|
name = " " + utils.hexdump(FID, short=True) + " "
|
||||||
|
type = "EF"
|
||||||
|
size = TCOS_Card._str_to_long(TCOS_Card._find_recursive(0x81, 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] )
|
||||||
|
|
||||||
ATRS = list(Card.ATRS)
|
ATRS = list(Card.ATRS)
|
||||||
ATRS.extend( [
|
ATRS.extend( [
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE Project SYSTEM "Project-3.5.dtd">
|
<!DOCTYPE Project SYSTEM "Project-3.7.dtd">
|
||||||
<!-- Project file for project cyberflex-shell -->
|
<!-- Project file for project cyberflex-shell -->
|
||||||
<!-- Saved: 2005-10-10, 03:45:04 -->
|
<!-- Saved: 2006-05-22, 09:18:42 -->
|
||||||
<!-- Copyright (C) 2005 Henryk Plötz, henryk@ploetzli.ch -->
|
<!-- Copyright (C) 2006 Henryk Plötz, henryk@ploetzli.ch -->
|
||||||
<Project version="3.5">
|
<Project version="3.7">
|
||||||
|
<ProgLanguage mixed="0">Python</ProgLanguage>
|
||||||
|
<UIType>Qt</UIType>
|
||||||
<Description></Description>
|
<Description></Description>
|
||||||
<Version>0.1</Version>
|
<Version>0.1</Version>
|
||||||
<Author>Henryk Plötz</Author>
|
<Author>Henryk Plötz</Author>
|
||||||
|
@ -37,6 +39,24 @@
|
||||||
<Source>
|
<Source>
|
||||||
<Name>shell.py</Name>
|
<Name>shell.py</Name>
|
||||||
</Source>
|
</Source>
|
||||||
|
<Source>
|
||||||
|
<Name>TLV_utils.py</Name>
|
||||||
|
</Source>
|
||||||
|
<Source>
|
||||||
|
<Name>brutefid.py</Name>
|
||||||
|
</Source>
|
||||||
|
<Source>
|
||||||
|
<Dir>cards</Dir>
|
||||||
|
<Name>iso_7816_4_card.py</Name>
|
||||||
|
</Source>
|
||||||
|
<Source>
|
||||||
|
<Dir>cards</Dir>
|
||||||
|
<Name>tcos_card.py</Name>
|
||||||
|
</Source>
|
||||||
|
<Source>
|
||||||
|
<Dir>cards</Dir>
|
||||||
|
<Name>starcos_card.py</Name>
|
||||||
|
</Source>
|
||||||
</Sources>
|
</Sources>
|
||||||
<Forms>
|
<Forms>
|
||||||
</Forms>
|
</Forms>
|
||||||
|
|
Loading…
Reference in New Issue