]> cvs.zerfleddert.de Git - proxmark3-svn/commitdiff
Merge branch 'master' of https://github.com/Proxmark/proxmark3
authoriceman1001 <iceman@iuse.se>
Thu, 29 Jan 2015 20:39:33 +0000 (21:39 +0100)
committericeman1001 <iceman@iuse.se>
Thu, 29 Jan 2015 20:39:33 +0000 (21:39 +0100)
Conflicts:
armsrc/Makefile
armsrc/appmain.c
armsrc/apps.h
armsrc/epa.c
armsrc/iclass.c
armsrc/iso14443a.c
armsrc/iso14443a.h
armsrc/iso15693.c
armsrc/lfops.c
armsrc/mifarecmd.c
armsrc/mifareutil.c
armsrc/mifareutil.h
armsrc/string.h
armsrc/util.h
bootrom/bootrom.c
client/Makefile
client/cmddata.c
client/cmddata.h
client/cmdhf.c
client/cmdhf14a.c
client/cmdhf14b.c
client/cmdhf15.c
client/cmdhficlass.c
client/cmdhfmf.c
client/cmdhfmfu.c
client/cmdlf.c
client/cmdlfem4x.c
client/cmdlfhid.c
client/cmdlfhitag.c
client/cmdlfio.c
client/cmdmain.c
client/data.h
client/flash.c
client/graph.c
client/graph.h
client/loclass/elite_crack.c
client/loclass/fileutils.c
client/lualibs/commands.lua
client/lualibs/html_dumplib.lua
client/lualibs/mf_default_keys.lua
client/lualibs/utils.lua
client/mifarehost.c
client/nonce2key/crapto1.c
client/proxmark3.c
client/scripting.c
client/scripts/tnp3dump.lua
client/scripts/tnp3sim.lua
client/scripts/tracetest.lua
common/Makefile.common
common/cmd.c
common/cmd.h
common/lfdemod.c
common/lfdemod.h
common/usb_cdc.c
common/usb_cdc.h
include/usb_cmd.h

21 files changed:
1  2 
armsrc/Makefile
armsrc/appmain.c
armsrc/apps.h
armsrc/epa.c
armsrc/hitag2.c
armsrc/iclass.c
armsrc/iso14443.c
armsrc/iso14443a.h
armsrc/legicrf.c
armsrc/mifarecmd.c
armsrc/mifareutil.c
client/loclass/cipher.c
client/lualibs/commands.lua
client/lualibs/html_dumplib.lua
client/lualibs/mf_default_keys.lua
client/lualibs/utils.lua
client/mifarehost.c
client/nonce2key/crapto1.c
client/proxmark3.c
client/scripting.c
common/Makefile.common

diff --cc armsrc/Makefile
index 69e4738ad544e1328c96968c32887767c7f1b943,bbcbcb1c4263819f861abb13acf465456d90bba7..523171656925a585c3440d9aa5403307f0573ac9
@@@ -41,9 -41,9 +41,10 @@@ ARMSRC = fpgaloader.c 
        $(SRC_CRAPTO1) \
        $(SRC_CRC) \
        legic_prng.c \
-       iclass.c
+       iclass.c \
+       BigBuf.c \
  
 +
  # stdint.h provided locally until GCC 4.5 becomes C99 compliant
  APP_CFLAGS += -I.
  
