Exclude certain files from injection

No virtual as origin, no injecting file into itself
This commit is contained in:
d0k3 2016-06-18 15:23:21 +02:00
parent d4df8bbb3d
commit e388dd4ca7
2 changed files with 9 additions and 2 deletions

View File

@ -314,6 +314,10 @@ bool FileInjectFile(const char* dest, const char* orig, u32 offset) {
bool ret; bool ret;
if (!CheckWritePermissions(dest)) return false; if (!CheckWritePermissions(dest)) return false;
if (strncmp(dest, orig, 256) == 0) {
ShowPrompt(false, "Error: Can't inject file into itself");
return false;
}
// open destination // open destination
if (GetVirtualSource(dest)) { if (GetVirtualSource(dest)) {

View File

@ -438,7 +438,10 @@ u32 GodMode() {
} else cursor = 0; } else cursor = 0;
} else if ((pad_state & BUTTON_A) && (curr_entry->type == T_FILE)) { // process a file } else if ((pad_state & BUTTON_A) && (curr_entry->type == T_FILE)) { // process a file
u32 file_type = IdentifyImage(curr_entry->path); u32 file_type = IdentifyImage(curr_entry->path);
bool injectable = (clipboard->n_entries == 1) && (clipboard->entry[0].type == T_FILE); bool injectable = (clipboard->n_entries == 1) &&
(clipboard->entry[0].type == T_FILE) &&
(PathToNumFS(clipboard->entry[0].path) >= 0) &&
(strncmp(clipboard->entry[0].path, curr_entry->path, 256) != 0);
char pathstr[32 + 1]; char pathstr[32 + 1];
const char* optionstr[4]; const char* optionstr[4];
u32 n_opt = 2; u32 n_opt = 2;
@ -503,7 +506,7 @@ u32 GodMode() {
clipboard->n_entries = 0; // remove invalid clipboard stuff clipboard->n_entries = 0; // remove invalid clipboard stuff
} else if (injectable && (user_select == 3)) { // -> inject data from clipboard } else if (injectable && (user_select == 3)) { // -> inject data from clipboard
char origstr[18 + 1]; char origstr[18 + 1];
TruncateString(origstr, clipboard->entry[0].name, 18, 8); TruncateString(origstr, clipboard->entry[0].name, 18, 10);
u64 offset = ShowHexPrompt(0, 8, "Inject data from %s?\nSpecifiy offset below.", origstr); u64 offset = ShowHexPrompt(0, 8, "Inject data from %s?\nSpecifiy offset below.", origstr);
if ((offset != (u64) -1) && !FileInjectFile(curr_entry->path, clipboard->entry[0].path, (u32) offset)) if ((offset != (u64) -1) && !FileInjectFile(curr_entry->path, clipboard->entry[0].path, (u32) offset))
ShowPrompt(false, "Failed injecting %s", origstr); ShowPrompt(false, "Failed injecting %s", origstr);