]> cvs.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdhficlass.c
fix a warning
[proxmark3-svn] / client / cmdhficlass.c
index 70c18aba204a518419b3eb8df37633de3a03dc66..156b7f651b664e7854f7806324df61e1a1a1a198 100644 (file)
@@ -672,9 +672,9 @@ int CmdHFiClassReader_Dump(const char *Cmd) {
                return 0;
        }
        
-       if( readStatus & (FLAG_ICLASS_READER_CSN|FLAG_ICLASS_READER_CONF|FLAG_ICLASS_READER_CC)){
+       if( readStatus & (FLAG_ICLASS_READER_CSN | FLAG_ICLASS_READER_CONF | FLAG_ICLASS_READER_CC)){
                memcpy(tag_data, data, 8*3);
-               blockno+=2; // 2 to force re-read of block 2 later. (seems to respond differently..)
+               blockno += 2; // 2 to force re-read of block 2 later. (seems to respond differently..)
                numblks = data[8];
                getMemConfig(data[13], data[12], &maxBlk, &app_areas, &kb);
                // large memory - not able to dump pages currently
@@ -768,10 +768,14 @@ int CmdHFiClassReader_Dump(const char *Cmd) {
        // add diversified keys to dump
        if (have_debit_key) memcpy(tag_data+(3*8),div_key,8);
        if (have_credit_key) memcpy(tag_data+(4*8),c_div_key,8);
+       
+       printf("Num of bytes:  %u\n", gotBytes);
+       
        // print the dump
-       printf("CSN   |00| %s |\n", sprint_hex(tag_data, 8));
-       printf("CSN   |00| %s |\n", sprint_hex(tag_data, 8));
-       printIclassDumpContents(tag_data, 1, (gotBytes/8)-1, gotBytes-8);
+       printf("------+--+-------------------------+\n");
+       printf("CSN   |00| %s|\n", sprint_hex(tag_data, 8));    
+       //printIclassDumpContents(tag_data, 1, (gotBytes/8)-1, gotBytes-8);
+       printIclassDumpContents(tag_data, 1, (gotBytes/8), gotBytes);
 
        if (filename[0] == 0){
                snprintf(filename, FILE_PATH_SIZE,"iclass_tagdump-%02x%02x%02x%02x%02x%02x%02x%02x",
@@ -1212,7 +1216,7 @@ int CmdHFiClass_loclass(const char *Cmd) {
                PrintAndLog("f <filename>  Bruteforce iclass dumpfile");
                PrintAndLog("                   An iclass dumpfile is assumed to consist of an arbitrary number of");
                PrintAndLog("                   malicious CSNs, and their protocol responses");
-               PrintAndLog("                   The the binary format of the file is expected to be as follows: ");
+               PrintAndLog("                   The binary format of the file is expected to be as follows: ");
                PrintAndLog("                   <8 byte CSN><8 byte CC><4 byte NR><4 byte MAC>");
                PrintAndLog("                   <8 byte CSN><8 byte CC><4 byte NR><4 byte MAC>");
                PrintAndLog("                   <8 byte CSN><8 byte CC><4 byte NR><4 byte MAC>");
@@ -1240,17 +1244,16 @@ int CmdHFiClass_loclass(const char *Cmd) {
 }
 
 void printIclassDumpContents(uint8_t *iclass_dump, uint8_t startblock, uint8_t endblock, size_t filesize) {
-       uint8_t blockdata[8];
        uint8_t mem_config;
        memcpy(&mem_config, iclass_dump + 13,1);
        uint8_t maxmemcount;
+       
        uint8_t filemaxblock = filesize / 8;
 
        if (mem_config & 0x80)
                maxmemcount = 255;
        else
                maxmemcount = 31;
-       //PrintAndLog   ("endblock: %d, filesize: %d, maxmemcount: %d, filemaxblock: %d", endblock,filesize, maxmemcount, filemaxblock);
 
        if (startblock == 0)
                startblock = 6;
@@ -1258,19 +1261,20 @@ void printIclassDumpContents(uint8_t *iclass_dump, uint8_t startblock, uint8_t e
        if ((endblock > maxmemcount) || (endblock == 0))
                endblock = maxmemcount;
        
-       if (endblock > filemaxblock)
-               endblock = filemaxblock;
+       // remember endblock needs to relate to zero-index arrays.
+       if (endblock > filemaxblock-1)
+               endblock = filemaxblock-1;
+
+       //PrintAndLog   ("startblock: %d, endblock: %d, filesize: %d, maxmemcount: %d, filemaxblock: %d",startblock, endblock,filesize, maxmemcount, filemaxblock);
        
        int i = startblock;
-       int j;
+       printf("------+--+-------------------------+\n");
        while (i <= endblock){
-               printf("Block |%02X| ",i);
-               memcpy(blockdata, iclass_dump + (i * 8), 8);
-               for (j = 0;j < 8;j++)
-                       printf("%02X ", blockdata[j]);
-               printf("|\n");
+               uint8_t *blk = iclass_dump + (i * 8);
+               printf("Block |%02X| %s|\n", i, sprint_hex(blk, 8) );   
                i++;
        }
+       printf("------+--+-------------------------+\n");
 }
 
 int usage_hf_iclass_readtagfile() {
@@ -1318,8 +1322,9 @@ int CmdHFiClassReadTagFile(const char *Cmd) {
        fclose(f);
        
        uint8_t *csn = dump;
-       printf("CSN   [00] | %s |\n", sprint_hex(csn, 8) );
-       printIclassDumpContents(dump,startblock,endblock,bytes_read);
+       printf("------+--+-------------------------+\n");
+       printf("CSN   |00| %s|\n", sprint_hex(csn, 8) );
+       printIclassDumpContents(dump, startblock, endblock, bytes_read);
        free(dump);
        return 0;
 }
@@ -1377,9 +1382,9 @@ static void HFiClassCalcNewKey(uint8_t *CSN, uint8_t *OLDKEY, uint8_t *NEWKEY, u
                xor_div_key[i] = old_div_key[i] ^ new_div_key[i];
        }
        if (verbose) {
-               printf("Old Div Key : %s\n",sprint_hex(old_div_key,8));
-               printf("New Div Key : %s\n",sprint_hex(new_div_key,8));
-               printf("Xor Div Key : %s\n",sprint_hex(xor_div_key,8));         
+               printf("Old div key : %s\n",sprint_hex(old_div_key,8));
+               printf("New div key : %s\n",sprint_hex(new_div_key,8));
+               printf("Xor div key : %s\n",sprint_hex(xor_div_key,8));         
        }
 }
 
@@ -1397,7 +1402,6 @@ int usage_hf_iclass_calc_newkey(void) {
        PrintAndLog(" std key to e key read csn: hf iclass calcnewkey o 1122334455667788 n 2233445566778899 e");
        PrintAndLog(" std to std read csn      : hf iclass calcnewkey o 1122334455667788 n 2233445566778899");
        PrintAndLog("NOTE: * = required\n");
-
        return 1;
 }
 
@@ -1520,9 +1524,9 @@ static int loadKeys(char *filename) {
                return 0;
        }
        uint8_t i = 0;
-       for (; i < bytes_read/8; i++){
+       for (; i < bytes_read/8; i++)
                memcpy(iClass_Key_Table[i],dump+(i*8),8);
-       }
+       
        free(dump);
        PrintAndLog("%u keys loaded", i);
        return 1;
@@ -1547,9 +1551,8 @@ static int saveKeys(char *filename) {
 
 static int printKeys(void) {
        PrintAndLog("");
-       for (uint8_t i = 0; i < ICLASS_KEYS_MAX; i++){
+       for (uint8_t i = 0; i < ICLASS_KEYS_MAX; i++)
                PrintAndLog("%u: %s", i, sprint_hex(iClass_Key_Table[i],8));
-       }
        PrintAndLog("");        
        return 0;
 }
Impressum, Datenschutz