chg: 'hf iclass loclass t' - now uses loadfile_safe

This commit is contained in:
iceman1001
2019-08-29 14:33:09 +02:00
parent f0d73dc3d1
commit 00f82304e2
2 changed files with 13 additions and 34 deletions

View File

@@ -540,37 +540,14 @@ int bruteforceDump(uint8_t dump[], size_t dumpsize, uint16_t keytable[]) {
* @return
*/
int bruteforceFile(const char *filename, uint16_t keytable[]) {
FILE *f = fopen(filename, "rb");
if (!f) {
PrintAndLogEx(WARNING, "Failed to read from file " _YELLOW_("%s"), filename);
return 1;
size_t dumplen = 0;
uint8_t *dump = NULL;
if ( loadFile_safe(filename, "", (void**)&dump, &dumplen) != PM3_SUCCESS ) {
return PM3_EFILE;
}
fseek(f, 0, SEEK_END);
long fsize = ftell(f);
fseek(f, 0, SEEK_SET);
if (fsize <= 0) {
PrintAndLogEx(ERR, "Error, when getting filesize");
fclose(f);
return 1;
}
uint8_t *dump = calloc(fsize, sizeof(uint8_t));
if (!dump) {
PrintAndLogEx(WARNING, "Failed to allocate memory");
fclose(f);
return 2;
}
size_t bytes_read = fread(dump, 1, fsize, f);
fclose(f);
if (bytes_read < fsize) {
PrintAndLogEx(WARNING, "Warning: could only read %d bytes (should be %d)", bytes_read, fsize);
}
uint8_t res = bruteforceDump(dump, fsize, keytable);
uint8_t res = bruteforceDump(dump, dumplen, keytable);
free(dump);
return res;
}