Add EM410x bruteforcing error checks

This commit is contained in:
Fl0-0 2017-06-30 10:00:03 +02:00
commit 47af8c5fa9

View file

@ -301,6 +301,7 @@ int usage_lf_em410x_brute(void) {
int CmdEM410xBrute(const char *Cmd) int CmdEM410xBrute(const char *Cmd)
{ {
char filename[FILE_PATH_SIZE]={0}; char filename[FILE_PATH_SIZE]={0};
FILE *f = NULL;
char buf[11]; char buf[11];
int i, n, j, binary[4], parity[4]; int i, n, j, binary[4], parity[4];
@ -314,14 +315,17 @@ int CmdEM410xBrute(const char *Cmd)
param_getdec(Cmd,1, &clock); param_getdec(Cmd,1, &clock);
param_getstr(Cmd, 0, filename); param_getstr(Cmd, 0, filename);
PrintAndLog("Filename: %s", filename);
FILE *f = fopen(filename, "r"); if (strlen(filename) > 0) {
if ((f = fopen(filename, "r")) == NULL) {
if(!f) { PrintAndLog("Error: Could not open IDs file [%s]",filename);
PrintAndLog("Couldn't open '%s'", Cmd); return 1;
return 0;
} }
} else {
PrintAndLog("Error: Please specify a filename");
return 1;
}
while( fgets(buf, sizeof(buf), f) ) { while( fgets(buf, sizeof(buf), f) ) {
msleep(1000); msleep(1000);
@ -341,7 +345,6 @@ int CmdEM410xBrute(const char *Cmd)
PrintAndLog("Starting simulating UID %02X%02X%02X%02X%02X clock: %d", uid[0],uid[1],uid[2],uid[3],uid[4],clock); PrintAndLog("Starting simulating UID %02X%02X%02X%02X%02X clock: %d", uid[0],uid[1],uid[2],uid[3],uid[4],clock);
/* clear our graph */ /* clear our graph */
ClearGraph(0); ClearGraph(0);
@ -385,15 +388,12 @@ int CmdEM410xBrute(const char *Cmd)
CmdLFSim("0"); //240 start_gap. CmdLFSim("0"); //240 start_gap.
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
} }
fclose(f); fclose(f);
return 0; return 0;
} }