From 8dc2ca2d376f56a16df589a5ddc6ead82bfdfb58 Mon Sep 17 00:00:00 2001 From: Philipp Maier Date: Thu, 27 Jul 2023 13:00:41 +0200 Subject: [PATCH] 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 --- pySim-trace.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pySim-trace.py b/pySim-trace.py index 8313c27c..325fb8ce 100755 --- a/pySim-trace.py +++ b/pySim-trace.py @@ -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()