mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-01-20 15:13:15 +08:00
chg 'mem spiffs load' - use loadfile_safe
This commit is contained in:
parent
5ff9cbaac0
commit
3352904f1d
1 changed files with 11 additions and 29 deletions
|
@ -330,12 +330,15 @@ static int CmdFlashMemSpiFFSLoad(const char *Cmd) {
|
||||||
if (param_getstr(Cmd, cmdp + 1, filename, FILE_PATH_SIZE) >= FILE_PATH_SIZE) {
|
if (param_getstr(Cmd, cmdp + 1, filename, FILE_PATH_SIZE) >= FILE_PATH_SIZE) {
|
||||||
PrintAndLogEx(FAILED, "Filename too long");
|
PrintAndLogEx(FAILED, "Filename too long");
|
||||||
errors = true;
|
errors = true;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
cmdp += 2;
|
cmdp += 2;
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
param_getstr(Cmd, cmdp + 1, destfilename, 32);
|
param_getstr(Cmd, cmdp + 1, destfilename, 32);
|
||||||
|
if (strlen(destfilename) == 0) {
|
||||||
|
PrintAndLogEx(FAILED, "Destination Filename missing or invalid");
|
||||||
|
errors = true;
|
||||||
|
}
|
||||||
cmdp += 2;
|
cmdp += 2;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -345,42 +348,20 @@ static int CmdFlashMemSpiFFSLoad(const char *Cmd) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (destfilename[0] == '\0') {
|
|
||||||
PrintAndLogEx(FAILED, "Destination Filename missing or invalid");
|
|
||||||
errors = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validations
|
// Validations
|
||||||
if (errors || cmdp == 0) {
|
if (errors || cmdp == 0)
|
||||||
usage_flashmemspiffs_load();
|
return usage_flashmemspiffs_load();
|
||||||
return PM3_EINVARG;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t datalen = 0;
|
size_t datalen = 0;
|
||||||
int res = 0;
|
uint8_t *data = NULL;
|
||||||
uint8_t *data = calloc(FLASH_MEM_MAX_SIZE, sizeof(uint8_t));
|
|
||||||
|
|
||||||
res = loadFile(filename, "", data, FLASH_MEM_MAX_SIZE, &datalen);
|
int res = loadFile_safe(filename, "", (void**)&data, &datalen);
|
||||||
// int res = loadFileEML( filename, data, &datalen);
|
// int res = loadFileEML( filename, data, &datalen);
|
||||||
if (res) {
|
if (res != PM3_SUCCESS) {
|
||||||
free(data);
|
free(data);
|
||||||
return PM3_EFILE;
|
return PM3_EFILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (datalen > FLASH_MEM_MAX_SIZE) {
|
|
||||||
PrintAndLogEx(ERR, "error, filesize is larger than available memory");
|
|
||||||
free(data);
|
|
||||||
return PM3_EOVFLOW;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t *newdata = realloc(data, datalen);
|
|
||||||
if (newdata == NULL) {
|
|
||||||
free(data);
|
|
||||||
return PM3_EMALLOC;
|
|
||||||
} else {
|
|
||||||
data = newdata;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We want to mount before multiple operation so the lazy writes/append will not
|
// We want to mount before multiple operation so the lazy writes/append will not
|
||||||
// trigger a mount + umount each loop iteration (lazy ops device side)
|
// trigger a mount + umount each loop iteration (lazy ops device side)
|
||||||
SendCommandNG(CMD_SPIFFS_MOUNT, NULL, 0);
|
SendCommandNG(CMD_SPIFFS_MOUNT, NULL, 0);
|
||||||
|
@ -425,6 +406,7 @@ static int CmdFlashMemSpiFFSLoad(const char *Cmd) {
|
||||||
if (!isok) {
|
if (!isok) {
|
||||||
conn.block_after_ACK = false;
|
conn.block_after_ACK = false;
|
||||||
PrintAndLogEx(FAILED, "Flash write fail [offset %u]", bytes_sent);
|
PrintAndLogEx(FAILED, "Flash write fail [offset %u]", bytes_sent);
|
||||||
|
free(data);
|
||||||
return PM3_EFLASH;
|
return PM3_EFLASH;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue