laforge has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/pysim/+/37925?usp=email )


Change subject: pySim.apdu_source.stdin_hex
......................................................................

pySim.apdu_source.stdin_hex

Change-Id: I5aacf13b7c27cea9efd42f01dacca61068c3aa33
---
M pySim-trace.py
A pySim/apdu_source/stdin_hex.py
2 files changed, 48 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/25/37925/1

diff --git a/pySim-trace.py b/pySim-trace.py
index 74dc8b9..a43d05c 100755
--- a/pySim-trace.py
+++ b/pySim-trace.py
@@ -22,6 +22,7 @@
 from pySim.apdu_source.pyshark_rspro import PysharkRsproPcap, PysharkRsproLive
 from pySim.apdu_source.pyshark_gsmtap import PysharkGsmtapPcap
 from pySim.apdu_source.tca_loader_log import TcaLoaderLogApduSource
+from pySim.apdu_source.stdin_hex import StdinHexApduSource

 from pySim.apdu.ts_102_221 import UiccSelect, UiccStatus

@@ -189,6 +190,10 @@
 parser_tcaloader_log.add_argument('-f', '--log-file', required=True,
                                   help='Name of te log file to be read')

+parser_stdin_hex = subparsers.add_parser('stdin-hex', help="""
+    Read APDUs as hex-string from stdin.""")
+
+
 if __name__ == '__main__':

     opts = option_parser.parse_args()
@@ -204,6 +209,8 @@
         s = PysharkGsmtapPcap(opts.pcap_file)
     elif opts.source == 'tca-loader-log':
         s = TcaLoaderLogApduSource(opts.log_file)
+    elif opts.source == 'stdin-hex':
+        s = StdinHexApduSource()
     else:
         raise ValueError("unsupported source %s", opts.source)

diff --git a/pySim/apdu_source/stdin_hex.py b/pySim/apdu_source/stdin_hex.py
new file mode 100644
index 0000000..53d3106
--- /dev/null
+++ b/pySim/apdu_source/stdin_hex.py
@@ -0,0 +1,41 @@
+# coding=utf-8
+
+# (C) 2024 by Harald Welte <[email protected]>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+
+from pySim.utils import h2b
+from pySim.gsmtap import GsmtapSource
+
+from pySim.apdu.ts_102_221 import ApduCommands as UiccApduCommands
+from pySim.apdu.ts_102_222 import ApduCommands as UiccAdmApduCommands
+from pySim.apdu.ts_31_102 import ApduCommands as UsimApduCommands
+from pySim.apdu.global_platform import ApduCommands as GpApduCommands
+
+from . import ApduSource, PacketType, CardReset
+
+ApduCommands = UiccApduCommands + UiccAdmApduCommands + UsimApduCommands + 
GpApduCommands
+
+class StdinHexApduSource(ApduSource):
+    """ApduSource for reading apdu hex-strings from stdin."""
+
+    def read_packet(self) -> PacketType:
+        command = None
+        response = None
+        while True:
+            command = input("C-APDU >")
+            response = '9000'
+            return ApduCommands.parse_cmd_bytes(h2b(command) + h2b(response))
+        raise StopIteration

--
To view, visit https://gerrit.osmocom.org/c/pysim/+/37925?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I5aacf13b7c27cea9efd42f01dacca61068c3aa33
Gerrit-Change-Number: 37925
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <[email protected]>

Reply via email to