From eca02a12eb933c208ef9dca59bc156350d5ff287 Mon Sep 17 00:00:00 2001 From: Exant64 Date: Mon, 3 Jun 2024 16:58:13 +0200 Subject: [PATCH 1/2] Added quotation mark check in files::pathFromWindows --- files.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/files.cpp b/files.cpp index 2701d30..9fb98c3 100644 --- a/files.cpp +++ b/files.cpp @@ -15,6 +15,11 @@ namespace files { std::string str = inStr; std::replace(str.begin(), str.end(), '\\', '/'); + // Detect quotation marks around path, and remove them + if (str.length() >= 2 && str.front() == '"' && str.back() == '"') { + str = str.substr(1, str.length() - 2); + } + // Remove "//?/" prefix if (str.rfind("//?/", 0) == 0) { str.erase(0, 4); From 2d45aeae0cabd6b31bb6c2094414f16c815813da Mon Sep 17 00:00:00 2001 From: Exant64 Date: Fri, 7 Jun 2024 11:56:52 +0200 Subject: [PATCH 2/2] Moved quotation mark logic to createprocess argument processing code --- dll/kernel32.cpp | 14 ++++++++++++++ files.cpp | 5 ----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/dll/kernel32.cpp b/dll/kernel32.cpp index f5195d8..6a03ea3 100644 --- a/dll/kernel32.cpp +++ b/dll/kernel32.cpp @@ -226,6 +226,20 @@ namespace kernel32 { // to prevent from doubling up on the target executable name // (it appears as lpApplicationName, and as the first token in lpCommandLine) arg = strtok(NULL, " "); + + if (arg) { + // Trim all quotation marks from the start and the end of the string + while(*arg == '\"') { + arg++; + } + + char* end = arg + strlen(arg) - 1; + while(end > arg && *end == '\"') { + *end = '\0'; + end--; + } + } + argv[current_arg_index++] = arg; } diff --git a/files.cpp b/files.cpp index 9fb98c3..2701d30 100644 --- a/files.cpp +++ b/files.cpp @@ -15,11 +15,6 @@ namespace files { std::string str = inStr; std::replace(str.begin(), str.end(), '\\', '/'); - // Detect quotation marks around path, and remove them - if (str.length() >= 2 && str.front() == '"' && str.back() == '"') { - str = str.substr(1, str.length() - 2); - } - // Remove "//?/" prefix if (str.rfind("//?/", 0) == 0) { str.erase(0, 4);