mirror of
https://github.com/RfidResearchGroup/ChameleonMini.git
synced 2026-05-12 11:20:37 -07:00
Add decoder selection parameter
-d MFDESFire/None for different cards (cherry picked from commit 93635d9)
This commit is contained in:
@@ -20,6 +20,16 @@ class ReaderCMD(Enum):
|
||||
|
||||
readerCMD = ReaderCMD.NONE
|
||||
|
||||
# Map card types string to decoder
|
||||
def DummyCardDecoder(data, source):
|
||||
return ""
|
||||
|
||||
CardTypesMap = {
|
||||
"None": {"ApplicationDecoder": DummyCardDecoder},
|
||||
"MFDESFire": {"ApplicationDecoder": MFDESFireDecode},
|
||||
|
||||
}
|
||||
|
||||
|
||||
class BlockData:
|
||||
@staticmethod
|
||||
@@ -29,7 +39,8 @@ class BlockData:
|
||||
else:
|
||||
return False
|
||||
|
||||
def __init__(self, byteCount, data, source):
|
||||
|
||||
def __init__(self, byteCount, data, source, Cardtype):
|
||||
self.byteCount = byteCount
|
||||
self.data = data
|
||||
self.PCB = data[0]
|
||||
@@ -39,7 +50,7 @@ class BlockData:
|
||||
self.INF = None
|
||||
self.source = source
|
||||
self.CRCChecked = CRC_A_check(data)
|
||||
self.CardApplicationDecoder = MFDESFireDecode
|
||||
self.CardApplicationDecoder = CardTypesMap[Cardtype]["ApplicationDecoder"]
|
||||
|
||||
if self.CRCChecked:
|
||||
|
||||
@@ -218,7 +229,7 @@ def parseReader_3(data):
|
||||
|
||||
return note
|
||||
|
||||
def parseReader_4(data):
|
||||
def parseReader_4(data, Cardtype):
|
||||
global readerCMD
|
||||
byteCount = len(data)
|
||||
note = ""
|
||||
@@ -250,7 +261,7 @@ def parseReader_4(data):
|
||||
# Half-duplex block transmission
|
||||
# PCB bit mask: 0b11100110
|
||||
elif (BlockData.isBlockData(byteCount, data)):
|
||||
blockData = BlockData(byteCount,data, TrafficSource.Reader)
|
||||
blockData = BlockData(byteCount,data, TrafficSource.Reader, Cardtype)
|
||||
note = blockData.decode()
|
||||
|
||||
return note
|
||||
@@ -275,7 +286,7 @@ def parseCard_3(data):
|
||||
|
||||
return note
|
||||
|
||||
def parseCard_4(data):
|
||||
def parseCard_4(data, Cardtype):
|
||||
global readerCMD
|
||||
byteCount = len(data)
|
||||
note = ""
|
||||
@@ -318,15 +329,15 @@ def parseCard_4(data):
|
||||
note += " WRONG CRC "
|
||||
# Application Data
|
||||
elif (BlockData.isBlockData(byteCount, data)):
|
||||
blockData = BlockData(byteCount,data, TrafficSource.Card)
|
||||
blockData = BlockData(byteCount,data, TrafficSource.Card, Cardtype)
|
||||
note = blockData.decode()
|
||||
|
||||
readerCMD = ReaderCMD.NONE
|
||||
|
||||
return note
|
||||
|
||||
def parseReader(data):
|
||||
return parseReader_3(data) + parseReader_4(data)
|
||||
def parseReader(data, Cardtype):
|
||||
return parseReader_3(data) + parseReader_4(data, Cardtype)
|
||||
|
||||
def parseCard(data):
|
||||
return parseCard_3(data) + parseCard_4(data)
|
||||
def parseCard(data, Cardtype):
|
||||
return parseCard_3(data) + parseCard_4(data, Cardtype)
|
||||
|
||||
@@ -97,7 +97,7 @@ eventTypes = {
|
||||
TIMESTAMP_MAX = 65536
|
||||
eventTypes = { i : ({'name': 'UNKNOWN', 'decoder': binaryDecoder} if i not in eventTypes.keys() else eventTypes[i]) for i in range(256) }
|
||||
|
||||
def parseBinary(binaryStream, decode=False):
|
||||
def parseBinary(binaryStream, decoder=None):
|
||||
log = []
|
||||
|
||||
# Completely read file contents and process them byte by byte
|
||||
@@ -138,12 +138,12 @@ def parseBinary(binaryStream, decode=False):
|
||||
|
||||
note = ""
|
||||
# If we need to decode the data and paritybit check success
|
||||
if (decode and logData[-1] != '!'):
|
||||
if (decoder!=None and logData[-1] != '!'):
|
||||
# Decode the data from Reader
|
||||
if(event == 0x44 or event == 0x45):
|
||||
note = iso14443_3.parseReader(binascii.a2b_hex(logData))
|
||||
note = iso14443_3.parseReader(binascii.a2b_hex(logData), decoder)
|
||||
elif (event == 0x46 or event == 0x47):
|
||||
note = iso14443_3.parseCard(binascii.a2b_hex(logData))
|
||||
note = iso14443_3.parseCard(binascii.a2b_hex(logData), decoder)
|
||||
|
||||
# Create log entry as dict and append it to event list
|
||||
logEntry = {
|
||||
|
||||
+2
-1
@@ -11,6 +11,7 @@ import json
|
||||
import Chameleon
|
||||
import io
|
||||
import datetime
|
||||
from Chameleon.ISO14443 import CardTypesMap
|
||||
|
||||
def verboseLog(text):
|
||||
formatString = "[{}] {}"
|
||||
@@ -48,7 +49,7 @@ def main():
|
||||
|
||||
argParser.add_argument("-t", "--type", choices=outputTypes.keys(), default='text',
|
||||
help="specifies output type")
|
||||
argParser.add_argument("-d", "--decode", dest="decode", action='store_true', default=False)
|
||||
argParser.add_argument("-d", "--decode", dest="decode", choices=CardTypesMap.keys(), default=None, help="Decode the sniffed traffic and application data with a decoder")
|
||||
argParser.add_argument("-l", "--live", dest="live", action='store_true', help="Use live logging capabilities of Chameleon")
|
||||
argParser.add_argument("-c", "--clear", dest="clear", action='store_true', help="Clear Chameleon's log memory when using -p")
|
||||
argParser.add_argument("-m", "--mode", dest="mode", metavar="LOGMODE", help="Additionally set Chameleon's log mode after reading it's memory")
|
||||
|
||||
Reference in New Issue
Block a user