====== Smartcard-Kommunikation mitschneiden ====== CSV-Export des [[http://www.saleae.com/logic|Saleae Logic]] einer mitgeschnittenen Smartcard-Kommunikation rudimentär aufbereiten. #!/usr/bin/awk -f # Andreas Schiermeier - http://ccc-ffm.de/ function init() { waitRSThi=1; # erwarte HI auf RST waitIOlo=1; etu=0; # Anzahl Zeile pro Byte lastIO=0; # Zustand von IO in der vorausgehenden Zeile lastIOch=0; # Zeilennummer zum letzten Zustandswechsel von IO byte=0; bitPos=-1; } BEGIN { FS=", "; # Spaltendefinition der CSV-Datei TIME=1; RST=2; CLK=3; IO=4; init(); } # Warten auf RST Signal ( waitRSThi == 1 && $RST == 1 ) { waitRSThi=0; next; } # Verlust des RST Signals => neu initialisieren ( waitRSThi == 0 && $RST == 0 ) { print "\n--------------------------" init(); next; } ( $IO != lastIO ) { if ( waitIOlo == 1 && $IO == 0) { waitIOlo=0; } if ( etu == 0 && $IO == 1 && waitIOlo == 0 ) { etu=NR-lastIOch; } if ( etu != 0 ) { bitCount=int(sprintf("%d", (NR-lastIOch)/etu+0.49)) for (i=0; i 0 && bitPos < 9 ) { byte=byte+(2^(bitPos-1))*lastIO; # Annahme: lsb } if ( bitPos == 9 ) { # TODO gerade Parität anhand lastIO prüfen printf "0x%02X, ", byte; } if ( bitPos > 9 ) { bitPos=-1; byte=0; break; } } } lastIOch=NR lastIO=$IO } Beispiel: > du -h tan_sync.csv 132M tan_sync.csv > time ./analyze.awk < tan_sync.csv 0x3B, 0xFF, 0x18, 0x00, 0xFF, 0x81, 0x31, ...., 0xD4, -------------------------- -------------------------- ... -------------------------- real 0m11.567s user 0m11.489s sys 0m0.064s >