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);
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);
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;
}
// 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
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;
PrintAndLog("File reading error");
free(data);
fclose(f);
+ f = NULL;
return 2;
}
fclose(f);
+ f = NULL;
// transfer to device
legic_seteml(data, 0, numofbytes);
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;