mirror of
https://gitea.osmocom.org/sim-card/simtrace2.git
synced 2026-03-26 02:08:32 +03:00
renamed ccid reader select file python script
The command can be called now using the following command: ./simtrace -S
This commit is contained in:
@@ -1,72 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
from smartcard.scard import *
|
|
||||||
import smartcard.util
|
|
||||||
|
|
||||||
SELECT = [0x00, 0xA4, 0x04, 0x00, 0x0A, 0xA0, 0x00, 0x00, 0x00, 0x62,
|
|
||||||
0x03, 0x01, 0x0C, 0x06, 0x01]
|
|
||||||
COMMAND = [0x00, 0x00, 0x00, 0x00]
|
|
||||||
|
|
||||||
try:
|
|
||||||
hresult, hcontext = SCardEstablishContext(SCARD_SCOPE_USER)
|
|
||||||
if hresult != SCARD_S_SUCCESS:
|
|
||||||
raise Exception('Failed to establish context : ' +
|
|
||||||
SCardGetErrorMessage(hresult))
|
|
||||||
print 'Context established!'
|
|
||||||
|
|
||||||
try:
|
|
||||||
hresult, readers = SCardListReaders(hcontext, [])
|
|
||||||
if hresult != SCARD_S_SUCCESS:
|
|
||||||
raise Exception('Failed to list readers: ' +
|
|
||||||
SCardGetErrorMessage(hresult))
|
|
||||||
print 'PCSC Readers:', readers
|
|
||||||
|
|
||||||
if len(readers) < 1:
|
|
||||||
raise Exception('No smart card readers')
|
|
||||||
|
|
||||||
reader = readers[0]
|
|
||||||
print "Using reader:", reader
|
|
||||||
|
|
||||||
try:
|
|
||||||
hresult, hcard, dwActiveProtocol = SCardConnect(hcontext, reader,
|
|
||||||
SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1)
|
|
||||||
if hresult != SCARD_S_SUCCESS:
|
|
||||||
raise Exception('Unable to connect: ' +
|
|
||||||
SCardGetErrorMessage(hresult))
|
|
||||||
print 'Connected with active protocol', dwActiveProtocol
|
|
||||||
|
|
||||||
try:
|
|
||||||
hresult, response = SCardTransmit(hcard, dwActiveProtocol,
|
|
||||||
SELECT)
|
|
||||||
if hresult != SCARD_S_SUCCESS:
|
|
||||||
raise Exception('Failed to transmit: ' +
|
|
||||||
SCardGetErrorMessage(hresult))
|
|
||||||
print 'Select: ' + smartcard.util.toHexString(response,
|
|
||||||
smartcard.util.HEX)
|
|
||||||
hresult, response = SCardTransmit(hcard, dwActiveProtocol,
|
|
||||||
COMMAND)
|
|
||||||
if hresult != SCARD_S_SUCCESS:
|
|
||||||
raise Exception('Failed to transmit: ' +
|
|
||||||
SCardGetErrorMessage(hresult))
|
|
||||||
print 'Command: ' + smartcard.util.toHexString(response,
|
|
||||||
smartcard.util.HEX)
|
|
||||||
finally:
|
|
||||||
hresult = SCardDisconnect(hcard, SCARD_UNPOWER_CARD)
|
|
||||||
if hresult != SCARD_S_SUCCESS:
|
|
||||||
raise Exception('Failed to disconnect: ' +
|
|
||||||
SCardGetErrorMessage(hresult))
|
|
||||||
print 'Disconnected'
|
|
||||||
|
|
||||||
|
|
||||||
except Exception, message:
|
|
||||||
print "Exception:", message
|
|
||||||
|
|
||||||
finally:
|
|
||||||
hresult = SCardReleaseContext(hcontext)
|
|
||||||
if hresult != SCARD_S_SUCCESS:
|
|
||||||
raise Exception('Failed to release context: ' +
|
|
||||||
SCardGetErrorMessage(hresult))
|
|
||||||
print 'Released context.'
|
|
||||||
|
|
||||||
except Exception, message:
|
|
||||||
print "Exception:", message
|
|
||||||
73
usb_application/ccid_select.py
Executable file
73
usb_application/ccid_select.py
Executable file
@@ -0,0 +1,73 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
from smartcard.scard import *
|
||||||
|
import smartcard.util
|
||||||
|
|
||||||
|
SELECT = [0x00, 0xA4, 0x04, 0x00, 0x0A, 0xA0, 0x00, 0x00, 0x00, 0x62,
|
||||||
|
0x03, 0x01, 0x0C, 0x06, 0x01]
|
||||||
|
COMMAND = [0x00, 0x00, 0x00, 0x00]
|
||||||
|
|
||||||
|
def select():
|
||||||
|
try:
|
||||||
|
hresult, hcontext = SCardEstablishContext(SCARD_SCOPE_USER)
|
||||||
|
if hresult != SCARD_S_SUCCESS:
|
||||||
|
raise Exception('Failed to establish context : ' +
|
||||||
|
SCardGetErrorMessage(hresult))
|
||||||
|
print 'Context established!'
|
||||||
|
|
||||||
|
try:
|
||||||
|
hresult, readers = SCardListReaders(hcontext, [])
|
||||||
|
if hresult != SCARD_S_SUCCESS:
|
||||||
|
raise Exception('Failed to list readers: ' +
|
||||||
|
SCardGetErrorMessage(hresult))
|
||||||
|
print 'PCSC Readers:', readers
|
||||||
|
|
||||||
|
if len(readers) < 1:
|
||||||
|
raise Exception('No smart card readers')
|
||||||
|
|
||||||
|
reader = readers[0]
|
||||||
|
print "Using reader:", reader
|
||||||
|
|
||||||
|
try:
|
||||||
|
hresult, hcard, dwActiveProtocol = SCardConnect(hcontext, reader,
|
||||||
|
SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1)
|
||||||
|
if hresult != SCARD_S_SUCCESS:
|
||||||
|
raise Exception('Unable to connect: ' +
|
||||||
|
SCardGetErrorMessage(hresult))
|
||||||
|
print 'Connected with active protocol', dwActiveProtocol
|
||||||
|
|
||||||
|
try:
|
||||||
|
hresult, response = SCardTransmit(hcard, dwActiveProtocol,
|
||||||
|
SELECT)
|
||||||
|
if hresult != SCARD_S_SUCCESS:
|
||||||
|
raise Exception('Failed to transmit: ' +
|
||||||
|
SCardGetErrorMessage(hresult))
|
||||||
|
print 'Select: ' + smartcard.util.toHexString(response,
|
||||||
|
smartcard.util.HEX)
|
||||||
|
hresult, response = SCardTransmit(hcard, dwActiveProtocol,
|
||||||
|
COMMAND)
|
||||||
|
if hresult != SCARD_S_SUCCESS:
|
||||||
|
raise Exception('Failed to transmit: ' +
|
||||||
|
SCardGetErrorMessage(hresult))
|
||||||
|
print 'Command: ' + smartcard.util.toHexString(response,
|
||||||
|
smartcard.util.HEX)
|
||||||
|
finally:
|
||||||
|
hresult = SCardDisconnect(hcard, SCARD_UNPOWER_CARD)
|
||||||
|
if hresult != SCARD_S_SUCCESS:
|
||||||
|
raise Exception('Failed to disconnect: ' +
|
||||||
|
SCardGetErrorMessage(hresult))
|
||||||
|
print 'Disconnected'
|
||||||
|
|
||||||
|
|
||||||
|
except Exception, message:
|
||||||
|
print "Exception:", message
|
||||||
|
|
||||||
|
finally:
|
||||||
|
hresult = SCardReleaseContext(hcontext)
|
||||||
|
if hresult != SCARD_S_SUCCESS:
|
||||||
|
raise Exception('Failed to release context: ' +
|
||||||
|
SCardGetErrorMessage(hresult))
|
||||||
|
print 'Released context.'
|
||||||
|
|
||||||
|
except Exception, message:
|
||||||
|
print "Exception:", message
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import sniffer
|
import sniffer
|
||||||
import ccid
|
import ccid
|
||||||
|
import ccid_select
|
||||||
|
|
||||||
import usb.core
|
import usb.core
|
||||||
import usb.util
|
import usb.util
|
||||||
@@ -48,6 +49,7 @@ def main():
|
|||||||
parser.add_argument("-c", "--cmd", help="cmds to send to sim card (Not supported yet)",
|
parser.add_argument("-c", "--cmd", help="cmds to send to sim card (Not supported yet)",
|
||||||
choices=["cmd1", "cmd2", "cmd_poweron", "cmd_poweroff", "cmd_get_slot_stat", "cmd_get_param"])
|
choices=["cmd1", "cmd2", "cmd_poweron", "cmd_poweroff", "cmd_get_slot_stat", "cmd_get_param"])
|
||||||
parser.add_argument("-s", "--sniff", help="Sniff communication!", action='store_true')
|
parser.add_argument("-s", "--sniff", help="Sniff communication!", action='store_true')
|
||||||
|
parser.add_argument("-S", "--select_file", help="Transmit SELECT cmd!", action='store_true')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
print("args: ", args)
|
print("args: ", args)
|
||||||
@@ -57,6 +59,7 @@ def main():
|
|||||||
devs = usb.core.find(find_all=1, custom_match=find_class(0xb)) # 0xb = Smartcard
|
devs = usb.core.find(find_all=1, custom_match=find_class(0xb)) # 0xb = Smartcard
|
||||||
for dev in devs:
|
for dev in devs:
|
||||||
dev.set_configuration(args.conf)
|
dev.set_configuration(args.conf)
|
||||||
|
# ret = dev.read(0x83, 64, 100)
|
||||||
|
|
||||||
if args.read_bin is True:
|
if args.read_bin is True:
|
||||||
ccid.pySim_read()
|
ccid.pySim_read()
|
||||||
@@ -66,9 +69,13 @@ def main():
|
|||||||
for dev in devs:
|
for dev in devs:
|
||||||
dev.write(0x1, args.cmd)
|
dev.write(0x1, args.cmd)
|
||||||
ret = dev.read(0x82, 64)
|
ret = dev.read(0x82, 64)
|
||||||
|
# ret = dev.read(0x83, 64, 100)
|
||||||
print(ret)
|
print(ret)
|
||||||
if args.sniff is True:
|
if args.sniff is True:
|
||||||
sniffer.sniff()
|
sniffer.sniff()
|
||||||
|
if args.select_file is True:
|
||||||
|
ccid_select.select()
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# (epi, epo) = find_eps(dev)
|
# (epi, epo) = find_eps(dev)
|
||||||
|
|||||||
Reference in New Issue
Block a user