chg: 'hf lto restore' - now uses save loads and case-ignore extensions

This commit is contained in:
iceman1001 2020-06-03 17:28:29 +02:00
commit bbd9271fa3

View file

@ -566,13 +566,7 @@ static int CmdHfLTRestore(const char *Cmd) {
uint8_t cmdp = 0; uint8_t cmdp = 0;
bool errors = false; bool errors = false;
int is_data_loaded = PM3_ESOFT;
char filename[FILE_PATH_SIZE] = {0}; char filename[FILE_PATH_SIZE] = {0};
char extension[FILE_PATH_SIZE] = {0};
uint8_t dump_data[CM_MEM_MAX_SIZE] = {0};
size_t dump_datalen = 0;
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch (tolower(param_getchar(Cmd, cmdp))) { switch (tolower(param_getchar(Cmd, cmdp))) {
@ -580,8 +574,9 @@ static int CmdHfLTRestore(const char *Cmd) {
return usage_lto_restore(); return usage_lto_restore();
case 'f': case 'f':
param_getstr(Cmd, cmdp + 1, filename, FILE_PATH_SIZE); param_getstr(Cmd, cmdp + 1, filename, FILE_PATH_SIZE);
if (strlen(filename) == 0) if (strlen(filename) < 5)
errors = true; errors = true;
cmdp += 2; cmdp += 2;
break; break;
default: default:
@ -591,40 +586,33 @@ static int CmdHfLTRestore(const char *Cmd) {
} }
} }
if (errors || (strlen(filename)) == 0) { if (errors || strlen(Cmd) == 0 ) {
usage_lto_restore(); return usage_lto_restore();
return PM3_EINVARG;
} }
// split file name into prefix and ext. size_t dump_len = 0;
int fnLength; char *lowstr = str_dup(filename);
str_lower(lowstr);
fnLength = strlen(filename); if (str_endswith(lowstr, ".bin")) {
if (fnLength > 4) { uint8_t *dump = NULL;
memcpy(extension, &filename[fnLength - 4], 4); if (loadFile_safe(filename, "", (void**)&dump, &dump_len) == PM3_SUCCESS) {
extension[5] = 0x00; restoreLTO(dump, true);
free(dump);
// check if valid file extension and attempt to load data
if (memcmp(extension, ".bin", 4) == 0) {
filename[fnLength - 4] = 0x00;
is_data_loaded = loadFile(filename, ".bin", dump_data, sizeof(dump_data), &dump_datalen);
} else if (memcmp(extension, ".eml", 4) == 0) {
filename[fnLength - 4] = 0x00;
dump_datalen = 12;
is_data_loaded = loadFileEML(filename, (uint8_t *)dump_data, &dump_datalen);
} else
PrintAndLogEx(WARNING, "\nWarning: invalid dump filename "_YELLOW_("%s")" to restore!\n", filename);
} }
} else if (str_endswith(lowstr, ".eml")) {
if (is_data_loaded == PM3_SUCCESS) { uint8_t *dump = NULL;
return restoreLTO(dump_data, true); if (loadFileEML_safe(filename, (void**)&dump, &dump_len) == PM3_SUCCESS) {
restoreLTO(dump, true);
free(dump);
}
} else { } else {
return PM3_EFILE; PrintAndLogEx(WARNING, "Warning: invalid dump filename " _YELLOW_("%s") " to restore", filename);
} }
free(lowstr);
return PM3_SUCCESS;
} }
static command_t CommandTable[] = { static command_t CommandTable[] = {