pySim-trace: catch StopIteration exception on trace file end

When the trace file end is reaced, pyShark raises a StopIteration
exception. Let's catch this exception and exit gracefully.

Related: OS#6094
Change-Id: I6ab5689b909333531d08bf46e5dfea59b161a79e
This commit is contained in:
Philipp Maier 2023-07-27 13:00:41 +02:00
parent 162ba3af3e
commit 8dc2ca2d37
1 changed files with 7 additions and 1 deletions

View File

@ -100,9 +100,15 @@ class Tracer:
def main(self):
"""Main loop of tracer: Iterates over all Apdu received from source."""
apdu_counter = 0
while True:
# obtain the next APDU from the source (blocking read)
apdu = self.source.read()
try:
apdu = self.source.read()
apdu_counter = apdu_counter + 1
except StopIteration:
print("%i APDUs parsed, stop iteration." % apdu_counter)
return 0
if isinstance(apdu, CardReset):
self.rs.reset()