index c158ad2c2d005bfd507625dd4ec273655444110d,791ad4f861bcdb64e5003fdfe17087b66cb47502..00e9ba4dadc85d9b95e43c8ac9742981ff24d8ae
@@@ -811,11 -805,11 +808,11 @@@ void UsbPacketReceived(uint8_t *packet
                        MifareUC_Auth2(c->arg[0],c->d.asBytes);
                        break;
                case CMD_MIFAREU_READCARD:
-                       MifareUReadCard(c->arg[0],c->arg[1],c->d.asBytes);
+                       MifareUReadCard(c->arg[0], c->arg[1], c->d.asBytes);
 -                      break;
 +                        break;
                case CMD_MIFAREUC_READCARD:
-                       MifareUReadCard(c->arg[0],c->arg[1],c->d.asBytes);
-                         break;
+                       MifareUReadCard(c->arg[0], c->arg[1], c->d.asBytes);
+                       break;
                case CMD_MIFARE_READSC:
                        MifareReadSector(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes);
                        break;
diff --cc armsrc/apps.h
index 30010f1b3290b34a1799743fa22790529e98bc98,5ef876232ceb2230596e93e7428f8507866ca765..39ee321154db33209c104f66ac42fa121a22cacd
  
  #include <stdint.h>
  #include <stddef.h>
 -#include "common.h"
 -#include "hitag2.h"
 -#include "mifare.h"
 +#include <stdlib.h>
 +#include <sys/types.h>
 +#include <string.h>
 +#include <strings.h>
- #include "../include/common.h"
- #include "../include/hitag2.h"
- #include "../include/mifare.h"
- //#include <openssl/des.h>
- //#include <openssl/aes.h>
- //#include "des.h"
- //#include "aes.h"
- #include "../common/desfire.h"
  #include "../common/crc32.h"
- // The large multi-purpose buffer, typically used to hold A/D samples,
- // maybe processed in some way.
- #define BIGBUF_SIZE   40000      
- uint32_t BigBuf[BIGBUF_SIZE / sizeof(uint32_t)];
- #define TRACE_OFFSET  0
- #define TRACE_SIZE    3000
- #define RECV_CMD_OFFSET       (TRACE_OFFSET + TRACE_SIZE)
- #define MAX_FRAME_SIZE        256
- #define MAX_PARITY_SIZE       ((MAX_FRAME_SIZE + 1)/ 8)
- #define RECV_CMD_PAR_OFFSET   (RECV_CMD_OFFSET + MAX_FRAME_SIZE)
- #define RECV_RESP_OFFSET      (RECV_CMD_PAR_OFFSET + MAX_PARITY_SIZE)
- #define RECV_RESP_PAR_OFFSET (RECV_RESP_OFFSET + MAX_FRAME_SIZE)
- #define CARD_MEMORY_OFFSET    (RECV_RESP_PAR_OFFSET + MAX_PARITY_SIZE)
- #define CARD_MEMORY_SIZE      4096    
- #define DMA_BUFFER_OFFSET CARD_MEMORY_OFFSET
- #define DMA_BUFFER_SIZE CARD_MEMORY_SIZE
- #define FREE_BUFFER_OFFSET (CARD_MEMORY_OFFSET + CARD_MEMORY_SIZE)
- #define FREE_BUFFER_SIZE (BIGBUF_SIZE - FREE_BUFFER_OFFSET - 1)
+ #include "BigBuf.h"
  
  extern const uint8_t OddByteParity[256];
- extern uint8_t *trace; // = (uint8_t *) BigBuf;
- extern int traceLen;   // = 0;
  extern int rsamples;   // = 0;
  extern int tracing;    // = TRUE;
  extern uint8_t trigger;
@@@ -76,13 -45,9 +46,12 @@@ void ToSendReset(void)
  void ListenReaderField(int limit);
  void AcquireRawAdcSamples125k(int at134khz);
  void SnoopLFRawAdcSamples(int divisor, int trigger_threshold);
 -void DoAcquisition125k(int trigger_threshold);
 +void DoAcquisition125k_internal(int trigger_threshold, bool silent);
 +void DoAcquisition125k_threshold(int trigger_threshold);
 +void DoAcquisition125k();
 +
  extern int ToSendMax;
  extern uint8_t ToSend[];
- extern uint32_t BigBuf[];
  
  /// fpga.h
  void FpgaSendCommand(uint16_t cmd, uint16_t v);
diff --cc armsrc/epa.c
index 0bbd2dd786e18af9a43a927dcf66c5b6618a9446,bec79e61d075852c3d088c4667c21e8c97faf53d..a04b76280d8f387a9f35504735e6670c112e29e8
@@@ -432,9 -425,9 +432,11 @@@ int EPA_Setup(
  
        // power up the field
        iso14443a_setup(FPGA_HF_ISO14443A_READER_MOD);
 -
 +      
 +      iso14a_set_timeout(10500);
 +      
+       iso14a_set_timeout(10500);
+       
        // select the card
        return_code = iso14443a_select_card(uid, &card_select_info, NULL);
        if (return_code != 1) {
diff --cc armsrc/hitag2.c
Simple merge
diff --cc armsrc/iclass.c
index aca2c91833363f7357bda1506c657e59fe31446a,1a3751182f6e9553bb944ba405fe081861e4d3c8..c0edc1e08db6156c57060a94961efcf93f8d69d6
@@@ -642,21 -640,25 +642,25 @@@ void RAMFUNC SnoopIClass(void
      // The command (reader -> tag) that we're receiving.
        // The length of a received command will in most cases be no more than 18 bytes.
        // So 32 should be enough!
-       uint8_t *readerToTagCmd = (((uint8_t *)BigBuf) + RECV_CMD_OFFSET);
+       #define ICLASS_BUFFER_SIZE 32
+       uint8_t readerToTagCmd[ICLASS_BUFFER_SIZE];
      // The response (tag -> reader) that we're receiving.
-       uint8_t *tagToReaderResponse = (((uint8_t *)BigBuf) + RECV_RESP_OFFSET);
+       uint8_t tagToReaderResponse[ICLASS_BUFFER_SIZE];
+       
      FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
   
 -      // reset traceLen to 0
+       // free all BigBuf memory
+       BigBuf_free();
+     // The DMA buffer, used to stream samples from the FPGA
+     uint8_t *dmaBuf = BigBuf_malloc(DMA_BUFFER_SIZE);
+  
 +    // reset traceLen to 0
      iso14a_set_tracing(TRUE);
      iso14a_clear_trace();
      iso14a_set_trigger(FALSE);
  
-     // The DMA buffer, used to stream samples from the FPGA
-     int8_t *dmaBuf = ((int8_t *)BigBuf) + DMA_BUFFER_OFFSET;
 -      int lastRxCounter;
 +    int lastRxCounter;
-     int8_t *upTo;
+     uint8_t *upTo;
      int smpl;
      int maxBehindBy = 0;
  
        if(div > 3) {
                smpl = decbyte;
                if(ManchesterDecoding(smpl & 0x0F)) {
 -                      rsamples = samples - Demod.samples;
+                       time_stop = (GetCountSspClk()-time_0) << 4;
 +                  rsamples = samples - Demod.samples;
                    LED_B_ON();
  
-                       if(tracing) {
+                       if(tracing)     {
                                uint8_t parity[MAX_PARITY_SIZE];
                                GetParity(Demod.output, Demod.len, parity);
-                               LogTrace(Demod.output, Demod.len, (GetCountSspClk()-time_0) << 4, (GetCountSspClk()-time_0) << 4, parity, FALSE);
+                               LogTrace(Demod.output, Demod.len, time_start, time_stop, parity, FALSE);
                        }
  
                    // And ready to receive another response.
                    memset(&Demod, 0, sizeof(Demod));
                        Demod.output = tagToReaderResponse;
@@@ -865,44 -937,17 +939,17 @@@ static void CodeIClassTagAnswer(const u
        ToSendReset();
  
        // Send SOF
-       ToSend[++ToSendMax] = 0x00;
-       ToSend[++ToSendMax] = 0x00;
-       ToSend[++ToSendMax] = 0x00;
-       ToSend[++ToSendMax] = 0xff;//Proxtoair duration starts here
-       ToSend[++ToSendMax] = 0xff;
-       ToSend[++ToSendMax] = 0xff;
-       ToSend[++ToSendMax] = 0x00;
-       ToSend[++ToSendMax] = 0xff;
+       ToSend[++ToSendMax] = 0x1D;
  
        for(i = 0; i < len; i++) {
-               int j;
                uint8_t b = cmd[i];
-               // Data bits
-               for(j = 0; j < 8; j++) {
-                       if(b & 1) {
-                               ToSend[++ToSendMax] = 0x00;
-                               ToSend[++ToSendMax] = 0xff;
-                       } else {
-                               ToSend[++ToSendMax] = 0xff;
-                               ToSend[++ToSendMax] = 0x00;
+               ToSend[++ToSendMax] = encode4Bits(b & 0xF); //Least significant half
+               ToSend[++ToSendMax] = encode4Bits((b >>4) & 0xF);//Most significant half
 -      }
 +                      }
-                       b >>= 1;
-               }
-       }
  
        // Send EOF
-       ToSend[++ToSendMax] = 0xff;
-       ToSend[++ToSendMax] = 0x00;
-       ToSend[++ToSendMax] = 0xff;
-       ToSend[++ToSendMax] = 0xff;
-       ToSend[++ToSendMax] = 0xff;     
-       ToSend[++ToSendMax] = 0x00;
-       ToSend[++ToSendMax] = 0x00;
-       ToSend[++ToSendMax] = 0x00;
+       ToSend[++ToSendMax] = 0xB8;
        //lastProxToAirDuration  = 8*ToSendMax - 3*8 - 3*8;//Not counting zeroes in the beginning or end
        // Convert from last byte pos to length
        ToSendMax++;
  }
@@@ -1267,18 -1309,18 +1311,18 @@@ static void TransmitIClassCommand(cons
     if (wait)
     {
       if(*wait < 10) *wait = 10;
+      
 -     for(c = 0; c < *wait;) {
 -       if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
 -         AT91C_BASE_SSC->SSC_THR = 0x00;              // For exact timing!
 -         c++;
 -       }
 -       if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
 -         volatile uint32_t r = AT91C_BASE_SSC->SSC_RHR;
 -         (void)r;
 -       }
 -       WDT_HIT();
 -     }
 +  for(c = 0; c < *wait;) {
 +    if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
 +      AT91C_BASE_SSC->SSC_THR = 0x00;         // For exact timing!
 +      c++;
 +    }
 +    if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
 +      volatile uint32_t r = AT91C_BASE_SSC->SSC_RHR;
 +      (void)r;
 +    }
 +    WDT_HIT();
 +  }
  
     }
  
@@@ -1361,19 -1403,19 +1405,19 @@@ void CodeIClassCommand(const uint8_t * 
  
  void ReaderTransmitIClass(uint8_t* frame, int len)
  {
 -      int wait = 0;
 -      int samples = 0;
 +  int wait = 0;
 +  int samples = 0;
  
 -      // This is tied to other size changes
 -      CodeIClassCommand(frame,len);
 +  // This is tied to other size changes
 +  CodeIClassCommand(frame,len);
  
 -      // Select the card
 -      TransmitIClassCommand(ToSend, ToSendMax, &samples, &wait);
 -      if(trigger)
 -              LED_A_ON();
 +  // Select the card
 +  TransmitIClassCommand(ToSend, ToSendMax, &samples, &wait);
 +  if(trigger)
 +      LED_A_ON();
  
 -      // Store reader command in buffer
 +  // Store reader command in buffer
-   if (tracing) {
+       if (tracing) {
                uint8_t par[MAX_PARITY_SIZE];
                GetParity(frame, len, par);
                LogTrace(frame, len, rsamples, rsamples, par, TRUE);
Simple merge
Simple merge
Simple merge
index 7a33afbba343a545d19bcebf98cea8dac44d6bf8,4279e63f2295e0f7e9e03e3cb22453bf1646f0c7..50a5634dc2d694db6f0a64ae1093bb750f020b10
@@@ -1190,4 -1183,4 +1183,4 @@@ void Mifare_DES_Auth2(uint32_t arg0, ui
        cmd_send(CMD_ACK, isOK, 0, 0, dataout, sizeof(dataout));\r
        FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
        LEDsoff();\r
--}
++}\r
index 1859819194c66bd2e1ddd41230d6a2e85e0b4b01,f79c2ede2d78676ddc6aef7b373129e3198a23ca..c3ba1b816a0b1388da9915a256ff1c790e7bdbb6
@@@ -76,26 -65,26 +65,26 @@@ uint8_t mf_crypto1_encrypt4bit(struct C
  }\r
  \r
  // send commands\r
- int mifare_sendcmd_short(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t data, uint8_t *answer, uint8_t *answer_parity, uint32_t *timing)\r
+ int mifare_sendcmd_short(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t data, uint8_tanswer, uint8_t *answer_parity, uint32_t *timing)\r
  {\r
--      return mifare_sendcmd_shortex(pcs, crypted, cmd, data, answer, answer_parity, timing);
--}
--
--int mifare_sendcmd_short_special(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t* data, uint8_t* answer, uint8_t *answer_parity, uint32_t *timing)
--{
--      uint8_t dcmd[8];
-       dcmd[0] = cmd;\r
 -    dcmd[0] = cmd;
 -    dcmd[1] = data[0];
 -      dcmd[2] = data[1];
 -      dcmd[3] = data[2];
 -      dcmd[4] = data[3];
 -      dcmd[5] = data[4];
 -      AppendCrc14443a(dcmd, 6);
 -      ReaderTransmit(dcmd, sizeof(dcmd), NULL);
 -      int len = ReaderReceive(answer, answer_parity);
 -      if(!len) {
 -                if (MF_DBGLEVEL >= 1)   Dbprintf("Authentication failed. Card timeout.");
 -                return 2;
++      return mifare_sendcmd_shortex(pcs, crypted, cmd, data, answer, answer_parity, timing);\r
++}\r
++\r
++int mifare_sendcmd_short_special(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t* data, uint8_t* answer, uint8_t *answer_parity, uint32_t *timing)\r
++{\r
++      uint8_t dcmd[8];\r
++    dcmd[0] = cmd;\r
 +    dcmd[1] = data[0];\r
-       dcmd[2] = data[1];
++      dcmd[2] = data[1];\r
 +      dcmd[3] = data[2];\r
 +      dcmd[4] = data[3];\r
 +      dcmd[5] = data[4];\r
-       AppendCrc14443a(dcmd, 6);
-       ReaderTransmit(dcmd, sizeof(dcmd), NULL);
-       int len = ReaderReceive(answer, answer_parity);
-       if(!len) {
-         if (MF_DBGLEVEL >= 1)   Dbprintf("Authentication failed. Card timeout.");
-         return 2;
++      AppendCrc14443a(dcmd, 6);\r
++      ReaderTransmit(dcmd, sizeof(dcmd), NULL);\r
++      int len = ReaderReceive(answer, answer_parity);\r
++      if(!len) {\r
++                if (MF_DBGLEVEL >= 1)   Dbprintf("Authentication failed. Card timeout.");\r
++                return 2;\r
      }\r
        return len;\r
  }\r
@@@ -117,13 -106,13 +106,13 @@@ int mifare_sendcmd_short_mfucauth(struc
      if(len==1)        {\r
                if (MF_DBGLEVEL >= MF_DBG_ERROR)   Dbprintf("NAK - Authentication failed.");\r
                return 1;\r
--        }
--      return len;
--}
--
--int mifare_sendcmd_shortex(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t data, uint8_t *answer, uint8_t *answer_parity, uint32_t *timing)
--{
--      uint8_t dcmd[4], ecmd[4];
++        }\r
++      return len;\r
++}\r
++\r
++int mifare_sendcmd_shortex(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t data, uint8_t *answer, uint8_t *answer_parity, uint32_t *timing)\r
++{\r
++      uint8_t dcmd[4], ecmd[4];\r
        uint16_t pos, res;\r
        uint8_t par[1];                 // 1 Byte parity is enough here\r
        dcmd[0] = cmd;\r
@@@ -295,9 -284,9 +284,9 @@@ int mifare_classic_readblock(struct Cry
        }\r
        \r
        memcpy(blockData, receivedAnswer, 16);\r
--      return 0;
 -}
 -
++      return 0;\r
 +}\r
 +\r
  // mifare ultralight commands\r
  int mifare_ultra_auth1(uint32_t uid, uint8_t *blockData){\r
  \r
@@@ -347,45 -336,45 +336,45 @@@ int mifare_ultra_auth2(uint32_t uid, ui
        }\r
        memcpy(blockData, receivedAnswer, 11);\r
        return 0;\r
- }
- int mifare_ultra_readblock(uint32_t uid, uint8_t blockNo, uint8_t *blockData)
- {
-       uint16_t len;
-       uint8_t bt[2];
-       uint8_t *receivedAnswer = get_bigbufptr_recvrespbuf();
-       uint8_t *receivedAnswerPar = receivedAnswer + MAX_FRAME_SIZE;\r
-       \r
-       
-       // command MIFARE_CLASSIC_READBLOCK
-       len = mifare_sendcmd_short(NULL, 1, 0x30, blockNo, receivedAnswer, receivedAnswerPar, NULL);
-       if (len == 1) {
+ }\r
\r
 -int mifare_ultra_readblock(uint32_t uid, uint8_t blockNo, uint8_t *blockData)
 -{
 -      uint16_t len;
 -      uint8_t bt[2];
++int mifare_ultra_readblock(uint32_t uid, uint8_t blockNo, uint8_t *blockData)\r
++{\r
++      uint16_t len;\r
++      uint8_t bt[2];\r
+       uint8_t receivedAnswer[MAX_MIFARE_FRAME_SIZE];\r
+       uint8_t receivedAnswerPar[MAX_MIFARE_PARITY_SIZE];\r
 -      
+       \r
 -      // command MIFARE_CLASSIC_READBLOCK
 -      len = mifare_sendcmd_short(NULL, 1, 0x30, blockNo, receivedAnswer, receivedAnswerPar, NULL);
 -      if (len == 1) {
++      \r
++      // command MIFARE_CLASSIC_READBLOCK\r
++      len = mifare_sendcmd_short(NULL, 1, 0x30, blockNo, receivedAnswer, receivedAnswerPar, NULL);\r
++      if (len == 1) {\r
                if (MF_DBGLEVEL >= MF_DBG_ERROR)\r
--                      Dbprintf("Cmd Error: %02x", receivedAnswer[0]);
--              return 1;
--      }
--      if (len != 18) {
++                      Dbprintf("Cmd Error: %02x", receivedAnswer[0]);\r
++              return 1;\r
++      }\r
++      if (len != 18) {\r
                if (MF_DBGLEVEL >= MF_DBG_ERROR)\r
--                      Dbprintf("Cmd Error: card timeout. len: %x", len);
--              return 2;
--      }
--    
--      memcpy(bt, receivedAnswer + 16, 2);
--      AppendCrc14443a(receivedAnswer, 16);
--      if (bt[0] != receivedAnswer[16] || bt[1] != receivedAnswer[17]) {
++                      Dbprintf("Cmd Error: card timeout. len: %x", len);\r
++              return 2;\r
++      }\r
++    \r
++      memcpy(bt, receivedAnswer + 16, 2);\r
++      AppendCrc14443a(receivedAnswer, 16);\r
++      if (bt[0] != receivedAnswer[16] || bt[1] != receivedAnswer[17]) {\r
                if (MF_DBGLEVEL >= MF_DBG_ERROR)\r
--                      Dbprintf("Cmd CRC response error.");
--              return 3;
--      }
--      
--      memcpy(blockData, receivedAnswer, 14);
--      return 0;
--}
--
--
--int mifare_classic_writeblock(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo, uint8_t *blockData) 
--{
--      // variables
++                      Dbprintf("Cmd CRC response error.");\r
++              return 3;\r
++      }\r
++      \r
++      memcpy(blockData, receivedAnswer, 14);\r
++      return 0;\r
++}\r
++\r
++\r
++int mifare_classic_writeblock(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo, uint8_t *blockData) \r
++{\r
++      // variables\r
        uint16_t len, i;        \r
        uint32_t pos;\r
        uint8_t par[3] = {0};           // enough for 18 Bytes to send\r
                return 2;\r
        }\r
        \r
--      return 0;
--}
--
--int mifare_ultra_writeblock(uint32_t uid, uint8_t blockNo, uint8_t *blockData) 
--{
-       uint16_t len;     
-       uint8_t par[3] = {0}; // enough for 18 parity bits
 -    uint16_t len;     
 -    uint8_t par[3] = {0};  // enough for 18 parity bits
--      uint8_t d_block[18] = {0x00};
-       uint8_t *receivedAnswer = get_bigbufptr_recvrespbuf();\r
-       uint8_t *receivedAnswerPar = receivedAnswer + MAX_FRAME_SIZE;
-       
-       // command MIFARE_CLASSIC_WRITEBLOCK
-       len = mifare_sendcmd_short(NULL, true, 0xA0, blockNo, receivedAnswer, receivedAnswerPar, NULL);
-       if ((len != 1) || (receivedAnswer[0] != 0x0A)) {   //  0x0a - ACK
++      return 0;\r
++}\r
++\r
++int mifare_ultra_writeblock(uint32_t uid, uint8_t blockNo, uint8_t *blockData) \r
++{\r
++    uint16_t len;     \r
++    uint8_t par[3] = {0};  // enough for 18 parity bits\r
++      uint8_t d_block[18] = {0x00};\r
+       uint8_t receivedAnswer[MAX_MIFARE_FRAME_SIZE];\r
+       uint8_t receivedAnswerPar[MAX_MIFARE_PARITY_SIZE];\r
 -        
 -    // command MIFARE_CLASSIC_WRITEBLOCK
 -    len = mifare_sendcmd_short(NULL, true, 0xA0, blockNo, receivedAnswer, receivedAnswerPar, NULL);
 -
 -    if ((len != 1) || (receivedAnswer[0] != 0x0A)) {   //  0x0a - ACK
++        \r
++    // command MIFARE_CLASSIC_WRITEBLOCK\r
++    len = mifare_sendcmd_short(NULL, true, 0xA0, blockNo, receivedAnswer, receivedAnswerPar, NULL);\r
++\r
++    if ((len != 1) || (receivedAnswer[0] != 0x0A)) {   //  0x0a - ACK\r
                if (MF_DBGLEVEL >= MF_DBG_ERROR)\r
--                      Dbprintf("Cmd Addr Error: %02x", receivedAnswer[0]);  
-               return 1;
-       }
 -        return 1;
 -    }
--
--      memcpy(d_block, blockData, 16);
--    AppendCrc14443a(d_block, 16);
--
--      ReaderTransmitPar(d_block, sizeof(d_block), par, NULL);
\r
 -
--    len = ReaderReceive(receivedAnswer, receivedAnswerPar);    
--
--      if ((len != 1) || (receivedAnswer[0] != 0x0A)) {   //  0x0a - ACK
++                      Dbprintf("Cmd Addr Error: %02x", receivedAnswer[0]);  \r
++        return 1;\r
++    }\r
++\r
++      memcpy(d_block, blockData, 16);\r
++    AppendCrc14443a(d_block, 16);\r
++\r
++      ReaderTransmitPar(d_block, sizeof(d_block), par, NULL);\r
++\r
++    len = ReaderReceive(receivedAnswer, receivedAnswerPar);    \r
++\r
++      if ((len != 1) || (receivedAnswer[0] != 0x0A)) {   //  0x0a - ACK\r
                if (MF_DBGLEVEL >= MF_DBG_ERROR)\r
--                      Dbprintf("Cmd Data Error: %02x %d", receivedAnswer[0],len);
-               return 2;
-       }        
 -        return 2;
 -    }        
--    return 0;
--} 
--
--int mifare_ultra_special_writeblock(uint32_t uid, uint8_t blockNo, uint8_t *blockData)
--{
--    uint16_t len;
--      uint8_t d_block[8] = {0x00};
-       uint8_t *receivedAnswer = get_bigbufptr_recvrespbuf();\r
-       uint8_t *receivedAnswerPar = receivedAnswer + MAX_FRAME_SIZE;
-     // command MIFARE_CLASSIC_WRITEBLOCK
-       d_block[0]= blockNo;
-       memcpy(d_block+1,blockData,4);
-       AppendCrc14443a(d_block, 6);
-     len = mifare_sendcmd_short_special(NULL, 1, 0xA2, d_block, receivedAnswer, receivedAnswerPar, NULL);
-       if (receivedAnswer[0] != 0x0A) {   //  0x0a - ACK
++                      Dbprintf("Cmd Data Error: %02x %d", receivedAnswer[0],len);\r
++        return 2;\r
++    }        \r
++    return 0;\r
++} \r
++\r
++int mifare_ultra_special_writeblock(uint32_t uid, uint8_t blockNo, uint8_t *blockData)\r
++{\r
++    uint16_t len;\r
++      uint8_t d_block[8] = {0x00};\r
+       uint8_t receivedAnswer[MAX_MIFARE_FRAME_SIZE];\r
+       uint8_t receivedAnswerPar[MAX_MIFARE_PARITY_SIZE];\r
 -
 -    // command MIFARE_CLASSIC_WRITEBLOCK
 -      d_block[0]= blockNo;
 -      memcpy(d_block+1,blockData,4);
 -      AppendCrc14443a(d_block, 6);
 -
 -    len = mifare_sendcmd_short_special(NULL, 1, 0xA2, d_block, receivedAnswer, receivedAnswerPar, NULL);
 -
 -    if (receivedAnswer[0] != 0x0A) {   //  0x0a - ACK
++\r
++    // command MIFARE_CLASSIC_WRITEBLOCK\r
++      d_block[0]= blockNo;\r
++      memcpy(d_block+1,blockData,4);\r
++      AppendCrc14443a(d_block, 6);\r
++\r
++    len = mifare_sendcmd_short_special(NULL, 1, 0xA2, d_block, receivedAnswer, receivedAnswerPar, NULL);\r
++\r
++    if (receivedAnswer[0] != 0x0A) {   //  0x0a - ACK\r
                if (MF_DBGLEVEL >= MF_DBG_ERROR)\r
--                      Dbprintf("Cmd Send Error: %02x %d", receivedAnswer[0],len);
-               return 1;
-       }
-       return 0;
 -        return 1;
 -    }
 -\r    return 0;
--}
--
--int mifare_classic_halt(struct Crypto1State *pcs, uint32_t uid) 
--{
++                      Dbprintf("Cmd Send Error: %02x %d", receivedAnswer[0],len);\r
++        return 1;\r
++    }\r
++    return 0;\r
++}\r
++\r
++int mifare_classic_halt(struct Crypto1State *pcs, uint32_t uid) \r
++{\r
        uint16_t len;   \r
-       uint8_t* receivedAnswer = get_bigbufptr_recvrespbuf();\r
-       uint8_t *receivedAnswerPar = receivedAnswer + MAX_FRAME_SIZE;\r
+       uint8_t receivedAnswer[MAX_MIFARE_FRAME_SIZE];\r
+       uint8_t receivedAnswerPar[MAX_MIFARE_PARITY_SIZE];\r
  \r
        len = mifare_sendcmd_short(pcs, pcs == NULL ? false:true, 0x50, 0x00, receivedAnswer, receivedAnswerPar, NULL);\r
        if (len != 0) {\r
                return 1;\r
        }\r
  \r
--      return 0;
--}
--
--int mifare_ultra_halt(uint32_t uid)
--{
-       uint16_t len;   \r
-       uint8_t *receivedAnswer = get_bigbufptr_recvrespbuf();\r
-       uint8_t *receivedAnswerPar = receivedAnswer + MAX_FRAME_SIZE;\r
-     
-       len = mifare_sendcmd_short(NULL, true, 0x50, 0x00, receivedAnswer, receivedAnswerPar, NULL);
-       if (len != 0) {
 -      uint16_t len;
++      return 0;\r
++}\r
++\r
++int mifare_ultra_halt(uint32_t uid)\r
++{\r
++      uint16_t len;\r
+       uint8_t receivedAnswer[MAX_MIFARE_FRAME_SIZE];\r
+       uint8_t receivedAnswerPar[MAX_MIFARE_PARITY_SIZE];\r
 -    
 -      len = mifare_sendcmd_short(NULL, true, 0x50, 0x00, receivedAnswer, receivedAnswerPar, NULL);
 -      if (len != 0) {
++    \r
++      len = mifare_sendcmd_short(NULL, true, 0x50, 0x00, receivedAnswer, receivedAnswerPar, NULL);\r
++      if (len != 0) {\r
                if (MF_DBGLEVEL >= MF_DBG_ERROR)\r
--                      Dbprintf("halt error. response len: %x", len);
--              return 1;
 -      }
 -      return 0;
 -}
 -
++                      Dbprintf("halt error. response len: %x", len);\r
++              return 1;\r
 +      }\r
-       return 0;
- }
++      return 0;\r
++}\r
++\r
  \r
  // Mifare Memory Structure: up to 32 Sectors with 4 blocks each (1k and 2k cards),\r
  // plus evtl. 8 sectors with 16 blocks each (4k cards)\r
@@@ -536,9 -525,9 +525,9 @@@ uint8_t FirstBlockOfSector(uint8_t sect
  }\r
  \r
  \r
--// work with emulator memory
--void emlSetMem(uint8_t *data, int blockNum, int blocksCount) {
-       uint8_t* emCARD = get_bigbufptr_emlcardmem();\r
 -      uint8_t* emCARD = BigBuf_get_EM_addr();
++// work with emulator memory\r
++void emlSetMem(uint8_t *data, int blockNum, int blocksCount) {\r
++      uint8_t* emCARD = BigBuf_get_EM_addr();\r
        memcpy(emCARD + blockNum * 16, data, blocksCount * 16);\r
  }\r
  \r
@@@ -717,4 -706,4 +706,4 @@@ int mifare_desfire_des_auth2(uint32_t u
                return 0;\r
        }\r
        return 1;\r
--}
++}\r
Simple merge
index d2acb3be4dfc9d488ccd8908cc6de19a9ebe426c,a5442f2a8b221ee565f07b3da9c857477755c63e..6f309001da3b31dd96af6627f4c57dc103db788c
@@@ -212,7 -212,7 +212,6 @@@ function Command:getBytes(
        local data  = self.data
        local cmd = self.cmd 
        local arg1, arg2, arg3 = self.arg1, self.arg2, self.arg3
 -      
        return bin.pack("LLLLH",cmd, arg1, arg2, arg3,data);
  end
  return _commands
index a7890885153350a995313f9f481a2d6ef13aabd7,3a28d5ae6f988cf5b30c0ffb40094342bca797e6..bd8e6d0cc20ea2942ba2b370c9907e01ea02b570
@@@ -192,7 -192,7 +192,9 @@@ en
  return {
        convert_bin_to_html = convert_bin_to_html,
        convert_eml_to_html = convert_eml_to_html,
 -    convert_eml_to_bin = convert_eml_to_bin,  
 +    convert_eml_to_bin = convert_eml_to_bin,
 +    SaveAsBinary = save_BIN,
 +      SaveAsText = save_TEXT,
+     SaveAsBinary = save_BIN,
+       SaveAsText = save_TEXT,
  }
index 810f0d6eab466b7fd8a6b40f06d4e9468bbb4249,757112c671f0169fc26ea53f76326bd0db073f77..cca4699e9741e36040221e43f58774c1a5166828
@@@ -158,9 -158,9 +158,23 @@@ local _keys = 
        'eff603e1efe9',
        '644672bd4afe',
  
+       'b5ff67cba951',
+   }
++      --[[
++    Kiev metro cards
++    --]]      
++      '8fe644038790',
++      'f14ee7cae863',
++      '632193be1c3c',
++      '569369c5a0e5',
++      '9de89e070277',
++      'eff603e1efe9',
++      '644672bd4afe',
++
 +      'b5ff67cba951',
 +}
 +
  ---
  --    The keys above have just been pasted in, for completeness sake. They contain duplicates. 
  --    We need to weed the duplicates out before we expose the list to someone who actually wants to use them
Simple merge
index 3516fca499fd3daa921345b7b4e0eb0d39f0dd85,7f784850841095713a0a54284259bf9e1b552d05..60dba6c07800849bafb38ec3fe8152ec160698dd
@@@ -72,7 -72,7 +72,6 @@@ int mfnested(uint8_t blockNo, uint8_t k
        uint16_t i, len;\r
        uint32_t uid;\r
        UsbCommand resp;\r
-       \r
 -\r
        StateList_t statelists[2];\r
        struct Crypto1State *p1, *p2, *p3, *p4;\r
        \r
@@@ -250,11 -263,13 +262,13 @@@ int mfCSetBlock(uint8_t blockNo, uint8_
        memcpy(c.d.asBytes, data, 16); \r
        SendCommand(&c);\r
  \r
 -  UsbCommand resp;\r
 +      UsbCommand resp;\r
        if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {\r
                isOK  = resp.arg[0] & 0xff;\r
-               if (uid != NULL) memcpy(uid, resp.d.asBytes, 4);\r
-               if (!isOK) return 2;\r
+               if (uid != NULL) \r
+                       memcpy(uid, resp.d.asBytes, 4);\r
+               if (!isOK) \r
+                       return 2;\r
        } else {\r
                PrintAndLog("Command execute timeout");\r
                return 1;\r
@@@ -333,16 -351,21 +350,21 @@@ int loadTraceCard(uint8_t *tuid) 
        FillFileNameByUID(traceFileName, tuid, ".eml", 7);\r
  \r
        f = fopen(traceFileName, "r");\r
-       if (!f) return 1;\r
+       if (!f) {\r
+               fclose(f);\r
+               return 1;\r
+       }\r
        \r
        blockNum = 0;\r
+               \r
        while(!feof(f)){\r
+       \r
                memset(buf, 0, sizeof(buf));\r
                if (fgets(buf, sizeof(buf), f) == NULL) {\r
 -                      PrintAndLog("File reading error.");\r
 +      PrintAndLog("File reading error.");\r
                        fclose(f);\r
                        return 2;\r
 -      }\r
 +    }\r
  \r
                if (strlen(buf) < 32){\r
                        if (feof(f)) break;\r
index c2dd7a547bfff60365f3b6a36ac87e280aeb4409,6c0fcafa09ef6bb9c038a6f593de93a0495d9400..ca926a7382a8d3e77b1d5078e65154452dce7bfa
@@@ -545,10 -545,10 +545,10 @@@ lfsr_common_prefix(uint32_t pfx, uint32
        statelist = malloc((sizeof *statelist) << 21);  //how large should be? \r
        if(!statelist || !odd || !even)\r
        {\r
-          free(statelist);\r
-          free(odd);\r
-          free(even);\r
+                               free(statelist);\r
+                               free(odd);\r
+                               free(even);\r
 -                return 0;\r
 +         return 0;\r
        }\r
  \r
        s = statelist;\r
index 7d50c35aecc4c79a0e353a7b72a98a47d2fa78d6,0e2a698c1b8ca3783f2a1bc16d980539c423ce22..c100bbea0985d05222f580adbf90d05d887540bd
@@@ -34,9 -34,9 +34,9 @@@ static UsbCommand txcmd
  volatile static bool txcmd_pending = false;
  
  void SendCommand(UsbCommand *c) {
- #if 0
      #if 0
 -              printf("Sending %d bytes\n", sizeof(UsbCommand));
 +  printf("Sending %d bytes\n", sizeof(UsbCommand));
- #endif
      #endif
  
        if (offline) {
        PrintAndLog("Sending bytes to proxmark failed - offline");
@@@ -65,86 -65,86 +65,86 @@@ byte_t rx[0x1000000]
  byte_t* prx = rx;
  
  static void *uart_receiver(void *targ) {
 -      struct receiver_arg *arg = (struct receiver_arg*)targ;
 -      size_t rxlen;
 -      size_t cmd_count;
 +  struct receiver_arg *arg = (struct receiver_arg*)targ;
 +  size_t rxlen;
 +  size_t cmd_count;
-   
 -      while (arg->run) {
 -              rxlen = sizeof(UsbCommand);
 +  while (arg->run) {
 +    rxlen = sizeof(UsbCommand);
-     if (uart_receive(sp,prx,&rxlen)) {
+               if (uart_receive(sp, prx, &rxlen)) {
 -                      prx += rxlen;
 -                      if (((prx-rx) % sizeof(UsbCommand)) != 0) {
 -                              continue;
 -                      }
 -                      cmd_count = (prx-rx) / sizeof(UsbCommand);
 +      prx += rxlen;
 +      if (((prx-rx) % sizeof(UsbCommand)) != 0) {
 +        continue;
 +      }
 +      cmd_count = (prx-rx) / sizeof(UsbCommand);
  
-       for (size_t i=0; i<cmd_count; i++) {
+                       for (size_t i = 0; i < cmd_count; i++) {
 -                              UsbCommandReceived((UsbCommand*)(rx+(i*sizeof(UsbCommand))));
 -                      }
 -              }
 -              prx = rx;
 +        UsbCommandReceived((UsbCommand*)(rx+(i*sizeof(UsbCommand))));
 +      }
 +    }
 +    prx = rx;
-     
 -              if(txcmd_pending) {
 +    if(txcmd_pending) {
-       if (!uart_send(sp,(byte_t*)&txcmd,sizeof(UsbCommand))) {
+                       if (!uart_send(sp, (byte_t*) &txcmd, sizeof(UsbCommand))) {
 -                              PrintAndLog("Sending bytes to proxmark failed");
 -                      }
 -                      txcmd_pending = false;
 -              }
 -      }
 +        PrintAndLog("Sending bytes to proxmark failed");
 +      }
 +      txcmd_pending = false;
 +    }
 +  }
-   
 -      pthread_exit(NULL);
 -      return NULL;
 +  pthread_exit(NULL);
 +  return NULL;
  }
  
  static void *main_loop(void *targ) {
 -      struct main_loop_arg *arg = (struct main_loop_arg*)targ;
 -      struct receiver_arg rarg;
 -      char *cmd = NULL;
 -      pthread_t reader_thread;
 +  struct main_loop_arg *arg = (struct main_loop_arg*)targ;
 +  struct receiver_arg rarg;
 +  char *cmd = NULL;
 +  pthread_t reader_thread;
    
 -      if (arg->usb_present == 1) {
 +  if (arg->usb_present == 1) {
-     rarg.run=1;
+               rarg.run = 1;
 -              pthread_create(&reader_thread, NULL, &uart_receiver, &rarg);
 -      }
 +    pthread_create(&reader_thread, NULL, &uart_receiver, &rarg);
 +  }
-   
 -      FILE *script_file = NULL;
 +  FILE *script_file = NULL;
-   char script_cmd_buf[256];  // iceman, needs lua script the same file_path_buffer as the rest
-   
+       char script_cmd_buf[256];  // iceman, needs lua script the same file_path_buffer as the rest
        if (arg->script_cmds_file) {
 -              script_file = fopen(arg->script_cmds_file, "r");
 +    script_file = fopen(arg->script_cmds_file, "r");
                if (script_file) {
 -                      printf("using 'scripting' commands file %s\n", arg->script_cmds_file);
 -              }
 -      }
 +      printf("using 'scripting' commands file %s\n", arg->script_cmds_file);
 +    }
 +  }
  
        read_history(".history");
  
        while(1)  {
  
 -              // If there is a script file
 -              if (script_file)
 -              {
 +    // If there is a script file
 +    if (script_file)
 +    {
                        if (!fgets(script_cmd_buf, sizeof(script_cmd_buf), script_file)) {
 -                              fclose(script_file);
 -                              script_file = NULL;
 +        fclose(script_file);
 +        script_file = NULL;
                        } else {
 -                              char *nl;
 -                              nl = strrchr(script_cmd_buf, '\r');
 -                              if (nl) *nl = '\0';
 +        char *nl;
 +        nl = strrchr(script_cmd_buf, '\r');
 +        if (nl) *nl = '\0';
                                
 -                              nl = strrchr(script_cmd_buf, '\n');
 -                              if (nl) *nl = '\0';
 +        nl = strrchr(script_cmd_buf, '\n');
 +        if (nl) *nl = '\0';
-         
                                if ((cmd = (char*) malloc(strlen(script_cmd_buf) + 1)) != NULL) {
 -                                      memset(cmd, 0, strlen(script_cmd_buf));
 -                                      strcpy(cmd, script_cmd_buf);
 -                                      printf("%s\n", cmd);
 -                              }
 -                      }
 -              }
 +          memset(cmd, 0, strlen(script_cmd_buf));
 +          strcpy(cmd, script_cmd_buf);
 +          printf("%s\n", cmd);
 +        }
 +      }
 +    }
                
                if (!script_file) {
 -                      cmd = readline(PROXPROMPT);
 +      cmd = readline(PROXPROMPT);
                }
                
                if (cmd) {
    
        write_history(".history");
    
 -      if (arg->usb_present == 1) {
 -              rarg.run = 0;
 -              pthread_join(reader_thread, NULL);
 -      }
 +  if (arg->usb_present == 1) {
 +    rarg.run = 0;
 +    pthread_join(reader_thread, NULL);
 +  }
-   
        if (script_file) {
 -              fclose(script_file);
 -              script_file = NULL;
 -      }
 +    fclose(script_file);
 +    script_file = NULL;
 +  }
-   
 -      ExitGraphics();
 -      pthread_exit(NULL);
 -      return NULL;
 +  ExitGraphics();
 +  pthread_exit(NULL);
 +  return NULL;
  }
  
  static void dumpAllHelp(int markdown)
Simple merge
index b30294a8e940dff2a3cc717f7f77f9eda1d1165b,2b2bb2fbd7c47fa514d5d2c05dadd890b9a69400..9e8bfdf0e30530d2554f13bfb1ffe1a5c7bf0114
@@@ -69,8 -69,8 +69,10 @@@ INCLUDES = ../include/proxmark3.h ../in
  CFLAGS =  -c $(INCLUDE) -Wall -Werror -pedantic -std=c99 $(APP_CFLAGS) -Os
  LDFLAGS = -nostartfiles -nodefaultlibs -Wl,-gc-sections -n
  
+ LIBS = -lgcc
 +LIBS = -lgcc 
 +
  THUMBOBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(THUMBSRC))
  ARMOBJ   = $(ARMSRC:%.c=$(OBJDIR)/%.o)
  ASMOBJ   = $(patsubst %.s,$(OBJDIR)/%.o,$(ASMSRC))
Impressum, Datenschutz