mirror of
https://github.com/tnodir/fort
synced 2024-11-15 10:55:10 +00:00
UI: ServicesPage: Show only svchost.exe
services
This commit is contained in:
parent
b4b2338b41
commit
128d818286
@ -5,6 +5,8 @@
|
|||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include <qt_windows.h>
|
#include <qt_windows.h>
|
||||||
|
|
||||||
|
#include <util/regkey.h>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
const QLoggingCategory LC("serviceInfo.serviceInfoManager");
|
const QLoggingCategory LC("serviceInfo.serviceInfoManager");
|
||||||
@ -13,6 +15,8 @@ QVector<ServiceInfo> getServiceInfoList(SC_HANDLE mngr, DWORD state = SERVICE_ST
|
|||||||
{
|
{
|
||||||
QVector<ServiceInfo> infoList;
|
QVector<ServiceInfo> infoList;
|
||||||
|
|
||||||
|
const RegKey servicesReg(RegKey::HKLM, R"(SYSTEM\CurrentControlSet\Services)");
|
||||||
|
|
||||||
constexpr DWORD bufferMaxSize = 32 * 1024;
|
constexpr DWORD bufferMaxSize = 32 * 1024;
|
||||||
ENUM_SERVICE_STATUS_PROCESSW buffer[bufferMaxSize / sizeof(ENUM_SERVICE_STATUS_PROCESSW)];
|
ENUM_SERVICE_STATUS_PROCESSW buffer[bufferMaxSize / sizeof(ENUM_SERVICE_STATUS_PROCESSW)];
|
||||||
DWORD bytesRemaining = 0;
|
DWORD bytesRemaining = 0;
|
||||||
@ -23,16 +27,26 @@ QVector<ServiceInfo> getServiceInfoList(SC_HANDLE mngr, DWORD state = SERVICE_ST
|
|||||||
sizeof(buffer), &bytesRemaining, &serviceCount, &resumePoint, nullptr)
|
sizeof(buffer), &bytesRemaining, &serviceCount, &resumePoint, nullptr)
|
||||||
|| GetLastError() == ERROR_MORE_DATA) {
|
|| GetLastError() == ERROR_MORE_DATA) {
|
||||||
|
|
||||||
int infoIndex = infoList.size();
|
|
||||||
infoList.resize(infoIndex + serviceCount);
|
|
||||||
|
|
||||||
const ENUM_SERVICE_STATUS_PROCESSW *service = &buffer[0];
|
const ENUM_SERVICE_STATUS_PROCESSW *service = &buffer[0];
|
||||||
|
|
||||||
for (; serviceCount > 0; --serviceCount, ++service, ++infoIndex) {
|
for (int infoIndex = infoList.size(); serviceCount > 0;
|
||||||
ServiceInfo &info = infoList[infoIndex];
|
--serviceCount, ++service, ++infoIndex) {
|
||||||
|
const auto serviceName = QString::fromUtf16((const char16_t *) service->lpServiceName);
|
||||||
|
|
||||||
|
const RegKey svcReg(servicesReg, serviceName);
|
||||||
|
if (!svcReg.contains("ServiceSidType"))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const auto imagePath = svcReg.value("ImagePath").toString();
|
||||||
|
if (!imagePath.contains(R"(\system32\svchost.exe)", Qt::CaseInsensitive))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
ServiceInfo info;
|
||||||
info.processId = service->ServiceStatusProcess.dwProcessId;
|
info.processId = service->ServiceStatusProcess.dwProcessId;
|
||||||
info.serviceName = QString::fromUtf16((const char16_t *) service->lpServiceName);
|
info.serviceName = serviceName;
|
||||||
info.displayName = QString::fromUtf16((const char16_t *) service->lpDisplayName);
|
info.displayName = QString::fromUtf16((const char16_t *) service->lpDisplayName);
|
||||||
|
|
||||||
|
infoList.append(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bytesRemaining == 0)
|
if (bytesRemaining == 0)
|
||||||
|
@ -95,6 +95,31 @@ bool RegKey::setValue(const QString &name, const QVariant &value)
|
|||||||
return !RegSetValueEx((HKEY) handle(), (LPCWSTR) name.utf16(), 0, type, data, size);
|
return !RegSetValueEx((HKEY) handle(), (LPCWSTR) name.utf16(), 0, type, data, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVariant RegKey::value(const QString &name, bool *expand) const
|
||||||
|
{
|
||||||
|
char data[16 * 1024];
|
||||||
|
DWORD len = sizeof(data);
|
||||||
|
DWORD type;
|
||||||
|
|
||||||
|
if (!RegQueryValueEx((HKEY) handle(), (LPCWSTR) name.utf16(), 0, &type, (LPBYTE) data, &len)) {
|
||||||
|
switch (type) {
|
||||||
|
case REG_EXPAND_SZ:
|
||||||
|
if (expand) {
|
||||||
|
*expand = true;
|
||||||
|
}
|
||||||
|
Q_FALLTHROUGH();
|
||||||
|
case REG_SZ:
|
||||||
|
return QString::fromWCharArray((LPCWSTR) data, len);
|
||||||
|
case REG_DWORD:
|
||||||
|
return *((qint32 *) data);
|
||||||
|
case REG_QWORD:
|
||||||
|
return *((qint64 *) data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
bool RegKey::contains(const QString &name) const
|
bool RegKey::contains(const QString &name) const
|
||||||
{
|
{
|
||||||
return !RegQueryValueEx((HKEY) handle(), (LPCWSTR) name.utf16(), 0, nullptr, nullptr, nullptr);
|
return !RegQueryValueEx((HKEY) handle(), (LPCWSTR) name.utf16(), 0, nullptr, nullptr, nullptr);
|
||||||
|
@ -41,6 +41,7 @@ public:
|
|||||||
bool removeValue(const QString &name);
|
bool removeValue(const QString &name);
|
||||||
bool setValue(const QString &name, const QVariant &value);
|
bool setValue(const QString &name, const QVariant &value);
|
||||||
bool setDefaultValue(const QVariant &value) { return setValue(QString(), value); }
|
bool setDefaultValue(const QVariant &value) { return setValue(QString(), value); }
|
||||||
|
QVariant value(const QString &name, bool *expand = nullptr) const;
|
||||||
bool contains(const QString &name) const;
|
bool contains(const QString &name) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user