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

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

View file

@ -811,7 +811,8 @@ static int CmdHFiClassDecrypt(const char *Cmd) {
case 'h':
return usage_hf_iclass_decrypt();
case 'f':
if ( param_getstr(Cmd, cmdp + 1, filename, sizeof(filename) ) == 0){
if ( param_getstr(Cmd, cmdp + 1, filename, sizeof(filename) ) == 0) {
PrintAndLogEx(WARNING, "no filename found after f");
errors = true;
break;
}
@ -1261,9 +1262,10 @@ static int CmdHFiClassReader_Dump(const char *Cmd) {
printIclassDumpContents(tag_data, 1, (gotBytes / 8), gotBytes);
if (filename[0] == 0) {
snprintf(filename, FILE_PATH_SIZE, "iclass_tagdump-%02x%02x%02x%02x%02x%02x%02x%02x",
tag_data[0], tag_data[1], tag_data[2], tag_data[3],
tag_data[4], tag_data[5], tag_data[6], tag_data[7]);
//Use the first block (CSN) for filename
strcat(filename, "hf-iclass-");
FillFileNameByUID(filename, tag_data, "-data", 8 );
}
// save the dump to .bin file
@ -1271,7 +1273,7 @@ static int CmdHFiClassReader_Dump(const char *Cmd) {
saveFile(filename, ".bin", tag_data, gotBytes);
saveFileEML(filename, tag_data, gotBytes, 8);
saveFileJSON(filename, jsfIclass, tag_data, gotBytes);
return 1;
return PM3_SUCCESS;
}
static int WriteBlock(uint8_t blockno, uint8_t *bldata, uint8_t *KEY, bool use_credit_key, bool elite, bool rawkey, bool verbose) {

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;
}