]> cvs.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdlft55xx.c
add lf t5 read w/pwd warning and checks
[proxmark3-svn] / client / cmdlft55xx.c
index 887547248abe6e3945a4f6153bbcd493972d0e93..2297d249d41b2a0783405106ac68702599e9c902 100644 (file)
@@ -49,13 +49,18 @@ int usage_t55xx_config(){
        return 0;\r
 }\r
 int usage_t55xx_read(){\r
        return 0;\r
 }\r
 int usage_t55xx_read(){\r
-       PrintAndLog("Usage:  lf t55xx read <block> <password>");\r
+       PrintAndLog("Usage:  lf t55xx read <block> <password> <override_safety>");\r
        PrintAndLog("     <block>, block number to read. Between 0-7");\r
        PrintAndLog("     <password>, OPTIONAL password (8 hex characters)");\r
        PrintAndLog("     <block>, block number to read. Between 0-7");\r
        PrintAndLog("     <password>, OPTIONAL password (8 hex characters)");\r
+       PrintAndLog("     <override_safety>, OPTIONAL override safety check = 1");\r
+       PrintAndLog("     ****WARNING****");\r
+       PrintAndLog("     Use of read with password on a tag not configured for a pwd");\r
+       PrintAndLog("     can damage the tag");\r
        PrintAndLog("");\r
        PrintAndLog("Examples:");\r
        PrintAndLog("");\r
        PrintAndLog("Examples:");\r
-       PrintAndLog("      lf t55xx read 0           - read data from block 0");\r
-       PrintAndLog("      lf t55xx read 0 feedbeef  - read data from block 0 password feedbeef");\r
+       PrintAndLog("      lf t55xx read 0            - read data from block 0");\r
+       PrintAndLog("      lf t55xx read 0 feedbeef   - read data from block 0 password feedbeef");\r
+       PrintAndLog("      lf t55xx read 0 feedbeef 1 - read data from block 0 password feedbeef safety check");\r
        PrintAndLog("");\r
        return 0;\r
 }\r
        PrintAndLog("");\r
        return 0;\r
 }\r
