1
0
Fork 0

DBG+LAUNCHER: better command line forwarding and escaping

This commit is contained in:
mrexodia 2017-05-01 21:40:29 +02:00
parent 4fdf3084ae
commit b725aa63c9
No known key found for this signature in database
GPG Key ID: FC89E0AAA0C1AAD8
2 changed files with 27 additions and 7 deletions

View File

@ -601,6 +601,13 @@ static DWORD WINAPI loadDbThread(LPVOID)
return 0;
}
static WString escape(WString cmdline)
{
StringUtils::ReplaceAll(cmdline, L"\\", L"\\\\");
StringUtils::ReplaceAll(cmdline, L"\"", L"\\\"");
return cmdline;
}
extern "C" DLL_EXPORT const char* _dbg_dbginit()
{
if(!EngineCheckStructAlignment(UE_STRUCT_TITAN_ENGINE_CONTEXT, sizeof(TITAN_ENGINE_CONTEXT_t)))
@ -727,12 +734,13 @@ extern "C" DLL_EXPORT const char* _dbg_dbginit()
//handle command line
int argc = 0;
wchar_t** argv = CommandLineToArgvW(GetCommandLineW(), &argc);
//MessageBoxW(0, GetCommandLineW(), StringUtils::sprintf(L"%d", argc).c_str(), MB_SYSTEMMODAL);
if(argc == 2) //1 argument (init filename)
DbgCmdExec(StringUtils::Utf16ToUtf8(StringUtils::sprintf(L"init \"%s\"", argv[1])).c_str());
DbgCmdExec(StringUtils::Utf16ToUtf8(StringUtils::sprintf(L"init \"%s\"", escape(argv[1]).c_str())).c_str());
else if(argc == 3) //2 arguments (init filename, cmdline)
DbgCmdExec(StringUtils::Utf16ToUtf8(StringUtils::sprintf(L"init \"%s\", \"%s\"", argv[1], argv[2])).c_str());
DbgCmdExec(StringUtils::Utf16ToUtf8(StringUtils::sprintf(L"init \"%s\", \"%s\"", escape(argv[1]).c_str(), escape(argv[2]).c_str())).c_str());
else if(argc == 4) //3 arguments (init filename, cmdline, currentdir)
DbgCmdExec(StringUtils::Utf16ToUtf8(StringUtils::sprintf(L"init \"%s\", \"%s\", \"%s\"", argv[1], argv[2], argv[3])).c_str());
DbgCmdExec(StringUtils::Utf16ToUtf8(StringUtils::sprintf(L"init \"%s\", \"%s\", \"%s\"", escape(argv[1]).c_str(), escape(argv[2]).c_str(), escape(argv[3]).c_str())).c_str());
else if(argc == 5 && !_wcsicmp(argv[1], L"-a") && !_wcsicmp(argv[3], L"-e")) //4 arguments (JIT)
DbgCmdExec(StringUtils::Utf16ToUtf8(StringUtils::sprintf(L"attach .%s, .%s", argv[2], argv[4])).c_str()); //attach pid, event
LocalFree(argv);

View File

@ -461,7 +461,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
else if(!ResolveShortcut(nullptr, argv[1], szPath, _countof(szPath))) //attempt to resolve the shortcut path
_tcscpy_s(szPath, argv[1]); //fall back to the origin full path
std::wstring cmdLine;
std::wstring cmdLine, escaped;
cmdLine.push_back(L'\"');
cmdLine += szPath;
cmdLine.push_back(L'\"');
@ -472,9 +472,17 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
{
if(i > 2)
cmdLine.push_back(L' ');
cmdLine.push_back(L'\"');
cmdLine += argv[i];
cmdLine.push_back(L'\"');
escaped.clear();
auto len = wcslen(argv[i]);
for(size_t i = 0; i < len; i++)
{
if(escaped[i] == L'\"')
escaped.push_back(escaped[i]);
escaped.push_back(escaped[i]);
}
cmdLine += escaped;
}
cmdLine += L"\"";
}
@ -497,6 +505,10 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
if(architecture == dotnet)
architecture = isWoW64() ? x64 : x32;
//MessageBoxW(0, cmdLine.c_str(), L"x96dbg", MB_SYSTEMMODAL);
//MessageBoxW(0, GetCommandLineW(), L"GetCommandLineW", MB_SYSTEMMODAL);
//MessageBoxW(0, szCurDir, L"GetCurrentDirectory", MB_SYSTEMMODAL);
switch(architecture)
{
case x32: