]> cvs.zerfleddert.de Git - proxmark3-svn/commitdiff
CHG: "hf legic decode" now prints nicely. Still a strange bug for first row..
authoriceman1001 <iceman@iuse.se>
Mon, 15 Feb 2016 18:56:08 +0000 (19:56 +0100)
committericeman1001 <iceman@iuse.se>
Mon, 15 Feb 2016 18:56:08 +0000 (19:56 +0100)
client/cmdhflegic.c
client/util.c
client/util.h

index 21598bcddeee1e137692e57e0dc10ba0a2a0e6d9..0ef745342adb6983959c37ebe10d23ea967ce639 100644 (file)
@@ -92,7 +92,7 @@ int CmdLegicDecode(const char *Cmd) {
 
        stamp_len = 0xfc - data_buf[6];
 
-       PrintAndLog("DCF: %02x %02x, Token_Type=%s (OLE=%01u), Stamp_len=%02u",
+       PrintAndLog("DCF: %02x %02x, Token Type=%s (OLE=%01u), Stamp len=%02u",
                data_buf[5],
                data_buf[6],
                token_type,
@@ -116,6 +116,7 @@ int CmdLegicDecode(const char *Cmd) {
        uint32_t segCRC = 0;
 
        PrintAndLog("\nADF: User Area");
+       printf("-------------------------------------\n");
        i = 22;  
        // 64 potential segements
        for ( segmentNum=0; segmentNum<64; segmentNum++ ) {
@@ -143,16 +144,16 @@ int CmdLegicDecode(const char *Cmd) {
                segCalcCRC = CRC8Legic(segCrcBytes, 8);
                segCRC = data_buf[i+4]^crc;
 
-               PrintAndLog("Segment %02u: raw header=%02x %02x %02x %02x, flag=%01x (valid=%01u, last=%01u), len=%04u, WRP=%02u, WRC=%02u, RD=%01u, CRC=%02x  (%s)",
+               PrintAndLog("Segment %02u \nraw header=0x%02X 0x%02X 0x%02X 0x%02X \nSegment len: %u,  Flag: 0x%X (valid:%01u, last:%01u), WRP: %02u, WRC: %02u, RD: %01u, CRC: 0x%02X (%s)",
                        segmentNum,
                        data_buf[i]^crc,
                        data_buf[i+1]^crc,
                        data_buf[i+2]^crc,
                        data_buf[i+3]^crc,
+                       segment_len, 
                        segment_flag,
                        (segment_flag & 0x4) >> 2,
                        (segment_flag & 0x8) >> 3,
-                       segment_len,
                        wrp,
                        wrc,
                        ((data_buf[i+3]^crc) & 0x80) >> 7,
@@ -171,7 +172,7 @@ int CmdLegicDecode(const char *Cmd) {
                        //is WRC / 8? 
                        
                        // for ( k=i; k < wrc; k += 8)
-                       PrintAndLog("%s", sprint_hex( data_buf+i, wrc ) );
+                       print_hex_break( data_buf+i, wrc, 16);
                        
                        i += wrc;
                }
@@ -179,35 +180,36 @@ int CmdLegicDecode(const char *Cmd) {
                if ( hasWRP ) {
                        PrintAndLog("Remaining write protected area:  (I %d | K %d | WRC %d | WRP %d  WRP_LEN %d)",i, k, wrc, wrp, wrp_len);
 
-                       // // de-xor?
-                       // if ( data_buf[k] > 0) {
-                               // for (k=i; k < wrp_len; k++)
-                                       // data_buf[k] ^= crc;
-                       // }
+                       // de-xor?  if not zero, assume it needs xoring.
+                       if ( data_buf[i] > 0) {
+                               for (k=i; k < wrp_len; k++)
+                                       data_buf[k] ^= crc;
+                       }
                        
                        // for (k=i; k < wrp_len; k += 16) {
                                
-                       PrintAndLog("%s", sprint_hex( data_buf+i, wrp_len));
+                       print_hex_break( data_buf+i, wrp_len, 16);
                        // }
                        
                        i += wrp_len;
                        
-                       // if( wrp_len == 8 )
-                               // PrintAndLog("Card ID: %2X%02X%02X", data_buf[i-4]^crc, data_buf[i-3]^crc, data_buf[i-2]^crc);                        
+                       if( wrp_len == 8 )
+                               PrintAndLog("Card ID: %2X%02X%02X", data_buf[i-4]^crc, data_buf[i-3]^crc, data_buf[i-2]^crc);                   
                }
     
                PrintAndLog("Remaining segment payload:");
                
-               // if ( data_buf[k] > 0 ) {
-                       // for ( k=i; k < remain_seg_payload_len; k++)
-                               // data_buf[k] ^= crc;
-               // }
+               if ( data_buf[i] > 0 ) {
+                       for ( k=i; k < remain_seg_payload_len; k++)
+                               data_buf[k] ^= crc;
+               }
                
                // for ( k=i; k < remain_seg_payload_len; k++)
-               PrintAndLog("%s", sprint_hex( data_buf+i, remain_seg_payload_len )  );
+               print_hex_break( data_buf+i, remain_seg_payload_len, 16);
     
                i += remain_seg_payload_len;
                
+               printf("\n-------------------------------------\n");
                // end with last segment
                if (segment_flag & 0x8) return 0;
 
index fcda9bde0ae7815bf46d1e2c0567c564f43cb526..2bc5b2ba02f4fc0fda66ba8a678c6d399c1de121 100644 (file)
@@ -97,14 +97,22 @@ void FillFileNameByUID(char *fileName, uint8_t * uid, char *ext, int byteCount)
 }
 
 // printing and converting functions
-
-void print_hex(const uint8_t * data, const size_t len)
-{
+void print_hex(const uint8_t * data, const size_t len) {
        size_t i;
-
-       for (i=0; i < len; i++)
+       for (i=0; i < len; ++i)
                printf("%02x ", data[i]);
+       printf("\n");
+}
+void print_hex_break(const uint8_t *data, const size_t len, uint8_t breaks) {
+       size_t i;
+       for ( i = 0; i < len; ++i) {
 
+               printf("%02X ", data[i]);
+               
+               // check if a line break is needed
+               if ( (breaks > 0) && (i > 0) && !(i % breaks) )
+                       printf("\n");
+       }
        printf("\n");
 }
 
@@ -158,9 +166,10 @@ char *sprint_bin(const uint8_t *data, const size_t len) {
 
 char *sprint_hex_ascii(const uint8_t *data, const size_t len) {
        static char buf[1024];
-       memset(buf, 0x00, 1024);
        char *tmp = buf;
-       sprintf(tmp, "%s| %s", sprint_hex(data, len) , data);   
+       memset(buf, 0x00, 1024);
+       size_t max_len = (len > 1010) ? 1010 : len;
+       sprintf(tmp, "%s| %s", sprint_hex(data, max_len) , data);       
        return buf;
 }
 void num_to_bytes(uint64_t n, size_t len, uint8_t* dest)
index ce3bc24701a28d2288ef2ce19abce7df53c38b32..2813bb8c9ba30d00fda29e0016e67c1a93c82e9d 100644 (file)
@@ -45,6 +45,7 @@ void AddLogCurrentDT(char *fileName);
 void FillFileNameByUID(char *fileName, uint8_t * uid, char *ext, int byteCount);
 
 void print_hex(const uint8_t * data, const size_t len);
+void print_hex_break(const uint8_t *data, const size_t len, const uint8_t breaks);
 char *sprint_hex(const uint8_t * data, const size_t len);
 char *sprint_bin(const uint8_t * data, const size_t len);
 char *sprint_bin_break(const uint8_t *data, const size_t len, const uint8_t breaks);
Impressum, Datenschutz