mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 13:53:55 -07:00
chg: 'hf mfu restore' - now uses fileutils
This commit is contained in:
parent
e26f57628a
commit
8898000dac
1 changed files with 6 additions and 25 deletions
|
@ -2127,7 +2127,6 @@ static int CmdHF14AMfURestore(const char *Cmd) {
|
||||||
bool read_key = false;
|
bool read_key = false;
|
||||||
bool verbose = false;
|
bool verbose = false;
|
||||||
size_t filelen = 0;
|
size_t filelen = 0;
|
||||||
FILE *f;
|
|
||||||
|
|
||||||
memset(authkey, 0x00, sizeof(authkey));
|
memset(authkey, 0x00, sizeof(authkey));
|
||||||
|
|
||||||
|
@ -2188,35 +2187,17 @@ static int CmdHF14AMfURestore(const char *Cmd) {
|
||||||
//Validations
|
//Validations
|
||||||
if (errors || cmdp == 0) return usage_hf_mfu_restore();
|
if (errors || cmdp == 0) return usage_hf_mfu_restore();
|
||||||
|
|
||||||
if ((f = fopen(filename, "rb")) == NULL) {
|
uint8_t *dump = NULL;
|
||||||
|
size_t bytes_read = 0;
|
||||||
|
if (loadFile_safe(filename, "", (void**)&dump, &bytes_read) != PM3_SUCCESS) {
|
||||||
PrintAndLogEx(WARNING, "Could not find file " _YELLOW_("%s"), filename);
|
PrintAndLogEx(WARNING, "Could not find file " _YELLOW_("%s"), filename);
|
||||||
return 1;
|
return PM3_EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get filesize to know how memory to allocate
|
|
||||||
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 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// read all data
|
|
||||||
size_t bytes_read = fread(dump, 1, fsize, f);
|
|
||||||
fclose(f);
|
|
||||||
if (bytes_read < MFU_DUMP_PREFIX_LENGTH) {
|
if (bytes_read < MFU_DUMP_PREFIX_LENGTH) {
|
||||||
PrintAndLogEx(ERR, "Error, dump file is too small");
|
PrintAndLogEx(ERR, "Error, dump file is too small");
|
||||||
free(dump);
|
free(dump);
|
||||||
return 1;
|
return PM3_ESOFT;
|
||||||
}
|
}
|
||||||
|
|
||||||
int res = convert_mfu_dump_format(&dump, &bytes_read, verbose);
|
int res = convert_mfu_dump_format(&dump, &bytes_read, verbose);
|
||||||
|
@ -2232,7 +2213,7 @@ static int CmdHF14AMfURestore(const char *Cmd) {
|
||||||
if (pages - 1 != mem->pages) {
|
if (pages - 1 != mem->pages) {
|
||||||
PrintAndLogEx(ERR, "Error, invalid dump, wrong page count");
|
PrintAndLogEx(ERR, "Error, invalid dump, wrong page count");
|
||||||
free(dump);
|
free(dump);
|
||||||
return 1;
|
return PM3_ESOFT;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintAndLogEx(INFO, "Restoring " _YELLOW_("%s")" to card", filename);
|
PrintAndLogEx(INFO, "Restoring " _YELLOW_("%s")" to card", filename);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue