From: iceman1001 Date: Sun, 26 Oct 2014 20:25:06 +0000 (+0100) Subject: Minor bug fixes with help from Holiman. X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/commitdiff_plain/149aeadaa609b01db86ba3b4ee23b317f16bede5 Minor bug fixes with help from Holiman. FIX: sprint_hex, sprint_bin has better length detection. FIX: ui.c has removed all c99 array declarations, with malloc FIX: hfmfmfu.c wrong length in one array caused crashes in CmdHF14AMfURdCard FIX: cmdlft55xx.c CmdDump has now a correct pwd string. --- diff --git a/client/cmdhfmfu.c b/client/cmdhfmfu.c index 3b9f2e6d..72eb8895 100644 --- a/client/cmdhfmfu.c +++ b/client/cmdhfmfu.c @@ -24,9 +24,9 @@ static int CmdHelp(const char *Cmd); // Mifare Ultralight Write Single Block // int CmdHF14AMfUWrBl(const char *Cmd){ - uint8_t blockNo = 0; - bool chinese_card=0; - uint8_t bldata[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + uint8_t blockNo = 0; + bool chinese_card = 0; + uint8_t bldata[16] = {0x00}; UsbCommand resp; if (strlen(Cmd)<3) { @@ -173,10 +173,10 @@ int CmdHF14AMfURdCard(const char *Cmd){ uint8_t BlockNo = 0; int Pages=16; uint8_t *lockbytes_t=NULL; - uint8_t lockbytes[2]={0,0}; - bool bit[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; + uint8_t lockbytes[2]={0x00}; + bool bit[16]={0x00}; bool dump=false; - uint8_t datatemp[5]={0,0,0,0,0}; + uint8_t datatemp[7]= {0x00}; uint8_t isOK = 0; uint8_t * data = NULL; @@ -327,19 +327,17 @@ int CmdHF14AMfURdCard(const char *Cmd){ int CmdHF14AMfUDump(const char *Cmd){ int i; - uint8_t BlockNo = 0; - int Pages=16; - uint8_t *lockbytes_t=NULL; - uint8_t lockbytes[2]={0,0}; - bool bit[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; - bool dump=false; - uint8_t datatemp[5]={0,0,0,0,0}; - - uint8_t isOK = 0; - uint8_t * data = NULL; + uint8_t BlockNo = 0; + int Pages = 16; + uint8_t *lockbytes_t = NULL; + uint8_t lockbytes[2] = {0x00}; + bool bit[16] = {0x00}; + uint8_t datatemp[5] = {0x00}; + bool dump = true; + uint8_t isOK = 0; + uint8_t * data = NULL; FILE *fout; - dump=true; if ((fout = fopen("dump_ultralight_data.bin","wb")) == NULL) { PrintAndLog("Could not create file name dumpdata.bin"); return 1; @@ -468,12 +466,12 @@ void rol (uint8_t *data, const size_t len){ int CmdHF14AMfucAuth(const char *Cmd){ uint8_t blockNo = 0, keyNo=0; - uint8_t e_RndB[8]; + uint8_t e_RndB[8] = {0x00}; uint32_t cuid=0; - unsigned char RndARndB[16]; - uint8_t key[16]; + unsigned char RndARndB[16] = {0x00}; + uint8_t key[16] = {0x00}; DES_cblock RndA, RndB; - DES_cblock iv={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; + DES_cblock iv[8] = {0x00}; DES_key_schedule ks1,ks2; DES_cblock key1,key2; @@ -566,7 +564,6 @@ int CmdHF14AMfucAuth(const char *Cmd){ // int CmdHF14AMfUCRdBl(const char *Cmd) { - uint8_t blockNo = 0; if (strlen(Cmd)<1) { @@ -607,14 +604,13 @@ int CmdHF14AMfUCRdCard(const char *Cmd){ uint8_t BlockNo = 0; int Pages=44; uint8_t *lockbytes_t=NULL; - uint8_t lockbytes[2]={0,0}; + uint8_t lockbytes[2]={0x00}; uint8_t *lockbytes_t2=NULL; - uint8_t lockbytes2[2]={0,0}; - bool bit[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; - bool bit2[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; + uint8_t lockbytes2[2]={0x00}; + bool bit[16]={0x00}; + bool bit2[16]={0x00}; bool dump=false; - uint8_t datatemp[5]={0,0,0,0,0}; - + uint8_t datatemp[5]={0x00}; uint8_t isOK = 0; uint8_t * data = NULL; FILE *fout = NULL; @@ -817,19 +813,18 @@ int CmdHF14AMfUCDump(const char *Cmd){ uint8_t BlockNo = 0; int Pages=44; uint8_t *lockbytes_t=NULL; - uint8_t lockbytes[2]={0,0}; + uint8_t lockbytes[2]={0x00}; uint8_t *lockbytes_t2=NULL; - uint8_t lockbytes2[2]={0,0}; - bool bit[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; - bool bit2[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; - bool dump=false; - uint8_t datatemp[5]={0,0,0,0,0}; + uint8_t lockbytes2[2]={0x00}; + bool bit[16]={0x00}; + bool bit2[16]={0x00}; + bool dump=true; + uint8_t datatemp[5]={0x00}; uint8_t isOK = 0; uint8_t * data = NULL; FILE *fout; - dump=true; if ((fout = fopen("dump_ultralightc_data.bin","wb")) == NULL) { PrintAndLog("Could not create file name dumpdata.bin"); return 1; @@ -1024,8 +1019,8 @@ int CmdHF14AMfUCDump(const char *Cmd){ int CmdHF14AMfUCWrBl(const char *Cmd){ uint8_t blockNo = 0; - bool chinese_card=0; - uint8_t bldata[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + bool chinese_card = 0; + uint8_t bldata[16] = {0x00}; UsbCommand resp; if (strlen(Cmd)<3) { diff --git a/client/cmdlft55xx.c b/client/cmdlft55xx.c index 5804fbc7..31261a4f 100644 --- a/client/cmdlft55xx.c +++ b/client/cmdlft55xx.c @@ -306,14 +306,13 @@ int CmdDump(const char *Cmd){ char cmdp = param_getchar(Cmd, 0); char s[20]; uint8_t pwd[4] = {0x00}; - - if (strlen(Cmd)>1 || cmdp == 'h' || cmdp == 'H') { + bool hasPwd = ( strlen(Cmd) > 0); + + if ( cmdp == 'h' || cmdp == 'H') { PrintAndLog("Usage: lf t55xx dump "); PrintAndLog(" sample: lf t55xx dump FFFFFFFF"); return 0; } - - bool hasPwd = ( strlen(Cmd) > 0); if ( hasPwd ){ if (param_gethex(Cmd, 0, pwd, 4)) { @@ -323,9 +322,9 @@ int CmdDump(const char *Cmd){ } for ( int i = 0; i <8; ++i){ - *s = 0; + memset(s,0,sizeof(s)); if ( hasPwd ) { - sprintf(s,"%d %d", i, pwd); + sprintf(s,"%d %s", i, sprint_hex(pwd,4)); CmdReadBlkPWD(s); } else { sprintf(s,"%d", i); diff --git a/client/ui.c b/client/ui.c index 5d05da96..966ab2ca 100644 --- a/client/ui.c +++ b/client/ui.c @@ -101,8 +101,7 @@ int manchester_decode( int * data, const size_t len, uint8_t * dataout){ int i, clock, high, low, startindex; low = startindex = 0; high = 1; - uint8_t bitStream[len]; - + uint8_t * bitStream = (uint8_t* ) malloc(sizeof(uint8_t) * len); memset(bitStream, 0x00, len); /* Detect high and lows */ @@ -118,14 +117,14 @@ int manchester_decode( int * data, const size_t len, uint8_t * dataout){ startindex = DetectFirstTransition(data, len, high); PrintAndLog(" Clock : %d", clock); - //PrintAndLog(" startindex : %d", startindex); - + if (high != 1) bitlength = ManchesterConvertFrom255(data, len, bitStream, high, low, clock, startindex); else bitlength= ManchesterConvertFrom1(data, len, bitStream, clock, startindex); memcpy(dataout, bitStream, bitlength); + free(bitStream); return bitlength; } @@ -398,8 +397,9 @@ void PrintPaddedManchester( uint8_t* bitStream, size_t len, size_t blocksize){ void iceFsk2(int * data, const size_t len){ int i, j; - int output[len]; - + int * output = (int* ) malloc(sizeof(int) * len); + memset(output, 0x00, len); + // for (i=0; i 1024/3) ? 1024/3 : len; static char buf[1024]; char * tmp = buf; size_t i; - for (i=0; i < len && i < 1024/3; i++, tmp += 3) + for (i=0; i < maxLen; ++i, tmp += 3) sprintf(tmp, "%02x ", data[i]); return buf; } char * sprint_bin(const uint8_t * data, const size_t len) { + + int maxLen = ( len > 1024) ? 1024 : len; static char buf[1024]; char * tmp = buf; size_t i; - for (i=0; i < len && i < 1024; i++, tmp++) + for (i=0; i < maxLen; ++i, ++tmp) sprintf(tmp, "%u", data[i]); return buf;