o0 & windownames
This commit is contained in:
parent
42b30b1bf8
commit
517f117575
2 changed files with 27 additions and 159 deletions
|
|
@ -1,4 +1,4 @@
|
|||
QMAKE_CXXFLAGS += --target=x86_64-w64-mingw32 -g -gcodeview -Og
|
||||
QMAKE_CXXFLAGS += --target=x86_64-w64-mingw32 -g -gcodeview -O0 -Werror=return-type
|
||||
QMAKE_LFLAGS += --target=x86_64-w64-mingw32 -g -Wl,-pdb= -v
|
||||
LIBS += -LC:/capybara/libclang/x86_64-w64-mingw32/lib -lWinmm -lodbc32 -lodbccp32 -luuid -loleaut32 -lole32 -lshell32 -ladvapi32 -lcomdlg32 -lwinspool -lgdi32 -luser32 -lkernel32 -lpropsys -static -stdlib=libc++ -lunwind
|
||||
#"kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" -luuid -loleaut32 -lole32 -lshell32 -ladvapi32 -lcomdlg32 -lwinspool -lgdi32 -luser32 -lkernel32
|
||||
|
|
|
|||
|
|
@ -350,178 +350,46 @@ bool Session::fetchNameViaMSIX(std::wstring exePath, DWORD pid, std::wstring *se
|
|||
|
||||
}
|
||||
|
||||
BOOL test(HWND hwnd, LPARAM lParam) {
|
||||
int length = GetWindowTextLength(hwnd);
|
||||
wchar_t* buffer = new wchar_t[length + 1];
|
||||
GetWindowTextW(hwnd, buffer, length + 1);
|
||||
std::wstring windowTitle(buffer);
|
||||
delete[] buffer;
|
||||
|
||||
// List visible windows with a non-empty title
|
||||
if (IsWindowVisible(hwnd) && length != 0) {
|
||||
//std::wcout << hwnd << ": " << windowTitle << std::endl;
|
||||
log_wdebugcpp(windowTitle);
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
|
||||
/*
|
||||
* auto pParams = (DWORD)(lParam);
|
||||
*
|
||||
* DWORD processId;
|
||||
* if (GetWindowThreadProcessId(hwnd, &processId) && processId == pParams) {
|
||||
* // Stop enumerating
|
||||
* //SetLastError(-1);
|
||||
* //pParams->first = hwnd;
|
||||
* //return FALSE;
|
||||
* }
|
||||
*
|
||||
* // Continue enumerating
|
||||
* return TRUE;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
bool Session::fetchNameViaWindowName(std::wstring exePath, DWORD pid, std::wstring *sessionName) {
|
||||
//lParam is documented as in, so... Beware of future explosions, ig?
|
||||
std::pair<HWND, DWORD> params = { 0, pid };
|
||||
|
||||
BOOL result = EnumWindows(test, NULL);
|
||||
|
||||
/*
|
||||
* if (!params.first) goto msix;
|
||||
*/
|
||||
|
||||
BOOL result = EnumWindows([](HWND hwnd, LPARAM lParam) -> BOOL {
|
||||
auto pParams = (std::pair<HWND, DWORD>*)(lParam);
|
||||
|
||||
/*
|
||||
* if (!result && GetLastError() == -1 && params.first) {
|
||||
* return params.first;
|
||||
* }
|
||||
*/
|
||||
DWORD processId;
|
||||
if (GetWindowThreadProcessId(hwnd, &processId) && processId == pParams->second) {
|
||||
// Stop enumerating
|
||||
SetLastError(-1);
|
||||
pParams->first = hwnd;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Continue enumerating
|
||||
return TRUE;
|
||||
} , (LPARAM)¶ms);
|
||||
|
||||
if(!result && GetLastError() == -1 && params.first) {
|
||||
int length = GetWindowTextLength(params.first);
|
||||
wchar_t* buffer = new wchar_t[length + 1];
|
||||
GetWindowTextW(params.first, buffer, length + 1);
|
||||
*sessionName = buffer;
|
||||
delete[] buffer;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Session::fetchName(std::wstring exePath, DWORD pid) {
|
||||
if(fetchNameViaWindowName(exePath, pid, &this->sessionName))
|
||||
if(fetchNameViaFD(exePath, pid, &this->sessionName))
|
||||
return;
|
||||
else if(fetchNameViaMSIX(exePath, pid, &this->sessionName))
|
||||
return;
|
||||
else if(!fetchNameViaFD(exePath, pid, &this->sessionName))
|
||||
else if(!fetchNameViaWindowName(exePath, pid, &this->sessionName))
|
||||
this->sessionName = exePath;
|
||||
|
||||
/*
|
||||
* std::thread ttest(&Session::fetchNameViaWindowName, this, exePath, pid, &this->sessionName);
|
||||
* ttest.join();
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
* std::wstring Session::fetchProcessName(DWORD pid) {
|
||||
* /\* Executable path retrieval *\/
|
||||
* std::wstring exePath = L"";
|
||||
* std::wstring msixName;
|
||||
*
|
||||
* HANDLE processList = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, pid);
|
||||
* if (processList == INVALID_HANDLE_VALUE) {
|
||||
* log_wdebugcpp(L"aye no procname.");
|
||||
* return exePath;
|
||||
* }
|
||||
*
|
||||
* MODULEENTRY32W me32w;
|
||||
* me32w.dwSize = sizeof(MODULEENTRY32W);
|
||||
* if(Module32FirstW(processList, &me32w)) {
|
||||
* do {
|
||||
* if (me32w.th32ProcessID == pid) {
|
||||
* exePath = std::wstring(me32w.szExePath);
|
||||
* break;
|
||||
* /\*
|
||||
* * However, if the calling process is a 32-bit process, you must call the
|
||||
* * QueryFullProcessImageName function to retrieve the full path of the
|
||||
* * executable file for a 64-bit process.
|
||||
* *\/
|
||||
* }
|
||||
* } while(Module32NextW(processList, &me32w));
|
||||
* }
|
||||
* CloseHandle(processList);
|
||||
*
|
||||
*
|
||||
* //No FD info available. Window name?
|
||||
* nofdinfo:
|
||||
* if(fileVersionInfo)
|
||||
* free(fileVersionInfo);
|
||||
*
|
||||
* std::pair<HWND, DWORD> params = { 0, pid };
|
||||
* BOOL result = EnumWindows([](HWND hwnd, LPARAM lParam) -> BOOL {
|
||||
* auto pParams = (std::pair<HWND, DWORD>*)(lParam);
|
||||
*
|
||||
* DWORD processId;
|
||||
* if (GetWindowThreadProcessId(hwnd, &processId) && processId == pParams->second) {
|
||||
* // Stop enumerating
|
||||
* SetLastError(-1);
|
||||
* pParams->first = hwnd;
|
||||
* return FALSE;
|
||||
* }
|
||||
*
|
||||
* // Continue enumerating
|
||||
* return TRUE;
|
||||
* }, (LPARAM)¶ms);
|
||||
*
|
||||
* if (!params.first) goto msix;
|
||||
*
|
||||
*
|
||||
* /\*
|
||||
* * if (!result && GetLastError() == -1 && params.first) {
|
||||
* * return params.first;
|
||||
* * }
|
||||
* *\/
|
||||
*
|
||||
* //No window info. MSIX?
|
||||
* HANDLE process = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid);
|
||||
* if(!process) return exePath;
|
||||
*
|
||||
* //constant missing in mingw64. TB removed when I upgrade to a mingw64 ver that has it
|
||||
* #define APPLICATION_USER_MODEL_ID_MAX_LENGTH 130
|
||||
* uint32_t length = APPLICATION_USER_MODEL_ID_MAX_LENGTH;
|
||||
* PWSTR userModelId = (PWSTR)malloc(length * sizeof(wchar_t));
|
||||
* if(GetApplicationUserModelId(process, &length, userModelId) != ERROR_SUCCESS) {
|
||||
* CloseHandle(process);
|
||||
* return exePath;
|
||||
* }
|
||||
* CloseHandle(process);
|
||||
*
|
||||
* static constexpr wchar_t* prefix = L"shell:appsfolder\\";
|
||||
* uint32_t prefixLen = wcslen(prefix);
|
||||
* uint32_t userModelIdLen = wcslen(userModelId);
|
||||
* wchar_t* fullName;
|
||||
* fullName = (prefixLen + userModelIdLen < length)
|
||||
* ? (wchar_t*)malloc(length * sizeof(wchar_t))
|
||||
* : (wchar_t*)malloc((length * 2) * sizeof(wchar_t));
|
||||
* for (int32_t i = prefixLen - 1; i >= 0; i--) {
|
||||
* fullName[i] = prefix[i];
|
||||
* }
|
||||
* for (uint32_t i = 0; i < userModelIdLen + 1; i++) {
|
||||
* fullName[prefixLen + i] = userModelId[i];
|
||||
* }
|
||||
*
|
||||
* IShellItem* si;
|
||||
* HRESULT hr = SHCreateItemFromParsingName(fullName,
|
||||
* nullptr,
|
||||
* IID_IShellItem,
|
||||
* (void**)&si
|
||||
* );
|
||||
* free(fullName);
|
||||
* LPWSTR humanName = nullptr;
|
||||
* si->GetDisplayName(SIGDN_NORMALDISPLAY, &humanName);
|
||||
* if(humanName && humanName[0] != '\0') {
|
||||
* msixName = std::wstring(humanName);
|
||||
* CoTaskMemFree(humanName);
|
||||
* }
|
||||
* if(si) si->Release();
|
||||
*
|
||||
* if (msixName.length() > 0)
|
||||
* return msixName;
|
||||
* else return exePath;
|
||||
* }
|
||||
*/
|
||||
|
||||
//todo: conflicting names. change callback name
|
||||
void Session::setState(SessionState state) {
|
||||
sessionState = state;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue