X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/49dc1d0a9eafdb1e369ead88c3c8882bc6959a17..8a5b3c2a45adc51edc23f78621a34cf7956ff554:/client/cmdhfmfdes.c diff --git a/client/cmdhfmfdes.c b/client/cmdhfmfdes.c index c3cdde2c..a0059233 100644 --- a/client/cmdhfmfdes.c +++ b/client/cmdhfmfdes.c @@ -12,7 +12,6 @@ #include #include #include -//#include #include "loclass/des.h" #include "cmdmain.h" #include "proxmark3.h" @@ -24,6 +23,8 @@ #include "cmdparser.h" #include "util.h" #include "cmdhfmfdes.h" +#include "cmdhf14a.h" + uint8_t CMDPOS = 0; uint8_t LENPOS = 1; @@ -34,9 +35,6 @@ uint8_t key_defa_data[16] = { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09, uint8_t key_picc_data[16] = { 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f }; static int CmdHelp(const char *Cmd); -static void xor(unsigned char * dst, unsigned char * src, size_t len); -static int32_t le24toh (uint8_t data[3]); - int CmdHF14ADesWb(const char *Cmd) { @@ -158,15 +156,15 @@ int CmdHF14ADesInfo(const char *Cmd){ PrintAndLog(" Production date : week %02x, 20%02x",resp.d.asBytes[33], resp.d.asBytes[34]); PrintAndLog(" -----------------------------------------------------------"); PrintAndLog(" Hardware Information"); - PrintAndLog(" Vendor Id : %s", GetVendorStr(resp.d.asBytes[7])); + PrintAndLog(" Vendor Id : %s", getTagInfo(resp.d.asBytes[7])); PrintAndLog(" Type : 0x%02X",resp.d.asBytes[8]); PrintAndLog(" Subtype : 0x%02X",resp.d.asBytes[9]); - PrintAndLog(" Version : %d.%d",resp.d.asBytes[10], resp.d.asBytes[11]); + PrintAndLog(" Version : %s",GetVersionStr(resp.d.asBytes[10], resp.d.asBytes[11]) ); PrintAndLog(" Storage size : %s",GetCardSizeStr(resp.d.asBytes[12])); PrintAndLog(" Protocol : %s",GetProtocolStr(resp.d.asBytes[13])); PrintAndLog(" -----------------------------------------------------------"); PrintAndLog(" Software Information"); - PrintAndLog(" Vendor Id : %s",GetVendorStr(resp.d.asBytes[14])); + PrintAndLog(" Vendor Id : %s", getTagInfo(resp.d.asBytes[14])); PrintAndLog(" Type : 0x%02X",resp.d.asBytes[15]); PrintAndLog(" Subtype : 0x%02X",resp.d.asBytes[16]); PrintAndLog(" Version : %d.%d",resp.d.asBytes[17], resp.d.asBytes[18]); @@ -211,17 +209,6 @@ int CmdHF14ADesInfo(const char *Cmd){ return 1; } -char * GetVendorStr( uint8_t id){ - static char buf[30]; - char *retStr = buf; - - if ( id == 0x04 ) - sprintf(retStr, "0x%02X (NXP)",id); - else - sprintf(retStr,"0x%02X (Unknown)",id); - return buf; -} - /* The 7 MSBits (= n) code the storage size itself based on 2^n, the LSBit is set to '0' if the size is exactly 2^n @@ -230,7 +217,7 @@ char * GetVendorStr( uint8_t id){ */ char * GetCardSizeStr( uint8_t fsize ){ - static char buf[30]; + static char buf[30] = {0x00}; char *retStr = buf; uint16_t usize = 1 << ((fsize >>1) + 1); @@ -246,7 +233,7 @@ char * GetCardSizeStr( uint8_t fsize ){ char * GetProtocolStr(uint8_t id){ - static char buf[30]; + static char buf[30] = {0x00}; char *retStr = buf; if ( id == 0x05) @@ -256,6 +243,22 @@ char * GetProtocolStr(uint8_t id){ return buf; } +char * GetVersionStr(uint8_t major, uint8_t minor){ + + static char buf[30] = {0x00}; + char *retStr = buf; + + if ( major == 0x00) + sprintf(retStr,"%d.%d (Desfire MF3ICD40)", major, minor); + else if ( major == 0x01 && minor == 0x00) + sprintf(retStr,"%d.%d (Desfire EV1)", major, minor); + else if ( major == 0x12 && minor == 0x00) + sprintf(retStr,"%d.%d (Desfire EV2)", major, minor); + else + sprintf(retStr,"%d.%d (Unknown)", major, minor); + return buf; +} + void GetKeySettings( uint8_t *aid){ char messStr[512] = {0x00}; @@ -365,7 +368,7 @@ void GetKeySettings( uint8_t *aid){ PrintAndLog(" Can't read Application Master key settings"); } else { // Access rights. - uint8_t rights = (resp.d.asBytes[3] >> 4 && 0xff); + uint8_t rights = (resp.d.asBytes[3] >> 4 & 0xff); switch (rights){ case 0x00: str = "AMK authentication is necessary to change any key (default)"; @@ -624,7 +627,7 @@ int CmdHF14ADesAuth(const char *Cmd){ c.d.asBytes[0] = keylength; memcpy(c.d.asBytes+1, key, keylength); - + clearCommandBuffer(); SendCommand(&c); UsbCommand resp; @@ -649,38 +652,26 @@ int CmdHF14ADesAuth(const char *Cmd){ } -static void xor(unsigned char * dst, unsigned char * src, size_t len) { - for( ; len > 0; len--,dst++,src++) - *dst ^= *src; -} - -static int32_t le24toh (uint8_t data[3]) { - return (data[2] << 16) | (data[1] << 8) | data[0]; -} - -static command_t CommandTable[] = -{ +static command_t CommandTable[] = { {"help", CmdHelp, 1, "This help"}, - {"auth", CmdHF14ADesAuth, 0, "Tries a MIFARE DesFire Authentication"}, - {"rb", CmdHF14ADesRb, 0, "Read MIFARE DesFire block"}, - {"wb", CmdHF14ADesWb, 0, "write MIFARE DesFire block"}, {"info", CmdHF14ADesInfo, 0, "Get MIFARE DesFire information"}, {"enum", CmdHF14ADesEnumApplications,0, "Tries enumerate all applications"}, + {"auth", CmdHF14ADesAuth, 0, "Tries a MIFARE DesFire Authentication"}, + {"rdbl", CmdHF14ADesRb, 0, "Read MIFARE DesFire block"}, + {"wrbl", CmdHF14ADesWb, 0, "write MIFARE DesFire block"}, {NULL, NULL, 0, NULL} }; -int CmdHFMFDes(const char *Cmd) -{ +int CmdHFMFDes(const char *Cmd) { // flush - WaitForResponseTimeout(CMD_ACK,NULL,100); - CmdsParse(CommandTable, Cmd); - return 0; + clearCommandBuffer(); + CmdsParse(CommandTable, Cmd); + return 0; } -int CmdHelp(const char *Cmd) -{ - CmdsHelp(CommandTable); - return 0; +int CmdHelp(const char *Cmd) { + CmdsHelp(CommandTable); + return 0; }