load_response and pretend_application commands

git-svn-id: svn+ssh://localhost/home/henryk/svn/cyberflex-shell/trunk@213 f711b948-2313-0410-aaa9-d29f33439f0b
This commit is contained in:
hploetz 2007-06-05 02:31:17 +00:00
parent c4229f95e4
commit e4fa619d41
2 changed files with 27 additions and 0 deletions

View File

@ -121,6 +121,11 @@ class ISO_7816_4_Card(building_blocks.Card_with_read_binary,Card):
print utils.hexdump(result.data)
print TLV_utils.decode(result.data,tags=self.TLV_OBJECTS)
def cmd_pretendapplication(self, application):
"Pretend that an application has been selected on the card without actually sending a SELECT APPLICATION. Basically for debugging purposes."
aid = self.resolve_symbolic_aid(application)
Application.load_applications(self, aid)
ATRS = list(Card.ATRS)
ATRS.extend( [
(".*", None), ## For now we accept any card
@ -135,6 +140,7 @@ class ISO_7816_4_Card(building_blocks.Card_with_read_binary,Card):
COMMANDS.update(building_blocks.Card_with_read_binary.COMMANDS)
COMMANDS.update( {
"select_application": cmd_selectapplication,
"pretend_application": cmd_pretendapplication,
"select_file": cmd_selectfile,
"cd": cmd_cd,
"open": cmd_open,

View File

@ -190,6 +190,26 @@ class Cyberflex_Shell(Shell):
finally:
fp.close()
def cmd_load_response(self, filename, start=None, end=None):
"Load the data from a file and pretend it was the last response from the card. start and end are optional"
fp = file(filename, "r")
try:
data = fp.read()
finally:
fp.close()
datalen = len(data)
if start is not None:
start = (datalen + (int(start,0) % datalen) ) % datalen
else:
start = 0
if end is not None:
end = (datalen + (int(end,0) % datalen) ) % datalen
else:
end = datalen
self.card.last_result = utils.R_APDU(data[start:end] + "\x00\x00")
def cmd_disconnect(self, *args):
"Close the connection to the currently inserted card"
self.unregister_post_hook(self._print_sw)
@ -396,6 +416,7 @@ class Cyberflex_Shell(Shell):
"list_readers": cmd_listreaders,
"eval": cmd_eval,
"save_response": cmd_save_response,
"load_response": cmd_load_response,
"fancy": cmd_fancy,
"enc": cmd_enc,
"log": cmd_log,