X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/1f247f6ac63295c54f5e8a95b2c39c6077d2d5ec..e1778858ddc53a6a82e8ee24f02e6b673687f69a:/client/cmdhflegic.c?ds=sidebyside diff --git a/client/cmdhflegic.c b/client/cmdhflegic.c index 0ddc7466..4414efa1 100644 --- a/client/cmdhflegic.c +++ b/client/cmdhflegic.c @@ -527,7 +527,7 @@ int CmdLegicRdmem(const char *Cmd) { // int phase, int frame, int reqresp int CmdLegicRfSim(const char *Cmd) { UsbCommand c = {CMD_SIMULATE_TAG_LEGIC_RF, {6,3,0}}; - sscanf(Cmd, " %"lli" %"lli" %"lli, &c.arg[0], &c.arg[1], &c.arg[2]); + sscanf(Cmd, " %" SCNi64 " %" SCNi64 " %" SCNi64 , &c.arg[0], &c.arg[1], &c.arg[2]); clearCommandBuffer(); SendCommand(&c); return 0; @@ -636,14 +636,13 @@ int CmdLegicRfWrite(const char *Cmd) { PrintAndLog("############# DANGER ################"); PrintAndLog("# changing the DCF is irreversible #"); PrintAndLog("#####################################"); - PrintAndLog("do you really want to continue? y(es) n(o)"); - char answer; - sscanf(" %c", &answer); - bool exit = !(answer == 'n' || answer == 'N'); - if (exit) + char *answer = NULL; + answer = readline("do you really want to continue? y(es) n(o) : "); + bool overwrite = (answer[0] == 'y' || answer[0] == 'Y'); + if (!overwrite){ + PrintAndLog("command cancelled"); return 0; - printf("ICE DCF: %c answer, %d\n", answer, exit); - return 0; + } } legic_chk_iv(&IV); @@ -925,7 +924,8 @@ int CmdLegicDump(const char *Cmd){ else sprintf(fnameptr + fileNlen,".bin"); - if ((f = fopen(filename,"wb")) == NULL) { + f = fopen(filename,"wb"); + if (!f) { PrintAndLog("Could not create file name %s", filename); if (data) free(data); @@ -1001,7 +1001,8 @@ int CmdLegicRestore(const char *Cmd){ fnameptr += fileNlen; sprintf(fnameptr, ".bin"); - if ((f = fopen(filename,"rb")) == NULL) { + f = fopen(filename,"rb"); + if (!f) { PrintAndLog("File %s not found or locked", filename); return 3; } @@ -1020,14 +1021,14 @@ int CmdLegicRestore(const char *Cmd){ // load file size_t bytes_read = fread(data, 1, numofbytes, f); + fclose(f); + if ( bytes_read == 0){ PrintAndLog("File reading error"); free(data); - fclose(f); return 2; } - fclose(f); - + PrintAndLog("Restoring to card"); // transfer to device @@ -1097,7 +1098,8 @@ int CmdLegicELoad(const char *Cmd) { sprintf(fnameptr, ".bin"); // open file - if ((f = fopen(filename,"rb")) == NULL) { + f = fopen(filename,"rb"); + if (!f) { PrintAndLog("File %s not found or locked", filename); free(data); return 1; @@ -1109,9 +1111,11 @@ int CmdLegicELoad(const char *Cmd) { PrintAndLog("File reading error"); free(data); fclose(f); + f = NULL; return 2; } fclose(f); + f = NULL; // transfer to device legic_seteml(data, 0, numofbytes); @@ -1171,7 +1175,8 @@ int CmdLegicESave(const char *Cmd) { sprintf(fnameptr + fileNlen,".bin"); // open file - if ((f = fopen(filename,"wb")) == NULL) { + f = fopen(filename,"wb"); + if (!f) { PrintAndLog("Could not create file name %s", filename); free(data); return 1;