mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 05:43:48 -07:00
CHG: "hf legic restore" - added a filesize and cardsize check
This commit is contained in:
parent
cd79d97223
commit
367996567b
1 changed files with 17 additions and 5 deletions
|
@ -966,7 +966,7 @@ int CmdLegicRestore(const char *Cmd){
|
||||||
uint8_t *data = malloc(numofbytes);
|
uint8_t *data = malloc(numofbytes);
|
||||||
if (!data) {
|
if (!data) {
|
||||||
PrintAndLog("Fail, cannot allocate memory");
|
PrintAndLog("Fail, cannot allocate memory");
|
||||||
return 3;
|
return 2;
|
||||||
}
|
}
|
||||||
memset(data, 0, numofbytes);
|
memset(data, 0, numofbytes);
|
||||||
|
|
||||||
|
@ -976,14 +976,26 @@ int CmdLegicRestore(const char *Cmd){
|
||||||
fnameptr += fileNlen;
|
fnameptr += fileNlen;
|
||||||
sprintf(fnameptr, ".bin");
|
sprintf(fnameptr, ".bin");
|
||||||
|
|
||||||
PrintAndLog("Reading binary file...");
|
|
||||||
|
|
||||||
if ((f = fopen(filename,"rb")) == NULL) {
|
if ((f = fopen(filename,"rb")) == NULL) {
|
||||||
PrintAndLog("File %s not found or locked", filename);
|
PrintAndLog("File %s not found or locked", filename);
|
||||||
return 2;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
// verify size of dumpfile is the same as card.
|
// verify size of dumpfile is the same as card.
|
||||||
|
fseek(f, 0, SEEK_END); // seek to end of file
|
||||||
|
size_t filesize = ftell(f); // get current file pointer
|
||||||
|
fseek(f, 0, SEEK_SET); // seek back to beginning of file
|
||||||
|
|
||||||
|
if ( filesize != numofbytes) {
|
||||||
|
PrintAndLog("Fail, Filesize and cardsize is not equal. [%u != %u]", filesize, numofbytes);
|
||||||
|
free(data);
|
||||||
|
fclose(f);
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PrintAndLog("Reading binary file...");
|
||||||
|
|
||||||
|
|
||||||
// load file
|
// load file
|
||||||
size_t bytes_read = fread(data, 1, numofbytes, f);
|
size_t bytes_read = fread(data, 1, numofbytes, f);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue