1
0
Fork 0

Merge branch 'development' of https://github.com/x64dbg/x64dbg into development

This commit is contained in:
mrexodia 2017-06-07 04:26:53 +02:00
commit 2a73aed377
No known key found for this signature in database
GPG Key ID: FC89E0AAA0C1AAD8
2 changed files with 46 additions and 24 deletions

View File

@ -272,6 +272,7 @@ bool bNoWow64SingleStepWorkaround = false;
duint DbgEvents = 0;
duint maxSkipExceptionCount = 10000;
HANDLE mProcHandle;
HANDLE mForegroundHandle;
static duint dbgcleartracestate()
{
@ -2148,6 +2149,12 @@ cmdline_qoutes_placement_t getqoutesplacement(const char* cmdline)
return quotesPos;
}
BOOL ismainwindow(HWND handle)
{
// using only OWNER condition allows getting titles of hidden "main windows"
return !GetWindow(handle, GW_OWNER) && IsWindowVisible(handle);
}
BOOL CALLBACK chkWindowPidCallback(HWND hWnd, LPARAM lParam)
{
DWORD procId = (DWORD)lParam;
@ -2155,8 +2162,14 @@ BOOL CALLBACK chkWindowPidCallback(HWND hWnd, LPARAM lParam)
GetWindowThreadProcessId(hWnd, &hwndPid);
if(hwndPid == procId)
{
mProcHandle = hWnd;
return FALSE;
if(!mForegroundHandle) // get the foreground if no owner visible
mForegroundHandle = hWnd;
if(ismainwindow(hWnd))
{
mProcHandle = hWnd;
return FALSE;
}
}
return TRUE;
@ -2165,26 +2178,38 @@ BOOL CALLBACK chkWindowPidCallback(HWND hWnd, LPARAM lParam)
bool dbggetwintext(std::vector<std::string>* winTextList, const DWORD dwProcessId)
{
mProcHandle = NULL;
mForegroundHandle = NULL;
EnumWindows(chkWindowPidCallback, dwProcessId);
if(mProcHandle)
if(!mProcHandle && !mForegroundHandle)
return false;
wchar_t limitedbuffer[256];
limitedbuffer[255] = 0;
if(mProcHandle) // get info from the "main window" (GW_OWNER + visible)
{
wchar_t limitedbuffer[256];
limitedbuffer[255] = 0;
GetWindowTextW((HWND)mProcHandle, limitedbuffer, 256);
if(limitedbuffer[255] != 0) //Window title too long. Add "..." to the end of buffer.
{
if(limitedbuffer[252] < 0xDC00 || limitedbuffer[252] > 0xDFFF) //protect the last surrogate of UTF-16 surrogate pair
limitedbuffer[252] = L'.';
limitedbuffer[253] = L'.';
limitedbuffer[254] = L'.';
limitedbuffer[255] = 0;
}
auto UTF8WindowTitle = StringUtils::Utf16ToUtf8(limitedbuffer);
winTextList->push_back(UTF8WindowTitle);
return true;
if(!GetWindowTextW((HWND)mProcHandle, limitedbuffer, 256))
GetClassNameW((HWND)mProcHandle, limitedbuffer, 256); // go for the class name if none of the above
}
else if(mForegroundHandle) // get info from the foreground window
{
if(!GetWindowTextW((HWND)mForegroundHandle, limitedbuffer, 256))
GetClassNameW((HWND)mForegroundHandle, limitedbuffer, 256); // go for the class name if none of the above
}
return false;
if(limitedbuffer[255] != 0) //Window title too long. Add "..." to the end of buffer.
{
if(limitedbuffer[252] < 0xDC00 || limitedbuffer[252] > 0xDFFF) //protect the last surrogate of UTF-16 surrogate pair
limitedbuffer[252] = L'.';
limitedbuffer[253] = L'.';
limitedbuffer[254] = L'.';
limitedbuffer[255] = 0;
}
auto UTF8WindowTitle = StringUtils::Utf16ToUtf8(limitedbuffer);
winTextList->push_back(UTF8WindowTitle);
return true;
}
bool dbglistprocesses(std::vector<PROCESSENTRY32>* infoList, std::vector<std::string>* commandList, std::vector<std::string>* winTextList)
@ -2894,12 +2919,7 @@ bool dbgrestartadmin()
*last = L'\0';
//TODO: possibly escape characters in gInitCmd
std::wstring params = L"\"" + gInitExe + L"\" \"" + gInitCmd + L"\" \"" + gInitDir + L"\"";
OSVERSIONINFOW osvi;
memset(&osvi, 0, sizeof(osvi));
osvi.dwOSVersionInfoSize = sizeof(osvi);
GetVersionExW(&osvi);
auto operation = osvi.dwMajorVersion >= 6 ? L"runas" : L"open";
auto result = ShellExecuteW(NULL, operation, file.c_str(), params.c_str(), wszProgramPath, SW_SHOWDEFAULT);
auto result = ShellExecuteW(NULL, L"runas", file.c_str(), params.c_str(), wszProgramPath, SW_SHOWDEFAULT);
return int(result) > 32 && GetLastError() == ERROR_SUCCESS;
}
return false;

View File

@ -103,6 +103,7 @@ bool dbgrestartadmin();
void StepIntoWow64(void* traceCallBack);
bool dbgisdepenabled();
BOOL CALLBACK chkWindowPidCallback(HWND hWnd, LPARAM lParam);
BOOL ismainwindow(HWND handle);
//variables
extern PROCESS_INFORMATION* fdProcessInfo;
@ -121,5 +122,6 @@ extern bool bVerboseExceptionLogging;
extern bool bNoWow64SingleStepWorkaround;
extern duint maxSkipExceptionCount;
extern HANDLE mProcHandle;
extern HANDLE mForegroundHandle;
#endif // _DEBUGGER_H