@@ -217,29 +222,38 @@ int CmdT55xxSetConfig(const char *Cmd) {
 int CmdT55xxReadBlock(const char *Cmd) {\r
        int block = -1;\r
        int password = 0xFFFFFFFF; //default to blank Block 7\r
 int CmdT55xxReadBlock(const char *Cmd) {\r
        int block = -1;\r
        int password = 0xFFFFFFFF; //default to blank Block 7\r
-\r
+       int override = 0;\r
        char cmdp = param_getchar(Cmd, 0);\r
        if (cmdp == 'h' || cmdp == 'H')\r
                return usage_t55xx_read();\r
 \r
        char cmdp = param_getchar(Cmd, 0);\r
        if (cmdp == 'h' || cmdp == 'H')\r
                return usage_t55xx_read();\r
 \r
-       int res = sscanf(Cmd, "%d %x", &block, &password);\r
+       int res = sscanf(Cmd, "%d %x %d", &block, &password, &override);\r
 \r
 \r
-       if ( res < 1 || res > 2 )\r
+       if ( res < 1 || res > 3 )\r
                return usage_t55xx_read();\r
 \r
                return usage_t55xx_read();\r
 \r
-       \r
-       if ((block < 0) | (block > 7)) {\r
+       if ((block < 0) || (block > 7)) {\r
                PrintAndLog("Block must be between 0 and 7");\r
                return 1;\r
                PrintAndLog("Block must be between 0 and 7");\r
                return 1;\r
-       }       \r
+       }\r
 \r
        UsbCommand c = {CMD_T55XX_READ_BLOCK, {0, block, 0}};\r
 \r
        UsbCommand c = {CMD_T55XX_READ_BLOCK, {0, block, 0}};\r
-       c.d.asBytes[0] = 0x0; \r
+       c.d.asBytes[0] = 0x0;\r
 \r
        //Password mode\r
 \r
        //Password mode\r
-       if ( res == 2 ) {\r
-               c.arg[2] = password;\r
-               c.d.asBytes[0] = 0x1; \r
+       if ( res > 1 ) {\r
+               // try reading the config block and verify that PWD bit is set before doing this!\r
+               AquireData( CONFIGURATION_BLOCK );\r
+               if ( !tryDetectModulation() && !override) {\r
+                       PrintAndLog("Safety Check: Could not detect if PWD bit is set in config block. Exits.");\r
+                       return 1;\r
+               } else if (override) {\r
+                       PrintAndLog("Safety Check Overriden - proceeding despite risk");\r
+                       c.arg[2] = password;\r
+                       c.d.asBytes[0] = 0x1;\r
+               } else {\r
+                       PrintAndLog("Safety Check: PWD bit is NOT set in config block. Reading without password...");   \r
+               }\r
        }\r
 \r
        clearCommandBuffer();\r
        }\r
 \r
        clearCommandBuffer();\r
@@ -250,10 +264,10 @@ int CmdT55xxReadBlock(const char *Cmd) {
        }\r
        \r
        uint8_t got[12000];\r
        }\r
        \r
        uint8_t got[12000];\r
-       GetFromBigBuf(got,sizeof(got),0);\r
+       GetFromBigBuf(got, sizeof(got), 0);\r
        WaitForResponse(CMD_ACK,NULL);\r
        WaitForResponse(CMD_ACK,NULL);\r
-       setGraphBuf(got, 12000);\r
-       DemodBufferLen=0;\r
+       setGraphBuf(got, sizeof(got));\r
+       //DemodBufferLen=0;\r
        if (!DecodeT55xxBlock()) return 3;\r
        char blk[10]={0};\r
        sprintf(blk,"%d", block);\r
        if (!DecodeT55xxBlock()) return 3;\r
        char blk[10]={0};\r
        sprintf(blk,"%d", block);\r
@@ -270,8 +284,8 @@ bool DecodeT55xxBlock(){
        DemodBufferLen = 0x00;\r
 \r
        //trim 1/2 a clock from beginning\r
        DemodBufferLen = 0x00;\r
 \r
        //trim 1/2 a clock from beginning\r
-       snprintf(cmdStr, sizeof(buf),"%d", bitRate[config.bitrate]/2 );\r
-       CmdLtrim(cmdStr);\r
+       //snprintf(cmdStr, sizeof(buf),"%d", bitRate[config.bitrate]/2 );\r
+       //CmdLtrim(cmdStr);\r
        switch( config.modulation ){\r
                case DEMOD_FSK:\r
                        snprintf(cmdStr, sizeof(buf),"%d %d", bitRate[config.bitrate], config.inverted );\r
        switch( config.modulation ){\r
                case DEMOD_FSK:\r
                        snprintf(cmdStr, sizeof(buf),"%d %d", bitRate[config.bitrate], config.inverted );\r
@@ -333,7 +347,7 @@ int CmdT55xxDetect(const char *Cmd){
 \r
 // detect configuration?\r
 bool tryDetectModulation(){\r
 \r
 // detect configuration?\r
 bool tryDetectModulation(){\r
-       char cmdStr[8] = {0};\r
+       //char cmdStr[8] = {0};\r
        uint8_t hits = 0;\r
        t55xx_conf_block_t tests[15];\r
        int bitRate=0;\r
        uint8_t hits = 0;\r
        t55xx_conf_block_t tests[15];\r
        int bitRate=0;\r
@@ -341,8 +355,8 @@ bool tryDetectModulation(){
        save_restoreGB(1);\r
        if (GetFskClock("", FALSE, FALSE)){ \r
                fskClocks(&fc1, &fc2, &clk, FALSE);\r
        save_restoreGB(1);\r
        if (GetFskClock("", FALSE, FALSE)){ \r
                fskClocks(&fc1, &fc2, &clk, FALSE);\r
-               sprintf(cmdStr,"%d", clk/2);\r
-               CmdLtrim(cmdStr);\r
+               //sprintf(cmdStr,"%d", clk/2);\r
+               //CmdLtrim(cmdStr);\r
                if ( FSKrawDemod("0 0", FALSE) && test(DEMOD_FSK, &tests[hits].offset, &bitRate)){\r
                        tests[hits].modulation = DEMOD_FSK;\r
                        if (fc1==8 && fc2 == 5)\r
                if ( FSKrawDemod("0 0", FALSE) && test(DEMOD_FSK, &tests[hits].offset, &bitRate)){\r
                        tests[hits].modulation = DEMOD_FSK;\r
                        if (fc1==8 && fc2 == 5)\r
@@ -369,8 +383,8 @@ bool tryDetectModulation(){
        } else {\r
                clk = GetAskClock("", FALSE, FALSE);\r
                if (clk>0) {\r
        } else {\r
                clk = GetAskClock("", FALSE, FALSE);\r
                if (clk>0) {\r
-                       sprintf(cmdStr,"%d", clk/2);\r
-                       CmdLtrim(cmdStr);\r
+                       //sprintf(cmdStr,"%d", clk/2);\r
+                       //CmdLtrim(cmdStr);\r
                        if ( ASKDemod("0 0 0", FALSE, FALSE, 1) && test(DEMOD_ASK, &tests[hits].offset, &bitRate)) {\r
                                tests[hits].modulation = DEMOD_ASK;\r
                                tests[hits].bitrate = bitRate;\r
                        if ( ASKDemod("0 0 0", FALSE, FALSE, 1) && test(DEMOD_ASK, &tests[hits].offset, &bitRate)) {\r
                                tests[hits].modulation = DEMOD_ASK;\r
                                tests[hits].bitrate = bitRate;\r
@@ -404,8 +418,8 @@ bool tryDetectModulation(){
                save_restoreGB(0);\r
                clk = GetNrzClock("", FALSE, FALSE);\r
                if (clk>0) {\r
                save_restoreGB(0);\r
                clk = GetNrzClock("", FALSE, FALSE);\r
                if (clk>0) {\r
-                       sprintf(cmdStr,"%d", clk/2);\r
-                       CmdLtrim(cmdStr);\r
+                       //sprintf(cmdStr,"%d", clk/2);\r
+                       //CmdLtrim(cmdStr);\r
                        if ( NRZrawDemod("0 0 1", FALSE)  && test(DEMOD_NRZ, &tests[hits].offset, &bitRate)) {\r
                                tests[hits].modulation = DEMOD_NRZ;\r
                                tests[hits].bitrate = bitRate;\r
                        if ( NRZrawDemod("0 0 1", FALSE)  && test(DEMOD_NRZ, &tests[hits].offset, &bitRate)) {\r
                                tests[hits].modulation = DEMOD_NRZ;\r
                                tests[hits].bitrate = bitRate;\r
@@ -427,9 +441,9 @@ bool tryDetectModulation(){
                save_restoreGB(0);\r
                clk = GetPskClock("", FALSE, FALSE);\r
                if (clk>0) {\r
                save_restoreGB(0);\r
                clk = GetPskClock("", FALSE, FALSE);\r
                if (clk>0) {\r
-                       PrintAndLog("clk %d",clk);\r
-                       sprintf(cmdStr,"%d", clk/2);\r
-                       CmdLtrim(cmdStr);       \r
+                       //PrintAndLog("clk %d",clk);\r
+                       //sprintf(cmdStr,"%d", clk/2);\r
+                       //CmdLtrim(cmdStr);     \r
                        if ( PSKDemod("0 0 1", FALSE) && test(DEMOD_PSK1, &tests[hits].offset, &bitRate)) {\r
                                tests[hits].modulation = DEMOD_PSK1;\r
                                tests[hits].bitrate = bitRate;\r
                        if ( PSKDemod("0 0 1", FALSE) && test(DEMOD_PSK1, &tests[hits].offset, &bitRate)) {\r
                                tests[hits].modulation = DEMOD_PSK1;\r
                                tests[hits].bitrate = bitRate;\r
Impressum, Datenschutz