{"repo_name": "OpenSpeedy", "file_name": "/OpenSpeedy/taskscheduler.h", "inference_info": {"prefix_code": "class TaskScheduler {\n Q_OBJECT\n public:\n explicit TaskScheduler(QObject *parent = nullptr);\n ~TaskScheduler() {\n}\n bool createStartupTask(const QString &taskName,\n const QString &executablePath) {\n if (taskName.isEmpty() || executablePath.isEmpty())\n {\n qWarning() << \"任务名称或可执行文件路径不能为空\";\n return false;\n }\n\n if (!QFile::exists(executablePath))\n {\n qWarning() << \"可执行文件不存在\" << executablePath;\n return false;\n }\n\n QStringList arguments;\n arguments << \"/create\"\n << \"/f\"\n << \"/tn\" << taskName << \"/tr\"\n << QString(\"\\\"%1\\\" --minimize-to-tray\").arg(executablePath)\n << \"/sc\" << \"onlogon\"\n << \"/delay\" << \"0000:10\"\n << \"/rl\" << \"highest\";\n\n return execute(arguments);\n}\n bool deleteTask(const QString &taskName) {\n if (taskName.isEmpty())\n {\n qWarning() << \"任务名称不能为空\";\n return false;\n }\n\n if (!isTaskExists(taskName))\n {\n qWarning() << \"任务不存在, 无需删除\" << taskName;\n return true;\n }\n\n QStringList arguments;\n arguments << \"/delete\"\n << \"/f\"\n << \"/tn\" << taskName;\n\n return execute(arguments);\n}\n bool enableTask(const QString &taskName, bool enable) {\n if (!isTaskExists(taskName))\n {\n qWarning() << \"任务不存在:\" << taskName;\n return false;\n }\n\n QStringList arguments;\n arguments << \"/change\"\n << \"/tn\" << taskName << (enable ? \"/enable\" : \"/disable\");\n return execute(arguments);\n}\n bool isTaskExists(const QString &taskName) {\n QStringList arguments;\n arguments << \"/query\" << \"/tn\" << taskName;\n\n return execute(arguments);\n}\n ", "suffix_code": "\n bool createStartupShortcut(const QString &taskName,\n const QString &executablePath) {\n QString home = QDir::homePath();\n QString startupDir =\n home +\n \"\\\\AppData\\\\Roaming\\\\Microsoft\\\\Windows\\\\Start Menu\\\\Programs\\\\Startup\";\n QString shortcutPath = QDir(startupDir).absoluteFilePath(taskName + \".lnk\");\n QString arguments = \"--minimize-to-tray\";\n\n QString psScript =\n QString(\"$WScriptShell = New-Object -ComObject WScript.Shell; \"\n \"$Shortcut = $WScriptShell.CreateShortcut('%1'); \"\n \"$Shortcut.TargetPath = '%2'; \"\n \"$Shortcut.Arguments = '%3'; \"\n \"$Shortcut.Description = '%4'; \"\n \"$Shortcut.Save()\")\n .arg(shortcutPath, executablePath, arguments,\n QString(\"启动 %1\").arg(QFileInfo(executablePath).baseName()));\n\n return executePs(psScript);\n}\n bool deleteStartupShortcut(const QString &taskName) {\n QString home = QDir::homePath();\n QString startupDir =\n home + \"\\\\AppData\\\\Roaming\\\\Microsoft\\\\Windows\\\\Start Menu\\\\Programs\\\\Startup\";\n QString shortcutPath = QDir(startupDir).absoluteFilePath(taskName + \".lnk\");\n\n QString psScript = QString(\"Remove-Item '%1' -Force\").arg(shortcutPath);\n\n return executePs(psScript);\n}\n bool isStartupShortcutExists(const QString &taskName) {\n QString home = QDir::homePath();\n QString startupDir =\n home +\n \"\\\\AppData\\\\Roaming\\\\Microsoft\\\\Windows\\\\Start Menu\\\\Programs\\\\Startup\";\n QString shortcutPath = QDir(startupDir).absoluteFilePath(taskName + \".lnk\");\n\n return QFile::exists(shortcutPath);\n}\n bool executePs(const QString &psScript) {\n QProcess process;\n process.setProgram(\"powershell\");\n process.setArguments({\"-ExecutionPolicy\", \"Bypass\", \"-Command\", psScript});\n\n process.start();\n if (!process.waitForStarted(5000))\n {\n qDebug() << \"PowerShell 启动失败:\" << process.errorString();\n return false;\n }\n\n if (process.waitForFinished(5000) && process.exitCode() == 0)\n {\n qDebug() << \"PowerShell 执行成功\";\n return true;\n }\n else\n {\n QString error = QString::fromLocal8Bit(process.readAllStandardError());\n qDebug() << \"PowerShell 执行失败:\" << error;\n }\n\n return false;\n}\n};", "middle_code": "bool execute(const QStringList &arguments) {\n QProcess process;\n process.setProgram(\"schtasks\");\n process.setArguments(arguments);\n const int timeout = 10000;\n process.start();\n if (!process.waitForStarted(timeout))\n {\n qWarning() << \"无法运行:\" << process.errorString();\n return false;\n }\n if (!process.waitForFinished(timeout))\n {\n qWarning() << \"执行超时\";\n process.kill();\n return false;\n }\n int exitcode = process.exitCode();\n QString stdout_ = QString::fromLocal8Bit(process.readAllStandardOutput());\n QString stderr_ = QString::fromLocal8Bit(process.readAllStandardError());\n if (exitcode == 0)\n {\n qDebug() << \"执行成功:\" << arguments;\n qDebug() << \"输出:\" << stdout_;\n return true;\n }\n else\n {\n qDebug() << \"执行失败:\" << arguments;\n qDebug() << \"错误输出:\" << stderr_;\n qDebug() << \"标准输出:\" << stdout_;\n return false;\n }\n}", "code_description": null, "fill_type": "FUNCTION_TYPE", "language_type": "cpp", "sub_task_type": null}, "context_code": [["/OpenSpeedy/processmonitor.h", "class ProcessMonitor {\n Q_OBJECT\npublic:\nexplicit ProcessMonitor(QSettings* settings,\n QTreeWidget* treeWidget,\n QLabel* treeStatusLabel,\n QLabel* injector32StatusLabel,\n QLabel* injector64StatusLabel,\n\n QObject* parent = nullptr);\n ~ProcessMonitor() {\n this->terminalBridge();\n delete m_bridge32;\n delete m_bridge64;\n}\n void setInterval(int msec);\n void setFilter(QString processName) {\n m_filter = processName.toLower();\n}\n void changeSpeed(double factor) {\n QString cmd = QString(\"change %1\\n\").arg(factor);\n m_bridge32->write(cmd.toUtf8(), cmd.size());\n m_bridge32->waitForBytesWritten();\n m_bridge64->write(cmd.toUtf8(), cmd.size());\n m_bridge64->waitForBytesWritten();\n}\n public:\n void refresh() {\n healthcheckBridge();\n QList processList = winutils::getProcessList();\n if (m_filter == \"\")\n {\n update(processList);\n m_treeStatusLabel->setText(QString(tr(\"搜索到%1个进程, 已过滤展示%2个\"))\n .arg(processList.size())\n .arg(processList.size()));\n }\n else\n {\n QList filtered;\n for (ProcessInfo info : processList)\n {\n if (info.name.toLower().contains(m_filter))\n filtered.append(info);\n }\n update(filtered);\n m_treeStatusLabel->setText(QString(tr(\"搜索到%1个进程, 已过滤展示%2个\"))\n .arg(processList.size())\n .arg(filtered.size()));\n }\n}\n void start() {\n m_timer = new QTimer(this);\n connect(m_timer, &QTimer::timeout, this, &ProcessMonitor::refresh);\n m_timer->start(1000);\n}\n private:\n void onItemChanged(QTreeWidgetItem* item, int column) {\n if (column == 5 && (item->flags() & Qt::ItemIsUserCheckable))\n {\n bool state = m_treeWidget->blockSignals(true);\n\n Qt::CheckState checkState = item->checkState(column);\n QString processName = item->text(0);\n DWORD pid = item->text(1).toLong();\n bool is64Bit = item->text(3) == \"x64\" ? true : false;\n if (checkState == Qt::Checked)\n {\n m_targetNames.insert(processName);\n this->injectDll(pid, is64Bit);\n item->setText(5, tr(\"加速中\"));\n for (int col = 0; col < item->columnCount(); ++col)\n {\n item->setBackground(col, QBrush(QColor(\"#f3e5f5\")));\n item->setForeground(col, QBrush(QColor(\"#7b1fa2\")));\n }\n qDebug() << processName << \"勾选\";\n dump();\n }\n else\n {\n m_targetNames.remove(processName);\n this->unhookDll(pid, is64Bit);\n item->setText(5, \"\");\n for (int col = 0; col < item->columnCount(); ++col)\n {\n item->setBackground(col, QBrush());\n item->setForeground(col, QBrush());\n }\n qDebug() << processName << \"取消勾选\";\n dump();\n }\n\n m_treeWidget->blockSignals(state);\n }\n}\n private:\n QTreeWidget* m_treeWidget;\n QLabel* m_treeStatusLabel;\n QLabel* m_injector32StatusLabel;\n QLabel* m_injector64StatusLabel;\n QString m_filter;\n QTimer* m_timer = nullptr;\n QString m_dllPath;\n QProcess* m_bridge32;\n QProcess* m_bridge64;\n QSettings* m_settings;\n QHash m_iconCache;\n QMap m_processItems;\n QSet m_targetNames;\n void init() {\n QStringList targetNames =\n m_settings->value(CONFIG_TARGETNAMES_KEY).toStringList();\n m_targetNames = QSet(targetNames.begin(), targetNames.end());\n}\n void dump() {\n m_settings->setValue(CONFIG_TARGETNAMES_KEY,\n QStringList(m_targetNames.values()));\n}\n void update(const QList& processList) {\n // 跟踪现有进程,用于确定哪些已终止\n QSet currentPids;\n for (const ProcessInfo& info : processList)\n {\n currentPids.insert(info.pid);\n }\n\n // 移除已终止的进程\n QMutableMapIterator i(m_processItems);\n while (i.hasNext())\n {\n i.next();\n if (!currentPids.contains(i.key()))\n {\n QTreeWidgetItem* item = i.value();\n QTreeWidgetItem* parent = item->parent();\n\n if (parent)\n {\n parent->removeChild(item);\n }\n else\n {\n auto index = m_treeWidget->indexOfTopLevelItem(item);\n m_treeWidget->takeTopLevelItem(index);\n }\n\n while (item->childCount() > 0)\n {\n QTreeWidgetItem* child = item->takeChild(0);\n if (parent)\n {\n parent->addChild(child);\n }\n else\n {\n m_treeWidget->addTopLevelItem(child);\n }\n }\n\n // 删除节点\n delete item;\n\n // 从映射中移除\n i.remove();\n }\n }\n\n // 添加或更新进程信息\n for (const ProcessInfo& info : processList)\n {\n if (m_processItems.contains(info.pid))\n {\n // 更新已存在的进程信息\n QTreeWidgetItem* item = m_processItems[info.pid];\n item->setText(1, QString::number(info.pid));\n item->setData(1, Qt::UserRole, (long long)info.pid);\n item->setText(2,\n QString(\"%1 MB\").arg(info.memoryUsage / 1024 / 1024));\n item->setData(2, Qt::UserRole, (uint)info.memoryUsage);\n\n QString arch = info.is64Bit ? \"x64\" : \"x86\";\n item->setText(3, arch);\n QString priority;\n switch (info.priorityClass)\n {\n case HIGH_PRIORITY_CLASS:\n priority = tr(\"高\");\n break;\n case NORMAL_PRIORITY_CLASS:\n priority = tr(\"中\");\n break;\n case IDLE_PRIORITY_CLASS:\n priority = tr(\"低\");\n break;\n case REALTIME_PRIORITY_CLASS:\n priority = tr(\"实时\");\n break;\n default:\n priority = tr(\"未知\");\n break;\n }\n item->setText(4, priority);\n if (m_targetNames.contains(info.name))\n {\n if (item->checkState(5) == Qt::Unchecked)\n {\n item->setCheckState(5, Qt::Checked);\n }\n }\n else\n {\n if (item->checkState(5) == Qt::Checked)\n {\n item->setCheckState(5, Qt::Unchecked);\n }\n }\n }\n else\n {\n // 添加新进程\n QTreeWidgetItem* item = new SortTreeWidgetItem();\n\n item->setText(0, info.name);\n item->setData(0, Qt::UserRole, info.name.toLower());\n item->setText(1, QString::number(info.pid));\n item->setData(1, Qt::UserRole, (long long)info.pid);\n item->setText(2,\n QString(\"%1 MB\").arg(info.memoryUsage / 1024 / 1024));\n item->setData(2, Qt::UserRole, (uint)info.memoryUsage);\n\n QString arch = info.is64Bit ? \"x64\" : \"x86\";\n item->setText(3, arch);\n\n // 加载进程图标\n item->setIcon(0, getProcessIconCached(info.pid));\n\n QString priority;\n switch (info.priorityClass)\n {\n case HIGH_PRIORITY_CLASS:\n priority = tr(\"高\");\n break;\n case NORMAL_PRIORITY_CLASS:\n priority = tr(\"中\");\n break;\n case IDLE_PRIORITY_CLASS:\n priority = tr(\"低\");\n break;\n case REALTIME_PRIORITY_CLASS:\n priority = tr(\"实时\");\n break;\n default:\n priority = tr(\"未知\");\n break;\n }\n item->setText(4, priority);\n item->setCheckState(5, Qt::Unchecked);\n m_treeWidget->addTopLevelItem(item);\n m_processItems[info.pid] = item;\n }\n }\n}\n void injectDll(DWORD processId, bool is64Bit) {\n QString cmd = QString(\"inject %1\\n\").arg(processId);\n if (!is64Bit)\n {\n m_bridge32->write(cmd.toUtf8(), cmd.size());\n m_bridge32->waitForBytesWritten();\n }\n else\n {\n m_bridge64->write(cmd.toUtf8(), cmd.size());\n m_bridge64->waitForBytesWritten();\n }\n}\n void unhookDll(DWORD processId, bool is64Bit) {\n QString cmd = QString(\"unhook %1\\n\").arg(processId);\n if (!is64Bit)\n {\n m_bridge32->write(cmd.toUtf8(), cmd.size());\n m_bridge32->waitForBytesWritten();\n }\n else\n {\n m_bridge64->write(cmd.toUtf8(), cmd.size());\n m_bridge64->waitForBytesWritten();\n }\n}\n void startBridge32() {\n m_bridge32 = new QProcess();\n QStringList params32;\n m_bridge32->start(BRIDGE32_EXE, params32);\n if (!m_bridge32->waitForStarted())\n {\n qDebug() << \"32位桥接子进程启动失败\";\n }\n else\n {\n qDebug() << \"32位桥接子进程已启动\";\n }\n m_bridge32->setProcessChannelMode(QProcess::MergedChannels);\n connect(m_bridge32,\n &QProcess::readyReadStandardOutput,\n [&]()\n {\n QByteArray data = m_bridge32->readAllStandardOutput();\n qDebug() << \"收到输出:\" << QString(data).trimmed();\n });\n}\n void startBridge64() {\n m_bridge64 = new QProcess();\n QStringList params64;\n m_bridge64->start(BRIDGE64_EXE, params64);\n if (!m_bridge64->waitForStarted())\n {\n qDebug() << \"64位桥接子进程启动失败\";\n }\n else\n {\n qDebug() << \"64位桥接子进程已启动\";\n }\n m_bridge64->setProcessChannelMode(QProcess::MergedChannels);\n connect(m_bridge64,\n &QProcess::readyReadStandardOutput,\n [&]()\n {\n QByteArray data = m_bridge64->readAllStandardOutput();\n qDebug() << \"收到输出:\" << QString(data).trimmed();\n });\n}\n void healthcheckBridge() {\n if (this->m_bridge32->state() == QProcess::Running)\n {\n m_injector32StatusLabel->setStyleSheet(\"color: green\");\n m_injector32StatusLabel->setText(tr(\"正常\"));\n }\n else\n {\n m_injector32StatusLabel->setStyleSheet(\"color: red\");\n m_injector32StatusLabel->setText(tr(\"异常退出\"));\n }\n\n if (this->m_bridge64->state() == QProcess::Running)\n {\n m_injector64StatusLabel->setStyleSheet(\"color: green\");\n m_injector64StatusLabel->setText(tr(\"正常\"));\n }\n else\n {\n m_injector64StatusLabel->setStyleSheet(\"color:red\");\n m_injector64StatusLabel->setText(tr(\"异常退出\"));\n }\n}\n void terminalBridge() {\n QString cmd = QString(\"exit\\n\");\n m_bridge32->write(cmd.toUtf8(), cmd.size());\n m_bridge32->waitForBytesWritten();\n m_bridge64->write(cmd.toUtf8(), cmd.size());\n m_bridge64->waitForBytesWritten();\n}\n static QIcon getProcessIcon(QString processPath) {\n int lastSlashPos =\n std::max(processPath.lastIndexOf('/'), processPath.lastIndexOf('\\\\'));\n QString processName;\n if (lastSlashPos == -1)\n {\n processName = processPath;\n }\n processName = processPath.mid(lastSlashPos + 1);\n\n if (processPath.isEmpty())\n {\n qDebug() << processPath << \"无法获取进程完整路径\";\n return getDefaultIcon(processName);\n }\n\n SHFILEINFO sfi = {};\n if (SHGetFileInfo(reinterpret_cast(processPath.utf16()),\n FILE_ATTRIBUTE_NORMAL,\n &sfi,\n sizeof(SHFILEINFO),\n SHGFI_ICON | SHGFI_LARGEICON | SHGFI_USEFILEATTRIBUTES))\n {\n if (sfi.hIcon)\n {\n QIcon icon = QtWin::fromHICON(sfi.hIcon);\n DestroyIcon(sfi.hIcon);\n if (!icon.isNull())\n {\n qDebug() << processPath << \"通过SHGetFileInfo获取图标成功\";\n return icon;\n }\n }\n }\n\n HICON hIcon =\n ExtractIconW(nullptr, reinterpret_cast(processPath.utf16()), 0);\n if (hIcon)\n {\n QIcon icon = QtWin::fromHICON(hIcon);\n DestroyIcon(hIcon);\n if (!icon.isNull())\n return icon;\n }\n\n QFileInfo fileInfo(processPath);\n if (fileInfo.exists())\n {\n // 使用Qt的QFileIconProvider获取文件图标\n QFileIconProvider iconProvider;\n return iconProvider.icon(fileInfo);\n }\n qDebug() << processPath << \"无法获取进程图标使用默认图标\";\n\n return getDefaultIcon(processName);\n}\n static QIcon getDefaultIcon(const QString& processName) {\n // 根据进程名称或类型提供更有针对性的默认图标\n if (processName != \"\")\n {\n // 使用SHGetFileInfo获取.exe文件的图标\n SHFILEINFO sfi = {};\n QIcon icon;\n if (SHGetFileInfo(reinterpret_cast(processName.utf16()),\n FILE_ATTRIBUTE_NORMAL,\n &sfi,\n sizeof(SHFILEINFO),\n SHGFI_USEFILEATTRIBUTES | SHGFI_ICON |\n SHGFI_SMALLICON))\n {\n // 将HICON转换为QIcon\n icon = QtWin::fromHICON(sfi.hIcon);\n\n // 释放图标资源\n DestroyIcon(sfi.hIcon);\n }\n return icon;\n }\n else\n {\n // 使用SHGetFileInfo获取.exe文件的图标\n SHFILEINFO sfi = {};\n QIcon icon;\n if (SHGetFileInfo(reinterpret_cast(L\".exe\"),\n FILE_ATTRIBUTE_NORMAL,\n &sfi,\n sizeof(SHFILEINFO),\n SHGFI_USEFILEATTRIBUTES | SHGFI_ICON |\n SHGFI_SMALLICON))\n {\n // 将HICON转换为QIcon\n icon = QtWin::fromHICON(sfi.hIcon);\n\n // 释放图标资源\n DestroyIcon(sfi.hIcon);\n }\n return icon;\n }\n}\n QIcon getProcessIconCached(DWORD proccessId) {\n QString processPath = winutils::getProcessPath(processId);\n if (m_iconCache.contains(processPath))\n {\n return m_iconCache[processPath];\n }\n\n QIcon icon = getProcessIcon(processPath);\n m_iconCache.insert(processPath, icon);\n return icon;\n}\n public:\n};"], ["/OpenSpeedy/winutils.h", "class winutils {\n public:\n winutils() {\n}\n public:\n static bool injectDll(DWORD processId, const QString& dllPath) {\n HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);\n if (!hProcess)\n {\n qDebug() << \"Failed to open process:\" << GetLastError();\n return false;\n }\n\n if (checkDllExist(processId, dllPath))\n {\n qDebug() << \"Process already have been injected\";\n return true;\n }\n else if (injectDllViaCRTW(processId, dllPath))\n {\n return true;\n }\n else if (injectDllViaCRTA(processId, dllPath))\n {\n return true;\n }\n\n injectDllViaAPCW(processId, dllPath);\n injectDllViaAPCA(processId, dllPath);\n if (checkDllExist(processId, dllPath))\n {\n return true;\n }\n else if (injectDllViaWHKW(processId, dllPath))\n {\n return true;\n }\n else if (injectDllViaWHKA(processId, dllPath))\n {\n return true;\n }\n else\n {\n return false;\n }\n}\n static bool injectDllViaCRTA(DWORD processId, const QString& dllPath) {\n HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);\n if (!hProcess)\n {\n qDebug() << \"Failed to open process:\" << GetLastError();\n return false;\n }\n\n if (checkDllExist(processId, dllPath))\n {\n qDebug() << \"Process already have been injected\";\n return true;\n }\n SIZE_T pathSize = (dllPath.size() + 1) * sizeof(char);\n LPVOID pDllPath =\n VirtualAllocEx(hProcess,\n nullptr,\n pathSize,\n MEM_COMMIT | MEM_RESERVE,\n PAGE_EXECUTE_READWRITE);\n if (!pDllPath)\n {\n qDebug() << \"Failed to allocate memory in target process:\"\n << GetLastError();\n CloseHandle(hProcess);\n return false;\n }\n\n if (!WriteProcessMemory(hProcess,\n pDllPath,\n dllPath.toStdString().c_str(),\n pathSize,\n nullptr))\n {\n qDebug() << \"Failed to write memory in target process:\"\n << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n HMODULE hKernel32 = GetModuleHandle(L\"kernel32.dll\");\n if (!hKernel32)\n {\n qDebug() << \"Failed to get handle for kernel32.dll:\" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n FARPROC pLoadLibraryA = GetProcAddress(hKernel32, \"LoadLibraryA\");\n if (!pLoadLibraryA)\n {\n qDebug() << \"Failed to get address of LoadLibraryA:\" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n HANDLE hThread = CreateRemoteThread(hProcess,\n nullptr,\n 0,\n (LPTHREAD_START_ROUTINE)pLoadLibraryA,\n pDllPath,\n 0,\n nullptr);\n if (!hThread)\n {\n qDebug() << \"Failed to create remote thread:\" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n WaitForSingleObject(hThread, INFINITE);\n\n // 检查LoadLibrary是否执行成功\n DWORD exitCode = 0;\n if (GetExitCodeThread(hThread, &exitCode))\n {\n qDebug() << \"Remote thread exit code:\" << exitCode;\n // LoadLibrary返回的是模块句柄,如果为0则失败\n if (exitCode == 0)\n {\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n CloseHandle(hThread);\n qDebug() << \"LoadLibrary failed in remote process\";\n return false;\n }\n }\n\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hThread);\n CloseHandle(hProcess);\n\n return true;\n}\n static bool injectDllViaCRTW(DWORD processId, const QString& dllPath) {\n HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);\n if (!hProcess)\n {\n qDebug() << \"Failed to open process:\" << GetLastError();\n return false;\n }\n\n if (checkDllExist(processId, dllPath))\n {\n qDebug() << \"Process already have been injected\";\n return true;\n }\n SIZE_T pathSize = (dllPath.size() + 1) * sizeof(wchar_t);\n LPVOID pDllPath =\n VirtualAllocEx(hProcess, nullptr, pathSize, MEM_COMMIT | MEM_RESERVE,\n PAGE_EXECUTE_READWRITE);\n if (!pDllPath)\n {\n qDebug() << \"Failed to allocate memory in target process:\"\n << GetLastError();\n CloseHandle(hProcess);\n return false;\n }\n\n if (!WriteProcessMemory(hProcess,\n pDllPath,\n dllPath.toStdWString().c_str(),\n pathSize,\n nullptr))\n {\n qDebug() << \"Failed to write memory in target process:\"\n << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n HMODULE hKernel32 = GetModuleHandle(L\"kernel32.dll\");\n if (!hKernel32)\n {\n qDebug() << \"Failed to get handle for kernel32.dll:\" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n FARPROC pLoadLibraryW = GetProcAddress(hKernel32, \"LoadLibraryW\");\n if (!pLoadLibraryW)\n {\n qDebug() << \"Failed to get address of LoadLibraryW:\" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n HANDLE hThread = CreateRemoteThread(hProcess,\n nullptr,\n 0,\n (LPTHREAD_START_ROUTINE)pLoadLibraryW,\n pDllPath,\n 0,\n nullptr);\n if (!hThread)\n {\n qDebug() << \"Failed to create remote thread:\" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n WaitForSingleObject(hThread, INFINITE);\n\n // 检查LoadLibrary是否执行成功\n DWORD exitCode = 0;\n if (GetExitCodeThread(hThread, &exitCode))\n {\n qDebug() << \"Remote thread exit code:\" << exitCode;\n // LoadLibrary返回的是模块句柄,如果为0则失败\n if (exitCode == 0)\n {\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n CloseHandle(hThread);\n qDebug() << \"LoadLibrary failed in remote process\";\n return false;\n }\n }\n\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hThread);\n CloseHandle(hProcess);\n\n return true;\n}\n static bool injectDllViaAPCA(DWORD processId, const QString& dllPath) {\n HANDLE hProcess =\n OpenProcess(PROCESS_ALL_ACCESS,\n FALSE,\n processId);\n\n if (!hProcess)\n {\n qDebug() << \"Failed to open process: \" << GetLastError();\n return false;\n }\n\n if (checkDllExist(processId, dllPath))\n {\n qDebug() << \"Process already have been injected\";\n return true;\n }\n\n // 在目标进程中分配内存并写入DLL路径\n SIZE_T pathSize = (dllPath.toStdString().size() + 1) * sizeof(char);\n LPVOID pDllPath = VirtualAllocEx(hProcess,\n NULL,\n pathSize,\n MEM_COMMIT,\n PAGE_READWRITE);\n\n if (!pDllPath)\n {\n qDebug() << \"Failed to allocate memory: \" << GetLastError();\n CloseHandle(hProcess);\n return false;\n }\n\n if (!WriteProcessMemory(hProcess, pDllPath, dllPath.toStdString().c_str(),\n pathSize, NULL))\n {\n qDebug() << \"Failed to write memory: \" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 获取LoadLibraryW的地址\n HMODULE hKernel32 = GetModuleHandle(L\"kernel32.dll\");\n if (!hKernel32)\n {\n qDebug() << \"Failed to get kernel32 handle\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n FARPROC pLoadLibraryA = GetProcAddress(hKernel32, \"LoadLibraryA\");\n if (!pLoadLibraryA)\n {\n qDebug() << \"Failed to get LoadLibraryA address\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 获取进程中的所有线程\n DWORD threadId = getProcessMainThread(processId);\n if (!threadId)\n {\n qDebug() << \"No threads found in the process\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 向目标进程的所有线程队列中添加APC调用\n bool success = false;\n\n // 打开线程\n HANDLE hThread = OpenThread(THREAD_SET_CONTEXT, FALSE, threadId);\n if (hThread)\n {\n // 将LoadLibraryA作为APC函数加入队列\n PostThreadMessageA(threadId, WM_PAINT, 0, 0);\n DWORD result =\n QueueUserAPC((PAPCFUNC)pLoadLibraryA, hThread, (ULONG_PTR)pDllPath);\n PostThreadMessageA(threadId, WM_PAINT, 0, 0);\n if (result != 0)\n {\n success = true;\n qDebug() << \"APC queued to thread \" << threadId;\n }\n\n CloseHandle(hThread);\n }\n\n if (!success)\n {\n qDebug() << \"Failed to queue APC to any thread\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 注意:我们不释放分配的内存,因为APC函数尚未执行\n // 内存将在DLL加载后释放\n\n CloseHandle(hProcess);\n return true;\n}\n static bool injectDllViaAPCW(DWORD processId, const QString& dllPath) {\n HANDLE hProcess =\n OpenProcess(PROCESS_ALL_ACCESS,\n FALSE,\n processId);\n\n if (!hProcess)\n {\n qDebug() << \"Failed to open process: \" << GetLastError();\n return false;\n }\n\n if (checkDllExist(processId, dllPath))\n {\n qDebug() << \"Process already have been injected\";\n return true;\n }\n\n // 在目标进程中分配内存并写入DLL路径\n SIZE_T pathSize = (dllPath.toStdWString().size() + 1) * sizeof(wchar_t);\n LPVOID pDllPath = VirtualAllocEx(hProcess,\n NULL,\n pathSize,\n MEM_COMMIT,\n PAGE_READWRITE);\n\n if (!pDllPath)\n {\n qDebug() << \"Failed to allocate memory: \" << GetLastError();\n CloseHandle(hProcess);\n return false;\n }\n\n if (!WriteProcessMemory(hProcess,\n pDllPath,\n dllPath.toStdWString().c_str(),\n pathSize,\n NULL))\n {\n qDebug() << \"Failed to write memory: \" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 获取LoadLibraryW的地址\n HMODULE hKernel32 = GetModuleHandle(L\"kernel32.dll\");\n if (!hKernel32)\n {\n qDebug() << \"Failed to get kernel32 handle\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n FARPROC pLoadLibraryW = GetProcAddress(hKernel32, \"LoadLibraryW\");\n if (!pLoadLibraryW)\n {\n qDebug() << \"Failed to get LoadLibraryW address\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 获取进程中的所有线程\n DWORD threadId = getProcessMainThread(processId);\n if (!threadId)\n {\n qDebug() << \"No threads found in the process\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 向目标进程的所有线程队列中添加APC调用\n bool success = false;\n\n // 打开线程\n HANDLE hThread = OpenThread(THREAD_SET_CONTEXT, FALSE, threadId);\n if (hThread)\n {\n // 将LoadLibraryW作为APC函数加入队列\n PostThreadMessageW(threadId, WM_PAINT, 0, 0);\n DWORD result =\n QueueUserAPC((PAPCFUNC)pLoadLibraryW, hThread, (ULONG_PTR)pDllPath);\n PostThreadMessageW(threadId, WM_PAINT, 0, 0);\n if (result != 0)\n {\n success = true;\n qDebug() << \"APC queued to thread \" << threadId;\n }\n\n CloseHandle(hThread);\n }\n\n if (!success)\n {\n qDebug() << \"Failed to queue APC to any thread\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 注意:我们不释放分配的内存,因为APC函数尚未执行\n // 内存将在DLL加载后释放\n\n CloseHandle(hProcess);\n return true;\n}\n static bool injectDllViaWHKA(DWORD processId, const QString& dllPath) {\n if (checkProcessProtection(processId))\n {\n qDebug() << \"进程被保护 进程ID: \" << processId;\n return false;\n }\n\n // 1. 加载DLL到当前进程\n HMODULE hMod = LoadLibraryA(dllPath.toStdString().c_str());\n if (!hMod)\n return false;\n\n // 2. 获取Hook过程的地址\n HOOKPROC hookProc = (HOOKPROC)GetProcAddress(hMod, \"HookProc\");\n if (!hookProc)\n return false;\n\n // 3. 获取目标线程ID\n DWORD threadId = getProcessMainThread(processId);\n if (threadId == 0)\n return false;\n\n // 4. 安装Hook\n HHOOK hHook = SetWindowsHookExA(WH_CBT, // Hook类型\n hookProc, // Hook过程\n hMod, // DLL模块句柄\n threadId // 目标线程ID\n );\n\n if (!hHook)\n return false;\n // 5. 触发Hook执行\n PostThreadMessageA(threadId, WM_NULL, 0, 0);\n Sleep(5000);\n UnhookWindowsHookEx(hHook);\n\n return true;\n}\n static bool injectDllViaWHKW(DWORD processId, const QString& dllPath) {\n if (checkProcessProtection(processId))\n {\n qDebug() << \"进程被保护 进程ID: \" << processId;\n return false;\n }\n\n // 1. 加载DLL到当前进程\n HMODULE hMod = LoadLibraryW(dllPath.toStdWString().c_str());\n if (!hMod)\n return false;\n\n // 2. 获取Hook过程的地址\n HOOKPROC hookProc = (HOOKPROC)GetProcAddress(hMod, \"HookProc\");\n if (!hookProc)\n return false;\n\n // 3. 获取目标线程ID\n DWORD threadId = getProcessMainThread(processId);\n if (threadId == 0)\n return false;\n\n // 4. 安装Hook\n HHOOK hHook = SetWindowsHookExW(WH_CBT, // Hook类型\n hookProc, // Hook过程\n hMod, // DLL模块句柄\n threadId // 目标线程ID\n );\n\n if (!hHook)\n return false;\n // 5. 触发Hook执行\n PostThreadMessageW(threadId, WM_NULL, 0, 0);\n Sleep(5000);\n UnhookWindowsHookEx(hHook);\n\n return true;\n}\n static bool unhookDll(DWORD processId, const QString& dllPath) {\n HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);\n if (!hProcess)\n {\n qDebug() << \"Failed to open process:\" << GetLastError();\n return false;\n }\n\n HMODULE hModules[1024];\n DWORD cbNeeded;\n if (EnumProcessModules(hProcess, hModules, sizeof(hModules), &cbNeeded))\n {\n for (unsigned int i = 0; i < (cbNeeded / sizeof(HMODULE)); i++)\n {\n TCHAR moduleName[MAX_PATH];\n if (GetModuleFileNameEx(hProcess, hModules[i], moduleName,\n sizeof(moduleName) / sizeof(TCHAR)))\n {\n#ifdef UNICODE\n bool isDll = dllPath.toStdWString() == moduleName;\n#else\n bool isDll = dllPath.toStdString() == moduleName;\n#endif\n if (isDll)\n {\n FARPROC pFreeLibrary = GetProcAddress(\n GetModuleHandle(L\"kernel32.dll\"), \"FreeLibrary\");\n if (!pFreeLibrary)\n {\n qDebug() << \"Failed to get address of FreeLibrary:\"\n << GetLastError();\n CloseHandle(hProcess);\n return false;\n }\n\n HANDLE hThread =\n CreateRemoteThread(hProcess, nullptr, 0,\n (LPTHREAD_START_ROUTINE)pFreeLibrary,\n hModules[i], 0, nullptr);\n if (!hThread)\n {\n qDebug() << \"Failed to create remote thread for \"\n \"FreeLibrary:\"\n << GetLastError();\n CloseHandle(hProcess);\n return false;\n }\n\n WaitForSingleObject(hThread, INFINITE);\n CloseHandle(hThread);\n CloseHandle(hProcess);\n return true;\n }\n }\n }\n }\n\n CloseHandle(hProcess);\n return false;\n}\n static bool checkDllExist(DWORD processId, const QString& dllPath) {\n HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,\n FALSE,\n processId);\n if (!hProcess)\n {\n qDebug() << \"打开进程失败:\" << GetLastError();\n return false;\n }\n\n bool dllFound = false;\n HMODULE hModules[1024];\n DWORD cbNeeded;\n\n // 获取进程中所有已加载的模块\n if (EnumProcessModules(hProcess, hModules, sizeof(hModules), &cbNeeded))\n {\n DWORD moduleCount = cbNeeded / sizeof(HMODULE);\n for (DWORD i = 0; i < moduleCount; i++)\n {\n TCHAR moduleName[MAX_PATH] = {0};\n\n // 获取模块的完整路径\n if (GetModuleFileNameExW(hProcess, hModules[i], moduleName,\n sizeof(moduleName) / sizeof(TCHAR)))\n {\n#ifdef UNICODE\n bool isDll = dllPath.toStdWString() == moduleName;\n#else\n bool isDll = dllPath.toStdString() == moduleName;\n#endif\n if (isDll)\n {\n dllFound = true;\n break;\n }\n }\n }\n }\n else\n {\n qDebug() << \"枚举进程模块失败:\" << GetLastError();\n }\n\n CloseHandle(hProcess);\n return dllFound;\n}\n static bool checkProcessProtection(DWORD processId) {\n HANDLE hProcess =\n OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, processId);\n if (!hProcess)\n {\n qDebug() << \"Cannot open process - likely protected\";\n return true; // 可能被保护\n }\n\n // 检查是否是受保护进程\n PROCESS_PROTECTION_LEVEL_INFORMATION protectionInfo = {};\n DWORD returnLength;\n\n if (GetProcessInformation(hProcess, ProcessProtectionLevelInfo,\n &protectionInfo, sizeof(protectionInfo)))\n {\n CloseHandle(hProcess);\n return protectionInfo.ProtectionLevel != PROTECTION_LEVEL_NONE;\n }\n\n CloseHandle(hProcess);\n return false;\n}\n static void setAutoStart(bool enable,\n const QString& appName,\n const QString& execPath) {\n TaskScheduler scheduler;\n\n if (enable)\n {\n scheduler.createStartupShortcut(appName, execPath);\n }\n else\n {\n scheduler.deleteStartupShortcut(appName);\n }\n}\n static bool isAutoStartEnabled(const QString& appName) {\n TaskScheduler scheduler;\n return scheduler.isStartupShortcutExists(appName);\n}\n static BOOL getWindowsVersion(DWORD* majorVersion,\n DWORD* minorVersion,\n DWORD* buildNumber) {\n static char version[100] = {0};\n DWORD major, minor, build;\n\n if (!getWindowsVersion(&major, &minor, &build))\n return \"Unknown Windows Version\";\n\n // 确定Windows版本\n if (major == 10)\n {\n if (build >= 22000)\n {\n sprintf(version, \"Windows 11 (Build %lu)\", build);\n }\n else\n {\n sprintf(version, \"Windows 10 (Build %lu)\", build);\n }\n }\n else if (major == 6)\n {\n switch (minor)\n {\n case 3:\n sprintf(version, \"Windows 8.1 (Build %lu)\", build);\n break;\n case 2:\n sprintf(version, \"Windows 8 (Build %lu)\", build);\n break;\n case 1:\n sprintf(version, \"Windows 7 (Build %lu)\", build);\n break;\n case 0:\n sprintf(version, \"Windows Vista (Build %lu)\", build);\n break;\n default:\n sprintf(version, \"Windows NT %lu.%lu (Build %lu)\", major, minor,\n build);\n }\n }\n else if (major == 5)\n {\n switch (minor)\n {\n case 2:\n sprintf(version, \"Windows Server 2003 (Build %lu)\", build);\n break;\n case 1:\n sprintf(version, \"Windows XP (Build %lu)\", build);\n break;\n case 0:\n sprintf(version, \"Windows 2000 (Build %lu)\", build);\n break;\n default:\n sprintf(version, \"Windows NT %lu.%lu (Build %lu)\", major, minor,\n build);\n }\n }\n else\n {\n sprintf(version, \"Windows NT %lu.%lu (Build %lu)\", major, minor, build);\n }\n return version;\n}\n static QString getWindowsVersion() {\n static char version[100] = {0};\n DWORD major, minor, build;\n\n if (!getWindowsVersion(&major, &minor, &build))\n return \"Unknown Windows Version\";\n\n // 确定Windows版本\n if (major == 10)\n {\n if (build >= 22000)\n {\n sprintf(version, \"Windows 11 (Build %lu)\", build);\n }\n else\n {\n sprintf(version, \"Windows 10 (Build %lu)\", build);\n }\n }\n else if (major == 6)\n {\n switch (minor)\n {\n case 3:\n sprintf(version, \"Windows 8.1 (Build %lu)\", build);\n break;\n case 2:\n sprintf(version, \"Windows 8 (Build %lu)\", build);\n break;\n case 1:\n sprintf(version, \"Windows 7 (Build %lu)\", build);\n break;\n case 0:\n sprintf(version, \"Windows Vista (Build %lu)\", build);\n break;\n default:\n sprintf(version, \"Windows NT %lu.%lu (Build %lu)\", major, minor,\n build);\n }\n }\n else if (major == 5)\n {\n switch (minor)\n {\n case 2:\n sprintf(version, \"Windows Server 2003 (Build %lu)\", build);\n break;\n case 1:\n sprintf(version, \"Windows XP (Build %lu)\", build);\n break;\n case 0:\n sprintf(version, \"Windows 2000 (Build %lu)\", build);\n break;\n default:\n sprintf(version, \"Windows NT %lu.%lu (Build %lu)\", major, minor,\n build);\n }\n }\n else\n {\n sprintf(version, \"Windows NT %lu.%lu (Build %lu)\", major, minor, build);\n }\n return version;\n}\n static QList getProcessList() {\n QList processList;\n\n HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);\n if (hProcessSnap == INVALID_HANDLE_VALUE)\n {\n qDebug() << \"创建进程快照失败: \" << GetLastError();\n return processList;\n }\n\n PROCESSENTRY32 pe32;\n pe32.dwSize = sizeof(PROCESSENTRY32);\n\n if (!Process32First(hProcessSnap, &pe32))\n {\n qDebug() << \"获取首个进程信息失败: \" << GetLastError();\n CloseHandle(hProcessSnap);\n return processList;\n }\n\n do\n {\n if (systemNames.contains(pe32.szExeFile))\n {\n continue;\n }\n ProcessInfo info;\n info.pid = pe32.th32ProcessID;\n info.parentPid = pe32.th32ParentProcessID;\n info.name = QString::fromWCharArray(pe32.szExeFile);\n info.threadCount = pe32.cntThreads;\n\n // 获取内存使用和优先级信息\n HANDLE hProcess = OpenProcess(\n PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, info.pid);\n if (hProcess)\n {\n PROCESS_MEMORY_COUNTERS pmc;\n if (GetProcessMemoryInfo(hProcess, &pmc, sizeof(pmc)))\n {\n info.memoryUsage = pmc.WorkingSetSize;\n }\n else\n {\n info.memoryUsage = 0;\n }\n BOOL wow64Process = FALSE;\n IsWow64Process(hProcess, &wow64Process);\n info.is64Bit = !wow64Process;\n info.priorityClass = GetPriorityClass(hProcess);\n CloseHandle(hProcess);\n }\n else\n {\n info.memoryUsage = 0;\n info.priorityClass = 0;\n }\n\n processList.append(info);\n } while (Process32Next(hProcessSnap, &pe32));\n\n CloseHandle(hProcessSnap);\n return processList;\n}\n static QString getProcessPath(DWORD processId) {\n QString processPath;\n HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,\n FALSE, processId);\n\n if (hProcess != NULL)\n {\n wchar_t buffer[MAX_PATH];\n if (GetModuleFileNameEx(hProcess, NULL, buffer, MAX_PATH) > 0)\n {\n processPath = QString::fromWCharArray(buffer);\n }\n CloseHandle(hProcess);\n }\n\n return processPath;\n}\n static DWORD getProcessMainThread(DWORD processId) {\n HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);\n if (hSnapshot == INVALID_HANDLE_VALUE)\n {\n qDebug() << \"Failed to create thread snapshot:\" << GetLastError();\n return 0;\n }\n\n THREADENTRY32 te32;\n te32.dwSize = sizeof(THREADENTRY32);\n\n DWORD mainThreadId = 0;\n FILETIME earliestTime = {0xFFFFFFFF, 0xFFFFFFFF}; // 设为最大值\n\n if (Thread32First(hSnapshot, &te32))\n {\n do\n {\n if (te32.th32OwnerProcessID == processId)\n {\n // 打开线程获取创建时间\n HANDLE hThread = OpenThread(THREAD_QUERY_INFORMATION, FALSE,\n te32.th32ThreadID);\n if (hThread)\n {\n FILETIME creationTime, exitTime, kernelTime, userTime;\n if (GetThreadTimes(hThread, &creationTime, &exitTime,\n &kernelTime, &userTime))\n {\n // 比较创建时间,找最早的线程\n if (CompareFileTime(&creationTime, &earliestTime) < 0)\n {\n earliestTime = creationTime;\n mainThreadId = te32.th32ThreadID;\n }\n }\n CloseHandle(hThread);\n }\n }\n } while (Thread32Next(hSnapshot, &te32));\n }\n\n CloseHandle(hSnapshot);\n return mainThreadId;\n}\n static QString getProcessNameById(DWORD processId) {\n HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,\n FALSE, processId);\n if (hProcess == NULL)\n {\n return QString();\n }\n\n wchar_t processName[MAX_PATH];\n if (GetModuleBaseName(hProcess, NULL, processName, MAX_PATH))\n {\n CloseHandle(hProcess);\n QString name = QString::fromWCharArray(processName);\n return name;\n }\n\n CloseHandle(hProcess);\n return QString();\n}\n static bool enableAllPrivilege() {\n HANDLE hToken;\n // 获取进程token\n if (!OpenProcessToken(GetCurrentProcess(),\n TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))\n return false;\n\n const wchar_t *essentialPrivileges[] = {\n SE_DEBUG_NAME, // 最重要的调试权限\n };\n\n TOKEN_PRIVILEGES tkp;\n bool success = true;\n\n for (const auto &privilege : essentialPrivileges)\n {\n tkp.PrivilegeCount = 1;\n tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;\n if (LookupPrivilegeValue(NULL, privilege, &tkp.Privileges[0].Luid))\n {\n AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, NULL);\n }\n }\n\n CloseHandle(hToken);\n return success;\n}\n};"], ["/OpenSpeedy/bridge/main.cpp", "#include \"../config.h\"\n#include \"../speedpatch/speedpatch.h\"\n#include \"../windbg.h\"\n#include \"../winutils.h\"\n#include \n#include \n#include \n#include \n#include \n\n#ifndef _WIN64\n#define SPEEDPATCH_DLL SPEEDPATCH32_DLL\n#else\n#define SPEEDPATCH_DLL SPEEDPATCH64_DLL\n#endif\n\nvoid\nhandleInject(int processId, QString dllPath)\n{\n qDebug() << \"执行 inject,进程ID:\" << processId;\n winutils::injectDll(processId, dllPath);\n SetProcessStatus(processId, true);\n}\n\nvoid\nhandleUnhook(int processId, QString dllPath)\n{\n qDebug() << \"执行 unhook,进程ID:\" << processId;\n SetProcessStatus(processId, false);\n}\n\nvoid\nhandleChange(double factor)\n{\n qDebug() << \"执行 change,参数:\" << factor;\n ChangeSpeed(factor);\n}\n\nint\nmain(int argc, char* argv[])\n{\n SetUnhandledExceptionFilter(createMiniDump);\n QCoreApplication a(argc, argv);\n if (winutils::enableAllPrivilege())\n {\n qDebug() << \"权限提升成功\";\n }\n\n QString dllPath = QDir::toNativeSeparators(\n QCoreApplication::applicationDirPath() + \"/\" + SPEEDPATCH_DLL);\n\n QTextStream in(stdin);\n QTextStream out(stdout);\n\n QRegularExpression injectRegex(\"^\\\\s*inject\\\\s+(\\\\d+)\\\\s*$\",\n QRegularExpression::CaseInsensitiveOption);\n QRegularExpression unhookRegex(\"^\\\\s*unhook\\\\s+(\\\\d+)\\\\s*$\",\n QRegularExpression::CaseInsensitiveOption);\n QRegularExpression changeRegex(\"^\\\\s*change\\\\s+([+-]?\\\\d*\\\\.?\\\\d+)\\\\s*$\",\n QRegularExpression::CaseInsensitiveOption);\n QRegularExpression exitRegex(\"^\\\\s*exit\\\\s*$\",\n QRegularExpression::CaseInsensitiveOption);\n\n while (true)\n {\n QString line = in.readLine();\n if (line.isNull())\n {\n // 管道关闭或输入结束\n break;\n }\n line = line.trimmed();\n if (line.isEmpty())\n continue;\n\n QRegularExpressionMatch match;\n if ((match = injectRegex.match(line)).hasMatch())\n {\n int pid = match.captured(1).toInt();\n handleInject(pid, dllPath);\n }\n else if ((match = unhookRegex.match(line)).hasMatch())\n {\n int pid = match.captured(1).toInt();\n handleUnhook(pid, dllPath);\n }\n else if ((match = changeRegex.match(line)).hasMatch())\n {\n double factor = match.captured(1).toDouble();\n handleChange(factor);\n }\n else if (exitRegex.match(line).hasMatch())\n {\n qDebug() << \"收到exit命令,程序即将退出。\";\n break;\n }\n else\n {\n qDebug() << \"无效命令:\" << line;\n }\n }\n\n return 0;\n}\n"], ["/OpenSpeedy/main.cpp", "/*\n * OpenSpeedy - Open Source Game Speed Controller\n * Copyright (C) 2025 Game1024\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n#include \"mainwindow.h\"\n#include \"windbg.h\"\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nint\nmain(int argc, char* argv[])\n{\n SetUnhandledExceptionFilter(createMiniDump);\n SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);\n QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);\n QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);\n QApplication::setAttribute(Qt::AA_UseSoftwareOpenGL);\n QApplication a(argc, argv);\n winutils::enableAllPrivilege();\n\n // 检查是否已有实例在运行\n QString unique = \"OpenSpeedy\";\n QLocalSocket socket;\n socket.connectToServer(unique);\n if (socket.waitForConnected(500))\n {\n socket.close();\n return -1;\n }\n\n // 使用资源文件中的图标\n QIcon appIcon;\n appIcon.addFile(\":/icons/images/icon_16.ico\", QSize(16, 16));\n appIcon.addFile(\":/icons/images/icon_32.ico\", QSize(32, 32));\n appIcon.addFile(\":/icons/images/icon_64.ico\", QSize(64, 64));\n a.setWindowIcon(appIcon);\n\n QSettings settings =\n QSettings(QCoreApplication::applicationDirPath() + \"/config.ini\",\n QSettings::IniFormat);\n\n QTranslator translator;\n const QString baseName =\n \"OpenSpeedy_\" +\n settings.value(CONFIG_LANGUAGE, QLocale().system().name()).toString();\n\n if (translator.load(\":/i18n/translations/\" + baseName))\n {\n a.installTranslator(&translator);\n }\n\n // 解析命令行参数\n QCommandLineParser parser;\n parser.setApplicationDescription(\"OpenSpeedy\");\n QCommandLineOption minimizeOption(\n QStringList() << \"m\" << \"minimize-to-tray\", \"启动时最小化到托盘\");\n parser.addOption(minimizeOption);\n parser.process(a);\n\n MainWindow w;\n w.resize(1024, 768);\n\n if (parser.isSet(minimizeOption))\n {\n w.hide();\n }\n else\n {\n w.show();\n }\n\n // 创建并启动本地服务器\n QLocalServer server;\n QLocalServer::removeServer(unique);\n server.listen(unique);\n // 当用户尝试再运行一个进程时,将窗口显示到最前台\n QObject::connect(&server,\n &QLocalServer::newConnection,\n [&]\n {\n w.show();\n w.raise();\n w.showNormal();\n w.activateWindow();\n });\n return a.exec();\n}\n"], ["/OpenSpeedy/qsinglekeysequenceedit.h", "class QSingleKeySequenceEdit {\n Q_OBJECT\n\n public:\n explicit QSingleKeySequenceEdit(QWidget* parent = nullptr);\n static UINT toVK(int qtKey, Qt::KeyboardModifiers qtMod) {\n // 🔤 字母键 A-Z\n if (qtKey >= Qt::Key_A && qtKey <= Qt::Key_Z)\n {\n return qtKey; // Qt 和 Windows 的 A-Z 键码相同\n }\n\n // 🔢 小键盘 0-9\n if (qtMod & Qt::KeypadModifier)\n {\n switch (qtKey)\n {\n // 数字键盘\n case Qt::Key_0:\n return VK_NUMPAD0;\n case Qt::Key_1:\n return VK_NUMPAD1;\n case Qt::Key_2:\n return VK_NUMPAD2;\n case Qt::Key_3:\n return VK_NUMPAD3;\n case Qt::Key_4:\n return VK_NUMPAD4;\n case Qt::Key_5:\n return VK_NUMPAD5;\n case Qt::Key_6:\n return VK_NUMPAD6;\n case Qt::Key_7:\n return VK_NUMPAD7;\n case Qt::Key_8:\n return VK_NUMPAD8;\n case Qt::Key_9:\n return VK_NUMPAD9;\n }\n }\n\n // 🔢 数字键 0-9\n if (qtKey >= Qt::Key_0 && qtKey <= Qt::Key_9)\n {\n return qtKey; // Qt 和 Windows 的 0-9 键码相同\n }\n\n // 🎯 功能键映射\n switch (qtKey)\n {\n // F1-F12\n case Qt::Key_F1:\n return VK_F1;\n case Qt::Key_F2:\n return VK_F2;\n case Qt::Key_F3:\n return VK_F3;\n case Qt::Key_F4:\n return VK_F4;\n case Qt::Key_F5:\n return VK_F5;\n case Qt::Key_F6:\n return VK_F6;\n case Qt::Key_F7:\n return VK_F7;\n case Qt::Key_F8:\n return VK_F8;\n case Qt::Key_F9:\n return VK_F9;\n case Qt::Key_F10:\n return VK_F10;\n case Qt::Key_F11:\n return VK_F11;\n case Qt::Key_F12:\n return VK_F12;\n\n // 方向键\n case Qt::Key_Left:\n return VK_LEFT;\n case Qt::Key_Right:\n return VK_RIGHT;\n case Qt::Key_Up:\n return VK_UP;\n case Qt::Key_Down:\n return VK_DOWN;\n\n // 特殊键\n case Qt::Key_Enter:\n case Qt::Key_Return:\n return VK_RETURN;\n case Qt::Key_Escape:\n return VK_ESCAPE;\n case Qt::Key_Tab:\n return VK_TAB;\n case Qt::Key_Backspace:\n return VK_BACK;\n case Qt::Key_Delete:\n return VK_DELETE;\n case Qt::Key_Insert:\n return VK_INSERT;\n case Qt::Key_Home:\n return VK_HOME;\n case Qt::Key_End:\n return VK_END;\n case Qt::Key_PageUp:\n return VK_PRIOR;\n case Qt::Key_PageDown:\n return VK_NEXT;\n case Qt::Key_Space:\n return VK_SPACE;\n\n // 符号键\n case Qt::Key_Semicolon:\n return VK_OEM_1; // ;\n case Qt::Key_Equal:\n return VK_OEM_PLUS; // =\n case Qt::Key_Comma:\n return VK_OEM_COMMA; // ,\n case Qt::Key_Minus:\n return VK_OEM_MINUS; // -\n case Qt::Key_Period:\n return VK_OEM_PERIOD; // .\n case Qt::Key_Slash:\n return VK_OEM_2; // /\n case Qt::Key_QuoteLeft:\n return VK_OEM_3; // `\n case Qt::Key_BracketLeft:\n return VK_OEM_4; // [\n case Qt::Key_Backslash:\n return VK_OEM_5; //\n case Qt::Key_BracketRight:\n return VK_OEM_6; // ]\n case Qt::Key_Apostrophe:\n return VK_OEM_7; // '\n\n // 其他常用键\n case Qt::Key_CapsLock:\n return VK_CAPITAL;\n case Qt::Key_NumLock:\n return VK_NUMLOCK;\n case Qt::Key_ScrollLock:\n return VK_SCROLL;\n case Qt::Key_Pause:\n return VK_PAUSE;\n case Qt::Key_Print:\n return VK_PRINT;\n\n default:\n qDebug() << \"Unknown Qt key:\" << qtKey;\n return 0; // 未知按键\n }\n}\n static UINT toModifier(Qt::KeyboardModifiers qtMod) {\n UINT winMod = 0;\n\n if (qtMod & Qt::ControlModifier)\n {\n winMod |= MOD_CONTROL;\n }\n if (qtMod & Qt::AltModifier)\n {\n winMod |= MOD_ALT;\n }\n if (qtMod & Qt::ShiftModifier)\n {\n winMod |= MOD_SHIFT;\n }\n if (qtMod & Qt::MetaModifier)\n {\n winMod |= MOD_WIN; // Windows 键\n }\n\n return winMod;\n}\n static QtCombinedKey toQtCombinedKey(const QString& keyText) {\n QKeySequence sequence = QKeySequence(keyText);\n\n if (!sequence.isEmpty())\n {\n int combinedKey = sequence[0];\n Qt::KeyboardModifiers modifier =\n Qt::KeyboardModifiers(combinedKey & Qt::KeyboardModifierMask);\n int key = combinedKey & ~Qt::KeyboardModifierMask;\n return QtCombinedKey{ key, modifier };\n }\n else\n {\n return QtCombinedKey{ 0, Qt::NoModifier };\n }\n}\n static QString wrapText(QString keyText) {\n return keyText.replace(\"Up\", \"⬆️\")\n .replace(\"Down\", \"⬇️\")\n .replace(\"Left\", \"⬅️\")\n .replace(\"Right\", \"➡️\");\n}\n UINT getVK() {\n return toVK(m_key, m_modifier);\n}\n UINT getModifier() {\n return toModifier(m_modifier);\n}\n QtCombinedKey getQtCombinedKey() {\n return QtCombinedKey{ m_key, m_modifier };\n}\n QString getKeyText() {\n return keySequence().toString(QKeySequence::NativeText);\n}\n protected:\n void keyPressEvent(QKeyEvent* event) override {\n int key = event->key();\n Qt::KeyboardModifiers modifiers = event->modifiers();\n\n // 忽略单独的修饰键\n if (isModifierKey(key))\n {\n return;\n }\n\n m_key = key;\n m_modifier = modifiers;\n\n // 创建单个按键序列\n QKeySequence singleKey(key | modifiers);\n setKeySequence(singleKey);\n\n // 🔚 结束编辑\n emit editingFinished();\n clearFocus();\n}\n private:\n void update() {\n QKeySequence sequence = keySequence();\n\n if (sequence.isEmpty())\n {\n m_key = 0;\n m_modifier = Qt::NoModifier;\n }\n else\n {\n int combinedKey = sequence[0];\n m_modifier =\n Qt::KeyboardModifiers(combinedKey & Qt::KeyboardModifierMask);\n m_key = combinedKey & ~Qt::KeyboardModifierMask;\n }\n}\n private:\n bool isModifierKey(int key) const {\n return (key == Qt::Key_Control || key == Qt::Key_Alt ||\n key == Qt::Key_Shift || key == Qt::Key_Meta);\n}\n int m_key;\n Qt::KeyboardModifiers m_modifier;\n};"], ["/OpenSpeedy/windbg.h", "/*\n * OpenSpeedy - Open Source Game Speed Controller\n * Copyright (C) 2025 Game1024\n * \n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n * \n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n * \n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n#ifndef WINDBG_H\n#define WINDBG_H\n#include \n#include \n#include \n#include \n// 链接dbghelp库\n#pragma comment(lib, \"dbghelp.lib\")\n\ntypedef BOOL(WINAPI *MINIDUMPWRITEDUMP)(\n HANDLE hProcess,\n DWORD ProcessId,\n HANDLE hFile,\n MINIDUMP_TYPE DumpType,\n PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,\n PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,\n PMINIDUMP_CALLBACK_INFORMATION CallbackParam);\n\n// 自定义异常处理函数\nLONG WINAPI createMiniDump(EXCEPTION_POINTERS *exceptionPointers)\n{\n // 创建dump文件目录\n QDir dumpDir(QDir::currentPath() + \"/dumps\");\n if (!dumpDir.exists())\n {\n dumpDir.mkpath(\".\");\n }\n\n // 生成带时间戳的文件名\n QString dumpFileName =\n QString(\"%1/crash_%2.dmp\")\n .arg(dumpDir.absolutePath())\n .arg(QDateTime::currentDateTime().toString(\"yyyy-MM-dd_hh-mm-ss\"));\n\n // 创建文件\n HANDLE hFile = CreateFile(dumpFileName.toStdWString().c_str(),\n GENERIC_WRITE, FILE_SHARE_READ, NULL,\n CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);\n\n if (hFile == INVALID_HANDLE_VALUE)\n {\n return EXCEPTION_CONTINUE_SEARCH;\n }\n\n // 加载dbghelp.dll\n HMODULE dbgHelp = LoadLibrary(L\"dbghelp.dll\");\n if (!dbgHelp)\n {\n CloseHandle(hFile);\n return EXCEPTION_CONTINUE_SEARCH;\n }\n\n // 获取MiniDumpWriteDump函数地址\n MINIDUMPWRITEDUMP miniDumpWriteDump =\n (MINIDUMPWRITEDUMP)GetProcAddress(dbgHelp, \"MiniDumpWriteDump\");\n\n if (!miniDumpWriteDump)\n {\n FreeLibrary(dbgHelp);\n CloseHandle(hFile);\n return EXCEPTION_CONTINUE_SEARCH;\n }\n\n // 配置异常信息\n MINIDUMP_EXCEPTION_INFORMATION exInfo;\n exInfo.ThreadId = GetCurrentThreadId();\n exInfo.ExceptionPointers = exceptionPointers;\n exInfo.ClientPointers = FALSE;\n\n // 设置dump类型\n MINIDUMP_TYPE dumpType =\n (MINIDUMP_TYPE)(MiniDumpWithFullMemory | // 包含完整内存\n MiniDumpWithFullMemoryInfo | // 包含内存信息\n MiniDumpWithHandleData | // 包含句柄数据\n MiniDumpWithThreadInfo | // 包含线程信息\n MiniDumpWithUnloadedModules // 包含卸载的模块\n );\n\n // 写入dump文件\n BOOL success = miniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(),\n hFile, dumpType, &exInfo, NULL, NULL);\n\n // 清理资源\n FreeLibrary(dbgHelp);\n CloseHandle(hFile);\n\n // 显示通知\n if (success)\n {\n std::wstring message =\n QString(\"程序遇到错误已退出,崩溃转储文件已保存到:\\n%1\")\n .arg(dumpFileName)\n .toStdWString();\n MessageBoxW(nullptr, message.c_str(), L\"程序崩溃\",\n MB_OK | MB_ICONERROR);\n }\n\n return EXCEPTION_EXECUTE_HANDLER;\n}\n\n#endif // WINDBG_H\n"], ["/OpenSpeedy/cpuutils.h", "class CpuUtils {\n private:\n PDH_HQUERY hQuery = NULL;\n PDH_HCOUNTER hCounter = NULL;\n bool initialized = false;\n public:\n CpuUtils() {\n}\n ~CpuUtils() {\n if (hCounter) PdhRemoveCounter(hCounter);\n if (hQuery) PdhCloseQuery(hQuery);\n}\n bool init() {\n // 创建查询\n if (PdhOpenQuery(NULL, NULL, &hQuery) != ERROR_SUCCESS) return false;\n\n if (PdhAddEnglishCounter(hQuery,\n L\"\\\\Processor(_Total)\\\\% Processor Time\",\n NULL,\n &hCounter) != ERROR_SUCCESS)\n {\n PdhCloseQuery(hQuery);\n return false;\n }\n\n // 第一次采样\n PdhCollectQueryData(hQuery);\n initialized = true;\n return true;\n}\n double getUsage() {\n if (!initialized) return -1;\n\n // 收集数据\n if (PdhCollectQueryData(hQuery) != ERROR_SUCCESS) return -1;\n\n PDH_FMT_COUNTERVALUE value;\n if (PdhGetFormattedCounterValue(hCounter, PDH_FMT_DOUBLE, NULL, &value) !=\n ERROR_SUCCESS)\n return -1;\n\n return value.doubleValue;\n}\n QString getModel() {\n int cpuInfo[4];\n char cpuBrand[48 + 1] = {0};\n\n // 获取CPU品牌字符串(需要调用3次CPUID)\n __cpuid(cpuInfo, 0x80000002);\n memcpy(cpuBrand, cpuInfo, sizeof(cpuInfo));\n\n __cpuid(cpuInfo, 0x80000003);\n memcpy(cpuBrand + 16, cpuInfo, sizeof(cpuInfo));\n\n __cpuid(cpuInfo, 0x80000004);\n memcpy(cpuBrand + 32, cpuInfo, sizeof(cpuInfo));\n\n QString result(cpuBrand);\n\n return result.trimmed();\n}\n};"], ["/OpenSpeedy/preferencedialog.h", "class PreferenceDialog {\n Q_OBJECT\n\n public:\n explicit PreferenceDialog(HWND hMainWindow,\n QSettings* settings,\n QLabel* increaseSpeedLabel,\n QLabel* decreaseSpeedLabel,\n QLabel* resetSpeedLabel,\n QWidget* parent = nullptr);\n ~PreferenceDialog() {\n unregisterGlobalHotkeys();\n delete ui;\n}\n int getIncreaseStep() {\n return m_increaseStep;\n}\n int getDecreaseStep() {\n return m_decreaseStep;\n}\n double getShift1() {\n return m_shift1Value;\n}\n double getShift2() {\n return m_shift2Value;\n}\n double getShift3() {\n return m_shift3Value;\n}\n double getShift4() {\n return m_shift4Value;\n}\n double getShift5() {\n return m_shift5Value;\n}\n public:\n void show() {\n unregisterGlobalHotkeys();\n QDialog::show();\n}\n private:\n void on_buttonBox_accepted() {\n update();\n setupGlobalHotkeys();\n redraw();\n dump();\n}\n void on_buttonBox_rejected() {\n redraw();\n setupGlobalHotkeys();\n}\n void recreate() {\n layout()->invalidate();\n layout()->activate();\n adjustSize();\n}\n private:\n void setupGlobalHotkeys() {\n for (auto it = m_shortcuts.begin(); it != m_shortcuts.end(); it++)\n {\n int id = it.key();\n QtCombinedKey combined = it.value();\n\n UINT vk = QSingleKeySequenceEdit::toVK(combined.key, combined.modifier);\n UINT modifier = QSingleKeySequenceEdit::toModifier(combined.modifier);\n RegisterHotKey(m_mainwindow, id, modifier, vk);\n }\n\n qDebug() << \"全局快捷键已注册:\";\n}\n void unregisterGlobalHotkeys() {\n for (auto it = m_shortcuts.begin(); it != m_shortcuts.end(); it++)\n {\n int id = it.key();\n UnregisterHotKey(m_mainwindow, id);\n }\n qDebug() << \"全局快捷键已注销\";\n}\n void loadShortcut(int id,\n const QString& config,\n const QString& defaultValue) {\n m_shortcuts.insert(id,\n QSingleKeySequenceEdit::toQtCombinedKey(\n m_settings->value(config, defaultValue).toString()));\n}\n void dumpShortcut(const QString& config, const QString& keyText) {\n m_settings->setValue(config, keyText);\n}\n void dump() {\n dumpShortcut(CONFIG_HOTKEY_SPEEDUP,\n ui->speedUpKeySequenceEdit->getKeyText());\n dumpShortcut(CONFIG_HOTKEY_SPEEDDOWN,\n ui->speedDownKeySequenceEdit->getKeyText());\n dumpShortcut(CONFIG_HOTKEY_RESETSPEED,\n ui->resetSpeedKeySequenceEdit->getKeyText());\n\n dumpShortcut(CONFIG_HOTKEY_SHIFT1, ui->shift1KeySequenceEdit->getKeyText());\n dumpShortcut(CONFIG_HOTKEY_SHIFT2, ui->shift2KeySequenceEdit->getKeyText());\n dumpShortcut(CONFIG_HOTKEY_SHIFT3, ui->shift3KeySequenceEdit->getKeyText());\n dumpShortcut(CONFIG_HOTKEY_SHIFT4, ui->shift4KeySequenceEdit->getKeyText());\n dumpShortcut(CONFIG_HOTKEY_SHIFT5, ui->shift5KeySequenceEdit->getKeyText());\n m_settings->setValue(CONFIG_INCREASE_STEP,\n ui->increaseStepSpinBox->value());\n m_settings->setValue(CONFIG_DECREASE_STEP,\n ui->decreaseStepSpinBox->value());\n m_settings->setValue(CONFIG_SHIFT1_VALUE, ui->shift1DoubleSpinBox->value());\n m_settings->setValue(CONFIG_SHIFT2_VALUE, ui->shift2DoubleSpinBox->value());\n m_settings->setValue(CONFIG_SHIFT3_VALUE, ui->shift3DoubleSpinBox->value());\n m_settings->setValue(CONFIG_SHIFT4_VALUE, ui->shift4DoubleSpinBox->value());\n m_settings->setValue(CONFIG_SHIFT5_VALUE, ui->shift5DoubleSpinBox->value());\n m_settings->sync();\n}\n void updateShortcut(int id, QSingleKeySequenceEdit* keyEdit) {\n m_shortcuts[id] = keyEdit->getQtCombinedKey();\n}\n void update() {\n updateShortcut(HOTKEY_INCREASE_SPEED, ui->speedUpKeySequenceEdit);\n updateShortcut(HOTKEY_DECREASE_SPEED, ui->speedDownKeySequenceEdit);\n updateShortcut(HOTKEY_RESET_SPEED, ui->resetSpeedKeySequenceEdit);\n updateShortcut(HOTKEY_SHIFT1, ui->shift1KeySequenceEdit);\n updateShortcut(HOTKEY_SHIFT2, ui->shift2KeySequenceEdit);\n updateShortcut(HOTKEY_SHIFT3, ui->shift3KeySequenceEdit);\n updateShortcut(HOTKEY_SHIFT4, ui->shift4KeySequenceEdit);\n updateShortcut(HOTKEY_SHIFT5, ui->shift5KeySequenceEdit);\n\n m_increaseStep = ui->increaseStepSpinBox->value();\n m_decreaseStep = ui->decreaseStepSpinBox->value();\n m_shift1Value = ui->shift1DoubleSpinBox->value();\n m_shift2Value = ui->shift2DoubleSpinBox->value();\n m_shift3Value = ui->shift3DoubleSpinBox->value();\n m_shift4Value = ui->shift4DoubleSpinBox->value();\n m_shift5Value = ui->shift5DoubleSpinBox->value();\n}\n void redrawSpinBox(QSpinBox* spinbox, int value) {\n spinbox->setValue(value);\n}\n void redrawSpinBox(QDoubleSpinBox* spinbox, double value) {\n spinbox->setValue(value);\n}\n void redrawKeyEdit(QSingleKeySequenceEdit* keyEdit, int id) {\n QtCombinedKey combinedKey = m_shortcuts[id];\n keyEdit->setKeySequence(combinedKey.key | combinedKey.modifier);\n}\n void redraw() {\n redrawKeyEdit(ui->speedUpKeySequenceEdit, HOTKEY_INCREASE_SPEED);\n redrawKeyEdit(ui->speedDownKeySequenceEdit, HOTKEY_DECREASE_SPEED);\n redrawKeyEdit(ui->resetSpeedKeySequenceEdit, HOTKEY_RESET_SPEED);\n redrawKeyEdit(ui->shift1KeySequenceEdit, HOTKEY_SHIFT1);\n redrawKeyEdit(ui->shift2KeySequenceEdit, HOTKEY_SHIFT2);\n redrawKeyEdit(ui->shift3KeySequenceEdit, HOTKEY_SHIFT3);\n redrawKeyEdit(ui->shift4KeySequenceEdit, HOTKEY_SHIFT4);\n redrawKeyEdit(ui->shift5KeySequenceEdit, HOTKEY_SHIFT5);\n\n redrawSpinBox(ui->increaseStepSpinBox, m_increaseStep);\n redrawSpinBox(ui->decreaseStepSpinBox, m_decreaseStep);\n redrawSpinBox(ui->shift1DoubleSpinBox, m_shift1Value);\n redrawSpinBox(ui->shift2DoubleSpinBox, m_shift2Value);\n redrawSpinBox(ui->shift3DoubleSpinBox, m_shift3Value);\n redrawSpinBox(ui->shift4DoubleSpinBox, m_shift4Value);\n redrawSpinBox(ui->shift5DoubleSpinBox, m_shift5Value);\n\n m_increaseSpeedLabel->setText(\n QString(tr(\"%1 增加速度\"))\n .arg(QSingleKeySequenceEdit::wrapText(\n ui->speedUpKeySequenceEdit->getKeyText())));\n\n m_decreaseSpeedLabel->setText(\n QString(tr(\"%1 减少速度\"))\n .arg(QSingleKeySequenceEdit::wrapText(\n ui->speedDownKeySequenceEdit->getKeyText())));\n\n m_resetSpeedLabel->setText(\n QString(tr(\"%1 重置速度\"))\n .arg(QSingleKeySequenceEdit::wrapText(\n ui->resetSpeedKeySequenceEdit->getKeyText())));\n\n adjustSize();\n}\n Ui::PreferenceDialog* ui;\n QSettings* m_settings;\n QLabel* m_increaseSpeedLabel;\n QLabel* m_decreaseSpeedLabel;\n QLabel* m_resetSpeedLabel;\n QMap m_shortcuts;\n double m_shift1Value;\n double m_shift2Value;\n double m_shift3Value;\n double m_shift4Value;\n double m_shift5Value;\n int m_increaseStep;\n int m_decreaseStep;\n HWND m_mainwindow;\n};"], ["/OpenSpeedy/memutils.h", "class MemUtils {\n private:\n PDH_HQUERY hQuery = NULL;\n PDH_HCOUNTER hCounter = NULL;\n bool initialized = false;\n public:\n MemUtils() {\n}\n bool init() {\n if (PdhOpenQuery(NULL, NULL, &hQuery) != ERROR_SUCCESS) return false;\n\n if (PdhAddEnglishCounter(hQuery,\n L\"\\\\Memory\\\\Available Bytes\",\n NULL,\n &hCounter) != ERROR_SUCCESS)\n {\n PdhCloseQuery(hQuery);\n return false;\n }\n\n PdhCollectQueryData(hQuery);\n initialized = true;\n return true;\n}\n double getTotal() {\n MEMORYSTATUSEX memInfo;\n memInfo.dwLength = sizeof(MEMORYSTATUSEX);\n GlobalMemoryStatusEx(&memInfo);\n return memInfo.ullTotalPhys / (1024.0 * 1024.0 * 1024.0);\n}\n double getUsage() {\n if (!initialized) return -1;\n\n if (PdhCollectQueryData(hQuery) != ERROR_SUCCESS) return -1;\n\n PDH_FMT_COUNTERVALUE available;\n if (PdhGetFormattedCounterValue(hCounter,\n PDH_FMT_DOUBLE,\n NULL,\n &available) != ERROR_SUCCESS)\n return -1;\n\n double totalMemory = getTotal() * 1024 * 1024 * 1024;\n double usageMemory = totalMemory - available.doubleValue;\n\n return usageMemory / (1024.0 * 1024.0 * 1024.0);\n}\n};"], ["/OpenSpeedy/aboutdialog.h", "class AboutDialog {\n Q_OBJECT\n\n public:\n explicit AboutDialog(QWidget* parent = nullptr);\n ~AboutDialog() {\n delete ui;\n}\n private:\n void recreate() {\n layout()->invalidate();\n layout()->activate();\n adjustSize();\n}\n private:\n Ui::AboutDialog* ui;\n};"], ["/OpenSpeedy/config.h", "/*\n * OpenSpeedy - Open Source Game Speed Controller\n * Copyright (C) 2025 Game1024\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n#ifndef CONFIG_H\n#define CONFIG_H\n\n#define OPENSPEEDY_VERSION \"v1.7.6\"\n\n#define BRIDGE32_EXE \"bridge32.exe\"\n#define BRIDGE64_EXE \"bridge64.exe\"\n\n#define SPEEDPATCH32_DLL \"speedpatch32.dll\"\n#define SPEEDPATCH64_DLL \"speedpatch64.dll\"\n\n#define CONFIG_LANGUAGE \"General/Language\"\n\n// 热键ID\nenum HotkeyIds\n{\n HOTKEY_INCREASE_SPEED = 1001,\n HOTKEY_DECREASE_SPEED = 1002,\n HOTKEY_RESET_SPEED = 1003,\n HOTKEY_SHIFT1 = 1011,\n HOTKEY_SHIFT2 = 1012,\n HOTKEY_SHIFT3 = 1013,\n HOTKEY_SHIFT4 = 1014,\n HOTKEY_SHIFT5 = 1015\n};\n\n#endif // CONFIG_H\n"], ["/OpenSpeedy/speedpatch/SpeedPatch_global.h", "/*\n * OpenSpeedy - Open Source Game Speed Controller\n * Copyright (C) 2025 Game1024\n * \n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n * \n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n * \n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n#ifndef SPEEDPATCH_GLOBAL_H\n#define SPEEDPATCH_GLOBAL_H\n\n\n#endif // SPEEDPATCH_GLOBAL_H\n"], ["/OpenSpeedy/mainwindow.h", "class MainWindow {\n};"], ["/OpenSpeedy/speedpatch/speedpatch.h", "class speedpatch {\n};"]], "task_instance_info": {"created_time": "2025-08-20 19:51:26", "created_task_model": "DeepSeek-R1", "function_skeleton": "bool execute(const QStringList &arguments) {}", "code_description": "This code segment functions to: Execute system-level commands with specified parameters while handling process lifecycle management, error detection, and output logging through standardized system utilities."}, "inference_content": {"inference_model": "DeepSeek-R1", "inference_result": "```cpp\n[TASK_BEGIN]\nbool execute(const QStringList &arguments) {\n QProcess process;\n process.setProgram(\"schtasks\");\n process.setArguments(arguments);\n \n process.start();\n if (!process.waitForStarted(3000)) {\n qWarning() << \"任务计划程序命令启动失败:\" << process.errorString();\n return false;\n }\n\n if (!process.waitForFinished(5000)) {\n qWarning() << \"任务计划程序命令执行超时\";\n return false;\n }\n\n if (process.exitCode() != 0) {\n qWarning() << \"schtasks执行失败,退出码:\" << process.exitCode();\n qWarning() << \"错误信息:\" << QString::fromLocal8Bit(process.readAllStandardError());\n return false;\n }\n\n return true;\n}\n[TASK_END]\n```", "inference_time": "2025-08-20 19-51-51"}, "editdistance_info": {"edit_distance": 37.8261, "calculate_time": "2025-08-20 19:51:51", "true_code_clean": "bool execute(const QStringList &arguments) {\n QProcess process;\n process.setProgram(\"schtasks\");\n process.setArguments(arguments);\n const int timeout = 10000;\n process.start();\n if (!process.waitForStarted(timeout))\n {\n qWarning() << \"无法运行:\" << process.errorString();\n return false;\n }\n if (!process.waitForFinished(timeout))\n {\n qWarning() << \"执行超时\";\n process.kill();\n return false;\n }\n int exitcode = process.exitCode();\n QString stdout_ = QString::fromLocal8Bit(process.readAllStandardOutput());\n QString stderr_ = QString::fromLocal8Bit(process.readAllStandardError());\n if (exitcode == 0)\n {\n qDebug() << \"执行成功:\" << arguments;\n qDebug() << \"输出:\" << stdout_;\n return true;\n }\n else\n {\n qDebug() << \"执行失败:\" << arguments;\n qDebug() << \"错误输出:\" << stderr_;\n qDebug() << \"标准输出:\" << stdout_;\n return false;\n }\n}", "predict_code_clean": "bool execute(const QStringList &arguments) {\n QProcess process;\n process.setProgram(\"schtasks\");\n process.setArguments(arguments);\n process.start();\n if (!process.waitForStarted(3000)) {\n qWarning() << \"任务计划程序命令启动失败:\" << process.errorString();\n return false;\n }\n if (!process.waitForFinished(5000)) {\n qWarning() << \"任务计划程序命令执行超时\";\n return false;\n }\n if (process.exitCode() != 0) {\n qWarning() << \"schtasks执行失败,退出码:\" << process.exitCode();\n qWarning() << \"错误信息:\" << QString::fromLocal8Bit(process.readAllStandardError());\n return false;\n }\n return true;\n}"}} {"repo_name": "OpenSpeedy", "file_name": "/OpenSpeedy/main.cpp", "inference_info": {"prefix_code": "/*\n * OpenSpeedy - Open Source Game Speed Controller\n * Copyright (C) 2025 Game1024\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n#include \"mainwindow.h\"\n#include \"windbg.h\"\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n", "suffix_code": "\n", "middle_code": "int\nmain(int argc, char* argv[])\n{\n SetUnhandledExceptionFilter(createMiniDump);\n SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);\n QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);\n QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);\n QApplication::setAttribute(Qt::AA_UseSoftwareOpenGL);\n QApplication a(argc, argv);\n winutils::enableAllPrivilege();\n QString unique = \"OpenSpeedy\";\n QLocalSocket socket;\n socket.connectToServer(unique);\n if (socket.waitForConnected(500))\n {\n socket.close();\n return -1;\n }\n QIcon appIcon;\n appIcon.addFile(\":/icons/images/icon_16.ico\", QSize(16, 16));\n appIcon.addFile(\":/icons/images/icon_32.ico\", QSize(32, 32));\n appIcon.addFile(\":/icons/images/icon_64.ico\", QSize(64, 64));\n a.setWindowIcon(appIcon);\n QSettings settings =\n QSettings(QCoreApplication::applicationDirPath() + \"/config.ini\",\n QSettings::IniFormat);\n QTranslator translator;\n const QString baseName =\n \"OpenSpeedy_\" +\n settings.value(CONFIG_LANGUAGE, QLocale().system().name()).toString();\n if (translator.load(\":/i18n/translations/\" + baseName))\n {\n a.installTranslator(&translator);\n }\n QCommandLineParser parser;\n parser.setApplicationDescription(\"OpenSpeedy\");\n QCommandLineOption minimizeOption(\n QStringList() << \"m\" << \"minimize-to-tray\", \"启动时最小化到托盘\");\n parser.addOption(minimizeOption);\n parser.process(a);\n MainWindow w;\n w.resize(1024, 768);\n if (parser.isSet(minimizeOption))\n {\n w.hide();\n }\n else\n {\n w.show();\n }\n QLocalServer server;\n QLocalServer::removeServer(unique);\n server.listen(unique);\n QObject::connect(&server,\n &QLocalServer::newConnection,\n [&]\n {\n w.show();\n w.raise();\n w.showNormal();\n w.activateWindow();\n });\n return a.exec();\n}", "code_description": null, "fill_type": "FUNCTION_TYPE", "language_type": "cpp", "sub_task_type": null}, "context_code": [["/OpenSpeedy/windbg.h", "/*\n * OpenSpeedy - Open Source Game Speed Controller\n * Copyright (C) 2025 Game1024\n * \n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n * \n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n * \n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n#ifndef WINDBG_H\n#define WINDBG_H\n#include \n#include \n#include \n#include \n// 链接dbghelp库\n#pragma comment(lib, \"dbghelp.lib\")\n\ntypedef BOOL(WINAPI *MINIDUMPWRITEDUMP)(\n HANDLE hProcess,\n DWORD ProcessId,\n HANDLE hFile,\n MINIDUMP_TYPE DumpType,\n PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,\n PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,\n PMINIDUMP_CALLBACK_INFORMATION CallbackParam);\n\n// 自定义异常处理函数\nLONG WINAPI createMiniDump(EXCEPTION_POINTERS *exceptionPointers)\n{\n // 创建dump文件目录\n QDir dumpDir(QDir::currentPath() + \"/dumps\");\n if (!dumpDir.exists())\n {\n dumpDir.mkpath(\".\");\n }\n\n // 生成带时间戳的文件名\n QString dumpFileName =\n QString(\"%1/crash_%2.dmp\")\n .arg(dumpDir.absolutePath())\n .arg(QDateTime::currentDateTime().toString(\"yyyy-MM-dd_hh-mm-ss\"));\n\n // 创建文件\n HANDLE hFile = CreateFile(dumpFileName.toStdWString().c_str(),\n GENERIC_WRITE, FILE_SHARE_READ, NULL,\n CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);\n\n if (hFile == INVALID_HANDLE_VALUE)\n {\n return EXCEPTION_CONTINUE_SEARCH;\n }\n\n // 加载dbghelp.dll\n HMODULE dbgHelp = LoadLibrary(L\"dbghelp.dll\");\n if (!dbgHelp)\n {\n CloseHandle(hFile);\n return EXCEPTION_CONTINUE_SEARCH;\n }\n\n // 获取MiniDumpWriteDump函数地址\n MINIDUMPWRITEDUMP miniDumpWriteDump =\n (MINIDUMPWRITEDUMP)GetProcAddress(dbgHelp, \"MiniDumpWriteDump\");\n\n if (!miniDumpWriteDump)\n {\n FreeLibrary(dbgHelp);\n CloseHandle(hFile);\n return EXCEPTION_CONTINUE_SEARCH;\n }\n\n // 配置异常信息\n MINIDUMP_EXCEPTION_INFORMATION exInfo;\n exInfo.ThreadId = GetCurrentThreadId();\n exInfo.ExceptionPointers = exceptionPointers;\n exInfo.ClientPointers = FALSE;\n\n // 设置dump类型\n MINIDUMP_TYPE dumpType =\n (MINIDUMP_TYPE)(MiniDumpWithFullMemory | // 包含完整内存\n MiniDumpWithFullMemoryInfo | // 包含内存信息\n MiniDumpWithHandleData | // 包含句柄数据\n MiniDumpWithThreadInfo | // 包含线程信息\n MiniDumpWithUnloadedModules // 包含卸载的模块\n );\n\n // 写入dump文件\n BOOL success = miniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(),\n hFile, dumpType, &exInfo, NULL, NULL);\n\n // 清理资源\n FreeLibrary(dbgHelp);\n CloseHandle(hFile);\n\n // 显示通知\n if (success)\n {\n std::wstring message =\n QString(\"程序遇到错误已退出,崩溃转储文件已保存到:\\n%1\")\n .arg(dumpFileName)\n .toStdWString();\n MessageBoxW(nullptr, message.c_str(), L\"程序崩溃\",\n MB_OK | MB_ICONERROR);\n }\n\n return EXCEPTION_EXECUTE_HANDLER;\n}\n\n#endif // WINDBG_H\n"], ["/OpenSpeedy/config.h", "/*\n * OpenSpeedy - Open Source Game Speed Controller\n * Copyright (C) 2025 Game1024\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n#ifndef CONFIG_H\n#define CONFIG_H\n\n#define OPENSPEEDY_VERSION \"v1.7.6\"\n\n#define BRIDGE32_EXE \"bridge32.exe\"\n#define BRIDGE64_EXE \"bridge64.exe\"\n\n#define SPEEDPATCH32_DLL \"speedpatch32.dll\"\n#define SPEEDPATCH64_DLL \"speedpatch64.dll\"\n\n#define CONFIG_LANGUAGE \"General/Language\"\n\n// 热键ID\nenum HotkeyIds\n{\n HOTKEY_INCREASE_SPEED = 1001,\n HOTKEY_DECREASE_SPEED = 1002,\n HOTKEY_RESET_SPEED = 1003,\n HOTKEY_SHIFT1 = 1011,\n HOTKEY_SHIFT2 = 1012,\n HOTKEY_SHIFT3 = 1013,\n HOTKEY_SHIFT4 = 1014,\n HOTKEY_SHIFT5 = 1015\n};\n\n#endif // CONFIG_H\n"], ["/OpenSpeedy/bridge/main.cpp", "#include \"../config.h\"\n#include \"../speedpatch/speedpatch.h\"\n#include \"../windbg.h\"\n#include \"../winutils.h\"\n#include \n#include \n#include \n#include \n#include \n\n#ifndef _WIN64\n#define SPEEDPATCH_DLL SPEEDPATCH32_DLL\n#else\n#define SPEEDPATCH_DLL SPEEDPATCH64_DLL\n#endif\n\nvoid\nhandleInject(int processId, QString dllPath)\n{\n qDebug() << \"执行 inject,进程ID:\" << processId;\n winutils::injectDll(processId, dllPath);\n SetProcessStatus(processId, true);\n}\n\nvoid\nhandleUnhook(int processId, QString dllPath)\n{\n qDebug() << \"执行 unhook,进程ID:\" << processId;\n SetProcessStatus(processId, false);\n}\n\nvoid\nhandleChange(double factor)\n{\n qDebug() << \"执行 change,参数:\" << factor;\n ChangeSpeed(factor);\n}\n\nint\nmain(int argc, char* argv[])\n{\n SetUnhandledExceptionFilter(createMiniDump);\n QCoreApplication a(argc, argv);\n if (winutils::enableAllPrivilege())\n {\n qDebug() << \"权限提升成功\";\n }\n\n QString dllPath = QDir::toNativeSeparators(\n QCoreApplication::applicationDirPath() + \"/\" + SPEEDPATCH_DLL);\n\n QTextStream in(stdin);\n QTextStream out(stdout);\n\n QRegularExpression injectRegex(\"^\\\\s*inject\\\\s+(\\\\d+)\\\\s*$\",\n QRegularExpression::CaseInsensitiveOption);\n QRegularExpression unhookRegex(\"^\\\\s*unhook\\\\s+(\\\\d+)\\\\s*$\",\n QRegularExpression::CaseInsensitiveOption);\n QRegularExpression changeRegex(\"^\\\\s*change\\\\s+([+-]?\\\\d*\\\\.?\\\\d+)\\\\s*$\",\n QRegularExpression::CaseInsensitiveOption);\n QRegularExpression exitRegex(\"^\\\\s*exit\\\\s*$\",\n QRegularExpression::CaseInsensitiveOption);\n\n while (true)\n {\n QString line = in.readLine();\n if (line.isNull())\n {\n // 管道关闭或输入结束\n break;\n }\n line = line.trimmed();\n if (line.isEmpty())\n continue;\n\n QRegularExpressionMatch match;\n if ((match = injectRegex.match(line)).hasMatch())\n {\n int pid = match.captured(1).toInt();\n handleInject(pid, dllPath);\n }\n else if ((match = unhookRegex.match(line)).hasMatch())\n {\n int pid = match.captured(1).toInt();\n handleUnhook(pid, dllPath);\n }\n else if ((match = changeRegex.match(line)).hasMatch())\n {\n double factor = match.captured(1).toDouble();\n handleChange(factor);\n }\n else if (exitRegex.match(line).hasMatch())\n {\n qDebug() << \"收到exit命令,程序即将退出。\";\n break;\n }\n else\n {\n qDebug() << \"无效命令:\" << line;\n }\n }\n\n return 0;\n}\n"], ["/OpenSpeedy/speedpatch/SpeedPatch_global.h", "/*\n * OpenSpeedy - Open Source Game Speed Controller\n * Copyright (C) 2025 Game1024\n * \n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n * \n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n * \n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n#ifndef SPEEDPATCH_GLOBAL_H\n#define SPEEDPATCH_GLOBAL_H\n\n\n#endif // SPEEDPATCH_GLOBAL_H\n"], ["/OpenSpeedy/processmonitor.h", "class ProcessMonitor {\n Q_OBJECT\npublic:\nexplicit ProcessMonitor(QSettings* settings,\n QTreeWidget* treeWidget,\n QLabel* treeStatusLabel,\n QLabel* injector32StatusLabel,\n QLabel* injector64StatusLabel,\n\n QObject* parent = nullptr);\n ~ProcessMonitor() {\n this->terminalBridge();\n delete m_bridge32;\n delete m_bridge64;\n}\n void setInterval(int msec);\n void setFilter(QString processName) {\n m_filter = processName.toLower();\n}\n void changeSpeed(double factor) {\n QString cmd = QString(\"change %1\\n\").arg(factor);\n m_bridge32->write(cmd.toUtf8(), cmd.size());\n m_bridge32->waitForBytesWritten();\n m_bridge64->write(cmd.toUtf8(), cmd.size());\n m_bridge64->waitForBytesWritten();\n}\n public:\n void refresh() {\n healthcheckBridge();\n QList processList = winutils::getProcessList();\n if (m_filter == \"\")\n {\n update(processList);\n m_treeStatusLabel->setText(QString(tr(\"搜索到%1个进程, 已过滤展示%2个\"))\n .arg(processList.size())\n .arg(processList.size()));\n }\n else\n {\n QList filtered;\n for (ProcessInfo info : processList)\n {\n if (info.name.toLower().contains(m_filter))\n filtered.append(info);\n }\n update(filtered);\n m_treeStatusLabel->setText(QString(tr(\"搜索到%1个进程, 已过滤展示%2个\"))\n .arg(processList.size())\n .arg(filtered.size()));\n }\n}\n void start() {\n m_timer = new QTimer(this);\n connect(m_timer, &QTimer::timeout, this, &ProcessMonitor::refresh);\n m_timer->start(1000);\n}\n private:\n void onItemChanged(QTreeWidgetItem* item, int column) {\n if (column == 5 && (item->flags() & Qt::ItemIsUserCheckable))\n {\n bool state = m_treeWidget->blockSignals(true);\n\n Qt::CheckState checkState = item->checkState(column);\n QString processName = item->text(0);\n DWORD pid = item->text(1).toLong();\n bool is64Bit = item->text(3) == \"x64\" ? true : false;\n if (checkState == Qt::Checked)\n {\n m_targetNames.insert(processName);\n this->injectDll(pid, is64Bit);\n item->setText(5, tr(\"加速中\"));\n for (int col = 0; col < item->columnCount(); ++col)\n {\n item->setBackground(col, QBrush(QColor(\"#f3e5f5\")));\n item->setForeground(col, QBrush(QColor(\"#7b1fa2\")));\n }\n qDebug() << processName << \"勾选\";\n dump();\n }\n else\n {\n m_targetNames.remove(processName);\n this->unhookDll(pid, is64Bit);\n item->setText(5, \"\");\n for (int col = 0; col < item->columnCount(); ++col)\n {\n item->setBackground(col, QBrush());\n item->setForeground(col, QBrush());\n }\n qDebug() << processName << \"取消勾选\";\n dump();\n }\n\n m_treeWidget->blockSignals(state);\n }\n}\n private:\n QTreeWidget* m_treeWidget;\n QLabel* m_treeStatusLabel;\n QLabel* m_injector32StatusLabel;\n QLabel* m_injector64StatusLabel;\n QString m_filter;\n QTimer* m_timer = nullptr;\n QString m_dllPath;\n QProcess* m_bridge32;\n QProcess* m_bridge64;\n QSettings* m_settings;\n QHash m_iconCache;\n QMap m_processItems;\n QSet m_targetNames;\n void init() {\n QStringList targetNames =\n m_settings->value(CONFIG_TARGETNAMES_KEY).toStringList();\n m_targetNames = QSet(targetNames.begin(), targetNames.end());\n}\n void dump() {\n m_settings->setValue(CONFIG_TARGETNAMES_KEY,\n QStringList(m_targetNames.values()));\n}\n void update(const QList& processList) {\n // 跟踪现有进程,用于确定哪些已终止\n QSet currentPids;\n for (const ProcessInfo& info : processList)\n {\n currentPids.insert(info.pid);\n }\n\n // 移除已终止的进程\n QMutableMapIterator i(m_processItems);\n while (i.hasNext())\n {\n i.next();\n if (!currentPids.contains(i.key()))\n {\n QTreeWidgetItem* item = i.value();\n QTreeWidgetItem* parent = item->parent();\n\n if (parent)\n {\n parent->removeChild(item);\n }\n else\n {\n auto index = m_treeWidget->indexOfTopLevelItem(item);\n m_treeWidget->takeTopLevelItem(index);\n }\n\n while (item->childCount() > 0)\n {\n QTreeWidgetItem* child = item->takeChild(0);\n if (parent)\n {\n parent->addChild(child);\n }\n else\n {\n m_treeWidget->addTopLevelItem(child);\n }\n }\n\n // 删除节点\n delete item;\n\n // 从映射中移除\n i.remove();\n }\n }\n\n // 添加或更新进程信息\n for (const ProcessInfo& info : processList)\n {\n if (m_processItems.contains(info.pid))\n {\n // 更新已存在的进程信息\n QTreeWidgetItem* item = m_processItems[info.pid];\n item->setText(1, QString::number(info.pid));\n item->setData(1, Qt::UserRole, (long long)info.pid);\n item->setText(2,\n QString(\"%1 MB\").arg(info.memoryUsage / 1024 / 1024));\n item->setData(2, Qt::UserRole, (uint)info.memoryUsage);\n\n QString arch = info.is64Bit ? \"x64\" : \"x86\";\n item->setText(3, arch);\n QString priority;\n switch (info.priorityClass)\n {\n case HIGH_PRIORITY_CLASS:\n priority = tr(\"高\");\n break;\n case NORMAL_PRIORITY_CLASS:\n priority = tr(\"中\");\n break;\n case IDLE_PRIORITY_CLASS:\n priority = tr(\"低\");\n break;\n case REALTIME_PRIORITY_CLASS:\n priority = tr(\"实时\");\n break;\n default:\n priority = tr(\"未知\");\n break;\n }\n item->setText(4, priority);\n if (m_targetNames.contains(info.name))\n {\n if (item->checkState(5) == Qt::Unchecked)\n {\n item->setCheckState(5, Qt::Checked);\n }\n }\n else\n {\n if (item->checkState(5) == Qt::Checked)\n {\n item->setCheckState(5, Qt::Unchecked);\n }\n }\n }\n else\n {\n // 添加新进程\n QTreeWidgetItem* item = new SortTreeWidgetItem();\n\n item->setText(0, info.name);\n item->setData(0, Qt::UserRole, info.name.toLower());\n item->setText(1, QString::number(info.pid));\n item->setData(1, Qt::UserRole, (long long)info.pid);\n item->setText(2,\n QString(\"%1 MB\").arg(info.memoryUsage / 1024 / 1024));\n item->setData(2, Qt::UserRole, (uint)info.memoryUsage);\n\n QString arch = info.is64Bit ? \"x64\" : \"x86\";\n item->setText(3, arch);\n\n // 加载进程图标\n item->setIcon(0, getProcessIconCached(info.pid));\n\n QString priority;\n switch (info.priorityClass)\n {\n case HIGH_PRIORITY_CLASS:\n priority = tr(\"高\");\n break;\n case NORMAL_PRIORITY_CLASS:\n priority = tr(\"中\");\n break;\n case IDLE_PRIORITY_CLASS:\n priority = tr(\"低\");\n break;\n case REALTIME_PRIORITY_CLASS:\n priority = tr(\"实时\");\n break;\n default:\n priority = tr(\"未知\");\n break;\n }\n item->setText(4, priority);\n item->setCheckState(5, Qt::Unchecked);\n m_treeWidget->addTopLevelItem(item);\n m_processItems[info.pid] = item;\n }\n }\n}\n void injectDll(DWORD processId, bool is64Bit) {\n QString cmd = QString(\"inject %1\\n\").arg(processId);\n if (!is64Bit)\n {\n m_bridge32->write(cmd.toUtf8(), cmd.size());\n m_bridge32->waitForBytesWritten();\n }\n else\n {\n m_bridge64->write(cmd.toUtf8(), cmd.size());\n m_bridge64->waitForBytesWritten();\n }\n}\n void unhookDll(DWORD processId, bool is64Bit) {\n QString cmd = QString(\"unhook %1\\n\").arg(processId);\n if (!is64Bit)\n {\n m_bridge32->write(cmd.toUtf8(), cmd.size());\n m_bridge32->waitForBytesWritten();\n }\n else\n {\n m_bridge64->write(cmd.toUtf8(), cmd.size());\n m_bridge64->waitForBytesWritten();\n }\n}\n void startBridge32() {\n m_bridge32 = new QProcess();\n QStringList params32;\n m_bridge32->start(BRIDGE32_EXE, params32);\n if (!m_bridge32->waitForStarted())\n {\n qDebug() << \"32位桥接子进程启动失败\";\n }\n else\n {\n qDebug() << \"32位桥接子进程已启动\";\n }\n m_bridge32->setProcessChannelMode(QProcess::MergedChannels);\n connect(m_bridge32,\n &QProcess::readyReadStandardOutput,\n [&]()\n {\n QByteArray data = m_bridge32->readAllStandardOutput();\n qDebug() << \"收到输出:\" << QString(data).trimmed();\n });\n}\n void startBridge64() {\n m_bridge64 = new QProcess();\n QStringList params64;\n m_bridge64->start(BRIDGE64_EXE, params64);\n if (!m_bridge64->waitForStarted())\n {\n qDebug() << \"64位桥接子进程启动失败\";\n }\n else\n {\n qDebug() << \"64位桥接子进程已启动\";\n }\n m_bridge64->setProcessChannelMode(QProcess::MergedChannels);\n connect(m_bridge64,\n &QProcess::readyReadStandardOutput,\n [&]()\n {\n QByteArray data = m_bridge64->readAllStandardOutput();\n qDebug() << \"收到输出:\" << QString(data).trimmed();\n });\n}\n void healthcheckBridge() {\n if (this->m_bridge32->state() == QProcess::Running)\n {\n m_injector32StatusLabel->setStyleSheet(\"color: green\");\n m_injector32StatusLabel->setText(tr(\"正常\"));\n }\n else\n {\n m_injector32StatusLabel->setStyleSheet(\"color: red\");\n m_injector32StatusLabel->setText(tr(\"异常退出\"));\n }\n\n if (this->m_bridge64->state() == QProcess::Running)\n {\n m_injector64StatusLabel->setStyleSheet(\"color: green\");\n m_injector64StatusLabel->setText(tr(\"正常\"));\n }\n else\n {\n m_injector64StatusLabel->setStyleSheet(\"color:red\");\n m_injector64StatusLabel->setText(tr(\"异常退出\"));\n }\n}\n void terminalBridge() {\n QString cmd = QString(\"exit\\n\");\n m_bridge32->write(cmd.toUtf8(), cmd.size());\n m_bridge32->waitForBytesWritten();\n m_bridge64->write(cmd.toUtf8(), cmd.size());\n m_bridge64->waitForBytesWritten();\n}\n static QIcon getProcessIcon(QString processPath) {\n int lastSlashPos =\n std::max(processPath.lastIndexOf('/'), processPath.lastIndexOf('\\\\'));\n QString processName;\n if (lastSlashPos == -1)\n {\n processName = processPath;\n }\n processName = processPath.mid(lastSlashPos + 1);\n\n if (processPath.isEmpty())\n {\n qDebug() << processPath << \"无法获取进程完整路径\";\n return getDefaultIcon(processName);\n }\n\n SHFILEINFO sfi = {};\n if (SHGetFileInfo(reinterpret_cast(processPath.utf16()),\n FILE_ATTRIBUTE_NORMAL,\n &sfi,\n sizeof(SHFILEINFO),\n SHGFI_ICON | SHGFI_LARGEICON | SHGFI_USEFILEATTRIBUTES))\n {\n if (sfi.hIcon)\n {\n QIcon icon = QtWin::fromHICON(sfi.hIcon);\n DestroyIcon(sfi.hIcon);\n if (!icon.isNull())\n {\n qDebug() << processPath << \"通过SHGetFileInfo获取图标成功\";\n return icon;\n }\n }\n }\n\n HICON hIcon =\n ExtractIconW(nullptr, reinterpret_cast(processPath.utf16()), 0);\n if (hIcon)\n {\n QIcon icon = QtWin::fromHICON(hIcon);\n DestroyIcon(hIcon);\n if (!icon.isNull())\n return icon;\n }\n\n QFileInfo fileInfo(processPath);\n if (fileInfo.exists())\n {\n // 使用Qt的QFileIconProvider获取文件图标\n QFileIconProvider iconProvider;\n return iconProvider.icon(fileInfo);\n }\n qDebug() << processPath << \"无法获取进程图标使用默认图标\";\n\n return getDefaultIcon(processName);\n}\n static QIcon getDefaultIcon(const QString& processName) {\n // 根据进程名称或类型提供更有针对性的默认图标\n if (processName != \"\")\n {\n // 使用SHGetFileInfo获取.exe文件的图标\n SHFILEINFO sfi = {};\n QIcon icon;\n if (SHGetFileInfo(reinterpret_cast(processName.utf16()),\n FILE_ATTRIBUTE_NORMAL,\n &sfi,\n sizeof(SHFILEINFO),\n SHGFI_USEFILEATTRIBUTES | SHGFI_ICON |\n SHGFI_SMALLICON))\n {\n // 将HICON转换为QIcon\n icon = QtWin::fromHICON(sfi.hIcon);\n\n // 释放图标资源\n DestroyIcon(sfi.hIcon);\n }\n return icon;\n }\n else\n {\n // 使用SHGetFileInfo获取.exe文件的图标\n SHFILEINFO sfi = {};\n QIcon icon;\n if (SHGetFileInfo(reinterpret_cast(L\".exe\"),\n FILE_ATTRIBUTE_NORMAL,\n &sfi,\n sizeof(SHFILEINFO),\n SHGFI_USEFILEATTRIBUTES | SHGFI_ICON |\n SHGFI_SMALLICON))\n {\n // 将HICON转换为QIcon\n icon = QtWin::fromHICON(sfi.hIcon);\n\n // 释放图标资源\n DestroyIcon(sfi.hIcon);\n }\n return icon;\n }\n}\n QIcon getProcessIconCached(DWORD proccessId) {\n QString processPath = winutils::getProcessPath(processId);\n if (m_iconCache.contains(processPath))\n {\n return m_iconCache[processPath];\n }\n\n QIcon icon = getProcessIcon(processPath);\n m_iconCache.insert(processPath, icon);\n return icon;\n}\n public:\n};"], ["/OpenSpeedy/taskscheduler.h", "class TaskScheduler {\n Q_OBJECT\n public:\n explicit TaskScheduler(QObject *parent = nullptr);\n ~TaskScheduler() {\n}\n bool createStartupTask(const QString &taskName,\n const QString &executablePath) {\n if (taskName.isEmpty() || executablePath.isEmpty())\n {\n qWarning() << \"任务名称或可执行文件路径不能为空\";\n return false;\n }\n\n if (!QFile::exists(executablePath))\n {\n qWarning() << \"可执行文件不存在\" << executablePath;\n return false;\n }\n\n QStringList arguments;\n arguments << \"/create\"\n << \"/f\"\n << \"/tn\" << taskName << \"/tr\"\n << QString(\"\\\"%1\\\" --minimize-to-tray\").arg(executablePath)\n << \"/sc\" << \"onlogon\"\n << \"/delay\" << \"0000:10\"\n << \"/rl\" << \"highest\";\n\n return execute(arguments);\n}\n bool deleteTask(const QString &taskName) {\n if (taskName.isEmpty())\n {\n qWarning() << \"任务名称不能为空\";\n return false;\n }\n\n if (!isTaskExists(taskName))\n {\n qWarning() << \"任务不存在, 无需删除\" << taskName;\n return true;\n }\n\n QStringList arguments;\n arguments << \"/delete\"\n << \"/f\"\n << \"/tn\" << taskName;\n\n return execute(arguments);\n}\n bool enableTask(const QString &taskName, bool enable) {\n if (!isTaskExists(taskName))\n {\n qWarning() << \"任务不存在:\" << taskName;\n return false;\n }\n\n QStringList arguments;\n arguments << \"/change\"\n << \"/tn\" << taskName << (enable ? \"/enable\" : \"/disable\");\n return execute(arguments);\n}\n bool isTaskExists(const QString &taskName) {\n QStringList arguments;\n arguments << \"/query\" << \"/tn\" << taskName;\n\n return execute(arguments);\n}\n bool execute(const QStringList &arguments) {\n QProcess process;\n process.setProgram(\"schtasks\");\n process.setArguments(arguments);\n\n const int timeout = 10000;\n process.start();\n if (!process.waitForStarted(timeout))\n {\n qWarning() << \"无法运行:\" << process.errorString();\n return false;\n }\n\n if (!process.waitForFinished(timeout))\n {\n qWarning() << \"执行超时\";\n process.kill();\n return false;\n }\n\n int exitcode = process.exitCode();\n QString stdout_ = QString::fromLocal8Bit(process.readAllStandardOutput());\n QString stderr_ = QString::fromLocal8Bit(process.readAllStandardError());\n\n if (exitcode == 0)\n {\n qDebug() << \"执行成功:\" << arguments;\n qDebug() << \"输出:\" << stdout_;\n return true;\n }\n else\n {\n qDebug() << \"执行失败:\" << arguments;\n qDebug() << \"错误输出:\" << stderr_;\n qDebug() << \"标准输出:\" << stdout_;\n return false;\n }\n}\n bool createStartupShortcut(const QString &taskName,\n const QString &executablePath) {\n QString home = QDir::homePath();\n QString startupDir =\n home +\n \"\\\\AppData\\\\Roaming\\\\Microsoft\\\\Windows\\\\Start Menu\\\\Programs\\\\Startup\";\n QString shortcutPath = QDir(startupDir).absoluteFilePath(taskName + \".lnk\");\n QString arguments = \"--minimize-to-tray\";\n\n QString psScript =\n QString(\"$WScriptShell = New-Object -ComObject WScript.Shell; \"\n \"$Shortcut = $WScriptShell.CreateShortcut('%1'); \"\n \"$Shortcut.TargetPath = '%2'; \"\n \"$Shortcut.Arguments = '%3'; \"\n \"$Shortcut.Description = '%4'; \"\n \"$Shortcut.Save()\")\n .arg(shortcutPath, executablePath, arguments,\n QString(\"启动 %1\").arg(QFileInfo(executablePath).baseName()));\n\n return executePs(psScript);\n}\n bool deleteStartupShortcut(const QString &taskName) {\n QString home = QDir::homePath();\n QString startupDir =\n home + \"\\\\AppData\\\\Roaming\\\\Microsoft\\\\Windows\\\\Start Menu\\\\Programs\\\\Startup\";\n QString shortcutPath = QDir(startupDir).absoluteFilePath(taskName + \".lnk\");\n\n QString psScript = QString(\"Remove-Item '%1' -Force\").arg(shortcutPath);\n\n return executePs(psScript);\n}\n bool isStartupShortcutExists(const QString &taskName) {\n QString home = QDir::homePath();\n QString startupDir =\n home +\n \"\\\\AppData\\\\Roaming\\\\Microsoft\\\\Windows\\\\Start Menu\\\\Programs\\\\Startup\";\n QString shortcutPath = QDir(startupDir).absoluteFilePath(taskName + \".lnk\");\n\n return QFile::exists(shortcutPath);\n}\n bool executePs(const QString &psScript) {\n QProcess process;\n process.setProgram(\"powershell\");\n process.setArguments({\"-ExecutionPolicy\", \"Bypass\", \"-Command\", psScript});\n\n process.start();\n if (!process.waitForStarted(5000))\n {\n qDebug() << \"PowerShell 启动失败:\" << process.errorString();\n return false;\n }\n\n if (process.waitForFinished(5000) && process.exitCode() == 0)\n {\n qDebug() << \"PowerShell 执行成功\";\n return true;\n }\n else\n {\n QString error = QString::fromLocal8Bit(process.readAllStandardError());\n qDebug() << \"PowerShell 执行失败:\" << error;\n }\n\n return false;\n}\n};"], ["/OpenSpeedy/winutils.h", "class winutils {\n public:\n winutils() {\n}\n public:\n static bool injectDll(DWORD processId, const QString& dllPath) {\n HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);\n if (!hProcess)\n {\n qDebug() << \"Failed to open process:\" << GetLastError();\n return false;\n }\n\n if (checkDllExist(processId, dllPath))\n {\n qDebug() << \"Process already have been injected\";\n return true;\n }\n else if (injectDllViaCRTW(processId, dllPath))\n {\n return true;\n }\n else if (injectDllViaCRTA(processId, dllPath))\n {\n return true;\n }\n\n injectDllViaAPCW(processId, dllPath);\n injectDllViaAPCA(processId, dllPath);\n if (checkDllExist(processId, dllPath))\n {\n return true;\n }\n else if (injectDllViaWHKW(processId, dllPath))\n {\n return true;\n }\n else if (injectDllViaWHKA(processId, dllPath))\n {\n return true;\n }\n else\n {\n return false;\n }\n}\n static bool injectDllViaCRTA(DWORD processId, const QString& dllPath) {\n HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);\n if (!hProcess)\n {\n qDebug() << \"Failed to open process:\" << GetLastError();\n return false;\n }\n\n if (checkDllExist(processId, dllPath))\n {\n qDebug() << \"Process already have been injected\";\n return true;\n }\n SIZE_T pathSize = (dllPath.size() + 1) * sizeof(char);\n LPVOID pDllPath =\n VirtualAllocEx(hProcess,\n nullptr,\n pathSize,\n MEM_COMMIT | MEM_RESERVE,\n PAGE_EXECUTE_READWRITE);\n if (!pDllPath)\n {\n qDebug() << \"Failed to allocate memory in target process:\"\n << GetLastError();\n CloseHandle(hProcess);\n return false;\n }\n\n if (!WriteProcessMemory(hProcess,\n pDllPath,\n dllPath.toStdString().c_str(),\n pathSize,\n nullptr))\n {\n qDebug() << \"Failed to write memory in target process:\"\n << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n HMODULE hKernel32 = GetModuleHandle(L\"kernel32.dll\");\n if (!hKernel32)\n {\n qDebug() << \"Failed to get handle for kernel32.dll:\" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n FARPROC pLoadLibraryA = GetProcAddress(hKernel32, \"LoadLibraryA\");\n if (!pLoadLibraryA)\n {\n qDebug() << \"Failed to get address of LoadLibraryA:\" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n HANDLE hThread = CreateRemoteThread(hProcess,\n nullptr,\n 0,\n (LPTHREAD_START_ROUTINE)pLoadLibraryA,\n pDllPath,\n 0,\n nullptr);\n if (!hThread)\n {\n qDebug() << \"Failed to create remote thread:\" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n WaitForSingleObject(hThread, INFINITE);\n\n // 检查LoadLibrary是否执行成功\n DWORD exitCode = 0;\n if (GetExitCodeThread(hThread, &exitCode))\n {\n qDebug() << \"Remote thread exit code:\" << exitCode;\n // LoadLibrary返回的是模块句柄,如果为0则失败\n if (exitCode == 0)\n {\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n CloseHandle(hThread);\n qDebug() << \"LoadLibrary failed in remote process\";\n return false;\n }\n }\n\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hThread);\n CloseHandle(hProcess);\n\n return true;\n}\n static bool injectDllViaCRTW(DWORD processId, const QString& dllPath) {\n HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);\n if (!hProcess)\n {\n qDebug() << \"Failed to open process:\" << GetLastError();\n return false;\n }\n\n if (checkDllExist(processId, dllPath))\n {\n qDebug() << \"Process already have been injected\";\n return true;\n }\n SIZE_T pathSize = (dllPath.size() + 1) * sizeof(wchar_t);\n LPVOID pDllPath =\n VirtualAllocEx(hProcess, nullptr, pathSize, MEM_COMMIT | MEM_RESERVE,\n PAGE_EXECUTE_READWRITE);\n if (!pDllPath)\n {\n qDebug() << \"Failed to allocate memory in target process:\"\n << GetLastError();\n CloseHandle(hProcess);\n return false;\n }\n\n if (!WriteProcessMemory(hProcess,\n pDllPath,\n dllPath.toStdWString().c_str(),\n pathSize,\n nullptr))\n {\n qDebug() << \"Failed to write memory in target process:\"\n << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n HMODULE hKernel32 = GetModuleHandle(L\"kernel32.dll\");\n if (!hKernel32)\n {\n qDebug() << \"Failed to get handle for kernel32.dll:\" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n FARPROC pLoadLibraryW = GetProcAddress(hKernel32, \"LoadLibraryW\");\n if (!pLoadLibraryW)\n {\n qDebug() << \"Failed to get address of LoadLibraryW:\" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n HANDLE hThread = CreateRemoteThread(hProcess,\n nullptr,\n 0,\n (LPTHREAD_START_ROUTINE)pLoadLibraryW,\n pDllPath,\n 0,\n nullptr);\n if (!hThread)\n {\n qDebug() << \"Failed to create remote thread:\" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n WaitForSingleObject(hThread, INFINITE);\n\n // 检查LoadLibrary是否执行成功\n DWORD exitCode = 0;\n if (GetExitCodeThread(hThread, &exitCode))\n {\n qDebug() << \"Remote thread exit code:\" << exitCode;\n // LoadLibrary返回的是模块句柄,如果为0则失败\n if (exitCode == 0)\n {\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n CloseHandle(hThread);\n qDebug() << \"LoadLibrary failed in remote process\";\n return false;\n }\n }\n\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hThread);\n CloseHandle(hProcess);\n\n return true;\n}\n static bool injectDllViaAPCA(DWORD processId, const QString& dllPath) {\n HANDLE hProcess =\n OpenProcess(PROCESS_ALL_ACCESS,\n FALSE,\n processId);\n\n if (!hProcess)\n {\n qDebug() << \"Failed to open process: \" << GetLastError();\n return false;\n }\n\n if (checkDllExist(processId, dllPath))\n {\n qDebug() << \"Process already have been injected\";\n return true;\n }\n\n // 在目标进程中分配内存并写入DLL路径\n SIZE_T pathSize = (dllPath.toStdString().size() + 1) * sizeof(char);\n LPVOID pDllPath = VirtualAllocEx(hProcess,\n NULL,\n pathSize,\n MEM_COMMIT,\n PAGE_READWRITE);\n\n if (!pDllPath)\n {\n qDebug() << \"Failed to allocate memory: \" << GetLastError();\n CloseHandle(hProcess);\n return false;\n }\n\n if (!WriteProcessMemory(hProcess, pDllPath, dllPath.toStdString().c_str(),\n pathSize, NULL))\n {\n qDebug() << \"Failed to write memory: \" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 获取LoadLibraryW的地址\n HMODULE hKernel32 = GetModuleHandle(L\"kernel32.dll\");\n if (!hKernel32)\n {\n qDebug() << \"Failed to get kernel32 handle\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n FARPROC pLoadLibraryA = GetProcAddress(hKernel32, \"LoadLibraryA\");\n if (!pLoadLibraryA)\n {\n qDebug() << \"Failed to get LoadLibraryA address\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 获取进程中的所有线程\n DWORD threadId = getProcessMainThread(processId);\n if (!threadId)\n {\n qDebug() << \"No threads found in the process\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 向目标进程的所有线程队列中添加APC调用\n bool success = false;\n\n // 打开线程\n HANDLE hThread = OpenThread(THREAD_SET_CONTEXT, FALSE, threadId);\n if (hThread)\n {\n // 将LoadLibraryA作为APC函数加入队列\n PostThreadMessageA(threadId, WM_PAINT, 0, 0);\n DWORD result =\n QueueUserAPC((PAPCFUNC)pLoadLibraryA, hThread, (ULONG_PTR)pDllPath);\n PostThreadMessageA(threadId, WM_PAINT, 0, 0);\n if (result != 0)\n {\n success = true;\n qDebug() << \"APC queued to thread \" << threadId;\n }\n\n CloseHandle(hThread);\n }\n\n if (!success)\n {\n qDebug() << \"Failed to queue APC to any thread\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 注意:我们不释放分配的内存,因为APC函数尚未执行\n // 内存将在DLL加载后释放\n\n CloseHandle(hProcess);\n return true;\n}\n static bool injectDllViaAPCW(DWORD processId, const QString& dllPath) {\n HANDLE hProcess =\n OpenProcess(PROCESS_ALL_ACCESS,\n FALSE,\n processId);\n\n if (!hProcess)\n {\n qDebug() << \"Failed to open process: \" << GetLastError();\n return false;\n }\n\n if (checkDllExist(processId, dllPath))\n {\n qDebug() << \"Process already have been injected\";\n return true;\n }\n\n // 在目标进程中分配内存并写入DLL路径\n SIZE_T pathSize = (dllPath.toStdWString().size() + 1) * sizeof(wchar_t);\n LPVOID pDllPath = VirtualAllocEx(hProcess,\n NULL,\n pathSize,\n MEM_COMMIT,\n PAGE_READWRITE);\n\n if (!pDllPath)\n {\n qDebug() << \"Failed to allocate memory: \" << GetLastError();\n CloseHandle(hProcess);\n return false;\n }\n\n if (!WriteProcessMemory(hProcess,\n pDllPath,\n dllPath.toStdWString().c_str(),\n pathSize,\n NULL))\n {\n qDebug() << \"Failed to write memory: \" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 获取LoadLibraryW的地址\n HMODULE hKernel32 = GetModuleHandle(L\"kernel32.dll\");\n if (!hKernel32)\n {\n qDebug() << \"Failed to get kernel32 handle\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n FARPROC pLoadLibraryW = GetProcAddress(hKernel32, \"LoadLibraryW\");\n if (!pLoadLibraryW)\n {\n qDebug() << \"Failed to get LoadLibraryW address\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 获取进程中的所有线程\n DWORD threadId = getProcessMainThread(processId);\n if (!threadId)\n {\n qDebug() << \"No threads found in the process\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 向目标进程的所有线程队列中添加APC调用\n bool success = false;\n\n // 打开线程\n HANDLE hThread = OpenThread(THREAD_SET_CONTEXT, FALSE, threadId);\n if (hThread)\n {\n // 将LoadLibraryW作为APC函数加入队列\n PostThreadMessageW(threadId, WM_PAINT, 0, 0);\n DWORD result =\n QueueUserAPC((PAPCFUNC)pLoadLibraryW, hThread, (ULONG_PTR)pDllPath);\n PostThreadMessageW(threadId, WM_PAINT, 0, 0);\n if (result != 0)\n {\n success = true;\n qDebug() << \"APC queued to thread \" << threadId;\n }\n\n CloseHandle(hThread);\n }\n\n if (!success)\n {\n qDebug() << \"Failed to queue APC to any thread\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 注意:我们不释放分配的内存,因为APC函数尚未执行\n // 内存将在DLL加载后释放\n\n CloseHandle(hProcess);\n return true;\n}\n static bool injectDllViaWHKA(DWORD processId, const QString& dllPath) {\n if (checkProcessProtection(processId))\n {\n qDebug() << \"进程被保护 进程ID: \" << processId;\n return false;\n }\n\n // 1. 加载DLL到当前进程\n HMODULE hMod = LoadLibraryA(dllPath.toStdString().c_str());\n if (!hMod)\n return false;\n\n // 2. 获取Hook过程的地址\n HOOKPROC hookProc = (HOOKPROC)GetProcAddress(hMod, \"HookProc\");\n if (!hookProc)\n return false;\n\n // 3. 获取目标线程ID\n DWORD threadId = getProcessMainThread(processId);\n if (threadId == 0)\n return false;\n\n // 4. 安装Hook\n HHOOK hHook = SetWindowsHookExA(WH_CBT, // Hook类型\n hookProc, // Hook过程\n hMod, // DLL模块句柄\n threadId // 目标线程ID\n );\n\n if (!hHook)\n return false;\n // 5. 触发Hook执行\n PostThreadMessageA(threadId, WM_NULL, 0, 0);\n Sleep(5000);\n UnhookWindowsHookEx(hHook);\n\n return true;\n}\n static bool injectDllViaWHKW(DWORD processId, const QString& dllPath) {\n if (checkProcessProtection(processId))\n {\n qDebug() << \"进程被保护 进程ID: \" << processId;\n return false;\n }\n\n // 1. 加载DLL到当前进程\n HMODULE hMod = LoadLibraryW(dllPath.toStdWString().c_str());\n if (!hMod)\n return false;\n\n // 2. 获取Hook过程的地址\n HOOKPROC hookProc = (HOOKPROC)GetProcAddress(hMod, \"HookProc\");\n if (!hookProc)\n return false;\n\n // 3. 获取目标线程ID\n DWORD threadId = getProcessMainThread(processId);\n if (threadId == 0)\n return false;\n\n // 4. 安装Hook\n HHOOK hHook = SetWindowsHookExW(WH_CBT, // Hook类型\n hookProc, // Hook过程\n hMod, // DLL模块句柄\n threadId // 目标线程ID\n );\n\n if (!hHook)\n return false;\n // 5. 触发Hook执行\n PostThreadMessageW(threadId, WM_NULL, 0, 0);\n Sleep(5000);\n UnhookWindowsHookEx(hHook);\n\n return true;\n}\n static bool unhookDll(DWORD processId, const QString& dllPath) {\n HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);\n if (!hProcess)\n {\n qDebug() << \"Failed to open process:\" << GetLastError();\n return false;\n }\n\n HMODULE hModules[1024];\n DWORD cbNeeded;\n if (EnumProcessModules(hProcess, hModules, sizeof(hModules), &cbNeeded))\n {\n for (unsigned int i = 0; i < (cbNeeded / sizeof(HMODULE)); i++)\n {\n TCHAR moduleName[MAX_PATH];\n if (GetModuleFileNameEx(hProcess, hModules[i], moduleName,\n sizeof(moduleName) / sizeof(TCHAR)))\n {\n#ifdef UNICODE\n bool isDll = dllPath.toStdWString() == moduleName;\n#else\n bool isDll = dllPath.toStdString() == moduleName;\n#endif\n if (isDll)\n {\n FARPROC pFreeLibrary = GetProcAddress(\n GetModuleHandle(L\"kernel32.dll\"), \"FreeLibrary\");\n if (!pFreeLibrary)\n {\n qDebug() << \"Failed to get address of FreeLibrary:\"\n << GetLastError();\n CloseHandle(hProcess);\n return false;\n }\n\n HANDLE hThread =\n CreateRemoteThread(hProcess, nullptr, 0,\n (LPTHREAD_START_ROUTINE)pFreeLibrary,\n hModules[i], 0, nullptr);\n if (!hThread)\n {\n qDebug() << \"Failed to create remote thread for \"\n \"FreeLibrary:\"\n << GetLastError();\n CloseHandle(hProcess);\n return false;\n }\n\n WaitForSingleObject(hThread, INFINITE);\n CloseHandle(hThread);\n CloseHandle(hProcess);\n return true;\n }\n }\n }\n }\n\n CloseHandle(hProcess);\n return false;\n}\n static bool checkDllExist(DWORD processId, const QString& dllPath) {\n HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,\n FALSE,\n processId);\n if (!hProcess)\n {\n qDebug() << \"打开进程失败:\" << GetLastError();\n return false;\n }\n\n bool dllFound = false;\n HMODULE hModules[1024];\n DWORD cbNeeded;\n\n // 获取进程中所有已加载的模块\n if (EnumProcessModules(hProcess, hModules, sizeof(hModules), &cbNeeded))\n {\n DWORD moduleCount = cbNeeded / sizeof(HMODULE);\n for (DWORD i = 0; i < moduleCount; i++)\n {\n TCHAR moduleName[MAX_PATH] = {0};\n\n // 获取模块的完整路径\n if (GetModuleFileNameExW(hProcess, hModules[i], moduleName,\n sizeof(moduleName) / sizeof(TCHAR)))\n {\n#ifdef UNICODE\n bool isDll = dllPath.toStdWString() == moduleName;\n#else\n bool isDll = dllPath.toStdString() == moduleName;\n#endif\n if (isDll)\n {\n dllFound = true;\n break;\n }\n }\n }\n }\n else\n {\n qDebug() << \"枚举进程模块失败:\" << GetLastError();\n }\n\n CloseHandle(hProcess);\n return dllFound;\n}\n static bool checkProcessProtection(DWORD processId) {\n HANDLE hProcess =\n OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, processId);\n if (!hProcess)\n {\n qDebug() << \"Cannot open process - likely protected\";\n return true; // 可能被保护\n }\n\n // 检查是否是受保护进程\n PROCESS_PROTECTION_LEVEL_INFORMATION protectionInfo = {};\n DWORD returnLength;\n\n if (GetProcessInformation(hProcess, ProcessProtectionLevelInfo,\n &protectionInfo, sizeof(protectionInfo)))\n {\n CloseHandle(hProcess);\n return protectionInfo.ProtectionLevel != PROTECTION_LEVEL_NONE;\n }\n\n CloseHandle(hProcess);\n return false;\n}\n static void setAutoStart(bool enable,\n const QString& appName,\n const QString& execPath) {\n TaskScheduler scheduler;\n\n if (enable)\n {\n scheduler.createStartupShortcut(appName, execPath);\n }\n else\n {\n scheduler.deleteStartupShortcut(appName);\n }\n}\n static bool isAutoStartEnabled(const QString& appName) {\n TaskScheduler scheduler;\n return scheduler.isStartupShortcutExists(appName);\n}\n static BOOL getWindowsVersion(DWORD* majorVersion,\n DWORD* minorVersion,\n DWORD* buildNumber) {\n static char version[100] = {0};\n DWORD major, minor, build;\n\n if (!getWindowsVersion(&major, &minor, &build))\n return \"Unknown Windows Version\";\n\n // 确定Windows版本\n if (major == 10)\n {\n if (build >= 22000)\n {\n sprintf(version, \"Windows 11 (Build %lu)\", build);\n }\n else\n {\n sprintf(version, \"Windows 10 (Build %lu)\", build);\n }\n }\n else if (major == 6)\n {\n switch (minor)\n {\n case 3:\n sprintf(version, \"Windows 8.1 (Build %lu)\", build);\n break;\n case 2:\n sprintf(version, \"Windows 8 (Build %lu)\", build);\n break;\n case 1:\n sprintf(version, \"Windows 7 (Build %lu)\", build);\n break;\n case 0:\n sprintf(version, \"Windows Vista (Build %lu)\", build);\n break;\n default:\n sprintf(version, \"Windows NT %lu.%lu (Build %lu)\", major, minor,\n build);\n }\n }\n else if (major == 5)\n {\n switch (minor)\n {\n case 2:\n sprintf(version, \"Windows Server 2003 (Build %lu)\", build);\n break;\n case 1:\n sprintf(version, \"Windows XP (Build %lu)\", build);\n break;\n case 0:\n sprintf(version, \"Windows 2000 (Build %lu)\", build);\n break;\n default:\n sprintf(version, \"Windows NT %lu.%lu (Build %lu)\", major, minor,\n build);\n }\n }\n else\n {\n sprintf(version, \"Windows NT %lu.%lu (Build %lu)\", major, minor, build);\n }\n return version;\n}\n static QString getWindowsVersion() {\n static char version[100] = {0};\n DWORD major, minor, build;\n\n if (!getWindowsVersion(&major, &minor, &build))\n return \"Unknown Windows Version\";\n\n // 确定Windows版本\n if (major == 10)\n {\n if (build >= 22000)\n {\n sprintf(version, \"Windows 11 (Build %lu)\", build);\n }\n else\n {\n sprintf(version, \"Windows 10 (Build %lu)\", build);\n }\n }\n else if (major == 6)\n {\n switch (minor)\n {\n case 3:\n sprintf(version, \"Windows 8.1 (Build %lu)\", build);\n break;\n case 2:\n sprintf(version, \"Windows 8 (Build %lu)\", build);\n break;\n case 1:\n sprintf(version, \"Windows 7 (Build %lu)\", build);\n break;\n case 0:\n sprintf(version, \"Windows Vista (Build %lu)\", build);\n break;\n default:\n sprintf(version, \"Windows NT %lu.%lu (Build %lu)\", major, minor,\n build);\n }\n }\n else if (major == 5)\n {\n switch (minor)\n {\n case 2:\n sprintf(version, \"Windows Server 2003 (Build %lu)\", build);\n break;\n case 1:\n sprintf(version, \"Windows XP (Build %lu)\", build);\n break;\n case 0:\n sprintf(version, \"Windows 2000 (Build %lu)\", build);\n break;\n default:\n sprintf(version, \"Windows NT %lu.%lu (Build %lu)\", major, minor,\n build);\n }\n }\n else\n {\n sprintf(version, \"Windows NT %lu.%lu (Build %lu)\", major, minor, build);\n }\n return version;\n}\n static QList getProcessList() {\n QList processList;\n\n HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);\n if (hProcessSnap == INVALID_HANDLE_VALUE)\n {\n qDebug() << \"创建进程快照失败: \" << GetLastError();\n return processList;\n }\n\n PROCESSENTRY32 pe32;\n pe32.dwSize = sizeof(PROCESSENTRY32);\n\n if (!Process32First(hProcessSnap, &pe32))\n {\n qDebug() << \"获取首个进程信息失败: \" << GetLastError();\n CloseHandle(hProcessSnap);\n return processList;\n }\n\n do\n {\n if (systemNames.contains(pe32.szExeFile))\n {\n continue;\n }\n ProcessInfo info;\n info.pid = pe32.th32ProcessID;\n info.parentPid = pe32.th32ParentProcessID;\n info.name = QString::fromWCharArray(pe32.szExeFile);\n info.threadCount = pe32.cntThreads;\n\n // 获取内存使用和优先级信息\n HANDLE hProcess = OpenProcess(\n PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, info.pid);\n if (hProcess)\n {\n PROCESS_MEMORY_COUNTERS pmc;\n if (GetProcessMemoryInfo(hProcess, &pmc, sizeof(pmc)))\n {\n info.memoryUsage = pmc.WorkingSetSize;\n }\n else\n {\n info.memoryUsage = 0;\n }\n BOOL wow64Process = FALSE;\n IsWow64Process(hProcess, &wow64Process);\n info.is64Bit = !wow64Process;\n info.priorityClass = GetPriorityClass(hProcess);\n CloseHandle(hProcess);\n }\n else\n {\n info.memoryUsage = 0;\n info.priorityClass = 0;\n }\n\n processList.append(info);\n } while (Process32Next(hProcessSnap, &pe32));\n\n CloseHandle(hProcessSnap);\n return processList;\n}\n static QString getProcessPath(DWORD processId) {\n QString processPath;\n HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,\n FALSE, processId);\n\n if (hProcess != NULL)\n {\n wchar_t buffer[MAX_PATH];\n if (GetModuleFileNameEx(hProcess, NULL, buffer, MAX_PATH) > 0)\n {\n processPath = QString::fromWCharArray(buffer);\n }\n CloseHandle(hProcess);\n }\n\n return processPath;\n}\n static DWORD getProcessMainThread(DWORD processId) {\n HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);\n if (hSnapshot == INVALID_HANDLE_VALUE)\n {\n qDebug() << \"Failed to create thread snapshot:\" << GetLastError();\n return 0;\n }\n\n THREADENTRY32 te32;\n te32.dwSize = sizeof(THREADENTRY32);\n\n DWORD mainThreadId = 0;\n FILETIME earliestTime = {0xFFFFFFFF, 0xFFFFFFFF}; // 设为最大值\n\n if (Thread32First(hSnapshot, &te32))\n {\n do\n {\n if (te32.th32OwnerProcessID == processId)\n {\n // 打开线程获取创建时间\n HANDLE hThread = OpenThread(THREAD_QUERY_INFORMATION, FALSE,\n te32.th32ThreadID);\n if (hThread)\n {\n FILETIME creationTime, exitTime, kernelTime, userTime;\n if (GetThreadTimes(hThread, &creationTime, &exitTime,\n &kernelTime, &userTime))\n {\n // 比较创建时间,找最早的线程\n if (CompareFileTime(&creationTime, &earliestTime) < 0)\n {\n earliestTime = creationTime;\n mainThreadId = te32.th32ThreadID;\n }\n }\n CloseHandle(hThread);\n }\n }\n } while (Thread32Next(hSnapshot, &te32));\n }\n\n CloseHandle(hSnapshot);\n return mainThreadId;\n}\n static QString getProcessNameById(DWORD processId) {\n HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,\n FALSE, processId);\n if (hProcess == NULL)\n {\n return QString();\n }\n\n wchar_t processName[MAX_PATH];\n if (GetModuleBaseName(hProcess, NULL, processName, MAX_PATH))\n {\n CloseHandle(hProcess);\n QString name = QString::fromWCharArray(processName);\n return name;\n }\n\n CloseHandle(hProcess);\n return QString();\n}\n static bool enableAllPrivilege() {\n HANDLE hToken;\n // 获取进程token\n if (!OpenProcessToken(GetCurrentProcess(),\n TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))\n return false;\n\n const wchar_t *essentialPrivileges[] = {\n SE_DEBUG_NAME, // 最重要的调试权限\n };\n\n TOKEN_PRIVILEGES tkp;\n bool success = true;\n\n for (const auto &privilege : essentialPrivileges)\n {\n tkp.PrivilegeCount = 1;\n tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;\n if (LookupPrivilegeValue(NULL, privilege, &tkp.Privileges[0].Luid))\n {\n AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, NULL);\n }\n }\n\n CloseHandle(hToken);\n return success;\n}\n};"], ["/OpenSpeedy/qsinglekeysequenceedit.h", "class QSingleKeySequenceEdit {\n Q_OBJECT\n\n public:\n explicit QSingleKeySequenceEdit(QWidget* parent = nullptr);\n static UINT toVK(int qtKey, Qt::KeyboardModifiers qtMod) {\n // 🔤 字母键 A-Z\n if (qtKey >= Qt::Key_A && qtKey <= Qt::Key_Z)\n {\n return qtKey; // Qt 和 Windows 的 A-Z 键码相同\n }\n\n // 🔢 小键盘 0-9\n if (qtMod & Qt::KeypadModifier)\n {\n switch (qtKey)\n {\n // 数字键盘\n case Qt::Key_0:\n return VK_NUMPAD0;\n case Qt::Key_1:\n return VK_NUMPAD1;\n case Qt::Key_2:\n return VK_NUMPAD2;\n case Qt::Key_3:\n return VK_NUMPAD3;\n case Qt::Key_4:\n return VK_NUMPAD4;\n case Qt::Key_5:\n return VK_NUMPAD5;\n case Qt::Key_6:\n return VK_NUMPAD6;\n case Qt::Key_7:\n return VK_NUMPAD7;\n case Qt::Key_8:\n return VK_NUMPAD8;\n case Qt::Key_9:\n return VK_NUMPAD9;\n }\n }\n\n // 🔢 数字键 0-9\n if (qtKey >= Qt::Key_0 && qtKey <= Qt::Key_9)\n {\n return qtKey; // Qt 和 Windows 的 0-9 键码相同\n }\n\n // 🎯 功能键映射\n switch (qtKey)\n {\n // F1-F12\n case Qt::Key_F1:\n return VK_F1;\n case Qt::Key_F2:\n return VK_F2;\n case Qt::Key_F3:\n return VK_F3;\n case Qt::Key_F4:\n return VK_F4;\n case Qt::Key_F5:\n return VK_F5;\n case Qt::Key_F6:\n return VK_F6;\n case Qt::Key_F7:\n return VK_F7;\n case Qt::Key_F8:\n return VK_F8;\n case Qt::Key_F9:\n return VK_F9;\n case Qt::Key_F10:\n return VK_F10;\n case Qt::Key_F11:\n return VK_F11;\n case Qt::Key_F12:\n return VK_F12;\n\n // 方向键\n case Qt::Key_Left:\n return VK_LEFT;\n case Qt::Key_Right:\n return VK_RIGHT;\n case Qt::Key_Up:\n return VK_UP;\n case Qt::Key_Down:\n return VK_DOWN;\n\n // 特殊键\n case Qt::Key_Enter:\n case Qt::Key_Return:\n return VK_RETURN;\n case Qt::Key_Escape:\n return VK_ESCAPE;\n case Qt::Key_Tab:\n return VK_TAB;\n case Qt::Key_Backspace:\n return VK_BACK;\n case Qt::Key_Delete:\n return VK_DELETE;\n case Qt::Key_Insert:\n return VK_INSERT;\n case Qt::Key_Home:\n return VK_HOME;\n case Qt::Key_End:\n return VK_END;\n case Qt::Key_PageUp:\n return VK_PRIOR;\n case Qt::Key_PageDown:\n return VK_NEXT;\n case Qt::Key_Space:\n return VK_SPACE;\n\n // 符号键\n case Qt::Key_Semicolon:\n return VK_OEM_1; // ;\n case Qt::Key_Equal:\n return VK_OEM_PLUS; // =\n case Qt::Key_Comma:\n return VK_OEM_COMMA; // ,\n case Qt::Key_Minus:\n return VK_OEM_MINUS; // -\n case Qt::Key_Period:\n return VK_OEM_PERIOD; // .\n case Qt::Key_Slash:\n return VK_OEM_2; // /\n case Qt::Key_QuoteLeft:\n return VK_OEM_3; // `\n case Qt::Key_BracketLeft:\n return VK_OEM_4; // [\n case Qt::Key_Backslash:\n return VK_OEM_5; //\n case Qt::Key_BracketRight:\n return VK_OEM_6; // ]\n case Qt::Key_Apostrophe:\n return VK_OEM_7; // '\n\n // 其他常用键\n case Qt::Key_CapsLock:\n return VK_CAPITAL;\n case Qt::Key_NumLock:\n return VK_NUMLOCK;\n case Qt::Key_ScrollLock:\n return VK_SCROLL;\n case Qt::Key_Pause:\n return VK_PAUSE;\n case Qt::Key_Print:\n return VK_PRINT;\n\n default:\n qDebug() << \"Unknown Qt key:\" << qtKey;\n return 0; // 未知按键\n }\n}\n static UINT toModifier(Qt::KeyboardModifiers qtMod) {\n UINT winMod = 0;\n\n if (qtMod & Qt::ControlModifier)\n {\n winMod |= MOD_CONTROL;\n }\n if (qtMod & Qt::AltModifier)\n {\n winMod |= MOD_ALT;\n }\n if (qtMod & Qt::ShiftModifier)\n {\n winMod |= MOD_SHIFT;\n }\n if (qtMod & Qt::MetaModifier)\n {\n winMod |= MOD_WIN; // Windows 键\n }\n\n return winMod;\n}\n static QtCombinedKey toQtCombinedKey(const QString& keyText) {\n QKeySequence sequence = QKeySequence(keyText);\n\n if (!sequence.isEmpty())\n {\n int combinedKey = sequence[0];\n Qt::KeyboardModifiers modifier =\n Qt::KeyboardModifiers(combinedKey & Qt::KeyboardModifierMask);\n int key = combinedKey & ~Qt::KeyboardModifierMask;\n return QtCombinedKey{ key, modifier };\n }\n else\n {\n return QtCombinedKey{ 0, Qt::NoModifier };\n }\n}\n static QString wrapText(QString keyText) {\n return keyText.replace(\"Up\", \"⬆️\")\n .replace(\"Down\", \"⬇️\")\n .replace(\"Left\", \"⬅️\")\n .replace(\"Right\", \"➡️\");\n}\n UINT getVK() {\n return toVK(m_key, m_modifier);\n}\n UINT getModifier() {\n return toModifier(m_modifier);\n}\n QtCombinedKey getQtCombinedKey() {\n return QtCombinedKey{ m_key, m_modifier };\n}\n QString getKeyText() {\n return keySequence().toString(QKeySequence::NativeText);\n}\n protected:\n void keyPressEvent(QKeyEvent* event) override {\n int key = event->key();\n Qt::KeyboardModifiers modifiers = event->modifiers();\n\n // 忽略单独的修饰键\n if (isModifierKey(key))\n {\n return;\n }\n\n m_key = key;\n m_modifier = modifiers;\n\n // 创建单个按键序列\n QKeySequence singleKey(key | modifiers);\n setKeySequence(singleKey);\n\n // 🔚 结束编辑\n emit editingFinished();\n clearFocus();\n}\n private:\n void update() {\n QKeySequence sequence = keySequence();\n\n if (sequence.isEmpty())\n {\n m_key = 0;\n m_modifier = Qt::NoModifier;\n }\n else\n {\n int combinedKey = sequence[0];\n m_modifier =\n Qt::KeyboardModifiers(combinedKey & Qt::KeyboardModifierMask);\n m_key = combinedKey & ~Qt::KeyboardModifierMask;\n }\n}\n private:\n bool isModifierKey(int key) const {\n return (key == Qt::Key_Control || key == Qt::Key_Alt ||\n key == Qt::Key_Shift || key == Qt::Key_Meta);\n}\n int m_key;\n Qt::KeyboardModifiers m_modifier;\n};"], ["/OpenSpeedy/preferencedialog.h", "class PreferenceDialog {\n Q_OBJECT\n\n public:\n explicit PreferenceDialog(HWND hMainWindow,\n QSettings* settings,\n QLabel* increaseSpeedLabel,\n QLabel* decreaseSpeedLabel,\n QLabel* resetSpeedLabel,\n QWidget* parent = nullptr);\n ~PreferenceDialog() {\n unregisterGlobalHotkeys();\n delete ui;\n}\n int getIncreaseStep() {\n return m_increaseStep;\n}\n int getDecreaseStep() {\n return m_decreaseStep;\n}\n double getShift1() {\n return m_shift1Value;\n}\n double getShift2() {\n return m_shift2Value;\n}\n double getShift3() {\n return m_shift3Value;\n}\n double getShift4() {\n return m_shift4Value;\n}\n double getShift5() {\n return m_shift5Value;\n}\n public:\n void show() {\n unregisterGlobalHotkeys();\n QDialog::show();\n}\n private:\n void on_buttonBox_accepted() {\n update();\n setupGlobalHotkeys();\n redraw();\n dump();\n}\n void on_buttonBox_rejected() {\n redraw();\n setupGlobalHotkeys();\n}\n void recreate() {\n layout()->invalidate();\n layout()->activate();\n adjustSize();\n}\n private:\n void setupGlobalHotkeys() {\n for (auto it = m_shortcuts.begin(); it != m_shortcuts.end(); it++)\n {\n int id = it.key();\n QtCombinedKey combined = it.value();\n\n UINT vk = QSingleKeySequenceEdit::toVK(combined.key, combined.modifier);\n UINT modifier = QSingleKeySequenceEdit::toModifier(combined.modifier);\n RegisterHotKey(m_mainwindow, id, modifier, vk);\n }\n\n qDebug() << \"全局快捷键已注册:\";\n}\n void unregisterGlobalHotkeys() {\n for (auto it = m_shortcuts.begin(); it != m_shortcuts.end(); it++)\n {\n int id = it.key();\n UnregisterHotKey(m_mainwindow, id);\n }\n qDebug() << \"全局快捷键已注销\";\n}\n void loadShortcut(int id,\n const QString& config,\n const QString& defaultValue) {\n m_shortcuts.insert(id,\n QSingleKeySequenceEdit::toQtCombinedKey(\n m_settings->value(config, defaultValue).toString()));\n}\n void dumpShortcut(const QString& config, const QString& keyText) {\n m_settings->setValue(config, keyText);\n}\n void dump() {\n dumpShortcut(CONFIG_HOTKEY_SPEEDUP,\n ui->speedUpKeySequenceEdit->getKeyText());\n dumpShortcut(CONFIG_HOTKEY_SPEEDDOWN,\n ui->speedDownKeySequenceEdit->getKeyText());\n dumpShortcut(CONFIG_HOTKEY_RESETSPEED,\n ui->resetSpeedKeySequenceEdit->getKeyText());\n\n dumpShortcut(CONFIG_HOTKEY_SHIFT1, ui->shift1KeySequenceEdit->getKeyText());\n dumpShortcut(CONFIG_HOTKEY_SHIFT2, ui->shift2KeySequenceEdit->getKeyText());\n dumpShortcut(CONFIG_HOTKEY_SHIFT3, ui->shift3KeySequenceEdit->getKeyText());\n dumpShortcut(CONFIG_HOTKEY_SHIFT4, ui->shift4KeySequenceEdit->getKeyText());\n dumpShortcut(CONFIG_HOTKEY_SHIFT5, ui->shift5KeySequenceEdit->getKeyText());\n m_settings->setValue(CONFIG_INCREASE_STEP,\n ui->increaseStepSpinBox->value());\n m_settings->setValue(CONFIG_DECREASE_STEP,\n ui->decreaseStepSpinBox->value());\n m_settings->setValue(CONFIG_SHIFT1_VALUE, ui->shift1DoubleSpinBox->value());\n m_settings->setValue(CONFIG_SHIFT2_VALUE, ui->shift2DoubleSpinBox->value());\n m_settings->setValue(CONFIG_SHIFT3_VALUE, ui->shift3DoubleSpinBox->value());\n m_settings->setValue(CONFIG_SHIFT4_VALUE, ui->shift4DoubleSpinBox->value());\n m_settings->setValue(CONFIG_SHIFT5_VALUE, ui->shift5DoubleSpinBox->value());\n m_settings->sync();\n}\n void updateShortcut(int id, QSingleKeySequenceEdit* keyEdit) {\n m_shortcuts[id] = keyEdit->getQtCombinedKey();\n}\n void update() {\n updateShortcut(HOTKEY_INCREASE_SPEED, ui->speedUpKeySequenceEdit);\n updateShortcut(HOTKEY_DECREASE_SPEED, ui->speedDownKeySequenceEdit);\n updateShortcut(HOTKEY_RESET_SPEED, ui->resetSpeedKeySequenceEdit);\n updateShortcut(HOTKEY_SHIFT1, ui->shift1KeySequenceEdit);\n updateShortcut(HOTKEY_SHIFT2, ui->shift2KeySequenceEdit);\n updateShortcut(HOTKEY_SHIFT3, ui->shift3KeySequenceEdit);\n updateShortcut(HOTKEY_SHIFT4, ui->shift4KeySequenceEdit);\n updateShortcut(HOTKEY_SHIFT5, ui->shift5KeySequenceEdit);\n\n m_increaseStep = ui->increaseStepSpinBox->value();\n m_decreaseStep = ui->decreaseStepSpinBox->value();\n m_shift1Value = ui->shift1DoubleSpinBox->value();\n m_shift2Value = ui->shift2DoubleSpinBox->value();\n m_shift3Value = ui->shift3DoubleSpinBox->value();\n m_shift4Value = ui->shift4DoubleSpinBox->value();\n m_shift5Value = ui->shift5DoubleSpinBox->value();\n}\n void redrawSpinBox(QSpinBox* spinbox, int value) {\n spinbox->setValue(value);\n}\n void redrawSpinBox(QDoubleSpinBox* spinbox, double value) {\n spinbox->setValue(value);\n}\n void redrawKeyEdit(QSingleKeySequenceEdit* keyEdit, int id) {\n QtCombinedKey combinedKey = m_shortcuts[id];\n keyEdit->setKeySequence(combinedKey.key | combinedKey.modifier);\n}\n void redraw() {\n redrawKeyEdit(ui->speedUpKeySequenceEdit, HOTKEY_INCREASE_SPEED);\n redrawKeyEdit(ui->speedDownKeySequenceEdit, HOTKEY_DECREASE_SPEED);\n redrawKeyEdit(ui->resetSpeedKeySequenceEdit, HOTKEY_RESET_SPEED);\n redrawKeyEdit(ui->shift1KeySequenceEdit, HOTKEY_SHIFT1);\n redrawKeyEdit(ui->shift2KeySequenceEdit, HOTKEY_SHIFT2);\n redrawKeyEdit(ui->shift3KeySequenceEdit, HOTKEY_SHIFT3);\n redrawKeyEdit(ui->shift4KeySequenceEdit, HOTKEY_SHIFT4);\n redrawKeyEdit(ui->shift5KeySequenceEdit, HOTKEY_SHIFT5);\n\n redrawSpinBox(ui->increaseStepSpinBox, m_increaseStep);\n redrawSpinBox(ui->decreaseStepSpinBox, m_decreaseStep);\n redrawSpinBox(ui->shift1DoubleSpinBox, m_shift1Value);\n redrawSpinBox(ui->shift2DoubleSpinBox, m_shift2Value);\n redrawSpinBox(ui->shift3DoubleSpinBox, m_shift3Value);\n redrawSpinBox(ui->shift4DoubleSpinBox, m_shift4Value);\n redrawSpinBox(ui->shift5DoubleSpinBox, m_shift5Value);\n\n m_increaseSpeedLabel->setText(\n QString(tr(\"%1 增加速度\"))\n .arg(QSingleKeySequenceEdit::wrapText(\n ui->speedUpKeySequenceEdit->getKeyText())));\n\n m_decreaseSpeedLabel->setText(\n QString(tr(\"%1 减少速度\"))\n .arg(QSingleKeySequenceEdit::wrapText(\n ui->speedDownKeySequenceEdit->getKeyText())));\n\n m_resetSpeedLabel->setText(\n QString(tr(\"%1 重置速度\"))\n .arg(QSingleKeySequenceEdit::wrapText(\n ui->resetSpeedKeySequenceEdit->getKeyText())));\n\n adjustSize();\n}\n Ui::PreferenceDialog* ui;\n QSettings* m_settings;\n QLabel* m_increaseSpeedLabel;\n QLabel* m_decreaseSpeedLabel;\n QLabel* m_resetSpeedLabel;\n QMap m_shortcuts;\n double m_shift1Value;\n double m_shift2Value;\n double m_shift3Value;\n double m_shift4Value;\n double m_shift5Value;\n int m_increaseStep;\n int m_decreaseStep;\n HWND m_mainwindow;\n};"], ["/OpenSpeedy/cpuutils.h", "class CpuUtils {\n private:\n PDH_HQUERY hQuery = NULL;\n PDH_HCOUNTER hCounter = NULL;\n bool initialized = false;\n public:\n CpuUtils() {\n}\n ~CpuUtils() {\n if (hCounter) PdhRemoveCounter(hCounter);\n if (hQuery) PdhCloseQuery(hQuery);\n}\n bool init() {\n // 创建查询\n if (PdhOpenQuery(NULL, NULL, &hQuery) != ERROR_SUCCESS) return false;\n\n if (PdhAddEnglishCounter(hQuery,\n L\"\\\\Processor(_Total)\\\\% Processor Time\",\n NULL,\n &hCounter) != ERROR_SUCCESS)\n {\n PdhCloseQuery(hQuery);\n return false;\n }\n\n // 第一次采样\n PdhCollectQueryData(hQuery);\n initialized = true;\n return true;\n}\n double getUsage() {\n if (!initialized) return -1;\n\n // 收集数据\n if (PdhCollectQueryData(hQuery) != ERROR_SUCCESS) return -1;\n\n PDH_FMT_COUNTERVALUE value;\n if (PdhGetFormattedCounterValue(hCounter, PDH_FMT_DOUBLE, NULL, &value) !=\n ERROR_SUCCESS)\n return -1;\n\n return value.doubleValue;\n}\n QString getModel() {\n int cpuInfo[4];\n char cpuBrand[48 + 1] = {0};\n\n // 获取CPU品牌字符串(需要调用3次CPUID)\n __cpuid(cpuInfo, 0x80000002);\n memcpy(cpuBrand, cpuInfo, sizeof(cpuInfo));\n\n __cpuid(cpuInfo, 0x80000003);\n memcpy(cpuBrand + 16, cpuInfo, sizeof(cpuInfo));\n\n __cpuid(cpuInfo, 0x80000004);\n memcpy(cpuBrand + 32, cpuInfo, sizeof(cpuInfo));\n\n QString result(cpuBrand);\n\n return result.trimmed();\n}\n};"], ["/OpenSpeedy/memutils.h", "class MemUtils {\n private:\n PDH_HQUERY hQuery = NULL;\n PDH_HCOUNTER hCounter = NULL;\n bool initialized = false;\n public:\n MemUtils() {\n}\n bool init() {\n if (PdhOpenQuery(NULL, NULL, &hQuery) != ERROR_SUCCESS) return false;\n\n if (PdhAddEnglishCounter(hQuery,\n L\"\\\\Memory\\\\Available Bytes\",\n NULL,\n &hCounter) != ERROR_SUCCESS)\n {\n PdhCloseQuery(hQuery);\n return false;\n }\n\n PdhCollectQueryData(hQuery);\n initialized = true;\n return true;\n}\n double getTotal() {\n MEMORYSTATUSEX memInfo;\n memInfo.dwLength = sizeof(MEMORYSTATUSEX);\n GlobalMemoryStatusEx(&memInfo);\n return memInfo.ullTotalPhys / (1024.0 * 1024.0 * 1024.0);\n}\n double getUsage() {\n if (!initialized) return -1;\n\n if (PdhCollectQueryData(hQuery) != ERROR_SUCCESS) return -1;\n\n PDH_FMT_COUNTERVALUE available;\n if (PdhGetFormattedCounterValue(hCounter,\n PDH_FMT_DOUBLE,\n NULL,\n &available) != ERROR_SUCCESS)\n return -1;\n\n double totalMemory = getTotal() * 1024 * 1024 * 1024;\n double usageMemory = totalMemory - available.doubleValue;\n\n return usageMemory / (1024.0 * 1024.0 * 1024.0);\n}\n};"], ["/OpenSpeedy/aboutdialog.h", "class AboutDialog {\n Q_OBJECT\n\n public:\n explicit AboutDialog(QWidget* parent = nullptr);\n ~AboutDialog() {\n delete ui;\n}\n private:\n void recreate() {\n layout()->invalidate();\n layout()->activate();\n adjustSize();\n}\n private:\n Ui::AboutDialog* ui;\n};"], ["/OpenSpeedy/mainwindow.h", "class MainWindow {\n};"], ["/OpenSpeedy/speedpatch/speedpatch.h", "class speedpatch {\n};"]], "task_instance_info": {"created_time": "2025-08-20 19:51:26", "created_task_model": "DeepSeek-R1", "function_skeleton": "int main(int argc, char* argv[]) {}", "code_description": "This code segment functions to: Initialize application settings and user interface components, enforce single instance behavior through inter-process communication, handle high-DPI display configurations, load localization resources based on system preferences, process command-line parameters for startup behavior, and implement a system tray activation mechanism for window management."}, "inference_content": {"inference_model": "DeepSeek-R1", "inference_result": "```cpp\n[TASK_BEGIN]\nint main(int argc, char* argv[])\n{\n SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);\n QApplication app(argc, argv);\n QApplication::setApplicationVersion(\"1.0.0\");\n QApplication::setOrganizationName(\"Game1024\");\n QApplication::setApplicationName(\"OpenSpeedy\");\n\n QCommandLineParser parser;\n parser.setApplicationDescription(\"OpenSpeedy Application\");\n parser.addHelpOption();\n parser.addVersionOption();\n QCommandLineOption overrideOption(\"multi\", \"Allow multiple instances\");\n parser.addOption(overrideOption);\n parser.process(app);\n\n QLocalServer server;\n bool singleInstance = true;\n if (!parser.isSet(overrideOption)) {\n QLocalSocket socket;\n socket.connectToServer(\"OpenSpeedyServer\");\n if (socket.waitForConnected(500)) {\n return 1;\n }\n singleInstance = server.listen(\"OpenSpeedyServer\");\n }\n\n QTranslator translator;\n if (translator.load(QLocale(), \"OpenSpeedy\", \".\", \":/i18n\")) {\n app.installTranslator(&translator);\n }\n\n QTranslator qtTranslator;\n if (qtTranslator.load(QLocale(), \"qtbase\", \"_\", \":/i18n\")) {\n app.installTranslator(&qtTranslator);\n }\n\n WinDBG::InitConsole();\n MainWindow w;\n w.show();\n return app.exec();\n}\n[TASK_END]\n```", "inference_time": "2025-08-20 19-51-54"}, "editdistance_info": {"edit_distance": 18.0698, "calculate_time": "2025-08-20 19:51:54", "true_code_clean": "int\nmain(int argc, char* argv[])\n{\n SetUnhandledExceptionFilter(createMiniDump);\n SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);\n QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);\n QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);\n QApplication::setAttribute(Qt::AA_UseSoftwareOpenGL);\n QApplication a(argc, argv);\n winutils::enableAllPrivilege();\n QString unique = \"OpenSpeedy\";\n QLocalSocket socket;\n socket.connectToServer(unique);\n if (socket.waitForConnected(500))\n {\n socket.close();\n return -1;\n }\n QIcon appIcon;\n appIcon.addFile(\":/icons/images/icon_16.ico\", QSize(16, 16));\n appIcon.addFile(\":/icons/images/icon_32.ico\", QSize(32, 32));\n appIcon.addFile(\":/icons/images/icon_64.ico\", QSize(64, 64));\n a.setWindowIcon(appIcon);\n QSettings settings =\n QSettings(QCoreApplication::applicationDirPath() + \"/config.ini\",\n QSettings::IniFormat);\n QTranslator translator;\n const QString baseName =\n \"OpenSpeedy_\" +\n settings.value(CONFIG_LANGUAGE, QLocale().system().name()).toString();\n if (translator.load(\":/i18n/translations/\" + baseName))\n {\n a.installTranslator(&translator);\n }\n QCommandLineParser parser;\n parser.setApplicationDescription(\"OpenSpeedy\");\n QCommandLineOption minimizeOption(\n QStringList() << \"m\" << \"minimize-to-tray\", \"启动时最小化到托盘\");\n parser.addOption(minimizeOption);\n parser.process(a);\n MainWindow w;\n w.resize(1024, 768);\n if (parser.isSet(minimizeOption))\n {\n w.hide();\n }\n else\n {\n w.show();\n }\n QLocalServer server;\n QLocalServer::removeServer(unique);\n server.listen(unique);\n QObject::connect(&server,\n &QLocalServer::newConnection,\n [&]\n {\n w.show();\n w.raise();\n w.showNormal();\n w.activateWindow();\n });\n return a.exec();\n}", "predict_code_clean": "int main(int argc, char* argv[])\n{\n SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);\n QApplication app(argc, argv);\n QApplication::setApplicationVersion(\"1.0.0\");\n QApplication::setOrganizationName(\"Game1024\");\n QApplication::setApplicationName(\"OpenSpeedy\");\n QCommandLineParser parser;\n parser.setApplicationDescription(\"OpenSpeedy Application\");\n parser.addHelpOption();\n parser.addVersionOption();\n QCommandLineOption overrideOption(\"multi\", \"Allow multiple instances\");\n parser.addOption(overrideOption);\n parser.process(app);\n QLocalServer server;\n bool singleInstance = true;\n if (!parser.isSet(overrideOption)) {\n QLocalSocket socket;\n socket.connectToServer(\"OpenSpeedyServer\");\n if (socket.waitForConnected(500)) {\n return 1;\n }\n singleInstance = server.listen(\"OpenSpeedyServer\");\n }\n QTranslator translator;\n if (translator.load(QLocale(), \"OpenSpeedy\", \".\", \":/i18n\")) {\n app.installTranslator(&translator);\n }\n QTranslator qtTranslator;\n if (qtTranslator.load(QLocale(), \"qtbase\", \"_\", \":/i18n\")) {\n app.installTranslator(&qtTranslator);\n }\n WinDBG::InitConsole();\n MainWindow w;\n w.show();\n return app.exec();\n}"}} {"repo_name": "OpenSpeedy", "file_name": "/OpenSpeedy/main.cpp", "inference_info": {"prefix_code": "/*\n * OpenSpeedy - Open Source Game Speed Controller\n * Copyright (C) 2025 Game1024\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n#include \"mainwindow.h\"\n#include \"windbg.h\"\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n", "suffix_code": "\n", "middle_code": "int\nmain(int argc, char* argv[])\n{\n SetUnhandledExceptionFilter(createMiniDump);\n SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);\n QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);\n QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);\n QApplication::setAttribute(Qt::AA_UseSoftwareOpenGL);\n QApplication a(argc, argv);\n winutils::enableAllPrivilege();\n QString unique = \"OpenSpeedy\";\n QLocalSocket socket;\n socket.connectToServer(unique);\n if (socket.waitForConnected(500))\n {\n socket.close();\n return -1;\n }\n QIcon appIcon;\n appIcon.addFile(\":/icons/images/icon_16.ico\", QSize(16, 16));\n appIcon.addFile(\":/icons/images/icon_32.ico\", QSize(32, 32));\n appIcon.addFile(\":/icons/images/icon_64.ico\", QSize(64, 64));\n a.setWindowIcon(appIcon);\n QSettings settings =\n QSettings(QCoreApplication::applicationDirPath() + \"/config.ini\",\n QSettings::IniFormat);\n QTranslator translator;\n const QString baseName =\n \"OpenSpeedy_\" +\n settings.value(CONFIG_LANGUAGE, QLocale().system().name()).toString();\n if (translator.load(\":/i18n/translations/\" + baseName))\n {\n a.installTranslator(&translator);\n }\n QCommandLineParser parser;\n parser.setApplicationDescription(\"OpenSpeedy\");\n QCommandLineOption minimizeOption(\n QStringList() << \"m\" << \"minimize-to-tray\", \"启动时最小化到托盘\");\n parser.addOption(minimizeOption);\n parser.process(a);\n MainWindow w;\n w.resize(1024, 768);\n if (parser.isSet(minimizeOption))\n {\n w.hide();\n }\n else\n {\n w.show();\n }\n QLocalServer server;\n QLocalServer::removeServer(unique);\n server.listen(unique);\n QObject::connect(&server,\n &QLocalServer::newConnection,\n [&]\n {\n w.show();\n w.raise();\n w.showNormal();\n w.activateWindow();\n });\n return a.exec();\n}", "code_description": null, "fill_type": "FUNCTION_TYPE", "language_type": "cpp", "sub_task_type": null}, "context_code": [["/OpenSpeedy/windbg.h", "/*\n * OpenSpeedy - Open Source Game Speed Controller\n * Copyright (C) 2025 Game1024\n * \n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n * \n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n * \n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n#ifndef WINDBG_H\n#define WINDBG_H\n#include \n#include \n#include \n#include \n// 链接dbghelp库\n#pragma comment(lib, \"dbghelp.lib\")\n\ntypedef BOOL(WINAPI *MINIDUMPWRITEDUMP)(\n HANDLE hProcess,\n DWORD ProcessId,\n HANDLE hFile,\n MINIDUMP_TYPE DumpType,\n PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,\n PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,\n PMINIDUMP_CALLBACK_INFORMATION CallbackParam);\n\n// 自定义异常处理函数\nLONG WINAPI createMiniDump(EXCEPTION_POINTERS *exceptionPointers)\n{\n // 创建dump文件目录\n QDir dumpDir(QDir::currentPath() + \"/dumps\");\n if (!dumpDir.exists())\n {\n dumpDir.mkpath(\".\");\n }\n\n // 生成带时间戳的文件名\n QString dumpFileName =\n QString(\"%1/crash_%2.dmp\")\n .arg(dumpDir.absolutePath())\n .arg(QDateTime::currentDateTime().toString(\"yyyy-MM-dd_hh-mm-ss\"));\n\n // 创建文件\n HANDLE hFile = CreateFile(dumpFileName.toStdWString().c_str(),\n GENERIC_WRITE, FILE_SHARE_READ, NULL,\n CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);\n\n if (hFile == INVALID_HANDLE_VALUE)\n {\n return EXCEPTION_CONTINUE_SEARCH;\n }\n\n // 加载dbghelp.dll\n HMODULE dbgHelp = LoadLibrary(L\"dbghelp.dll\");\n if (!dbgHelp)\n {\n CloseHandle(hFile);\n return EXCEPTION_CONTINUE_SEARCH;\n }\n\n // 获取MiniDumpWriteDump函数地址\n MINIDUMPWRITEDUMP miniDumpWriteDump =\n (MINIDUMPWRITEDUMP)GetProcAddress(dbgHelp, \"MiniDumpWriteDump\");\n\n if (!miniDumpWriteDump)\n {\n FreeLibrary(dbgHelp);\n CloseHandle(hFile);\n return EXCEPTION_CONTINUE_SEARCH;\n }\n\n // 配置异常信息\n MINIDUMP_EXCEPTION_INFORMATION exInfo;\n exInfo.ThreadId = GetCurrentThreadId();\n exInfo.ExceptionPointers = exceptionPointers;\n exInfo.ClientPointers = FALSE;\n\n // 设置dump类型\n MINIDUMP_TYPE dumpType =\n (MINIDUMP_TYPE)(MiniDumpWithFullMemory | // 包含完整内存\n MiniDumpWithFullMemoryInfo | // 包含内存信息\n MiniDumpWithHandleData | // 包含句柄数据\n MiniDumpWithThreadInfo | // 包含线程信息\n MiniDumpWithUnloadedModules // 包含卸载的模块\n );\n\n // 写入dump文件\n BOOL success = miniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(),\n hFile, dumpType, &exInfo, NULL, NULL);\n\n // 清理资源\n FreeLibrary(dbgHelp);\n CloseHandle(hFile);\n\n // 显示通知\n if (success)\n {\n std::wstring message =\n QString(\"程序遇到错误已退出,崩溃转储文件已保存到:\\n%1\")\n .arg(dumpFileName)\n .toStdWString();\n MessageBoxW(nullptr, message.c_str(), L\"程序崩溃\",\n MB_OK | MB_ICONERROR);\n }\n\n return EXCEPTION_EXECUTE_HANDLER;\n}\n\n#endif // WINDBG_H\n"], ["/OpenSpeedy/config.h", "/*\n * OpenSpeedy - Open Source Game Speed Controller\n * Copyright (C) 2025 Game1024\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n#ifndef CONFIG_H\n#define CONFIG_H\n\n#define OPENSPEEDY_VERSION \"v1.7.6\"\n\n#define BRIDGE32_EXE \"bridge32.exe\"\n#define BRIDGE64_EXE \"bridge64.exe\"\n\n#define SPEEDPATCH32_DLL \"speedpatch32.dll\"\n#define SPEEDPATCH64_DLL \"speedpatch64.dll\"\n\n#define CONFIG_LANGUAGE \"General/Language\"\n\n// 热键ID\nenum HotkeyIds\n{\n HOTKEY_INCREASE_SPEED = 1001,\n HOTKEY_DECREASE_SPEED = 1002,\n HOTKEY_RESET_SPEED = 1003,\n HOTKEY_SHIFT1 = 1011,\n HOTKEY_SHIFT2 = 1012,\n HOTKEY_SHIFT3 = 1013,\n HOTKEY_SHIFT4 = 1014,\n HOTKEY_SHIFT5 = 1015\n};\n\n#endif // CONFIG_H\n"], ["/OpenSpeedy/bridge/main.cpp", "#include \"../config.h\"\n#include \"../speedpatch/speedpatch.h\"\n#include \"../windbg.h\"\n#include \"../winutils.h\"\n#include \n#include \n#include \n#include \n#include \n\n#ifndef _WIN64\n#define SPEEDPATCH_DLL SPEEDPATCH32_DLL\n#else\n#define SPEEDPATCH_DLL SPEEDPATCH64_DLL\n#endif\n\nvoid\nhandleInject(int processId, QString dllPath)\n{\n qDebug() << \"执行 inject,进程ID:\" << processId;\n winutils::injectDll(processId, dllPath);\n SetProcessStatus(processId, true);\n}\n\nvoid\nhandleUnhook(int processId, QString dllPath)\n{\n qDebug() << \"执行 unhook,进程ID:\" << processId;\n SetProcessStatus(processId, false);\n}\n\nvoid\nhandleChange(double factor)\n{\n qDebug() << \"执行 change,参数:\" << factor;\n ChangeSpeed(factor);\n}\n\nint\nmain(int argc, char* argv[])\n{\n SetUnhandledExceptionFilter(createMiniDump);\n QCoreApplication a(argc, argv);\n if (winutils::enableAllPrivilege())\n {\n qDebug() << \"权限提升成功\";\n }\n\n QString dllPath = QDir::toNativeSeparators(\n QCoreApplication::applicationDirPath() + \"/\" + SPEEDPATCH_DLL);\n\n QTextStream in(stdin);\n QTextStream out(stdout);\n\n QRegularExpression injectRegex(\"^\\\\s*inject\\\\s+(\\\\d+)\\\\s*$\",\n QRegularExpression::CaseInsensitiveOption);\n QRegularExpression unhookRegex(\"^\\\\s*unhook\\\\s+(\\\\d+)\\\\s*$\",\n QRegularExpression::CaseInsensitiveOption);\n QRegularExpression changeRegex(\"^\\\\s*change\\\\s+([+-]?\\\\d*\\\\.?\\\\d+)\\\\s*$\",\n QRegularExpression::CaseInsensitiveOption);\n QRegularExpression exitRegex(\"^\\\\s*exit\\\\s*$\",\n QRegularExpression::CaseInsensitiveOption);\n\n while (true)\n {\n QString line = in.readLine();\n if (line.isNull())\n {\n // 管道关闭或输入结束\n break;\n }\n line = line.trimmed();\n if (line.isEmpty())\n continue;\n\n QRegularExpressionMatch match;\n if ((match = injectRegex.match(line)).hasMatch())\n {\n int pid = match.captured(1).toInt();\n handleInject(pid, dllPath);\n }\n else if ((match = unhookRegex.match(line)).hasMatch())\n {\n int pid = match.captured(1).toInt();\n handleUnhook(pid, dllPath);\n }\n else if ((match = changeRegex.match(line)).hasMatch())\n {\n double factor = match.captured(1).toDouble();\n handleChange(factor);\n }\n else if (exitRegex.match(line).hasMatch())\n {\n qDebug() << \"收到exit命令,程序即将退出。\";\n break;\n }\n else\n {\n qDebug() << \"无效命令:\" << line;\n }\n }\n\n return 0;\n}\n"], ["/OpenSpeedy/speedpatch/SpeedPatch_global.h", "/*\n * OpenSpeedy - Open Source Game Speed Controller\n * Copyright (C) 2025 Game1024\n * \n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n * \n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n * \n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n#ifndef SPEEDPATCH_GLOBAL_H\n#define SPEEDPATCH_GLOBAL_H\n\n\n#endif // SPEEDPATCH_GLOBAL_H\n"], ["/OpenSpeedy/processmonitor.h", "class ProcessMonitor {\n Q_OBJECT\npublic:\nexplicit ProcessMonitor(QSettings* settings,\n QTreeWidget* treeWidget,\n QLabel* treeStatusLabel,\n QLabel* injector32StatusLabel,\n QLabel* injector64StatusLabel,\n\n QObject* parent = nullptr);\n ~ProcessMonitor() {\n this->terminalBridge();\n delete m_bridge32;\n delete m_bridge64;\n}\n void setInterval(int msec);\n void setFilter(QString processName) {\n m_filter = processName.toLower();\n}\n void changeSpeed(double factor) {\n QString cmd = QString(\"change %1\\n\").arg(factor);\n m_bridge32->write(cmd.toUtf8(), cmd.size());\n m_bridge32->waitForBytesWritten();\n m_bridge64->write(cmd.toUtf8(), cmd.size());\n m_bridge64->waitForBytesWritten();\n}\n public:\n void refresh() {\n healthcheckBridge();\n QList processList = winutils::getProcessList();\n if (m_filter == \"\")\n {\n update(processList);\n m_treeStatusLabel->setText(QString(tr(\"搜索到%1个进程, 已过滤展示%2个\"))\n .arg(processList.size())\n .arg(processList.size()));\n }\n else\n {\n QList filtered;\n for (ProcessInfo info : processList)\n {\n if (info.name.toLower().contains(m_filter))\n filtered.append(info);\n }\n update(filtered);\n m_treeStatusLabel->setText(QString(tr(\"搜索到%1个进程, 已过滤展示%2个\"))\n .arg(processList.size())\n .arg(filtered.size()));\n }\n}\n void start() {\n m_timer = new QTimer(this);\n connect(m_timer, &QTimer::timeout, this, &ProcessMonitor::refresh);\n m_timer->start(1000);\n}\n private:\n void onItemChanged(QTreeWidgetItem* item, int column) {\n if (column == 5 && (item->flags() & Qt::ItemIsUserCheckable))\n {\n bool state = m_treeWidget->blockSignals(true);\n\n Qt::CheckState checkState = item->checkState(column);\n QString processName = item->text(0);\n DWORD pid = item->text(1).toLong();\n bool is64Bit = item->text(3) == \"x64\" ? true : false;\n if (checkState == Qt::Checked)\n {\n m_targetNames.insert(processName);\n this->injectDll(pid, is64Bit);\n item->setText(5, tr(\"加速中\"));\n for (int col = 0; col < item->columnCount(); ++col)\n {\n item->setBackground(col, QBrush(QColor(\"#f3e5f5\")));\n item->setForeground(col, QBrush(QColor(\"#7b1fa2\")));\n }\n qDebug() << processName << \"勾选\";\n dump();\n }\n else\n {\n m_targetNames.remove(processName);\n this->unhookDll(pid, is64Bit);\n item->setText(5, \"\");\n for (int col = 0; col < item->columnCount(); ++col)\n {\n item->setBackground(col, QBrush());\n item->setForeground(col, QBrush());\n }\n qDebug() << processName << \"取消勾选\";\n dump();\n }\n\n m_treeWidget->blockSignals(state);\n }\n}\n private:\n QTreeWidget* m_treeWidget;\n QLabel* m_treeStatusLabel;\n QLabel* m_injector32StatusLabel;\n QLabel* m_injector64StatusLabel;\n QString m_filter;\n QTimer* m_timer = nullptr;\n QString m_dllPath;\n QProcess* m_bridge32;\n QProcess* m_bridge64;\n QSettings* m_settings;\n QHash m_iconCache;\n QMap m_processItems;\n QSet m_targetNames;\n void init() {\n QStringList targetNames =\n m_settings->value(CONFIG_TARGETNAMES_KEY).toStringList();\n m_targetNames = QSet(targetNames.begin(), targetNames.end());\n}\n void dump() {\n m_settings->setValue(CONFIG_TARGETNAMES_KEY,\n QStringList(m_targetNames.values()));\n}\n void update(const QList& processList) {\n // 跟踪现有进程,用于确定哪些已终止\n QSet currentPids;\n for (const ProcessInfo& info : processList)\n {\n currentPids.insert(info.pid);\n }\n\n // 移除已终止的进程\n QMutableMapIterator i(m_processItems);\n while (i.hasNext())\n {\n i.next();\n if (!currentPids.contains(i.key()))\n {\n QTreeWidgetItem* item = i.value();\n QTreeWidgetItem* parent = item->parent();\n\n if (parent)\n {\n parent->removeChild(item);\n }\n else\n {\n auto index = m_treeWidget->indexOfTopLevelItem(item);\n m_treeWidget->takeTopLevelItem(index);\n }\n\n while (item->childCount() > 0)\n {\n QTreeWidgetItem* child = item->takeChild(0);\n if (parent)\n {\n parent->addChild(child);\n }\n else\n {\n m_treeWidget->addTopLevelItem(child);\n }\n }\n\n // 删除节点\n delete item;\n\n // 从映射中移除\n i.remove();\n }\n }\n\n // 添加或更新进程信息\n for (const ProcessInfo& info : processList)\n {\n if (m_processItems.contains(info.pid))\n {\n // 更新已存在的进程信息\n QTreeWidgetItem* item = m_processItems[info.pid];\n item->setText(1, QString::number(info.pid));\n item->setData(1, Qt::UserRole, (long long)info.pid);\n item->setText(2,\n QString(\"%1 MB\").arg(info.memoryUsage / 1024 / 1024));\n item->setData(2, Qt::UserRole, (uint)info.memoryUsage);\n\n QString arch = info.is64Bit ? \"x64\" : \"x86\";\n item->setText(3, arch);\n QString priority;\n switch (info.priorityClass)\n {\n case HIGH_PRIORITY_CLASS:\n priority = tr(\"高\");\n break;\n case NORMAL_PRIORITY_CLASS:\n priority = tr(\"中\");\n break;\n case IDLE_PRIORITY_CLASS:\n priority = tr(\"低\");\n break;\n case REALTIME_PRIORITY_CLASS:\n priority = tr(\"实时\");\n break;\n default:\n priority = tr(\"未知\");\n break;\n }\n item->setText(4, priority);\n if (m_targetNames.contains(info.name))\n {\n if (item->checkState(5) == Qt::Unchecked)\n {\n item->setCheckState(5, Qt::Checked);\n }\n }\n else\n {\n if (item->checkState(5) == Qt::Checked)\n {\n item->setCheckState(5, Qt::Unchecked);\n }\n }\n }\n else\n {\n // 添加新进程\n QTreeWidgetItem* item = new SortTreeWidgetItem();\n\n item->setText(0, info.name);\n item->setData(0, Qt::UserRole, info.name.toLower());\n item->setText(1, QString::number(info.pid));\n item->setData(1, Qt::UserRole, (long long)info.pid);\n item->setText(2,\n QString(\"%1 MB\").arg(info.memoryUsage / 1024 / 1024));\n item->setData(2, Qt::UserRole, (uint)info.memoryUsage);\n\n QString arch = info.is64Bit ? \"x64\" : \"x86\";\n item->setText(3, arch);\n\n // 加载进程图标\n item->setIcon(0, getProcessIconCached(info.pid));\n\n QString priority;\n switch (info.priorityClass)\n {\n case HIGH_PRIORITY_CLASS:\n priority = tr(\"高\");\n break;\n case NORMAL_PRIORITY_CLASS:\n priority = tr(\"中\");\n break;\n case IDLE_PRIORITY_CLASS:\n priority = tr(\"低\");\n break;\n case REALTIME_PRIORITY_CLASS:\n priority = tr(\"实时\");\n break;\n default:\n priority = tr(\"未知\");\n break;\n }\n item->setText(4, priority);\n item->setCheckState(5, Qt::Unchecked);\n m_treeWidget->addTopLevelItem(item);\n m_processItems[info.pid] = item;\n }\n }\n}\n void injectDll(DWORD processId, bool is64Bit) {\n QString cmd = QString(\"inject %1\\n\").arg(processId);\n if (!is64Bit)\n {\n m_bridge32->write(cmd.toUtf8(), cmd.size());\n m_bridge32->waitForBytesWritten();\n }\n else\n {\n m_bridge64->write(cmd.toUtf8(), cmd.size());\n m_bridge64->waitForBytesWritten();\n }\n}\n void unhookDll(DWORD processId, bool is64Bit) {\n QString cmd = QString(\"unhook %1\\n\").arg(processId);\n if (!is64Bit)\n {\n m_bridge32->write(cmd.toUtf8(), cmd.size());\n m_bridge32->waitForBytesWritten();\n }\n else\n {\n m_bridge64->write(cmd.toUtf8(), cmd.size());\n m_bridge64->waitForBytesWritten();\n }\n}\n void startBridge32() {\n m_bridge32 = new QProcess();\n QStringList params32;\n m_bridge32->start(BRIDGE32_EXE, params32);\n if (!m_bridge32->waitForStarted())\n {\n qDebug() << \"32位桥接子进程启动失败\";\n }\n else\n {\n qDebug() << \"32位桥接子进程已启动\";\n }\n m_bridge32->setProcessChannelMode(QProcess::MergedChannels);\n connect(m_bridge32,\n &QProcess::readyReadStandardOutput,\n [&]()\n {\n QByteArray data = m_bridge32->readAllStandardOutput();\n qDebug() << \"收到输出:\" << QString(data).trimmed();\n });\n}\n void startBridge64() {\n m_bridge64 = new QProcess();\n QStringList params64;\n m_bridge64->start(BRIDGE64_EXE, params64);\n if (!m_bridge64->waitForStarted())\n {\n qDebug() << \"64位桥接子进程启动失败\";\n }\n else\n {\n qDebug() << \"64位桥接子进程已启动\";\n }\n m_bridge64->setProcessChannelMode(QProcess::MergedChannels);\n connect(m_bridge64,\n &QProcess::readyReadStandardOutput,\n [&]()\n {\n QByteArray data = m_bridge64->readAllStandardOutput();\n qDebug() << \"收到输出:\" << QString(data).trimmed();\n });\n}\n void healthcheckBridge() {\n if (this->m_bridge32->state() == QProcess::Running)\n {\n m_injector32StatusLabel->setStyleSheet(\"color: green\");\n m_injector32StatusLabel->setText(tr(\"正常\"));\n }\n else\n {\n m_injector32StatusLabel->setStyleSheet(\"color: red\");\n m_injector32StatusLabel->setText(tr(\"异常退出\"));\n }\n\n if (this->m_bridge64->state() == QProcess::Running)\n {\n m_injector64StatusLabel->setStyleSheet(\"color: green\");\n m_injector64StatusLabel->setText(tr(\"正常\"));\n }\n else\n {\n m_injector64StatusLabel->setStyleSheet(\"color:red\");\n m_injector64StatusLabel->setText(tr(\"异常退出\"));\n }\n}\n void terminalBridge() {\n QString cmd = QString(\"exit\\n\");\n m_bridge32->write(cmd.toUtf8(), cmd.size());\n m_bridge32->waitForBytesWritten();\n m_bridge64->write(cmd.toUtf8(), cmd.size());\n m_bridge64->waitForBytesWritten();\n}\n static QIcon getProcessIcon(QString processPath) {\n int lastSlashPos =\n std::max(processPath.lastIndexOf('/'), processPath.lastIndexOf('\\\\'));\n QString processName;\n if (lastSlashPos == -1)\n {\n processName = processPath;\n }\n processName = processPath.mid(lastSlashPos + 1);\n\n if (processPath.isEmpty())\n {\n qDebug() << processPath << \"无法获取进程完整路径\";\n return getDefaultIcon(processName);\n }\n\n SHFILEINFO sfi = {};\n if (SHGetFileInfo(reinterpret_cast(processPath.utf16()),\n FILE_ATTRIBUTE_NORMAL,\n &sfi,\n sizeof(SHFILEINFO),\n SHGFI_ICON | SHGFI_LARGEICON | SHGFI_USEFILEATTRIBUTES))\n {\n if (sfi.hIcon)\n {\n QIcon icon = QtWin::fromHICON(sfi.hIcon);\n DestroyIcon(sfi.hIcon);\n if (!icon.isNull())\n {\n qDebug() << processPath << \"通过SHGetFileInfo获取图标成功\";\n return icon;\n }\n }\n }\n\n HICON hIcon =\n ExtractIconW(nullptr, reinterpret_cast(processPath.utf16()), 0);\n if (hIcon)\n {\n QIcon icon = QtWin::fromHICON(hIcon);\n DestroyIcon(hIcon);\n if (!icon.isNull())\n return icon;\n }\n\n QFileInfo fileInfo(processPath);\n if (fileInfo.exists())\n {\n // 使用Qt的QFileIconProvider获取文件图标\n QFileIconProvider iconProvider;\n return iconProvider.icon(fileInfo);\n }\n qDebug() << processPath << \"无法获取进程图标使用默认图标\";\n\n return getDefaultIcon(processName);\n}\n static QIcon getDefaultIcon(const QString& processName) {\n // 根据进程名称或类型提供更有针对性的默认图标\n if (processName != \"\")\n {\n // 使用SHGetFileInfo获取.exe文件的图标\n SHFILEINFO sfi = {};\n QIcon icon;\n if (SHGetFileInfo(reinterpret_cast(processName.utf16()),\n FILE_ATTRIBUTE_NORMAL,\n &sfi,\n sizeof(SHFILEINFO),\n SHGFI_USEFILEATTRIBUTES | SHGFI_ICON |\n SHGFI_SMALLICON))\n {\n // 将HICON转换为QIcon\n icon = QtWin::fromHICON(sfi.hIcon);\n\n // 释放图标资源\n DestroyIcon(sfi.hIcon);\n }\n return icon;\n }\n else\n {\n // 使用SHGetFileInfo获取.exe文件的图标\n SHFILEINFO sfi = {};\n QIcon icon;\n if (SHGetFileInfo(reinterpret_cast(L\".exe\"),\n FILE_ATTRIBUTE_NORMAL,\n &sfi,\n sizeof(SHFILEINFO),\n SHGFI_USEFILEATTRIBUTES | SHGFI_ICON |\n SHGFI_SMALLICON))\n {\n // 将HICON转换为QIcon\n icon = QtWin::fromHICON(sfi.hIcon);\n\n // 释放图标资源\n DestroyIcon(sfi.hIcon);\n }\n return icon;\n }\n}\n QIcon getProcessIconCached(DWORD proccessId) {\n QString processPath = winutils::getProcessPath(processId);\n if (m_iconCache.contains(processPath))\n {\n return m_iconCache[processPath];\n }\n\n QIcon icon = getProcessIcon(processPath);\n m_iconCache.insert(processPath, icon);\n return icon;\n}\n public:\n};"], ["/OpenSpeedy/taskscheduler.h", "class TaskScheduler {\n Q_OBJECT\n public:\n explicit TaskScheduler(QObject *parent = nullptr);\n ~TaskScheduler() {\n}\n bool createStartupTask(const QString &taskName,\n const QString &executablePath) {\n if (taskName.isEmpty() || executablePath.isEmpty())\n {\n qWarning() << \"任务名称或可执行文件路径不能为空\";\n return false;\n }\n\n if (!QFile::exists(executablePath))\n {\n qWarning() << \"可执行文件不存在\" << executablePath;\n return false;\n }\n\n QStringList arguments;\n arguments << \"/create\"\n << \"/f\"\n << \"/tn\" << taskName << \"/tr\"\n << QString(\"\\\"%1\\\" --minimize-to-tray\").arg(executablePath)\n << \"/sc\" << \"onlogon\"\n << \"/delay\" << \"0000:10\"\n << \"/rl\" << \"highest\";\n\n return execute(arguments);\n}\n bool deleteTask(const QString &taskName) {\n if (taskName.isEmpty())\n {\n qWarning() << \"任务名称不能为空\";\n return false;\n }\n\n if (!isTaskExists(taskName))\n {\n qWarning() << \"任务不存在, 无需删除\" << taskName;\n return true;\n }\n\n QStringList arguments;\n arguments << \"/delete\"\n << \"/f\"\n << \"/tn\" << taskName;\n\n return execute(arguments);\n}\n bool enableTask(const QString &taskName, bool enable) {\n if (!isTaskExists(taskName))\n {\n qWarning() << \"任务不存在:\" << taskName;\n return false;\n }\n\n QStringList arguments;\n arguments << \"/change\"\n << \"/tn\" << taskName << (enable ? \"/enable\" : \"/disable\");\n return execute(arguments);\n}\n bool isTaskExists(const QString &taskName) {\n QStringList arguments;\n arguments << \"/query\" << \"/tn\" << taskName;\n\n return execute(arguments);\n}\n bool execute(const QStringList &arguments) {\n QProcess process;\n process.setProgram(\"schtasks\");\n process.setArguments(arguments);\n\n const int timeout = 10000;\n process.start();\n if (!process.waitForStarted(timeout))\n {\n qWarning() << \"无法运行:\" << process.errorString();\n return false;\n }\n\n if (!process.waitForFinished(timeout))\n {\n qWarning() << \"执行超时\";\n process.kill();\n return false;\n }\n\n int exitcode = process.exitCode();\n QString stdout_ = QString::fromLocal8Bit(process.readAllStandardOutput());\n QString stderr_ = QString::fromLocal8Bit(process.readAllStandardError());\n\n if (exitcode == 0)\n {\n qDebug() << \"执行成功:\" << arguments;\n qDebug() << \"输出:\" << stdout_;\n return true;\n }\n else\n {\n qDebug() << \"执行失败:\" << arguments;\n qDebug() << \"错误输出:\" << stderr_;\n qDebug() << \"标准输出:\" << stdout_;\n return false;\n }\n}\n bool createStartupShortcut(const QString &taskName,\n const QString &executablePath) {\n QString home = QDir::homePath();\n QString startupDir =\n home +\n \"\\\\AppData\\\\Roaming\\\\Microsoft\\\\Windows\\\\Start Menu\\\\Programs\\\\Startup\";\n QString shortcutPath = QDir(startupDir).absoluteFilePath(taskName + \".lnk\");\n QString arguments = \"--minimize-to-tray\";\n\n QString psScript =\n QString(\"$WScriptShell = New-Object -ComObject WScript.Shell; \"\n \"$Shortcut = $WScriptShell.CreateShortcut('%1'); \"\n \"$Shortcut.TargetPath = '%2'; \"\n \"$Shortcut.Arguments = '%3'; \"\n \"$Shortcut.Description = '%4'; \"\n \"$Shortcut.Save()\")\n .arg(shortcutPath, executablePath, arguments,\n QString(\"启动 %1\").arg(QFileInfo(executablePath).baseName()));\n\n return executePs(psScript);\n}\n bool deleteStartupShortcut(const QString &taskName) {\n QString home = QDir::homePath();\n QString startupDir =\n home + \"\\\\AppData\\\\Roaming\\\\Microsoft\\\\Windows\\\\Start Menu\\\\Programs\\\\Startup\";\n QString shortcutPath = QDir(startupDir).absoluteFilePath(taskName + \".lnk\");\n\n QString psScript = QString(\"Remove-Item '%1' -Force\").arg(shortcutPath);\n\n return executePs(psScript);\n}\n bool isStartupShortcutExists(const QString &taskName) {\n QString home = QDir::homePath();\n QString startupDir =\n home +\n \"\\\\AppData\\\\Roaming\\\\Microsoft\\\\Windows\\\\Start Menu\\\\Programs\\\\Startup\";\n QString shortcutPath = QDir(startupDir).absoluteFilePath(taskName + \".lnk\");\n\n return QFile::exists(shortcutPath);\n}\n bool executePs(const QString &psScript) {\n QProcess process;\n process.setProgram(\"powershell\");\n process.setArguments({\"-ExecutionPolicy\", \"Bypass\", \"-Command\", psScript});\n\n process.start();\n if (!process.waitForStarted(5000))\n {\n qDebug() << \"PowerShell 启动失败:\" << process.errorString();\n return false;\n }\n\n if (process.waitForFinished(5000) && process.exitCode() == 0)\n {\n qDebug() << \"PowerShell 执行成功\";\n return true;\n }\n else\n {\n QString error = QString::fromLocal8Bit(process.readAllStandardError());\n qDebug() << \"PowerShell 执行失败:\" << error;\n }\n\n return false;\n}\n};"], ["/OpenSpeedy/winutils.h", "class winutils {\n public:\n winutils() {\n}\n public:\n static bool injectDll(DWORD processId, const QString& dllPath) {\n HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);\n if (!hProcess)\n {\n qDebug() << \"Failed to open process:\" << GetLastError();\n return false;\n }\n\n if (checkDllExist(processId, dllPath))\n {\n qDebug() << \"Process already have been injected\";\n return true;\n }\n else if (injectDllViaCRTW(processId, dllPath))\n {\n return true;\n }\n else if (injectDllViaCRTA(processId, dllPath))\n {\n return true;\n }\n\n injectDllViaAPCW(processId, dllPath);\n injectDllViaAPCA(processId, dllPath);\n if (checkDllExist(processId, dllPath))\n {\n return true;\n }\n else if (injectDllViaWHKW(processId, dllPath))\n {\n return true;\n }\n else if (injectDllViaWHKA(processId, dllPath))\n {\n return true;\n }\n else\n {\n return false;\n }\n}\n static bool injectDllViaCRTA(DWORD processId, const QString& dllPath) {\n HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);\n if (!hProcess)\n {\n qDebug() << \"Failed to open process:\" << GetLastError();\n return false;\n }\n\n if (checkDllExist(processId, dllPath))\n {\n qDebug() << \"Process already have been injected\";\n return true;\n }\n SIZE_T pathSize = (dllPath.size() + 1) * sizeof(char);\n LPVOID pDllPath =\n VirtualAllocEx(hProcess,\n nullptr,\n pathSize,\n MEM_COMMIT | MEM_RESERVE,\n PAGE_EXECUTE_READWRITE);\n if (!pDllPath)\n {\n qDebug() << \"Failed to allocate memory in target process:\"\n << GetLastError();\n CloseHandle(hProcess);\n return false;\n }\n\n if (!WriteProcessMemory(hProcess,\n pDllPath,\n dllPath.toStdString().c_str(),\n pathSize,\n nullptr))\n {\n qDebug() << \"Failed to write memory in target process:\"\n << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n HMODULE hKernel32 = GetModuleHandle(L\"kernel32.dll\");\n if (!hKernel32)\n {\n qDebug() << \"Failed to get handle for kernel32.dll:\" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n FARPROC pLoadLibraryA = GetProcAddress(hKernel32, \"LoadLibraryA\");\n if (!pLoadLibraryA)\n {\n qDebug() << \"Failed to get address of LoadLibraryA:\" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n HANDLE hThread = CreateRemoteThread(hProcess,\n nullptr,\n 0,\n (LPTHREAD_START_ROUTINE)pLoadLibraryA,\n pDllPath,\n 0,\n nullptr);\n if (!hThread)\n {\n qDebug() << \"Failed to create remote thread:\" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n WaitForSingleObject(hThread, INFINITE);\n\n // 检查LoadLibrary是否执行成功\n DWORD exitCode = 0;\n if (GetExitCodeThread(hThread, &exitCode))\n {\n qDebug() << \"Remote thread exit code:\" << exitCode;\n // LoadLibrary返回的是模块句柄,如果为0则失败\n if (exitCode == 0)\n {\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n CloseHandle(hThread);\n qDebug() << \"LoadLibrary failed in remote process\";\n return false;\n }\n }\n\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hThread);\n CloseHandle(hProcess);\n\n return true;\n}\n static bool injectDllViaCRTW(DWORD processId, const QString& dllPath) {\n HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);\n if (!hProcess)\n {\n qDebug() << \"Failed to open process:\" << GetLastError();\n return false;\n }\n\n if (checkDllExist(processId, dllPath))\n {\n qDebug() << \"Process already have been injected\";\n return true;\n }\n SIZE_T pathSize = (dllPath.size() + 1) * sizeof(wchar_t);\n LPVOID pDllPath =\n VirtualAllocEx(hProcess, nullptr, pathSize, MEM_COMMIT | MEM_RESERVE,\n PAGE_EXECUTE_READWRITE);\n if (!pDllPath)\n {\n qDebug() << \"Failed to allocate memory in target process:\"\n << GetLastError();\n CloseHandle(hProcess);\n return false;\n }\n\n if (!WriteProcessMemory(hProcess,\n pDllPath,\n dllPath.toStdWString().c_str(),\n pathSize,\n nullptr))\n {\n qDebug() << \"Failed to write memory in target process:\"\n << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n HMODULE hKernel32 = GetModuleHandle(L\"kernel32.dll\");\n if (!hKernel32)\n {\n qDebug() << \"Failed to get handle for kernel32.dll:\" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n FARPROC pLoadLibraryW = GetProcAddress(hKernel32, \"LoadLibraryW\");\n if (!pLoadLibraryW)\n {\n qDebug() << \"Failed to get address of LoadLibraryW:\" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n HANDLE hThread = CreateRemoteThread(hProcess,\n nullptr,\n 0,\n (LPTHREAD_START_ROUTINE)pLoadLibraryW,\n pDllPath,\n 0,\n nullptr);\n if (!hThread)\n {\n qDebug() << \"Failed to create remote thread:\" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n WaitForSingleObject(hThread, INFINITE);\n\n // 检查LoadLibrary是否执行成功\n DWORD exitCode = 0;\n if (GetExitCodeThread(hThread, &exitCode))\n {\n qDebug() << \"Remote thread exit code:\" << exitCode;\n // LoadLibrary返回的是模块句柄,如果为0则失败\n if (exitCode == 0)\n {\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n CloseHandle(hThread);\n qDebug() << \"LoadLibrary failed in remote process\";\n return false;\n }\n }\n\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hThread);\n CloseHandle(hProcess);\n\n return true;\n}\n static bool injectDllViaAPCA(DWORD processId, const QString& dllPath) {\n HANDLE hProcess =\n OpenProcess(PROCESS_ALL_ACCESS,\n FALSE,\n processId);\n\n if (!hProcess)\n {\n qDebug() << \"Failed to open process: \" << GetLastError();\n return false;\n }\n\n if (checkDllExist(processId, dllPath))\n {\n qDebug() << \"Process already have been injected\";\n return true;\n }\n\n // 在目标进程中分配内存并写入DLL路径\n SIZE_T pathSize = (dllPath.toStdString().size() + 1) * sizeof(char);\n LPVOID pDllPath = VirtualAllocEx(hProcess,\n NULL,\n pathSize,\n MEM_COMMIT,\n PAGE_READWRITE);\n\n if (!pDllPath)\n {\n qDebug() << \"Failed to allocate memory: \" << GetLastError();\n CloseHandle(hProcess);\n return false;\n }\n\n if (!WriteProcessMemory(hProcess, pDllPath, dllPath.toStdString().c_str(),\n pathSize, NULL))\n {\n qDebug() << \"Failed to write memory: \" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 获取LoadLibraryW的地址\n HMODULE hKernel32 = GetModuleHandle(L\"kernel32.dll\");\n if (!hKernel32)\n {\n qDebug() << \"Failed to get kernel32 handle\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n FARPROC pLoadLibraryA = GetProcAddress(hKernel32, \"LoadLibraryA\");\n if (!pLoadLibraryA)\n {\n qDebug() << \"Failed to get LoadLibraryA address\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 获取进程中的所有线程\n DWORD threadId = getProcessMainThread(processId);\n if (!threadId)\n {\n qDebug() << \"No threads found in the process\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 向目标进程的所有线程队列中添加APC调用\n bool success = false;\n\n // 打开线程\n HANDLE hThread = OpenThread(THREAD_SET_CONTEXT, FALSE, threadId);\n if (hThread)\n {\n // 将LoadLibraryA作为APC函数加入队列\n PostThreadMessageA(threadId, WM_PAINT, 0, 0);\n DWORD result =\n QueueUserAPC((PAPCFUNC)pLoadLibraryA, hThread, (ULONG_PTR)pDllPath);\n PostThreadMessageA(threadId, WM_PAINT, 0, 0);\n if (result != 0)\n {\n success = true;\n qDebug() << \"APC queued to thread \" << threadId;\n }\n\n CloseHandle(hThread);\n }\n\n if (!success)\n {\n qDebug() << \"Failed to queue APC to any thread\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 注意:我们不释放分配的内存,因为APC函数尚未执行\n // 内存将在DLL加载后释放\n\n CloseHandle(hProcess);\n return true;\n}\n static bool injectDllViaAPCW(DWORD processId, const QString& dllPath) {\n HANDLE hProcess =\n OpenProcess(PROCESS_ALL_ACCESS,\n FALSE,\n processId);\n\n if (!hProcess)\n {\n qDebug() << \"Failed to open process: \" << GetLastError();\n return false;\n }\n\n if (checkDllExist(processId, dllPath))\n {\n qDebug() << \"Process already have been injected\";\n return true;\n }\n\n // 在目标进程中分配内存并写入DLL路径\n SIZE_T pathSize = (dllPath.toStdWString().size() + 1) * sizeof(wchar_t);\n LPVOID pDllPath = VirtualAllocEx(hProcess,\n NULL,\n pathSize,\n MEM_COMMIT,\n PAGE_READWRITE);\n\n if (!pDllPath)\n {\n qDebug() << \"Failed to allocate memory: \" << GetLastError();\n CloseHandle(hProcess);\n return false;\n }\n\n if (!WriteProcessMemory(hProcess,\n pDllPath,\n dllPath.toStdWString().c_str(),\n pathSize,\n NULL))\n {\n qDebug() << \"Failed to write memory: \" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 获取LoadLibraryW的地址\n HMODULE hKernel32 = GetModuleHandle(L\"kernel32.dll\");\n if (!hKernel32)\n {\n qDebug() << \"Failed to get kernel32 handle\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n FARPROC pLoadLibraryW = GetProcAddress(hKernel32, \"LoadLibraryW\");\n if (!pLoadLibraryW)\n {\n qDebug() << \"Failed to get LoadLibraryW address\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 获取进程中的所有线程\n DWORD threadId = getProcessMainThread(processId);\n if (!threadId)\n {\n qDebug() << \"No threads found in the process\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 向目标进程的所有线程队列中添加APC调用\n bool success = false;\n\n // 打开线程\n HANDLE hThread = OpenThread(THREAD_SET_CONTEXT, FALSE, threadId);\n if (hThread)\n {\n // 将LoadLibraryW作为APC函数加入队列\n PostThreadMessageW(threadId, WM_PAINT, 0, 0);\n DWORD result =\n QueueUserAPC((PAPCFUNC)pLoadLibraryW, hThread, (ULONG_PTR)pDllPath);\n PostThreadMessageW(threadId, WM_PAINT, 0, 0);\n if (result != 0)\n {\n success = true;\n qDebug() << \"APC queued to thread \" << threadId;\n }\n\n CloseHandle(hThread);\n }\n\n if (!success)\n {\n qDebug() << \"Failed to queue APC to any thread\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 注意:我们不释放分配的内存,因为APC函数尚未执行\n // 内存将在DLL加载后释放\n\n CloseHandle(hProcess);\n return true;\n}\n static bool injectDllViaWHKA(DWORD processId, const QString& dllPath) {\n if (checkProcessProtection(processId))\n {\n qDebug() << \"进程被保护 进程ID: \" << processId;\n return false;\n }\n\n // 1. 加载DLL到当前进程\n HMODULE hMod = LoadLibraryA(dllPath.toStdString().c_str());\n if (!hMod)\n return false;\n\n // 2. 获取Hook过程的地址\n HOOKPROC hookProc = (HOOKPROC)GetProcAddress(hMod, \"HookProc\");\n if (!hookProc)\n return false;\n\n // 3. 获取目标线程ID\n DWORD threadId = getProcessMainThread(processId);\n if (threadId == 0)\n return false;\n\n // 4. 安装Hook\n HHOOK hHook = SetWindowsHookExA(WH_CBT, // Hook类型\n hookProc, // Hook过程\n hMod, // DLL模块句柄\n threadId // 目标线程ID\n );\n\n if (!hHook)\n return false;\n // 5. 触发Hook执行\n PostThreadMessageA(threadId, WM_NULL, 0, 0);\n Sleep(5000);\n UnhookWindowsHookEx(hHook);\n\n return true;\n}\n static bool injectDllViaWHKW(DWORD processId, const QString& dllPath) {\n if (checkProcessProtection(processId))\n {\n qDebug() << \"进程被保护 进程ID: \" << processId;\n return false;\n }\n\n // 1. 加载DLL到当前进程\n HMODULE hMod = LoadLibraryW(dllPath.toStdWString().c_str());\n if (!hMod)\n return false;\n\n // 2. 获取Hook过程的地址\n HOOKPROC hookProc = (HOOKPROC)GetProcAddress(hMod, \"HookProc\");\n if (!hookProc)\n return false;\n\n // 3. 获取目标线程ID\n DWORD threadId = getProcessMainThread(processId);\n if (threadId == 0)\n return false;\n\n // 4. 安装Hook\n HHOOK hHook = SetWindowsHookExW(WH_CBT, // Hook类型\n hookProc, // Hook过程\n hMod, // DLL模块句柄\n threadId // 目标线程ID\n );\n\n if (!hHook)\n return false;\n // 5. 触发Hook执行\n PostThreadMessageW(threadId, WM_NULL, 0, 0);\n Sleep(5000);\n UnhookWindowsHookEx(hHook);\n\n return true;\n}\n static bool unhookDll(DWORD processId, const QString& dllPath) {\n HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);\n if (!hProcess)\n {\n qDebug() << \"Failed to open process:\" << GetLastError();\n return false;\n }\n\n HMODULE hModules[1024];\n DWORD cbNeeded;\n if (EnumProcessModules(hProcess, hModules, sizeof(hModules), &cbNeeded))\n {\n for (unsigned int i = 0; i < (cbNeeded / sizeof(HMODULE)); i++)\n {\n TCHAR moduleName[MAX_PATH];\n if (GetModuleFileNameEx(hProcess, hModules[i], moduleName,\n sizeof(moduleName) / sizeof(TCHAR)))\n {\n#ifdef UNICODE\n bool isDll = dllPath.toStdWString() == moduleName;\n#else\n bool isDll = dllPath.toStdString() == moduleName;\n#endif\n if (isDll)\n {\n FARPROC pFreeLibrary = GetProcAddress(\n GetModuleHandle(L\"kernel32.dll\"), \"FreeLibrary\");\n if (!pFreeLibrary)\n {\n qDebug() << \"Failed to get address of FreeLibrary:\"\n << GetLastError();\n CloseHandle(hProcess);\n return false;\n }\n\n HANDLE hThread =\n CreateRemoteThread(hProcess, nullptr, 0,\n (LPTHREAD_START_ROUTINE)pFreeLibrary,\n hModules[i], 0, nullptr);\n if (!hThread)\n {\n qDebug() << \"Failed to create remote thread for \"\n \"FreeLibrary:\"\n << GetLastError();\n CloseHandle(hProcess);\n return false;\n }\n\n WaitForSingleObject(hThread, INFINITE);\n CloseHandle(hThread);\n CloseHandle(hProcess);\n return true;\n }\n }\n }\n }\n\n CloseHandle(hProcess);\n return false;\n}\n static bool checkDllExist(DWORD processId, const QString& dllPath) {\n HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,\n FALSE,\n processId);\n if (!hProcess)\n {\n qDebug() << \"打开进程失败:\" << GetLastError();\n return false;\n }\n\n bool dllFound = false;\n HMODULE hModules[1024];\n DWORD cbNeeded;\n\n // 获取进程中所有已加载的模块\n if (EnumProcessModules(hProcess, hModules, sizeof(hModules), &cbNeeded))\n {\n DWORD moduleCount = cbNeeded / sizeof(HMODULE);\n for (DWORD i = 0; i < moduleCount; i++)\n {\n TCHAR moduleName[MAX_PATH] = {0};\n\n // 获取模块的完整路径\n if (GetModuleFileNameExW(hProcess, hModules[i], moduleName,\n sizeof(moduleName) / sizeof(TCHAR)))\n {\n#ifdef UNICODE\n bool isDll = dllPath.toStdWString() == moduleName;\n#else\n bool isDll = dllPath.toStdString() == moduleName;\n#endif\n if (isDll)\n {\n dllFound = true;\n break;\n }\n }\n }\n }\n else\n {\n qDebug() << \"枚举进程模块失败:\" << GetLastError();\n }\n\n CloseHandle(hProcess);\n return dllFound;\n}\n static bool checkProcessProtection(DWORD processId) {\n HANDLE hProcess =\n OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, processId);\n if (!hProcess)\n {\n qDebug() << \"Cannot open process - likely protected\";\n return true; // 可能被保护\n }\n\n // 检查是否是受保护进程\n PROCESS_PROTECTION_LEVEL_INFORMATION protectionInfo = {};\n DWORD returnLength;\n\n if (GetProcessInformation(hProcess, ProcessProtectionLevelInfo,\n &protectionInfo, sizeof(protectionInfo)))\n {\n CloseHandle(hProcess);\n return protectionInfo.ProtectionLevel != PROTECTION_LEVEL_NONE;\n }\n\n CloseHandle(hProcess);\n return false;\n}\n static void setAutoStart(bool enable,\n const QString& appName,\n const QString& execPath) {\n TaskScheduler scheduler;\n\n if (enable)\n {\n scheduler.createStartupShortcut(appName, execPath);\n }\n else\n {\n scheduler.deleteStartupShortcut(appName);\n }\n}\n static bool isAutoStartEnabled(const QString& appName) {\n TaskScheduler scheduler;\n return scheduler.isStartupShortcutExists(appName);\n}\n static BOOL getWindowsVersion(DWORD* majorVersion,\n DWORD* minorVersion,\n DWORD* buildNumber) {\n static char version[100] = {0};\n DWORD major, minor, build;\n\n if (!getWindowsVersion(&major, &minor, &build))\n return \"Unknown Windows Version\";\n\n // 确定Windows版本\n if (major == 10)\n {\n if (build >= 22000)\n {\n sprintf(version, \"Windows 11 (Build %lu)\", build);\n }\n else\n {\n sprintf(version, \"Windows 10 (Build %lu)\", build);\n }\n }\n else if (major == 6)\n {\n switch (minor)\n {\n case 3:\n sprintf(version, \"Windows 8.1 (Build %lu)\", build);\n break;\n case 2:\n sprintf(version, \"Windows 8 (Build %lu)\", build);\n break;\n case 1:\n sprintf(version, \"Windows 7 (Build %lu)\", build);\n break;\n case 0:\n sprintf(version, \"Windows Vista (Build %lu)\", build);\n break;\n default:\n sprintf(version, \"Windows NT %lu.%lu (Build %lu)\", major, minor,\n build);\n }\n }\n else if (major == 5)\n {\n switch (minor)\n {\n case 2:\n sprintf(version, \"Windows Server 2003 (Build %lu)\", build);\n break;\n case 1:\n sprintf(version, \"Windows XP (Build %lu)\", build);\n break;\n case 0:\n sprintf(version, \"Windows 2000 (Build %lu)\", build);\n break;\n default:\n sprintf(version, \"Windows NT %lu.%lu (Build %lu)\", major, minor,\n build);\n }\n }\n else\n {\n sprintf(version, \"Windows NT %lu.%lu (Build %lu)\", major, minor, build);\n }\n return version;\n}\n static QString getWindowsVersion() {\n static char version[100] = {0};\n DWORD major, minor, build;\n\n if (!getWindowsVersion(&major, &minor, &build))\n return \"Unknown Windows Version\";\n\n // 确定Windows版本\n if (major == 10)\n {\n if (build >= 22000)\n {\n sprintf(version, \"Windows 11 (Build %lu)\", build);\n }\n else\n {\n sprintf(version, \"Windows 10 (Build %lu)\", build);\n }\n }\n else if (major == 6)\n {\n switch (minor)\n {\n case 3:\n sprintf(version, \"Windows 8.1 (Build %lu)\", build);\n break;\n case 2:\n sprintf(version, \"Windows 8 (Build %lu)\", build);\n break;\n case 1:\n sprintf(version, \"Windows 7 (Build %lu)\", build);\n break;\n case 0:\n sprintf(version, \"Windows Vista (Build %lu)\", build);\n break;\n default:\n sprintf(version, \"Windows NT %lu.%lu (Build %lu)\", major, minor,\n build);\n }\n }\n else if (major == 5)\n {\n switch (minor)\n {\n case 2:\n sprintf(version, \"Windows Server 2003 (Build %lu)\", build);\n break;\n case 1:\n sprintf(version, \"Windows XP (Build %lu)\", build);\n break;\n case 0:\n sprintf(version, \"Windows 2000 (Build %lu)\", build);\n break;\n default:\n sprintf(version, \"Windows NT %lu.%lu (Build %lu)\", major, minor,\n build);\n }\n }\n else\n {\n sprintf(version, \"Windows NT %lu.%lu (Build %lu)\", major, minor, build);\n }\n return version;\n}\n static QList getProcessList() {\n QList processList;\n\n HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);\n if (hProcessSnap == INVALID_HANDLE_VALUE)\n {\n qDebug() << \"创建进程快照失败: \" << GetLastError();\n return processList;\n }\n\n PROCESSENTRY32 pe32;\n pe32.dwSize = sizeof(PROCESSENTRY32);\n\n if (!Process32First(hProcessSnap, &pe32))\n {\n qDebug() << \"获取首个进程信息失败: \" << GetLastError();\n CloseHandle(hProcessSnap);\n return processList;\n }\n\n do\n {\n if (systemNames.contains(pe32.szExeFile))\n {\n continue;\n }\n ProcessInfo info;\n info.pid = pe32.th32ProcessID;\n info.parentPid = pe32.th32ParentProcessID;\n info.name = QString::fromWCharArray(pe32.szExeFile);\n info.threadCount = pe32.cntThreads;\n\n // 获取内存使用和优先级信息\n HANDLE hProcess = OpenProcess(\n PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, info.pid);\n if (hProcess)\n {\n PROCESS_MEMORY_COUNTERS pmc;\n if (GetProcessMemoryInfo(hProcess, &pmc, sizeof(pmc)))\n {\n info.memoryUsage = pmc.WorkingSetSize;\n }\n else\n {\n info.memoryUsage = 0;\n }\n BOOL wow64Process = FALSE;\n IsWow64Process(hProcess, &wow64Process);\n info.is64Bit = !wow64Process;\n info.priorityClass = GetPriorityClass(hProcess);\n CloseHandle(hProcess);\n }\n else\n {\n info.memoryUsage = 0;\n info.priorityClass = 0;\n }\n\n processList.append(info);\n } while (Process32Next(hProcessSnap, &pe32));\n\n CloseHandle(hProcessSnap);\n return processList;\n}\n static QString getProcessPath(DWORD processId) {\n QString processPath;\n HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,\n FALSE, processId);\n\n if (hProcess != NULL)\n {\n wchar_t buffer[MAX_PATH];\n if (GetModuleFileNameEx(hProcess, NULL, buffer, MAX_PATH) > 0)\n {\n processPath = QString::fromWCharArray(buffer);\n }\n CloseHandle(hProcess);\n }\n\n return processPath;\n}\n static DWORD getProcessMainThread(DWORD processId) {\n HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);\n if (hSnapshot == INVALID_HANDLE_VALUE)\n {\n qDebug() << \"Failed to create thread snapshot:\" << GetLastError();\n return 0;\n }\n\n THREADENTRY32 te32;\n te32.dwSize = sizeof(THREADENTRY32);\n\n DWORD mainThreadId = 0;\n FILETIME earliestTime = {0xFFFFFFFF, 0xFFFFFFFF}; // 设为最大值\n\n if (Thread32First(hSnapshot, &te32))\n {\n do\n {\n if (te32.th32OwnerProcessID == processId)\n {\n // 打开线程获取创建时间\n HANDLE hThread = OpenThread(THREAD_QUERY_INFORMATION, FALSE,\n te32.th32ThreadID);\n if (hThread)\n {\n FILETIME creationTime, exitTime, kernelTime, userTime;\n if (GetThreadTimes(hThread, &creationTime, &exitTime,\n &kernelTime, &userTime))\n {\n // 比较创建时间,找最早的线程\n if (CompareFileTime(&creationTime, &earliestTime) < 0)\n {\n earliestTime = creationTime;\n mainThreadId = te32.th32ThreadID;\n }\n }\n CloseHandle(hThread);\n }\n }\n } while (Thread32Next(hSnapshot, &te32));\n }\n\n CloseHandle(hSnapshot);\n return mainThreadId;\n}\n static QString getProcessNameById(DWORD processId) {\n HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,\n FALSE, processId);\n if (hProcess == NULL)\n {\n return QString();\n }\n\n wchar_t processName[MAX_PATH];\n if (GetModuleBaseName(hProcess, NULL, processName, MAX_PATH))\n {\n CloseHandle(hProcess);\n QString name = QString::fromWCharArray(processName);\n return name;\n }\n\n CloseHandle(hProcess);\n return QString();\n}\n static bool enableAllPrivilege() {\n HANDLE hToken;\n // 获取进程token\n if (!OpenProcessToken(GetCurrentProcess(),\n TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))\n return false;\n\n const wchar_t *essentialPrivileges[] = {\n SE_DEBUG_NAME, // 最重要的调试权限\n };\n\n TOKEN_PRIVILEGES tkp;\n bool success = true;\n\n for (const auto &privilege : essentialPrivileges)\n {\n tkp.PrivilegeCount = 1;\n tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;\n if (LookupPrivilegeValue(NULL, privilege, &tkp.Privileges[0].Luid))\n {\n AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, NULL);\n }\n }\n\n CloseHandle(hToken);\n return success;\n}\n};"], ["/OpenSpeedy/qsinglekeysequenceedit.h", "class QSingleKeySequenceEdit {\n Q_OBJECT\n\n public:\n explicit QSingleKeySequenceEdit(QWidget* parent = nullptr);\n static UINT toVK(int qtKey, Qt::KeyboardModifiers qtMod) {\n // 🔤 字母键 A-Z\n if (qtKey >= Qt::Key_A && qtKey <= Qt::Key_Z)\n {\n return qtKey; // Qt 和 Windows 的 A-Z 键码相同\n }\n\n // 🔢 小键盘 0-9\n if (qtMod & Qt::KeypadModifier)\n {\n switch (qtKey)\n {\n // 数字键盘\n case Qt::Key_0:\n return VK_NUMPAD0;\n case Qt::Key_1:\n return VK_NUMPAD1;\n case Qt::Key_2:\n return VK_NUMPAD2;\n case Qt::Key_3:\n return VK_NUMPAD3;\n case Qt::Key_4:\n return VK_NUMPAD4;\n case Qt::Key_5:\n return VK_NUMPAD5;\n case Qt::Key_6:\n return VK_NUMPAD6;\n case Qt::Key_7:\n return VK_NUMPAD7;\n case Qt::Key_8:\n return VK_NUMPAD8;\n case Qt::Key_9:\n return VK_NUMPAD9;\n }\n }\n\n // 🔢 数字键 0-9\n if (qtKey >= Qt::Key_0 && qtKey <= Qt::Key_9)\n {\n return qtKey; // Qt 和 Windows 的 0-9 键码相同\n }\n\n // 🎯 功能键映射\n switch (qtKey)\n {\n // F1-F12\n case Qt::Key_F1:\n return VK_F1;\n case Qt::Key_F2:\n return VK_F2;\n case Qt::Key_F3:\n return VK_F3;\n case Qt::Key_F4:\n return VK_F4;\n case Qt::Key_F5:\n return VK_F5;\n case Qt::Key_F6:\n return VK_F6;\n case Qt::Key_F7:\n return VK_F7;\n case Qt::Key_F8:\n return VK_F8;\n case Qt::Key_F9:\n return VK_F9;\n case Qt::Key_F10:\n return VK_F10;\n case Qt::Key_F11:\n return VK_F11;\n case Qt::Key_F12:\n return VK_F12;\n\n // 方向键\n case Qt::Key_Left:\n return VK_LEFT;\n case Qt::Key_Right:\n return VK_RIGHT;\n case Qt::Key_Up:\n return VK_UP;\n case Qt::Key_Down:\n return VK_DOWN;\n\n // 特殊键\n case Qt::Key_Enter:\n case Qt::Key_Return:\n return VK_RETURN;\n case Qt::Key_Escape:\n return VK_ESCAPE;\n case Qt::Key_Tab:\n return VK_TAB;\n case Qt::Key_Backspace:\n return VK_BACK;\n case Qt::Key_Delete:\n return VK_DELETE;\n case Qt::Key_Insert:\n return VK_INSERT;\n case Qt::Key_Home:\n return VK_HOME;\n case Qt::Key_End:\n return VK_END;\n case Qt::Key_PageUp:\n return VK_PRIOR;\n case Qt::Key_PageDown:\n return VK_NEXT;\n case Qt::Key_Space:\n return VK_SPACE;\n\n // 符号键\n case Qt::Key_Semicolon:\n return VK_OEM_1; // ;\n case Qt::Key_Equal:\n return VK_OEM_PLUS; // =\n case Qt::Key_Comma:\n return VK_OEM_COMMA; // ,\n case Qt::Key_Minus:\n return VK_OEM_MINUS; // -\n case Qt::Key_Period:\n return VK_OEM_PERIOD; // .\n case Qt::Key_Slash:\n return VK_OEM_2; // /\n case Qt::Key_QuoteLeft:\n return VK_OEM_3; // `\n case Qt::Key_BracketLeft:\n return VK_OEM_4; // [\n case Qt::Key_Backslash:\n return VK_OEM_5; //\n case Qt::Key_BracketRight:\n return VK_OEM_6; // ]\n case Qt::Key_Apostrophe:\n return VK_OEM_7; // '\n\n // 其他常用键\n case Qt::Key_CapsLock:\n return VK_CAPITAL;\n case Qt::Key_NumLock:\n return VK_NUMLOCK;\n case Qt::Key_ScrollLock:\n return VK_SCROLL;\n case Qt::Key_Pause:\n return VK_PAUSE;\n case Qt::Key_Print:\n return VK_PRINT;\n\n default:\n qDebug() << \"Unknown Qt key:\" << qtKey;\n return 0; // 未知按键\n }\n}\n static UINT toModifier(Qt::KeyboardModifiers qtMod) {\n UINT winMod = 0;\n\n if (qtMod & Qt::ControlModifier)\n {\n winMod |= MOD_CONTROL;\n }\n if (qtMod & Qt::AltModifier)\n {\n winMod |= MOD_ALT;\n }\n if (qtMod & Qt::ShiftModifier)\n {\n winMod |= MOD_SHIFT;\n }\n if (qtMod & Qt::MetaModifier)\n {\n winMod |= MOD_WIN; // Windows 键\n }\n\n return winMod;\n}\n static QtCombinedKey toQtCombinedKey(const QString& keyText) {\n QKeySequence sequence = QKeySequence(keyText);\n\n if (!sequence.isEmpty())\n {\n int combinedKey = sequence[0];\n Qt::KeyboardModifiers modifier =\n Qt::KeyboardModifiers(combinedKey & Qt::KeyboardModifierMask);\n int key = combinedKey & ~Qt::KeyboardModifierMask;\n return QtCombinedKey{ key, modifier };\n }\n else\n {\n return QtCombinedKey{ 0, Qt::NoModifier };\n }\n}\n static QString wrapText(QString keyText) {\n return keyText.replace(\"Up\", \"⬆️\")\n .replace(\"Down\", \"⬇️\")\n .replace(\"Left\", \"⬅️\")\n .replace(\"Right\", \"➡️\");\n}\n UINT getVK() {\n return toVK(m_key, m_modifier);\n}\n UINT getModifier() {\n return toModifier(m_modifier);\n}\n QtCombinedKey getQtCombinedKey() {\n return QtCombinedKey{ m_key, m_modifier };\n}\n QString getKeyText() {\n return keySequence().toString(QKeySequence::NativeText);\n}\n protected:\n void keyPressEvent(QKeyEvent* event) override {\n int key = event->key();\n Qt::KeyboardModifiers modifiers = event->modifiers();\n\n // 忽略单独的修饰键\n if (isModifierKey(key))\n {\n return;\n }\n\n m_key = key;\n m_modifier = modifiers;\n\n // 创建单个按键序列\n QKeySequence singleKey(key | modifiers);\n setKeySequence(singleKey);\n\n // 🔚 结束编辑\n emit editingFinished();\n clearFocus();\n}\n private:\n void update() {\n QKeySequence sequence = keySequence();\n\n if (sequence.isEmpty())\n {\n m_key = 0;\n m_modifier = Qt::NoModifier;\n }\n else\n {\n int combinedKey = sequence[0];\n m_modifier =\n Qt::KeyboardModifiers(combinedKey & Qt::KeyboardModifierMask);\n m_key = combinedKey & ~Qt::KeyboardModifierMask;\n }\n}\n private:\n bool isModifierKey(int key) const {\n return (key == Qt::Key_Control || key == Qt::Key_Alt ||\n key == Qt::Key_Shift || key == Qt::Key_Meta);\n}\n int m_key;\n Qt::KeyboardModifiers m_modifier;\n};"], ["/OpenSpeedy/preferencedialog.h", "class PreferenceDialog {\n Q_OBJECT\n\n public:\n explicit PreferenceDialog(HWND hMainWindow,\n QSettings* settings,\n QLabel* increaseSpeedLabel,\n QLabel* decreaseSpeedLabel,\n QLabel* resetSpeedLabel,\n QWidget* parent = nullptr);\n ~PreferenceDialog() {\n unregisterGlobalHotkeys();\n delete ui;\n}\n int getIncreaseStep() {\n return m_increaseStep;\n}\n int getDecreaseStep() {\n return m_decreaseStep;\n}\n double getShift1() {\n return m_shift1Value;\n}\n double getShift2() {\n return m_shift2Value;\n}\n double getShift3() {\n return m_shift3Value;\n}\n double getShift4() {\n return m_shift4Value;\n}\n double getShift5() {\n return m_shift5Value;\n}\n public:\n void show() {\n unregisterGlobalHotkeys();\n QDialog::show();\n}\n private:\n void on_buttonBox_accepted() {\n update();\n setupGlobalHotkeys();\n redraw();\n dump();\n}\n void on_buttonBox_rejected() {\n redraw();\n setupGlobalHotkeys();\n}\n void recreate() {\n layout()->invalidate();\n layout()->activate();\n adjustSize();\n}\n private:\n void setupGlobalHotkeys() {\n for (auto it = m_shortcuts.begin(); it != m_shortcuts.end(); it++)\n {\n int id = it.key();\n QtCombinedKey combined = it.value();\n\n UINT vk = QSingleKeySequenceEdit::toVK(combined.key, combined.modifier);\n UINT modifier = QSingleKeySequenceEdit::toModifier(combined.modifier);\n RegisterHotKey(m_mainwindow, id, modifier, vk);\n }\n\n qDebug() << \"全局快捷键已注册:\";\n}\n void unregisterGlobalHotkeys() {\n for (auto it = m_shortcuts.begin(); it != m_shortcuts.end(); it++)\n {\n int id = it.key();\n UnregisterHotKey(m_mainwindow, id);\n }\n qDebug() << \"全局快捷键已注销\";\n}\n void loadShortcut(int id,\n const QString& config,\n const QString& defaultValue) {\n m_shortcuts.insert(id,\n QSingleKeySequenceEdit::toQtCombinedKey(\n m_settings->value(config, defaultValue).toString()));\n}\n void dumpShortcut(const QString& config, const QString& keyText) {\n m_settings->setValue(config, keyText);\n}\n void dump() {\n dumpShortcut(CONFIG_HOTKEY_SPEEDUP,\n ui->speedUpKeySequenceEdit->getKeyText());\n dumpShortcut(CONFIG_HOTKEY_SPEEDDOWN,\n ui->speedDownKeySequenceEdit->getKeyText());\n dumpShortcut(CONFIG_HOTKEY_RESETSPEED,\n ui->resetSpeedKeySequenceEdit->getKeyText());\n\n dumpShortcut(CONFIG_HOTKEY_SHIFT1, ui->shift1KeySequenceEdit->getKeyText());\n dumpShortcut(CONFIG_HOTKEY_SHIFT2, ui->shift2KeySequenceEdit->getKeyText());\n dumpShortcut(CONFIG_HOTKEY_SHIFT3, ui->shift3KeySequenceEdit->getKeyText());\n dumpShortcut(CONFIG_HOTKEY_SHIFT4, ui->shift4KeySequenceEdit->getKeyText());\n dumpShortcut(CONFIG_HOTKEY_SHIFT5, ui->shift5KeySequenceEdit->getKeyText());\n m_settings->setValue(CONFIG_INCREASE_STEP,\n ui->increaseStepSpinBox->value());\n m_settings->setValue(CONFIG_DECREASE_STEP,\n ui->decreaseStepSpinBox->value());\n m_settings->setValue(CONFIG_SHIFT1_VALUE, ui->shift1DoubleSpinBox->value());\n m_settings->setValue(CONFIG_SHIFT2_VALUE, ui->shift2DoubleSpinBox->value());\n m_settings->setValue(CONFIG_SHIFT3_VALUE, ui->shift3DoubleSpinBox->value());\n m_settings->setValue(CONFIG_SHIFT4_VALUE, ui->shift4DoubleSpinBox->value());\n m_settings->setValue(CONFIG_SHIFT5_VALUE, ui->shift5DoubleSpinBox->value());\n m_settings->sync();\n}\n void updateShortcut(int id, QSingleKeySequenceEdit* keyEdit) {\n m_shortcuts[id] = keyEdit->getQtCombinedKey();\n}\n void update() {\n updateShortcut(HOTKEY_INCREASE_SPEED, ui->speedUpKeySequenceEdit);\n updateShortcut(HOTKEY_DECREASE_SPEED, ui->speedDownKeySequenceEdit);\n updateShortcut(HOTKEY_RESET_SPEED, ui->resetSpeedKeySequenceEdit);\n updateShortcut(HOTKEY_SHIFT1, ui->shift1KeySequenceEdit);\n updateShortcut(HOTKEY_SHIFT2, ui->shift2KeySequenceEdit);\n updateShortcut(HOTKEY_SHIFT3, ui->shift3KeySequenceEdit);\n updateShortcut(HOTKEY_SHIFT4, ui->shift4KeySequenceEdit);\n updateShortcut(HOTKEY_SHIFT5, ui->shift5KeySequenceEdit);\n\n m_increaseStep = ui->increaseStepSpinBox->value();\n m_decreaseStep = ui->decreaseStepSpinBox->value();\n m_shift1Value = ui->shift1DoubleSpinBox->value();\n m_shift2Value = ui->shift2DoubleSpinBox->value();\n m_shift3Value = ui->shift3DoubleSpinBox->value();\n m_shift4Value = ui->shift4DoubleSpinBox->value();\n m_shift5Value = ui->shift5DoubleSpinBox->value();\n}\n void redrawSpinBox(QSpinBox* spinbox, int value) {\n spinbox->setValue(value);\n}\n void redrawSpinBox(QDoubleSpinBox* spinbox, double value) {\n spinbox->setValue(value);\n}\n void redrawKeyEdit(QSingleKeySequenceEdit* keyEdit, int id) {\n QtCombinedKey combinedKey = m_shortcuts[id];\n keyEdit->setKeySequence(combinedKey.key | combinedKey.modifier);\n}\n void redraw() {\n redrawKeyEdit(ui->speedUpKeySequenceEdit, HOTKEY_INCREASE_SPEED);\n redrawKeyEdit(ui->speedDownKeySequenceEdit, HOTKEY_DECREASE_SPEED);\n redrawKeyEdit(ui->resetSpeedKeySequenceEdit, HOTKEY_RESET_SPEED);\n redrawKeyEdit(ui->shift1KeySequenceEdit, HOTKEY_SHIFT1);\n redrawKeyEdit(ui->shift2KeySequenceEdit, HOTKEY_SHIFT2);\n redrawKeyEdit(ui->shift3KeySequenceEdit, HOTKEY_SHIFT3);\n redrawKeyEdit(ui->shift4KeySequenceEdit, HOTKEY_SHIFT4);\n redrawKeyEdit(ui->shift5KeySequenceEdit, HOTKEY_SHIFT5);\n\n redrawSpinBox(ui->increaseStepSpinBox, m_increaseStep);\n redrawSpinBox(ui->decreaseStepSpinBox, m_decreaseStep);\n redrawSpinBox(ui->shift1DoubleSpinBox, m_shift1Value);\n redrawSpinBox(ui->shift2DoubleSpinBox, m_shift2Value);\n redrawSpinBox(ui->shift3DoubleSpinBox, m_shift3Value);\n redrawSpinBox(ui->shift4DoubleSpinBox, m_shift4Value);\n redrawSpinBox(ui->shift5DoubleSpinBox, m_shift5Value);\n\n m_increaseSpeedLabel->setText(\n QString(tr(\"%1 增加速度\"))\n .arg(QSingleKeySequenceEdit::wrapText(\n ui->speedUpKeySequenceEdit->getKeyText())));\n\n m_decreaseSpeedLabel->setText(\n QString(tr(\"%1 减少速度\"))\n .arg(QSingleKeySequenceEdit::wrapText(\n ui->speedDownKeySequenceEdit->getKeyText())));\n\n m_resetSpeedLabel->setText(\n QString(tr(\"%1 重置速度\"))\n .arg(QSingleKeySequenceEdit::wrapText(\n ui->resetSpeedKeySequenceEdit->getKeyText())));\n\n adjustSize();\n}\n Ui::PreferenceDialog* ui;\n QSettings* m_settings;\n QLabel* m_increaseSpeedLabel;\n QLabel* m_decreaseSpeedLabel;\n QLabel* m_resetSpeedLabel;\n QMap m_shortcuts;\n double m_shift1Value;\n double m_shift2Value;\n double m_shift3Value;\n double m_shift4Value;\n double m_shift5Value;\n int m_increaseStep;\n int m_decreaseStep;\n HWND m_mainwindow;\n};"], ["/OpenSpeedy/cpuutils.h", "class CpuUtils {\n private:\n PDH_HQUERY hQuery = NULL;\n PDH_HCOUNTER hCounter = NULL;\n bool initialized = false;\n public:\n CpuUtils() {\n}\n ~CpuUtils() {\n if (hCounter) PdhRemoveCounter(hCounter);\n if (hQuery) PdhCloseQuery(hQuery);\n}\n bool init() {\n // 创建查询\n if (PdhOpenQuery(NULL, NULL, &hQuery) != ERROR_SUCCESS) return false;\n\n if (PdhAddEnglishCounter(hQuery,\n L\"\\\\Processor(_Total)\\\\% Processor Time\",\n NULL,\n &hCounter) != ERROR_SUCCESS)\n {\n PdhCloseQuery(hQuery);\n return false;\n }\n\n // 第一次采样\n PdhCollectQueryData(hQuery);\n initialized = true;\n return true;\n}\n double getUsage() {\n if (!initialized) return -1;\n\n // 收集数据\n if (PdhCollectQueryData(hQuery) != ERROR_SUCCESS) return -1;\n\n PDH_FMT_COUNTERVALUE value;\n if (PdhGetFormattedCounterValue(hCounter, PDH_FMT_DOUBLE, NULL, &value) !=\n ERROR_SUCCESS)\n return -1;\n\n return value.doubleValue;\n}\n QString getModel() {\n int cpuInfo[4];\n char cpuBrand[48 + 1] = {0};\n\n // 获取CPU品牌字符串(需要调用3次CPUID)\n __cpuid(cpuInfo, 0x80000002);\n memcpy(cpuBrand, cpuInfo, sizeof(cpuInfo));\n\n __cpuid(cpuInfo, 0x80000003);\n memcpy(cpuBrand + 16, cpuInfo, sizeof(cpuInfo));\n\n __cpuid(cpuInfo, 0x80000004);\n memcpy(cpuBrand + 32, cpuInfo, sizeof(cpuInfo));\n\n QString result(cpuBrand);\n\n return result.trimmed();\n}\n};"], ["/OpenSpeedy/memutils.h", "class MemUtils {\n private:\n PDH_HQUERY hQuery = NULL;\n PDH_HCOUNTER hCounter = NULL;\n bool initialized = false;\n public:\n MemUtils() {\n}\n bool init() {\n if (PdhOpenQuery(NULL, NULL, &hQuery) != ERROR_SUCCESS) return false;\n\n if (PdhAddEnglishCounter(hQuery,\n L\"\\\\Memory\\\\Available Bytes\",\n NULL,\n &hCounter) != ERROR_SUCCESS)\n {\n PdhCloseQuery(hQuery);\n return false;\n }\n\n PdhCollectQueryData(hQuery);\n initialized = true;\n return true;\n}\n double getTotal() {\n MEMORYSTATUSEX memInfo;\n memInfo.dwLength = sizeof(MEMORYSTATUSEX);\n GlobalMemoryStatusEx(&memInfo);\n return memInfo.ullTotalPhys / (1024.0 * 1024.0 * 1024.0);\n}\n double getUsage() {\n if (!initialized) return -1;\n\n if (PdhCollectQueryData(hQuery) != ERROR_SUCCESS) return -1;\n\n PDH_FMT_COUNTERVALUE available;\n if (PdhGetFormattedCounterValue(hCounter,\n PDH_FMT_DOUBLE,\n NULL,\n &available) != ERROR_SUCCESS)\n return -1;\n\n double totalMemory = getTotal() * 1024 * 1024 * 1024;\n double usageMemory = totalMemory - available.doubleValue;\n\n return usageMemory / (1024.0 * 1024.0 * 1024.0);\n}\n};"], ["/OpenSpeedy/aboutdialog.h", "class AboutDialog {\n Q_OBJECT\n\n public:\n explicit AboutDialog(QWidget* parent = nullptr);\n ~AboutDialog() {\n delete ui;\n}\n private:\n void recreate() {\n layout()->invalidate();\n layout()->activate();\n adjustSize();\n}\n private:\n Ui::AboutDialog* ui;\n};"], ["/OpenSpeedy/mainwindow.h", "class MainWindow {\n};"], ["/OpenSpeedy/speedpatch/speedpatch.h", "class speedpatch {\n};"]], "task_instance_info": {"created_time": "2025-08-20 19:51:26", "created_task_model": "DeepSeek-R1", "function_skeleton": "int main(int argc, char* argv[]) {}", "code_description": "This code segment functions to: Initialize application environment settings, enforce single instance execution through inter-process communication, configure localization and user interface elements, and manage window visibility based on command-line parameters while establishing a persistence mechanism for restoring focus to existing instances."}, "inference_content": {"inference_model": "DeepSeek-R1", "inference_result": "```cpp\n[TASK_BEGIN]\nint main(int argc, char* argv[])\n{\n // Set high DPI scaling attributes before creating QApplication\n QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);\n QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);\n\n QApplication a(argc, argv);\n \n // Single instance check using local server\n QLocalServer server;\n if (!server.listen(\"OpenSpeedyInstance\")) {\n QLocalSocket socket;\n socket.connectToServer(\"OpenSpeedyInstance\");\n if (socket.waitForConnected(1000)) {\n socket.write(\"activate\");\n socket.waitForBytesWritten();\n return 0;\n }\n }\n\n // Command line arguments parsing\n QCommandLineParser parser;\n parser.addOption({{\"a\", \"attach\"}, \"Attach to a process\"});\n parser.process(a);\n\n // Load translations\n QTranslator translator;\n if (translator.load(QLocale(), QLatin1String(\"OpenSpeedy\"), QLatin1String(\"_\"), QLatin1String(\":/translations\"))) {\n a.installTranslator(&translator);\n }\n\n // Initialize debug components\n Windbg::initialize();\n\n // Create and show main window\n MainWindow w;\n w.show();\n\n return a.exec();\n}\n[TASK_END]\n```", "inference_time": "2025-08-20 19-52-07"}, "editdistance_info": {"edit_distance": 20.7392, "calculate_time": "2025-08-20 19:52:07", "true_code_clean": "int\nmain(int argc, char* argv[])\n{\n SetUnhandledExceptionFilter(createMiniDump);\n SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);\n QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);\n QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);\n QApplication::setAttribute(Qt::AA_UseSoftwareOpenGL);\n QApplication a(argc, argv);\n winutils::enableAllPrivilege();\n QString unique = \"OpenSpeedy\";\n QLocalSocket socket;\n socket.connectToServer(unique);\n if (socket.waitForConnected(500))\n {\n socket.close();\n return -1;\n }\n QIcon appIcon;\n appIcon.addFile(\":/icons/images/icon_16.ico\", QSize(16, 16));\n appIcon.addFile(\":/icons/images/icon_32.ico\", QSize(32, 32));\n appIcon.addFile(\":/icons/images/icon_64.ico\", QSize(64, 64));\n a.setWindowIcon(appIcon);\n QSettings settings =\n QSettings(QCoreApplication::applicationDirPath() + \"/config.ini\",\n QSettings::IniFormat);\n QTranslator translator;\n const QString baseName =\n \"OpenSpeedy_\" +\n settings.value(CONFIG_LANGUAGE, QLocale().system().name()).toString();\n if (translator.load(\":/i18n/translations/\" + baseName))\n {\n a.installTranslator(&translator);\n }\n QCommandLineParser parser;\n parser.setApplicationDescription(\"OpenSpeedy\");\n QCommandLineOption minimizeOption(\n QStringList() << \"m\" << \"minimize-to-tray\", \"启动时最小化到托盘\");\n parser.addOption(minimizeOption);\n parser.process(a);\n MainWindow w;\n w.resize(1024, 768);\n if (parser.isSet(minimizeOption))\n {\n w.hide();\n }\n else\n {\n w.show();\n }\n QLocalServer server;\n QLocalServer::removeServer(unique);\n server.listen(unique);\n QObject::connect(&server,\n &QLocalServer::newConnection,\n [&]\n {\n w.show();\n w.raise();\n w.showNormal();\n w.activateWindow();\n });\n return a.exec();\n}", "predict_code_clean": "int main(int argc, char* argv[])\n{\n QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);\n QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);\n QApplication a(argc, argv);\n QLocalServer server;\n if (!server.listen(\"OpenSpeedyInstance\")) {\n QLocalSocket socket;\n socket.connectToServer(\"OpenSpeedyInstance\");\n if (socket.waitForConnected(1000)) {\n socket.write(\"activate\");\n socket.waitForBytesWritten();\n return 0;\n }\n }\n QCommandLineParser parser;\n parser.addOption({{\"a\", \"attach\"}, \"Attach to a process\"});\n parser.process(a);\n QTranslator translator;\n if (translator.load(QLocale(), QLatin1String(\"OpenSpeedy\"), QLatin1String(\"_\"), QLatin1String(\":/translations\"))) {\n a.installTranslator(&translator);\n }\n Windbg::initialize();\n MainWindow w;\n w.show();\n return a.exec();\n}"}} {"repo_name": "OpenSpeedy", "file_name": "/OpenSpeedy/qsinglekeysequenceedit.h", "inference_info": {"prefix_code": "class QSingleKeySequenceEdit {\n Q_OBJECT\n\n public:\n explicit QSingleKeySequenceEdit(QWidget* parent = nullptr);\n static UINT toVK(int qtKey, Qt::KeyboardModifiers qtMod) {\n // 🔤 字母键 A-Z\n if (qtKey >= Qt::Key_A && qtKey <= Qt::Key_Z)\n {\n return qtKey; // Qt 和 Windows 的 A-Z 键码相同\n }\n\n // 🔢 小键盘 0-9\n if (qtMod & Qt::KeypadModifier)\n {\n switch (qtKey)\n {\n // 数字键盘\n case Qt::Key_0:\n return VK_NUMPAD0;\n case Qt::Key_1:\n return VK_NUMPAD1;\n case Qt::Key_2:\n return VK_NUMPAD2;\n case Qt::Key_3:\n return VK_NUMPAD3;\n case Qt::Key_4:\n return VK_NUMPAD4;\n case Qt::Key_5:\n return VK_NUMPAD5;\n case Qt::Key_6:\n return VK_NUMPAD6;\n case Qt::Key_7:\n return VK_NUMPAD7;\n case Qt::Key_8:\n return VK_NUMPAD8;\n case Qt::Key_9:\n return VK_NUMPAD9;\n }\n }\n\n // 🔢 数字键 0-9\n if (qtKey >= Qt::Key_0 && qtKey <= Qt::Key_9)\n {\n return qtKey; // Qt 和 Windows 的 0-9 键码相同\n }\n\n // 🎯 功能键映射\n switch (qtKey)\n {\n // F1-F12\n case Qt::Key_F1:\n return VK_F1;\n case Qt::Key_F2:\n return VK_F2;\n case Qt::Key_F3:\n return VK_F3;\n case Qt::Key_F4:\n return VK_F4;\n case Qt::Key_F5:\n return VK_F5;\n case Qt::Key_F6:\n return VK_F6;\n case Qt::Key_F7:\n return VK_F7;\n case Qt::Key_F8:\n return VK_F8;\n case Qt::Key_F9:\n return VK_F9;\n case Qt::Key_F10:\n return VK_F10;\n case Qt::Key_F11:\n return VK_F11;\n case Qt::Key_F12:\n return VK_F12;\n\n // 方向键\n case Qt::Key_Left:\n return VK_LEFT;\n case Qt::Key_Right:\n return VK_RIGHT;\n case Qt::Key_Up:\n return VK_UP;\n case Qt::Key_Down:\n return VK_DOWN;\n\n // 特殊键\n case Qt::Key_Enter:\n case Qt::Key_Return:\n return VK_RETURN;\n case Qt::Key_Escape:\n return VK_ESCAPE;\n case Qt::Key_Tab:\n return VK_TAB;\n case Qt::Key_Backspace:\n return VK_BACK;\n case Qt::Key_Delete:\n return VK_DELETE;\n case Qt::Key_Insert:\n return VK_INSERT;\n case Qt::Key_Home:\n return VK_HOME;\n case Qt::Key_End:\n return VK_END;\n case Qt::Key_PageUp:\n return VK_PRIOR;\n case Qt::Key_PageDown:\n return VK_NEXT;\n case Qt::Key_Space:\n return VK_SPACE;\n\n // 符号键\n case Qt::Key_Semicolon:\n return VK_OEM_1; // ;\n case Qt::Key_Equal:\n return VK_OEM_PLUS; // =\n case Qt::Key_Comma:\n return VK_OEM_COMMA; // ,\n case Qt::Key_Minus:\n return VK_OEM_MINUS; // -\n case Qt::Key_Period:\n return VK_OEM_PERIOD; // .\n case Qt::Key_Slash:\n return VK_OEM_2; // /\n case Qt::Key_QuoteLeft:\n return VK_OEM_3; // `\n case Qt::Key_BracketLeft:\n return VK_OEM_4; // [\n case Qt::Key_Backslash:\n return VK_OEM_5; //\n case Qt::Key_BracketRight:\n return VK_OEM_6; // ]\n case Qt::Key_Apostrophe:\n return VK_OEM_7; // '\n\n // 其他常用键\n case Qt::Key_CapsLock:\n return VK_CAPITAL;\n case Qt::Key_NumLock:\n return VK_NUMLOCK;\n case Qt::Key_ScrollLock:\n return VK_SCROLL;\n case Qt::Key_Pause:\n return VK_PAUSE;\n case Qt::Key_Print:\n return VK_PRINT;\n\n default:\n qDebug() << \"Unknown Qt key:\" << qtKey;\n return 0; // 未知按键\n }\n}\n static UINT toModifier(Qt::KeyboardModifiers qtMod) {\n UINT winMod = 0;\n\n if (qtMod & Qt::ControlModifier)\n {\n winMod |= MOD_CONTROL;\n }\n if (qtMod & Qt::AltModifier)\n {\n winMod |= MOD_ALT;\n }\n if (qtMod & Qt::ShiftModifier)\n {\n winMod |= MOD_SHIFT;\n }\n if (qtMod & Qt::MetaModifier)\n {\n winMod |= MOD_WIN; // Windows 键\n }\n\n return winMod;\n}\n ", "suffix_code": "\n static QString wrapText(QString keyText) {\n return keyText.replace(\"Up\", \"⬆️\")\n .replace(\"Down\", \"⬇️\")\n .replace(\"Left\", \"⬅️\")\n .replace(\"Right\", \"➡️\");\n}\n UINT getVK() {\n return toVK(m_key, m_modifier);\n}\n UINT getModifier() {\n return toModifier(m_modifier);\n}\n QtCombinedKey getQtCombinedKey() {\n return QtCombinedKey{ m_key, m_modifier };\n}\n QString getKeyText() {\n return keySequence().toString(QKeySequence::NativeText);\n}\n protected:\n void keyPressEvent(QKeyEvent* event) override {\n int key = event->key();\n Qt::KeyboardModifiers modifiers = event->modifiers();\n\n // 忽略单独的修饰键\n if (isModifierKey(key))\n {\n return;\n }\n\n m_key = key;\n m_modifier = modifiers;\n\n // 创建单个按键序列\n QKeySequence singleKey(key | modifiers);\n setKeySequence(singleKey);\n\n // 🔚 结束编辑\n emit editingFinished();\n clearFocus();\n}\n private:\n void update() {\n QKeySequence sequence = keySequence();\n\n if (sequence.isEmpty())\n {\n m_key = 0;\n m_modifier = Qt::NoModifier;\n }\n else\n {\n int combinedKey = sequence[0];\n m_modifier =\n Qt::KeyboardModifiers(combinedKey & Qt::KeyboardModifierMask);\n m_key = combinedKey & ~Qt::KeyboardModifierMask;\n }\n}\n private:\n bool isModifierKey(int key) const {\n return (key == Qt::Key_Control || key == Qt::Key_Alt ||\n key == Qt::Key_Shift || key == Qt::Key_Meta);\n}\n int m_key;\n Qt::KeyboardModifiers m_modifier;\n};", "middle_code": "static QtCombinedKey toQtCombinedKey(const QString& keyText) {\n QKeySequence sequence = QKeySequence(keyText);\n if (!sequence.isEmpty())\n {\n int combinedKey = sequence[0];\n Qt::KeyboardModifiers modifier =\n Qt::KeyboardModifiers(combinedKey & Qt::KeyboardModifierMask);\n int key = combinedKey & ~Qt::KeyboardModifierMask;\n return QtCombinedKey{ key, modifier };\n }\n else\n {\n return QtCombinedKey{ 0, Qt::NoModifier };\n }\n}", "code_description": null, "fill_type": "FUNCTION_TYPE", "language_type": "cpp", "sub_task_type": null}, "context_code": [["/OpenSpeedy/preferencedialog.h", "class PreferenceDialog {\n Q_OBJECT\n\n public:\n explicit PreferenceDialog(HWND hMainWindow,\n QSettings* settings,\n QLabel* increaseSpeedLabel,\n QLabel* decreaseSpeedLabel,\n QLabel* resetSpeedLabel,\n QWidget* parent = nullptr);\n ~PreferenceDialog() {\n unregisterGlobalHotkeys();\n delete ui;\n}\n int getIncreaseStep() {\n return m_increaseStep;\n}\n int getDecreaseStep() {\n return m_decreaseStep;\n}\n double getShift1() {\n return m_shift1Value;\n}\n double getShift2() {\n return m_shift2Value;\n}\n double getShift3() {\n return m_shift3Value;\n}\n double getShift4() {\n return m_shift4Value;\n}\n double getShift5() {\n return m_shift5Value;\n}\n public:\n void show() {\n unregisterGlobalHotkeys();\n QDialog::show();\n}\n private:\n void on_buttonBox_accepted() {\n update();\n setupGlobalHotkeys();\n redraw();\n dump();\n}\n void on_buttonBox_rejected() {\n redraw();\n setupGlobalHotkeys();\n}\n void recreate() {\n layout()->invalidate();\n layout()->activate();\n adjustSize();\n}\n private:\n void setupGlobalHotkeys() {\n for (auto it = m_shortcuts.begin(); it != m_shortcuts.end(); it++)\n {\n int id = it.key();\n QtCombinedKey combined = it.value();\n\n UINT vk = QSingleKeySequenceEdit::toVK(combined.key, combined.modifier);\n UINT modifier = QSingleKeySequenceEdit::toModifier(combined.modifier);\n RegisterHotKey(m_mainwindow, id, modifier, vk);\n }\n\n qDebug() << \"全局快捷键已注册:\";\n}\n void unregisterGlobalHotkeys() {\n for (auto it = m_shortcuts.begin(); it != m_shortcuts.end(); it++)\n {\n int id = it.key();\n UnregisterHotKey(m_mainwindow, id);\n }\n qDebug() << \"全局快捷键已注销\";\n}\n void loadShortcut(int id,\n const QString& config,\n const QString& defaultValue) {\n m_shortcuts.insert(id,\n QSingleKeySequenceEdit::toQtCombinedKey(\n m_settings->value(config, defaultValue).toString()));\n}\n void dumpShortcut(const QString& config, const QString& keyText) {\n m_settings->setValue(config, keyText);\n}\n void dump() {\n dumpShortcut(CONFIG_HOTKEY_SPEEDUP,\n ui->speedUpKeySequenceEdit->getKeyText());\n dumpShortcut(CONFIG_HOTKEY_SPEEDDOWN,\n ui->speedDownKeySequenceEdit->getKeyText());\n dumpShortcut(CONFIG_HOTKEY_RESETSPEED,\n ui->resetSpeedKeySequenceEdit->getKeyText());\n\n dumpShortcut(CONFIG_HOTKEY_SHIFT1, ui->shift1KeySequenceEdit->getKeyText());\n dumpShortcut(CONFIG_HOTKEY_SHIFT2, ui->shift2KeySequenceEdit->getKeyText());\n dumpShortcut(CONFIG_HOTKEY_SHIFT3, ui->shift3KeySequenceEdit->getKeyText());\n dumpShortcut(CONFIG_HOTKEY_SHIFT4, ui->shift4KeySequenceEdit->getKeyText());\n dumpShortcut(CONFIG_HOTKEY_SHIFT5, ui->shift5KeySequenceEdit->getKeyText());\n m_settings->setValue(CONFIG_INCREASE_STEP,\n ui->increaseStepSpinBox->value());\n m_settings->setValue(CONFIG_DECREASE_STEP,\n ui->decreaseStepSpinBox->value());\n m_settings->setValue(CONFIG_SHIFT1_VALUE, ui->shift1DoubleSpinBox->value());\n m_settings->setValue(CONFIG_SHIFT2_VALUE, ui->shift2DoubleSpinBox->value());\n m_settings->setValue(CONFIG_SHIFT3_VALUE, ui->shift3DoubleSpinBox->value());\n m_settings->setValue(CONFIG_SHIFT4_VALUE, ui->shift4DoubleSpinBox->value());\n m_settings->setValue(CONFIG_SHIFT5_VALUE, ui->shift5DoubleSpinBox->value());\n m_settings->sync();\n}\n void updateShortcut(int id, QSingleKeySequenceEdit* keyEdit) {\n m_shortcuts[id] = keyEdit->getQtCombinedKey();\n}\n void update() {\n updateShortcut(HOTKEY_INCREASE_SPEED, ui->speedUpKeySequenceEdit);\n updateShortcut(HOTKEY_DECREASE_SPEED, ui->speedDownKeySequenceEdit);\n updateShortcut(HOTKEY_RESET_SPEED, ui->resetSpeedKeySequenceEdit);\n updateShortcut(HOTKEY_SHIFT1, ui->shift1KeySequenceEdit);\n updateShortcut(HOTKEY_SHIFT2, ui->shift2KeySequenceEdit);\n updateShortcut(HOTKEY_SHIFT3, ui->shift3KeySequenceEdit);\n updateShortcut(HOTKEY_SHIFT4, ui->shift4KeySequenceEdit);\n updateShortcut(HOTKEY_SHIFT5, ui->shift5KeySequenceEdit);\n\n m_increaseStep = ui->increaseStepSpinBox->value();\n m_decreaseStep = ui->decreaseStepSpinBox->value();\n m_shift1Value = ui->shift1DoubleSpinBox->value();\n m_shift2Value = ui->shift2DoubleSpinBox->value();\n m_shift3Value = ui->shift3DoubleSpinBox->value();\n m_shift4Value = ui->shift4DoubleSpinBox->value();\n m_shift5Value = ui->shift5DoubleSpinBox->value();\n}\n void redrawSpinBox(QSpinBox* spinbox, int value) {\n spinbox->setValue(value);\n}\n void redrawSpinBox(QDoubleSpinBox* spinbox, double value) {\n spinbox->setValue(value);\n}\n void redrawKeyEdit(QSingleKeySequenceEdit* keyEdit, int id) {\n QtCombinedKey combinedKey = m_shortcuts[id];\n keyEdit->setKeySequence(combinedKey.key | combinedKey.modifier);\n}\n void redraw() {\n redrawKeyEdit(ui->speedUpKeySequenceEdit, HOTKEY_INCREASE_SPEED);\n redrawKeyEdit(ui->speedDownKeySequenceEdit, HOTKEY_DECREASE_SPEED);\n redrawKeyEdit(ui->resetSpeedKeySequenceEdit, HOTKEY_RESET_SPEED);\n redrawKeyEdit(ui->shift1KeySequenceEdit, HOTKEY_SHIFT1);\n redrawKeyEdit(ui->shift2KeySequenceEdit, HOTKEY_SHIFT2);\n redrawKeyEdit(ui->shift3KeySequenceEdit, HOTKEY_SHIFT3);\n redrawKeyEdit(ui->shift4KeySequenceEdit, HOTKEY_SHIFT4);\n redrawKeyEdit(ui->shift5KeySequenceEdit, HOTKEY_SHIFT5);\n\n redrawSpinBox(ui->increaseStepSpinBox, m_increaseStep);\n redrawSpinBox(ui->decreaseStepSpinBox, m_decreaseStep);\n redrawSpinBox(ui->shift1DoubleSpinBox, m_shift1Value);\n redrawSpinBox(ui->shift2DoubleSpinBox, m_shift2Value);\n redrawSpinBox(ui->shift3DoubleSpinBox, m_shift3Value);\n redrawSpinBox(ui->shift4DoubleSpinBox, m_shift4Value);\n redrawSpinBox(ui->shift5DoubleSpinBox, m_shift5Value);\n\n m_increaseSpeedLabel->setText(\n QString(tr(\"%1 增加速度\"))\n .arg(QSingleKeySequenceEdit::wrapText(\n ui->speedUpKeySequenceEdit->getKeyText())));\n\n m_decreaseSpeedLabel->setText(\n QString(tr(\"%1 减少速度\"))\n .arg(QSingleKeySequenceEdit::wrapText(\n ui->speedDownKeySequenceEdit->getKeyText())));\n\n m_resetSpeedLabel->setText(\n QString(tr(\"%1 重置速度\"))\n .arg(QSingleKeySequenceEdit::wrapText(\n ui->resetSpeedKeySequenceEdit->getKeyText())));\n\n adjustSize();\n}\n Ui::PreferenceDialog* ui;\n QSettings* m_settings;\n QLabel* m_increaseSpeedLabel;\n QLabel* m_decreaseSpeedLabel;\n QLabel* m_resetSpeedLabel;\n QMap m_shortcuts;\n double m_shift1Value;\n double m_shift2Value;\n double m_shift3Value;\n double m_shift4Value;\n double m_shift5Value;\n int m_increaseStep;\n int m_decreaseStep;\n HWND m_mainwindow;\n};"], ["/OpenSpeedy/processmonitor.h", "class ProcessMonitor {\n Q_OBJECT\npublic:\nexplicit ProcessMonitor(QSettings* settings,\n QTreeWidget* treeWidget,\n QLabel* treeStatusLabel,\n QLabel* injector32StatusLabel,\n QLabel* injector64StatusLabel,\n\n QObject* parent = nullptr);\n ~ProcessMonitor() {\n this->terminalBridge();\n delete m_bridge32;\n delete m_bridge64;\n}\n void setInterval(int msec);\n void setFilter(QString processName) {\n m_filter = processName.toLower();\n}\n void changeSpeed(double factor) {\n QString cmd = QString(\"change %1\\n\").arg(factor);\n m_bridge32->write(cmd.toUtf8(), cmd.size());\n m_bridge32->waitForBytesWritten();\n m_bridge64->write(cmd.toUtf8(), cmd.size());\n m_bridge64->waitForBytesWritten();\n}\n public:\n void refresh() {\n healthcheckBridge();\n QList processList = winutils::getProcessList();\n if (m_filter == \"\")\n {\n update(processList);\n m_treeStatusLabel->setText(QString(tr(\"搜索到%1个进程, 已过滤展示%2个\"))\n .arg(processList.size())\n .arg(processList.size()));\n }\n else\n {\n QList filtered;\n for (ProcessInfo info : processList)\n {\n if (info.name.toLower().contains(m_filter))\n filtered.append(info);\n }\n update(filtered);\n m_treeStatusLabel->setText(QString(tr(\"搜索到%1个进程, 已过滤展示%2个\"))\n .arg(processList.size())\n .arg(filtered.size()));\n }\n}\n void start() {\n m_timer = new QTimer(this);\n connect(m_timer, &QTimer::timeout, this, &ProcessMonitor::refresh);\n m_timer->start(1000);\n}\n private:\n void onItemChanged(QTreeWidgetItem* item, int column) {\n if (column == 5 && (item->flags() & Qt::ItemIsUserCheckable))\n {\n bool state = m_treeWidget->blockSignals(true);\n\n Qt::CheckState checkState = item->checkState(column);\n QString processName = item->text(0);\n DWORD pid = item->text(1).toLong();\n bool is64Bit = item->text(3) == \"x64\" ? true : false;\n if (checkState == Qt::Checked)\n {\n m_targetNames.insert(processName);\n this->injectDll(pid, is64Bit);\n item->setText(5, tr(\"加速中\"));\n for (int col = 0; col < item->columnCount(); ++col)\n {\n item->setBackground(col, QBrush(QColor(\"#f3e5f5\")));\n item->setForeground(col, QBrush(QColor(\"#7b1fa2\")));\n }\n qDebug() << processName << \"勾选\";\n dump();\n }\n else\n {\n m_targetNames.remove(processName);\n this->unhookDll(pid, is64Bit);\n item->setText(5, \"\");\n for (int col = 0; col < item->columnCount(); ++col)\n {\n item->setBackground(col, QBrush());\n item->setForeground(col, QBrush());\n }\n qDebug() << processName << \"取消勾选\";\n dump();\n }\n\n m_treeWidget->blockSignals(state);\n }\n}\n private:\n QTreeWidget* m_treeWidget;\n QLabel* m_treeStatusLabel;\n QLabel* m_injector32StatusLabel;\n QLabel* m_injector64StatusLabel;\n QString m_filter;\n QTimer* m_timer = nullptr;\n QString m_dllPath;\n QProcess* m_bridge32;\n QProcess* m_bridge64;\n QSettings* m_settings;\n QHash m_iconCache;\n QMap m_processItems;\n QSet m_targetNames;\n void init() {\n QStringList targetNames =\n m_settings->value(CONFIG_TARGETNAMES_KEY).toStringList();\n m_targetNames = QSet(targetNames.begin(), targetNames.end());\n}\n void dump() {\n m_settings->setValue(CONFIG_TARGETNAMES_KEY,\n QStringList(m_targetNames.values()));\n}\n void update(const QList& processList) {\n // 跟踪现有进程,用于确定哪些已终止\n QSet currentPids;\n for (const ProcessInfo& info : processList)\n {\n currentPids.insert(info.pid);\n }\n\n // 移除已终止的进程\n QMutableMapIterator i(m_processItems);\n while (i.hasNext())\n {\n i.next();\n if (!currentPids.contains(i.key()))\n {\n QTreeWidgetItem* item = i.value();\n QTreeWidgetItem* parent = item->parent();\n\n if (parent)\n {\n parent->removeChild(item);\n }\n else\n {\n auto index = m_treeWidget->indexOfTopLevelItem(item);\n m_treeWidget->takeTopLevelItem(index);\n }\n\n while (item->childCount() > 0)\n {\n QTreeWidgetItem* child = item->takeChild(0);\n if (parent)\n {\n parent->addChild(child);\n }\n else\n {\n m_treeWidget->addTopLevelItem(child);\n }\n }\n\n // 删除节点\n delete item;\n\n // 从映射中移除\n i.remove();\n }\n }\n\n // 添加或更新进程信息\n for (const ProcessInfo& info : processList)\n {\n if (m_processItems.contains(info.pid))\n {\n // 更新已存在的进程信息\n QTreeWidgetItem* item = m_processItems[info.pid];\n item->setText(1, QString::number(info.pid));\n item->setData(1, Qt::UserRole, (long long)info.pid);\n item->setText(2,\n QString(\"%1 MB\").arg(info.memoryUsage / 1024 / 1024));\n item->setData(2, Qt::UserRole, (uint)info.memoryUsage);\n\n QString arch = info.is64Bit ? \"x64\" : \"x86\";\n item->setText(3, arch);\n QString priority;\n switch (info.priorityClass)\n {\n case HIGH_PRIORITY_CLASS:\n priority = tr(\"高\");\n break;\n case NORMAL_PRIORITY_CLASS:\n priority = tr(\"中\");\n break;\n case IDLE_PRIORITY_CLASS:\n priority = tr(\"低\");\n break;\n case REALTIME_PRIORITY_CLASS:\n priority = tr(\"实时\");\n break;\n default:\n priority = tr(\"未知\");\n break;\n }\n item->setText(4, priority);\n if (m_targetNames.contains(info.name))\n {\n if (item->checkState(5) == Qt::Unchecked)\n {\n item->setCheckState(5, Qt::Checked);\n }\n }\n else\n {\n if (item->checkState(5) == Qt::Checked)\n {\n item->setCheckState(5, Qt::Unchecked);\n }\n }\n }\n else\n {\n // 添加新进程\n QTreeWidgetItem* item = new SortTreeWidgetItem();\n\n item->setText(0, info.name);\n item->setData(0, Qt::UserRole, info.name.toLower());\n item->setText(1, QString::number(info.pid));\n item->setData(1, Qt::UserRole, (long long)info.pid);\n item->setText(2,\n QString(\"%1 MB\").arg(info.memoryUsage / 1024 / 1024));\n item->setData(2, Qt::UserRole, (uint)info.memoryUsage);\n\n QString arch = info.is64Bit ? \"x64\" : \"x86\";\n item->setText(3, arch);\n\n // 加载进程图标\n item->setIcon(0, getProcessIconCached(info.pid));\n\n QString priority;\n switch (info.priorityClass)\n {\n case HIGH_PRIORITY_CLASS:\n priority = tr(\"高\");\n break;\n case NORMAL_PRIORITY_CLASS:\n priority = tr(\"中\");\n break;\n case IDLE_PRIORITY_CLASS:\n priority = tr(\"低\");\n break;\n case REALTIME_PRIORITY_CLASS:\n priority = tr(\"实时\");\n break;\n default:\n priority = tr(\"未知\");\n break;\n }\n item->setText(4, priority);\n item->setCheckState(5, Qt::Unchecked);\n m_treeWidget->addTopLevelItem(item);\n m_processItems[info.pid] = item;\n }\n }\n}\n void injectDll(DWORD processId, bool is64Bit) {\n QString cmd = QString(\"inject %1\\n\").arg(processId);\n if (!is64Bit)\n {\n m_bridge32->write(cmd.toUtf8(), cmd.size());\n m_bridge32->waitForBytesWritten();\n }\n else\n {\n m_bridge64->write(cmd.toUtf8(), cmd.size());\n m_bridge64->waitForBytesWritten();\n }\n}\n void unhookDll(DWORD processId, bool is64Bit) {\n QString cmd = QString(\"unhook %1\\n\").arg(processId);\n if (!is64Bit)\n {\n m_bridge32->write(cmd.toUtf8(), cmd.size());\n m_bridge32->waitForBytesWritten();\n }\n else\n {\n m_bridge64->write(cmd.toUtf8(), cmd.size());\n m_bridge64->waitForBytesWritten();\n }\n}\n void startBridge32() {\n m_bridge32 = new QProcess();\n QStringList params32;\n m_bridge32->start(BRIDGE32_EXE, params32);\n if (!m_bridge32->waitForStarted())\n {\n qDebug() << \"32位桥接子进程启动失败\";\n }\n else\n {\n qDebug() << \"32位桥接子进程已启动\";\n }\n m_bridge32->setProcessChannelMode(QProcess::MergedChannels);\n connect(m_bridge32,\n &QProcess::readyReadStandardOutput,\n [&]()\n {\n QByteArray data = m_bridge32->readAllStandardOutput();\n qDebug() << \"收到输出:\" << QString(data).trimmed();\n });\n}\n void startBridge64() {\n m_bridge64 = new QProcess();\n QStringList params64;\n m_bridge64->start(BRIDGE64_EXE, params64);\n if (!m_bridge64->waitForStarted())\n {\n qDebug() << \"64位桥接子进程启动失败\";\n }\n else\n {\n qDebug() << \"64位桥接子进程已启动\";\n }\n m_bridge64->setProcessChannelMode(QProcess::MergedChannels);\n connect(m_bridge64,\n &QProcess::readyReadStandardOutput,\n [&]()\n {\n QByteArray data = m_bridge64->readAllStandardOutput();\n qDebug() << \"收到输出:\" << QString(data).trimmed();\n });\n}\n void healthcheckBridge() {\n if (this->m_bridge32->state() == QProcess::Running)\n {\n m_injector32StatusLabel->setStyleSheet(\"color: green\");\n m_injector32StatusLabel->setText(tr(\"正常\"));\n }\n else\n {\n m_injector32StatusLabel->setStyleSheet(\"color: red\");\n m_injector32StatusLabel->setText(tr(\"异常退出\"));\n }\n\n if (this->m_bridge64->state() == QProcess::Running)\n {\n m_injector64StatusLabel->setStyleSheet(\"color: green\");\n m_injector64StatusLabel->setText(tr(\"正常\"));\n }\n else\n {\n m_injector64StatusLabel->setStyleSheet(\"color:red\");\n m_injector64StatusLabel->setText(tr(\"异常退出\"));\n }\n}\n void terminalBridge() {\n QString cmd = QString(\"exit\\n\");\n m_bridge32->write(cmd.toUtf8(), cmd.size());\n m_bridge32->waitForBytesWritten();\n m_bridge64->write(cmd.toUtf8(), cmd.size());\n m_bridge64->waitForBytesWritten();\n}\n static QIcon getProcessIcon(QString processPath) {\n int lastSlashPos =\n std::max(processPath.lastIndexOf('/'), processPath.lastIndexOf('\\\\'));\n QString processName;\n if (lastSlashPos == -1)\n {\n processName = processPath;\n }\n processName = processPath.mid(lastSlashPos + 1);\n\n if (processPath.isEmpty())\n {\n qDebug() << processPath << \"无法获取进程完整路径\";\n return getDefaultIcon(processName);\n }\n\n SHFILEINFO sfi = {};\n if (SHGetFileInfo(reinterpret_cast(processPath.utf16()),\n FILE_ATTRIBUTE_NORMAL,\n &sfi,\n sizeof(SHFILEINFO),\n SHGFI_ICON | SHGFI_LARGEICON | SHGFI_USEFILEATTRIBUTES))\n {\n if (sfi.hIcon)\n {\n QIcon icon = QtWin::fromHICON(sfi.hIcon);\n DestroyIcon(sfi.hIcon);\n if (!icon.isNull())\n {\n qDebug() << processPath << \"通过SHGetFileInfo获取图标成功\";\n return icon;\n }\n }\n }\n\n HICON hIcon =\n ExtractIconW(nullptr, reinterpret_cast(processPath.utf16()), 0);\n if (hIcon)\n {\n QIcon icon = QtWin::fromHICON(hIcon);\n DestroyIcon(hIcon);\n if (!icon.isNull())\n return icon;\n }\n\n QFileInfo fileInfo(processPath);\n if (fileInfo.exists())\n {\n // 使用Qt的QFileIconProvider获取文件图标\n QFileIconProvider iconProvider;\n return iconProvider.icon(fileInfo);\n }\n qDebug() << processPath << \"无法获取进程图标使用默认图标\";\n\n return getDefaultIcon(processName);\n}\n static QIcon getDefaultIcon(const QString& processName) {\n // 根据进程名称或类型提供更有针对性的默认图标\n if (processName != \"\")\n {\n // 使用SHGetFileInfo获取.exe文件的图标\n SHFILEINFO sfi = {};\n QIcon icon;\n if (SHGetFileInfo(reinterpret_cast(processName.utf16()),\n FILE_ATTRIBUTE_NORMAL,\n &sfi,\n sizeof(SHFILEINFO),\n SHGFI_USEFILEATTRIBUTES | SHGFI_ICON |\n SHGFI_SMALLICON))\n {\n // 将HICON转换为QIcon\n icon = QtWin::fromHICON(sfi.hIcon);\n\n // 释放图标资源\n DestroyIcon(sfi.hIcon);\n }\n return icon;\n }\n else\n {\n // 使用SHGetFileInfo获取.exe文件的图标\n SHFILEINFO sfi = {};\n QIcon icon;\n if (SHGetFileInfo(reinterpret_cast(L\".exe\"),\n FILE_ATTRIBUTE_NORMAL,\n &sfi,\n sizeof(SHFILEINFO),\n SHGFI_USEFILEATTRIBUTES | SHGFI_ICON |\n SHGFI_SMALLICON))\n {\n // 将HICON转换为QIcon\n icon = QtWin::fromHICON(sfi.hIcon);\n\n // 释放图标资源\n DestroyIcon(sfi.hIcon);\n }\n return icon;\n }\n}\n QIcon getProcessIconCached(DWORD proccessId) {\n QString processPath = winutils::getProcessPath(processId);\n if (m_iconCache.contains(processPath))\n {\n return m_iconCache[processPath];\n }\n\n QIcon icon = getProcessIcon(processPath);\n m_iconCache.insert(processPath, icon);\n return icon;\n}\n public:\n};"], ["/OpenSpeedy/winutils.h", "class winutils {\n public:\n winutils() {\n}\n public:\n static bool injectDll(DWORD processId, const QString& dllPath) {\n HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);\n if (!hProcess)\n {\n qDebug() << \"Failed to open process:\" << GetLastError();\n return false;\n }\n\n if (checkDllExist(processId, dllPath))\n {\n qDebug() << \"Process already have been injected\";\n return true;\n }\n else if (injectDllViaCRTW(processId, dllPath))\n {\n return true;\n }\n else if (injectDllViaCRTA(processId, dllPath))\n {\n return true;\n }\n\n injectDllViaAPCW(processId, dllPath);\n injectDllViaAPCA(processId, dllPath);\n if (checkDllExist(processId, dllPath))\n {\n return true;\n }\n else if (injectDllViaWHKW(processId, dllPath))\n {\n return true;\n }\n else if (injectDllViaWHKA(processId, dllPath))\n {\n return true;\n }\n else\n {\n return false;\n }\n}\n static bool injectDllViaCRTA(DWORD processId, const QString& dllPath) {\n HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);\n if (!hProcess)\n {\n qDebug() << \"Failed to open process:\" << GetLastError();\n return false;\n }\n\n if (checkDllExist(processId, dllPath))\n {\n qDebug() << \"Process already have been injected\";\n return true;\n }\n SIZE_T pathSize = (dllPath.size() + 1) * sizeof(char);\n LPVOID pDllPath =\n VirtualAllocEx(hProcess,\n nullptr,\n pathSize,\n MEM_COMMIT | MEM_RESERVE,\n PAGE_EXECUTE_READWRITE);\n if (!pDllPath)\n {\n qDebug() << \"Failed to allocate memory in target process:\"\n << GetLastError();\n CloseHandle(hProcess);\n return false;\n }\n\n if (!WriteProcessMemory(hProcess,\n pDllPath,\n dllPath.toStdString().c_str(),\n pathSize,\n nullptr))\n {\n qDebug() << \"Failed to write memory in target process:\"\n << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n HMODULE hKernel32 = GetModuleHandle(L\"kernel32.dll\");\n if (!hKernel32)\n {\n qDebug() << \"Failed to get handle for kernel32.dll:\" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n FARPROC pLoadLibraryA = GetProcAddress(hKernel32, \"LoadLibraryA\");\n if (!pLoadLibraryA)\n {\n qDebug() << \"Failed to get address of LoadLibraryA:\" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n HANDLE hThread = CreateRemoteThread(hProcess,\n nullptr,\n 0,\n (LPTHREAD_START_ROUTINE)pLoadLibraryA,\n pDllPath,\n 0,\n nullptr);\n if (!hThread)\n {\n qDebug() << \"Failed to create remote thread:\" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n WaitForSingleObject(hThread, INFINITE);\n\n // 检查LoadLibrary是否执行成功\n DWORD exitCode = 0;\n if (GetExitCodeThread(hThread, &exitCode))\n {\n qDebug() << \"Remote thread exit code:\" << exitCode;\n // LoadLibrary返回的是模块句柄,如果为0则失败\n if (exitCode == 0)\n {\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n CloseHandle(hThread);\n qDebug() << \"LoadLibrary failed in remote process\";\n return false;\n }\n }\n\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hThread);\n CloseHandle(hProcess);\n\n return true;\n}\n static bool injectDllViaCRTW(DWORD processId, const QString& dllPath) {\n HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);\n if (!hProcess)\n {\n qDebug() << \"Failed to open process:\" << GetLastError();\n return false;\n }\n\n if (checkDllExist(processId, dllPath))\n {\n qDebug() << \"Process already have been injected\";\n return true;\n }\n SIZE_T pathSize = (dllPath.size() + 1) * sizeof(wchar_t);\n LPVOID pDllPath =\n VirtualAllocEx(hProcess, nullptr, pathSize, MEM_COMMIT | MEM_RESERVE,\n PAGE_EXECUTE_READWRITE);\n if (!pDllPath)\n {\n qDebug() << \"Failed to allocate memory in target process:\"\n << GetLastError();\n CloseHandle(hProcess);\n return false;\n }\n\n if (!WriteProcessMemory(hProcess,\n pDllPath,\n dllPath.toStdWString().c_str(),\n pathSize,\n nullptr))\n {\n qDebug() << \"Failed to write memory in target process:\"\n << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n HMODULE hKernel32 = GetModuleHandle(L\"kernel32.dll\");\n if (!hKernel32)\n {\n qDebug() << \"Failed to get handle for kernel32.dll:\" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n FARPROC pLoadLibraryW = GetProcAddress(hKernel32, \"LoadLibraryW\");\n if (!pLoadLibraryW)\n {\n qDebug() << \"Failed to get address of LoadLibraryW:\" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n HANDLE hThread = CreateRemoteThread(hProcess,\n nullptr,\n 0,\n (LPTHREAD_START_ROUTINE)pLoadLibraryW,\n pDllPath,\n 0,\n nullptr);\n if (!hThread)\n {\n qDebug() << \"Failed to create remote thread:\" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n WaitForSingleObject(hThread, INFINITE);\n\n // 检查LoadLibrary是否执行成功\n DWORD exitCode = 0;\n if (GetExitCodeThread(hThread, &exitCode))\n {\n qDebug() << \"Remote thread exit code:\" << exitCode;\n // LoadLibrary返回的是模块句柄,如果为0则失败\n if (exitCode == 0)\n {\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n CloseHandle(hThread);\n qDebug() << \"LoadLibrary failed in remote process\";\n return false;\n }\n }\n\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hThread);\n CloseHandle(hProcess);\n\n return true;\n}\n static bool injectDllViaAPCA(DWORD processId, const QString& dllPath) {\n HANDLE hProcess =\n OpenProcess(PROCESS_ALL_ACCESS,\n FALSE,\n processId);\n\n if (!hProcess)\n {\n qDebug() << \"Failed to open process: \" << GetLastError();\n return false;\n }\n\n if (checkDllExist(processId, dllPath))\n {\n qDebug() << \"Process already have been injected\";\n return true;\n }\n\n // 在目标进程中分配内存并写入DLL路径\n SIZE_T pathSize = (dllPath.toStdString().size() + 1) * sizeof(char);\n LPVOID pDllPath = VirtualAllocEx(hProcess,\n NULL,\n pathSize,\n MEM_COMMIT,\n PAGE_READWRITE);\n\n if (!pDllPath)\n {\n qDebug() << \"Failed to allocate memory: \" << GetLastError();\n CloseHandle(hProcess);\n return false;\n }\n\n if (!WriteProcessMemory(hProcess, pDllPath, dllPath.toStdString().c_str(),\n pathSize, NULL))\n {\n qDebug() << \"Failed to write memory: \" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 获取LoadLibraryW的地址\n HMODULE hKernel32 = GetModuleHandle(L\"kernel32.dll\");\n if (!hKernel32)\n {\n qDebug() << \"Failed to get kernel32 handle\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n FARPROC pLoadLibraryA = GetProcAddress(hKernel32, \"LoadLibraryA\");\n if (!pLoadLibraryA)\n {\n qDebug() << \"Failed to get LoadLibraryA address\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 获取进程中的所有线程\n DWORD threadId = getProcessMainThread(processId);\n if (!threadId)\n {\n qDebug() << \"No threads found in the process\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 向目标进程的所有线程队列中添加APC调用\n bool success = false;\n\n // 打开线程\n HANDLE hThread = OpenThread(THREAD_SET_CONTEXT, FALSE, threadId);\n if (hThread)\n {\n // 将LoadLibraryA作为APC函数加入队列\n PostThreadMessageA(threadId, WM_PAINT, 0, 0);\n DWORD result =\n QueueUserAPC((PAPCFUNC)pLoadLibraryA, hThread, (ULONG_PTR)pDllPath);\n PostThreadMessageA(threadId, WM_PAINT, 0, 0);\n if (result != 0)\n {\n success = true;\n qDebug() << \"APC queued to thread \" << threadId;\n }\n\n CloseHandle(hThread);\n }\n\n if (!success)\n {\n qDebug() << \"Failed to queue APC to any thread\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 注意:我们不释放分配的内存,因为APC函数尚未执行\n // 内存将在DLL加载后释放\n\n CloseHandle(hProcess);\n return true;\n}\n static bool injectDllViaAPCW(DWORD processId, const QString& dllPath) {\n HANDLE hProcess =\n OpenProcess(PROCESS_ALL_ACCESS,\n FALSE,\n processId);\n\n if (!hProcess)\n {\n qDebug() << \"Failed to open process: \" << GetLastError();\n return false;\n }\n\n if (checkDllExist(processId, dllPath))\n {\n qDebug() << \"Process already have been injected\";\n return true;\n }\n\n // 在目标进程中分配内存并写入DLL路径\n SIZE_T pathSize = (dllPath.toStdWString().size() + 1) * sizeof(wchar_t);\n LPVOID pDllPath = VirtualAllocEx(hProcess,\n NULL,\n pathSize,\n MEM_COMMIT,\n PAGE_READWRITE);\n\n if (!pDllPath)\n {\n qDebug() << \"Failed to allocate memory: \" << GetLastError();\n CloseHandle(hProcess);\n return false;\n }\n\n if (!WriteProcessMemory(hProcess,\n pDllPath,\n dllPath.toStdWString().c_str(),\n pathSize,\n NULL))\n {\n qDebug() << \"Failed to write memory: \" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 获取LoadLibraryW的地址\n HMODULE hKernel32 = GetModuleHandle(L\"kernel32.dll\");\n if (!hKernel32)\n {\n qDebug() << \"Failed to get kernel32 handle\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n FARPROC pLoadLibraryW = GetProcAddress(hKernel32, \"LoadLibraryW\");\n if (!pLoadLibraryW)\n {\n qDebug() << \"Failed to get LoadLibraryW address\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 获取进程中的所有线程\n DWORD threadId = getProcessMainThread(processId);\n if (!threadId)\n {\n qDebug() << \"No threads found in the process\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 向目标进程的所有线程队列中添加APC调用\n bool success = false;\n\n // 打开线程\n HANDLE hThread = OpenThread(THREAD_SET_CONTEXT, FALSE, threadId);\n if (hThread)\n {\n // 将LoadLibraryW作为APC函数加入队列\n PostThreadMessageW(threadId, WM_PAINT, 0, 0);\n DWORD result =\n QueueUserAPC((PAPCFUNC)pLoadLibraryW, hThread, (ULONG_PTR)pDllPath);\n PostThreadMessageW(threadId, WM_PAINT, 0, 0);\n if (result != 0)\n {\n success = true;\n qDebug() << \"APC queued to thread \" << threadId;\n }\n\n CloseHandle(hThread);\n }\n\n if (!success)\n {\n qDebug() << \"Failed to queue APC to any thread\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 注意:我们不释放分配的内存,因为APC函数尚未执行\n // 内存将在DLL加载后释放\n\n CloseHandle(hProcess);\n return true;\n}\n static bool injectDllViaWHKA(DWORD processId, const QString& dllPath) {\n if (checkProcessProtection(processId))\n {\n qDebug() << \"进程被保护 进程ID: \" << processId;\n return false;\n }\n\n // 1. 加载DLL到当前进程\n HMODULE hMod = LoadLibraryA(dllPath.toStdString().c_str());\n if (!hMod)\n return false;\n\n // 2. 获取Hook过程的地址\n HOOKPROC hookProc = (HOOKPROC)GetProcAddress(hMod, \"HookProc\");\n if (!hookProc)\n return false;\n\n // 3. 获取目标线程ID\n DWORD threadId = getProcessMainThread(processId);\n if (threadId == 0)\n return false;\n\n // 4. 安装Hook\n HHOOK hHook = SetWindowsHookExA(WH_CBT, // Hook类型\n hookProc, // Hook过程\n hMod, // DLL模块句柄\n threadId // 目标线程ID\n );\n\n if (!hHook)\n return false;\n // 5. 触发Hook执行\n PostThreadMessageA(threadId, WM_NULL, 0, 0);\n Sleep(5000);\n UnhookWindowsHookEx(hHook);\n\n return true;\n}\n static bool injectDllViaWHKW(DWORD processId, const QString& dllPath) {\n if (checkProcessProtection(processId))\n {\n qDebug() << \"进程被保护 进程ID: \" << processId;\n return false;\n }\n\n // 1. 加载DLL到当前进程\n HMODULE hMod = LoadLibraryW(dllPath.toStdWString().c_str());\n if (!hMod)\n return false;\n\n // 2. 获取Hook过程的地址\n HOOKPROC hookProc = (HOOKPROC)GetProcAddress(hMod, \"HookProc\");\n if (!hookProc)\n return false;\n\n // 3. 获取目标线程ID\n DWORD threadId = getProcessMainThread(processId);\n if (threadId == 0)\n return false;\n\n // 4. 安装Hook\n HHOOK hHook = SetWindowsHookExW(WH_CBT, // Hook类型\n hookProc, // Hook过程\n hMod, // DLL模块句柄\n threadId // 目标线程ID\n );\n\n if (!hHook)\n return false;\n // 5. 触发Hook执行\n PostThreadMessageW(threadId, WM_NULL, 0, 0);\n Sleep(5000);\n UnhookWindowsHookEx(hHook);\n\n return true;\n}\n static bool unhookDll(DWORD processId, const QString& dllPath) {\n HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);\n if (!hProcess)\n {\n qDebug() << \"Failed to open process:\" << GetLastError();\n return false;\n }\n\n HMODULE hModules[1024];\n DWORD cbNeeded;\n if (EnumProcessModules(hProcess, hModules, sizeof(hModules), &cbNeeded))\n {\n for (unsigned int i = 0; i < (cbNeeded / sizeof(HMODULE)); i++)\n {\n TCHAR moduleName[MAX_PATH];\n if (GetModuleFileNameEx(hProcess, hModules[i], moduleName,\n sizeof(moduleName) / sizeof(TCHAR)))\n {\n#ifdef UNICODE\n bool isDll = dllPath.toStdWString() == moduleName;\n#else\n bool isDll = dllPath.toStdString() == moduleName;\n#endif\n if (isDll)\n {\n FARPROC pFreeLibrary = GetProcAddress(\n GetModuleHandle(L\"kernel32.dll\"), \"FreeLibrary\");\n if (!pFreeLibrary)\n {\n qDebug() << \"Failed to get address of FreeLibrary:\"\n << GetLastError();\n CloseHandle(hProcess);\n return false;\n }\n\n HANDLE hThread =\n CreateRemoteThread(hProcess, nullptr, 0,\n (LPTHREAD_START_ROUTINE)pFreeLibrary,\n hModules[i], 0, nullptr);\n if (!hThread)\n {\n qDebug() << \"Failed to create remote thread for \"\n \"FreeLibrary:\"\n << GetLastError();\n CloseHandle(hProcess);\n return false;\n }\n\n WaitForSingleObject(hThread, INFINITE);\n CloseHandle(hThread);\n CloseHandle(hProcess);\n return true;\n }\n }\n }\n }\n\n CloseHandle(hProcess);\n return false;\n}\n static bool checkDllExist(DWORD processId, const QString& dllPath) {\n HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,\n FALSE,\n processId);\n if (!hProcess)\n {\n qDebug() << \"打开进程失败:\" << GetLastError();\n return false;\n }\n\n bool dllFound = false;\n HMODULE hModules[1024];\n DWORD cbNeeded;\n\n // 获取进程中所有已加载的模块\n if (EnumProcessModules(hProcess, hModules, sizeof(hModules), &cbNeeded))\n {\n DWORD moduleCount = cbNeeded / sizeof(HMODULE);\n for (DWORD i = 0; i < moduleCount; i++)\n {\n TCHAR moduleName[MAX_PATH] = {0};\n\n // 获取模块的完整路径\n if (GetModuleFileNameExW(hProcess, hModules[i], moduleName,\n sizeof(moduleName) / sizeof(TCHAR)))\n {\n#ifdef UNICODE\n bool isDll = dllPath.toStdWString() == moduleName;\n#else\n bool isDll = dllPath.toStdString() == moduleName;\n#endif\n if (isDll)\n {\n dllFound = true;\n break;\n }\n }\n }\n }\n else\n {\n qDebug() << \"枚举进程模块失败:\" << GetLastError();\n }\n\n CloseHandle(hProcess);\n return dllFound;\n}\n static bool checkProcessProtection(DWORD processId) {\n HANDLE hProcess =\n OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, processId);\n if (!hProcess)\n {\n qDebug() << \"Cannot open process - likely protected\";\n return true; // 可能被保护\n }\n\n // 检查是否是受保护进程\n PROCESS_PROTECTION_LEVEL_INFORMATION protectionInfo = {};\n DWORD returnLength;\n\n if (GetProcessInformation(hProcess, ProcessProtectionLevelInfo,\n &protectionInfo, sizeof(protectionInfo)))\n {\n CloseHandle(hProcess);\n return protectionInfo.ProtectionLevel != PROTECTION_LEVEL_NONE;\n }\n\n CloseHandle(hProcess);\n return false;\n}\n static void setAutoStart(bool enable,\n const QString& appName,\n const QString& execPath) {\n TaskScheduler scheduler;\n\n if (enable)\n {\n scheduler.createStartupShortcut(appName, execPath);\n }\n else\n {\n scheduler.deleteStartupShortcut(appName);\n }\n}\n static bool isAutoStartEnabled(const QString& appName) {\n TaskScheduler scheduler;\n return scheduler.isStartupShortcutExists(appName);\n}\n static BOOL getWindowsVersion(DWORD* majorVersion,\n DWORD* minorVersion,\n DWORD* buildNumber) {\n static char version[100] = {0};\n DWORD major, minor, build;\n\n if (!getWindowsVersion(&major, &minor, &build))\n return \"Unknown Windows Version\";\n\n // 确定Windows版本\n if (major == 10)\n {\n if (build >= 22000)\n {\n sprintf(version, \"Windows 11 (Build %lu)\", build);\n }\n else\n {\n sprintf(version, \"Windows 10 (Build %lu)\", build);\n }\n }\n else if (major == 6)\n {\n switch (minor)\n {\n case 3:\n sprintf(version, \"Windows 8.1 (Build %lu)\", build);\n break;\n case 2:\n sprintf(version, \"Windows 8 (Build %lu)\", build);\n break;\n case 1:\n sprintf(version, \"Windows 7 (Build %lu)\", build);\n break;\n case 0:\n sprintf(version, \"Windows Vista (Build %lu)\", build);\n break;\n default:\n sprintf(version, \"Windows NT %lu.%lu (Build %lu)\", major, minor,\n build);\n }\n }\n else if (major == 5)\n {\n switch (minor)\n {\n case 2:\n sprintf(version, \"Windows Server 2003 (Build %lu)\", build);\n break;\n case 1:\n sprintf(version, \"Windows XP (Build %lu)\", build);\n break;\n case 0:\n sprintf(version, \"Windows 2000 (Build %lu)\", build);\n break;\n default:\n sprintf(version, \"Windows NT %lu.%lu (Build %lu)\", major, minor,\n build);\n }\n }\n else\n {\n sprintf(version, \"Windows NT %lu.%lu (Build %lu)\", major, minor, build);\n }\n return version;\n}\n static QString getWindowsVersion() {\n static char version[100] = {0};\n DWORD major, minor, build;\n\n if (!getWindowsVersion(&major, &minor, &build))\n return \"Unknown Windows Version\";\n\n // 确定Windows版本\n if (major == 10)\n {\n if (build >= 22000)\n {\n sprintf(version, \"Windows 11 (Build %lu)\", build);\n }\n else\n {\n sprintf(version, \"Windows 10 (Build %lu)\", build);\n }\n }\n else if (major == 6)\n {\n switch (minor)\n {\n case 3:\n sprintf(version, \"Windows 8.1 (Build %lu)\", build);\n break;\n case 2:\n sprintf(version, \"Windows 8 (Build %lu)\", build);\n break;\n case 1:\n sprintf(version, \"Windows 7 (Build %lu)\", build);\n break;\n case 0:\n sprintf(version, \"Windows Vista (Build %lu)\", build);\n break;\n default:\n sprintf(version, \"Windows NT %lu.%lu (Build %lu)\", major, minor,\n build);\n }\n }\n else if (major == 5)\n {\n switch (minor)\n {\n case 2:\n sprintf(version, \"Windows Server 2003 (Build %lu)\", build);\n break;\n case 1:\n sprintf(version, \"Windows XP (Build %lu)\", build);\n break;\n case 0:\n sprintf(version, \"Windows 2000 (Build %lu)\", build);\n break;\n default:\n sprintf(version, \"Windows NT %lu.%lu (Build %lu)\", major, minor,\n build);\n }\n }\n else\n {\n sprintf(version, \"Windows NT %lu.%lu (Build %lu)\", major, minor, build);\n }\n return version;\n}\n static QList getProcessList() {\n QList processList;\n\n HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);\n if (hProcessSnap == INVALID_HANDLE_VALUE)\n {\n qDebug() << \"创建进程快照失败: \" << GetLastError();\n return processList;\n }\n\n PROCESSENTRY32 pe32;\n pe32.dwSize = sizeof(PROCESSENTRY32);\n\n if (!Process32First(hProcessSnap, &pe32))\n {\n qDebug() << \"获取首个进程信息失败: \" << GetLastError();\n CloseHandle(hProcessSnap);\n return processList;\n }\n\n do\n {\n if (systemNames.contains(pe32.szExeFile))\n {\n continue;\n }\n ProcessInfo info;\n info.pid = pe32.th32ProcessID;\n info.parentPid = pe32.th32ParentProcessID;\n info.name = QString::fromWCharArray(pe32.szExeFile);\n info.threadCount = pe32.cntThreads;\n\n // 获取内存使用和优先级信息\n HANDLE hProcess = OpenProcess(\n PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, info.pid);\n if (hProcess)\n {\n PROCESS_MEMORY_COUNTERS pmc;\n if (GetProcessMemoryInfo(hProcess, &pmc, sizeof(pmc)))\n {\n info.memoryUsage = pmc.WorkingSetSize;\n }\n else\n {\n info.memoryUsage = 0;\n }\n BOOL wow64Process = FALSE;\n IsWow64Process(hProcess, &wow64Process);\n info.is64Bit = !wow64Process;\n info.priorityClass = GetPriorityClass(hProcess);\n CloseHandle(hProcess);\n }\n else\n {\n info.memoryUsage = 0;\n info.priorityClass = 0;\n }\n\n processList.append(info);\n } while (Process32Next(hProcessSnap, &pe32));\n\n CloseHandle(hProcessSnap);\n return processList;\n}\n static QString getProcessPath(DWORD processId) {\n QString processPath;\n HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,\n FALSE, processId);\n\n if (hProcess != NULL)\n {\n wchar_t buffer[MAX_PATH];\n if (GetModuleFileNameEx(hProcess, NULL, buffer, MAX_PATH) > 0)\n {\n processPath = QString::fromWCharArray(buffer);\n }\n CloseHandle(hProcess);\n }\n\n return processPath;\n}\n static DWORD getProcessMainThread(DWORD processId) {\n HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);\n if (hSnapshot == INVALID_HANDLE_VALUE)\n {\n qDebug() << \"Failed to create thread snapshot:\" << GetLastError();\n return 0;\n }\n\n THREADENTRY32 te32;\n te32.dwSize = sizeof(THREADENTRY32);\n\n DWORD mainThreadId = 0;\n FILETIME earliestTime = {0xFFFFFFFF, 0xFFFFFFFF}; // 设为最大值\n\n if (Thread32First(hSnapshot, &te32))\n {\n do\n {\n if (te32.th32OwnerProcessID == processId)\n {\n // 打开线程获取创建时间\n HANDLE hThread = OpenThread(THREAD_QUERY_INFORMATION, FALSE,\n te32.th32ThreadID);\n if (hThread)\n {\n FILETIME creationTime, exitTime, kernelTime, userTime;\n if (GetThreadTimes(hThread, &creationTime, &exitTime,\n &kernelTime, &userTime))\n {\n // 比较创建时间,找最早的线程\n if (CompareFileTime(&creationTime, &earliestTime) < 0)\n {\n earliestTime = creationTime;\n mainThreadId = te32.th32ThreadID;\n }\n }\n CloseHandle(hThread);\n }\n }\n } while (Thread32Next(hSnapshot, &te32));\n }\n\n CloseHandle(hSnapshot);\n return mainThreadId;\n}\n static QString getProcessNameById(DWORD processId) {\n HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,\n FALSE, processId);\n if (hProcess == NULL)\n {\n return QString();\n }\n\n wchar_t processName[MAX_PATH];\n if (GetModuleBaseName(hProcess, NULL, processName, MAX_PATH))\n {\n CloseHandle(hProcess);\n QString name = QString::fromWCharArray(processName);\n return name;\n }\n\n CloseHandle(hProcess);\n return QString();\n}\n static bool enableAllPrivilege() {\n HANDLE hToken;\n // 获取进程token\n if (!OpenProcessToken(GetCurrentProcess(),\n TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))\n return false;\n\n const wchar_t *essentialPrivileges[] = {\n SE_DEBUG_NAME, // 最重要的调试权限\n };\n\n TOKEN_PRIVILEGES tkp;\n bool success = true;\n\n for (const auto &privilege : essentialPrivileges)\n {\n tkp.PrivilegeCount = 1;\n tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;\n if (LookupPrivilegeValue(NULL, privilege, &tkp.Privileges[0].Luid))\n {\n AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, NULL);\n }\n }\n\n CloseHandle(hToken);\n return success;\n}\n};"], ["/OpenSpeedy/taskscheduler.h", "class TaskScheduler {\n Q_OBJECT\n public:\n explicit TaskScheduler(QObject *parent = nullptr);\n ~TaskScheduler() {\n}\n bool createStartupTask(const QString &taskName,\n const QString &executablePath) {\n if (taskName.isEmpty() || executablePath.isEmpty())\n {\n qWarning() << \"任务名称或可执行文件路径不能为空\";\n return false;\n }\n\n if (!QFile::exists(executablePath))\n {\n qWarning() << \"可执行文件不存在\" << executablePath;\n return false;\n }\n\n QStringList arguments;\n arguments << \"/create\"\n << \"/f\"\n << \"/tn\" << taskName << \"/tr\"\n << QString(\"\\\"%1\\\" --minimize-to-tray\").arg(executablePath)\n << \"/sc\" << \"onlogon\"\n << \"/delay\" << \"0000:10\"\n << \"/rl\" << \"highest\";\n\n return execute(arguments);\n}\n bool deleteTask(const QString &taskName) {\n if (taskName.isEmpty())\n {\n qWarning() << \"任务名称不能为空\";\n return false;\n }\n\n if (!isTaskExists(taskName))\n {\n qWarning() << \"任务不存在, 无需删除\" << taskName;\n return true;\n }\n\n QStringList arguments;\n arguments << \"/delete\"\n << \"/f\"\n << \"/tn\" << taskName;\n\n return execute(arguments);\n}\n bool enableTask(const QString &taskName, bool enable) {\n if (!isTaskExists(taskName))\n {\n qWarning() << \"任务不存在:\" << taskName;\n return false;\n }\n\n QStringList arguments;\n arguments << \"/change\"\n << \"/tn\" << taskName << (enable ? \"/enable\" : \"/disable\");\n return execute(arguments);\n}\n bool isTaskExists(const QString &taskName) {\n QStringList arguments;\n arguments << \"/query\" << \"/tn\" << taskName;\n\n return execute(arguments);\n}\n bool execute(const QStringList &arguments) {\n QProcess process;\n process.setProgram(\"schtasks\");\n process.setArguments(arguments);\n\n const int timeout = 10000;\n process.start();\n if (!process.waitForStarted(timeout))\n {\n qWarning() << \"无法运行:\" << process.errorString();\n return false;\n }\n\n if (!process.waitForFinished(timeout))\n {\n qWarning() << \"执行超时\";\n process.kill();\n return false;\n }\n\n int exitcode = process.exitCode();\n QString stdout_ = QString::fromLocal8Bit(process.readAllStandardOutput());\n QString stderr_ = QString::fromLocal8Bit(process.readAllStandardError());\n\n if (exitcode == 0)\n {\n qDebug() << \"执行成功:\" << arguments;\n qDebug() << \"输出:\" << stdout_;\n return true;\n }\n else\n {\n qDebug() << \"执行失败:\" << arguments;\n qDebug() << \"错误输出:\" << stderr_;\n qDebug() << \"标准输出:\" << stdout_;\n return false;\n }\n}\n bool createStartupShortcut(const QString &taskName,\n const QString &executablePath) {\n QString home = QDir::homePath();\n QString startupDir =\n home +\n \"\\\\AppData\\\\Roaming\\\\Microsoft\\\\Windows\\\\Start Menu\\\\Programs\\\\Startup\";\n QString shortcutPath = QDir(startupDir).absoluteFilePath(taskName + \".lnk\");\n QString arguments = \"--minimize-to-tray\";\n\n QString psScript =\n QString(\"$WScriptShell = New-Object -ComObject WScript.Shell; \"\n \"$Shortcut = $WScriptShell.CreateShortcut('%1'); \"\n \"$Shortcut.TargetPath = '%2'; \"\n \"$Shortcut.Arguments = '%3'; \"\n \"$Shortcut.Description = '%4'; \"\n \"$Shortcut.Save()\")\n .arg(shortcutPath, executablePath, arguments,\n QString(\"启动 %1\").arg(QFileInfo(executablePath).baseName()));\n\n return executePs(psScript);\n}\n bool deleteStartupShortcut(const QString &taskName) {\n QString home = QDir::homePath();\n QString startupDir =\n home + \"\\\\AppData\\\\Roaming\\\\Microsoft\\\\Windows\\\\Start Menu\\\\Programs\\\\Startup\";\n QString shortcutPath = QDir(startupDir).absoluteFilePath(taskName + \".lnk\");\n\n QString psScript = QString(\"Remove-Item '%1' -Force\").arg(shortcutPath);\n\n return executePs(psScript);\n}\n bool isStartupShortcutExists(const QString &taskName) {\n QString home = QDir::homePath();\n QString startupDir =\n home +\n \"\\\\AppData\\\\Roaming\\\\Microsoft\\\\Windows\\\\Start Menu\\\\Programs\\\\Startup\";\n QString shortcutPath = QDir(startupDir).absoluteFilePath(taskName + \".lnk\");\n\n return QFile::exists(shortcutPath);\n}\n bool executePs(const QString &psScript) {\n QProcess process;\n process.setProgram(\"powershell\");\n process.setArguments({\"-ExecutionPolicy\", \"Bypass\", \"-Command\", psScript});\n\n process.start();\n if (!process.waitForStarted(5000))\n {\n qDebug() << \"PowerShell 启动失败:\" << process.errorString();\n return false;\n }\n\n if (process.waitForFinished(5000) && process.exitCode() == 0)\n {\n qDebug() << \"PowerShell 执行成功\";\n return true;\n }\n else\n {\n QString error = QString::fromLocal8Bit(process.readAllStandardError());\n qDebug() << \"PowerShell 执行失败:\" << error;\n }\n\n return false;\n}\n};"], ["/OpenSpeedy/bridge/main.cpp", "#include \"../config.h\"\n#include \"../speedpatch/speedpatch.h\"\n#include \"../windbg.h\"\n#include \"../winutils.h\"\n#include \n#include \n#include \n#include \n#include \n\n#ifndef _WIN64\n#define SPEEDPATCH_DLL SPEEDPATCH32_DLL\n#else\n#define SPEEDPATCH_DLL SPEEDPATCH64_DLL\n#endif\n\nvoid\nhandleInject(int processId, QString dllPath)\n{\n qDebug() << \"执行 inject,进程ID:\" << processId;\n winutils::injectDll(processId, dllPath);\n SetProcessStatus(processId, true);\n}\n\nvoid\nhandleUnhook(int processId, QString dllPath)\n{\n qDebug() << \"执行 unhook,进程ID:\" << processId;\n SetProcessStatus(processId, false);\n}\n\nvoid\nhandleChange(double factor)\n{\n qDebug() << \"执行 change,参数:\" << factor;\n ChangeSpeed(factor);\n}\n\nint\nmain(int argc, char* argv[])\n{\n SetUnhandledExceptionFilter(createMiniDump);\n QCoreApplication a(argc, argv);\n if (winutils::enableAllPrivilege())\n {\n qDebug() << \"权限提升成功\";\n }\n\n QString dllPath = QDir::toNativeSeparators(\n QCoreApplication::applicationDirPath() + \"/\" + SPEEDPATCH_DLL);\n\n QTextStream in(stdin);\n QTextStream out(stdout);\n\n QRegularExpression injectRegex(\"^\\\\s*inject\\\\s+(\\\\d+)\\\\s*$\",\n QRegularExpression::CaseInsensitiveOption);\n QRegularExpression unhookRegex(\"^\\\\s*unhook\\\\s+(\\\\d+)\\\\s*$\",\n QRegularExpression::CaseInsensitiveOption);\n QRegularExpression changeRegex(\"^\\\\s*change\\\\s+([+-]?\\\\d*\\\\.?\\\\d+)\\\\s*$\",\n QRegularExpression::CaseInsensitiveOption);\n QRegularExpression exitRegex(\"^\\\\s*exit\\\\s*$\",\n QRegularExpression::CaseInsensitiveOption);\n\n while (true)\n {\n QString line = in.readLine();\n if (line.isNull())\n {\n // 管道关闭或输入结束\n break;\n }\n line = line.trimmed();\n if (line.isEmpty())\n continue;\n\n QRegularExpressionMatch match;\n if ((match = injectRegex.match(line)).hasMatch())\n {\n int pid = match.captured(1).toInt();\n handleInject(pid, dllPath);\n }\n else if ((match = unhookRegex.match(line)).hasMatch())\n {\n int pid = match.captured(1).toInt();\n handleUnhook(pid, dllPath);\n }\n else if ((match = changeRegex.match(line)).hasMatch())\n {\n double factor = match.captured(1).toDouble();\n handleChange(factor);\n }\n else if (exitRegex.match(line).hasMatch())\n {\n qDebug() << \"收到exit命令,程序即将退出。\";\n break;\n }\n else\n {\n qDebug() << \"无效命令:\" << line;\n }\n }\n\n return 0;\n}\n"], ["/OpenSpeedy/windbg.h", "/*\n * OpenSpeedy - Open Source Game Speed Controller\n * Copyright (C) 2025 Game1024\n * \n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n * \n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n * \n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n#ifndef WINDBG_H\n#define WINDBG_H\n#include \n#include \n#include \n#include \n// 链接dbghelp库\n#pragma comment(lib, \"dbghelp.lib\")\n\ntypedef BOOL(WINAPI *MINIDUMPWRITEDUMP)(\n HANDLE hProcess,\n DWORD ProcessId,\n HANDLE hFile,\n MINIDUMP_TYPE DumpType,\n PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,\n PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,\n PMINIDUMP_CALLBACK_INFORMATION CallbackParam);\n\n// 自定义异常处理函数\nLONG WINAPI createMiniDump(EXCEPTION_POINTERS *exceptionPointers)\n{\n // 创建dump文件目录\n QDir dumpDir(QDir::currentPath() + \"/dumps\");\n if (!dumpDir.exists())\n {\n dumpDir.mkpath(\".\");\n }\n\n // 生成带时间戳的文件名\n QString dumpFileName =\n QString(\"%1/crash_%2.dmp\")\n .arg(dumpDir.absolutePath())\n .arg(QDateTime::currentDateTime().toString(\"yyyy-MM-dd_hh-mm-ss\"));\n\n // 创建文件\n HANDLE hFile = CreateFile(dumpFileName.toStdWString().c_str(),\n GENERIC_WRITE, FILE_SHARE_READ, NULL,\n CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);\n\n if (hFile == INVALID_HANDLE_VALUE)\n {\n return EXCEPTION_CONTINUE_SEARCH;\n }\n\n // 加载dbghelp.dll\n HMODULE dbgHelp = LoadLibrary(L\"dbghelp.dll\");\n if (!dbgHelp)\n {\n CloseHandle(hFile);\n return EXCEPTION_CONTINUE_SEARCH;\n }\n\n // 获取MiniDumpWriteDump函数地址\n MINIDUMPWRITEDUMP miniDumpWriteDump =\n (MINIDUMPWRITEDUMP)GetProcAddress(dbgHelp, \"MiniDumpWriteDump\");\n\n if (!miniDumpWriteDump)\n {\n FreeLibrary(dbgHelp);\n CloseHandle(hFile);\n return EXCEPTION_CONTINUE_SEARCH;\n }\n\n // 配置异常信息\n MINIDUMP_EXCEPTION_INFORMATION exInfo;\n exInfo.ThreadId = GetCurrentThreadId();\n exInfo.ExceptionPointers = exceptionPointers;\n exInfo.ClientPointers = FALSE;\n\n // 设置dump类型\n MINIDUMP_TYPE dumpType =\n (MINIDUMP_TYPE)(MiniDumpWithFullMemory | // 包含完整内存\n MiniDumpWithFullMemoryInfo | // 包含内存信息\n MiniDumpWithHandleData | // 包含句柄数据\n MiniDumpWithThreadInfo | // 包含线程信息\n MiniDumpWithUnloadedModules // 包含卸载的模块\n );\n\n // 写入dump文件\n BOOL success = miniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(),\n hFile, dumpType, &exInfo, NULL, NULL);\n\n // 清理资源\n FreeLibrary(dbgHelp);\n CloseHandle(hFile);\n\n // 显示通知\n if (success)\n {\n std::wstring message =\n QString(\"程序遇到错误已退出,崩溃转储文件已保存到:\\n%1\")\n .arg(dumpFileName)\n .toStdWString();\n MessageBoxW(nullptr, message.c_str(), L\"程序崩溃\",\n MB_OK | MB_ICONERROR);\n }\n\n return EXCEPTION_EXECUTE_HANDLER;\n}\n\n#endif // WINDBG_H\n"], ["/OpenSpeedy/main.cpp", "/*\n * OpenSpeedy - Open Source Game Speed Controller\n * Copyright (C) 2025 Game1024\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n#include \"mainwindow.h\"\n#include \"windbg.h\"\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nint\nmain(int argc, char* argv[])\n{\n SetUnhandledExceptionFilter(createMiniDump);\n SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);\n QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);\n QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);\n QApplication::setAttribute(Qt::AA_UseSoftwareOpenGL);\n QApplication a(argc, argv);\n winutils::enableAllPrivilege();\n\n // 检查是否已有实例在运行\n QString unique = \"OpenSpeedy\";\n QLocalSocket socket;\n socket.connectToServer(unique);\n if (socket.waitForConnected(500))\n {\n socket.close();\n return -1;\n }\n\n // 使用资源文件中的图标\n QIcon appIcon;\n appIcon.addFile(\":/icons/images/icon_16.ico\", QSize(16, 16));\n appIcon.addFile(\":/icons/images/icon_32.ico\", QSize(32, 32));\n appIcon.addFile(\":/icons/images/icon_64.ico\", QSize(64, 64));\n a.setWindowIcon(appIcon);\n\n QSettings settings =\n QSettings(QCoreApplication::applicationDirPath() + \"/config.ini\",\n QSettings::IniFormat);\n\n QTranslator translator;\n const QString baseName =\n \"OpenSpeedy_\" +\n settings.value(CONFIG_LANGUAGE, QLocale().system().name()).toString();\n\n if (translator.load(\":/i18n/translations/\" + baseName))\n {\n a.installTranslator(&translator);\n }\n\n // 解析命令行参数\n QCommandLineParser parser;\n parser.setApplicationDescription(\"OpenSpeedy\");\n QCommandLineOption minimizeOption(\n QStringList() << \"m\" << \"minimize-to-tray\", \"启动时最小化到托盘\");\n parser.addOption(minimizeOption);\n parser.process(a);\n\n MainWindow w;\n w.resize(1024, 768);\n\n if (parser.isSet(minimizeOption))\n {\n w.hide();\n }\n else\n {\n w.show();\n }\n\n // 创建并启动本地服务器\n QLocalServer server;\n QLocalServer::removeServer(unique);\n server.listen(unique);\n // 当用户尝试再运行一个进程时,将窗口显示到最前台\n QObject::connect(&server,\n &QLocalServer::newConnection,\n [&]\n {\n w.show();\n w.raise();\n w.showNormal();\n w.activateWindow();\n });\n return a.exec();\n}\n"], ["/OpenSpeedy/cpuutils.h", "class CpuUtils {\n private:\n PDH_HQUERY hQuery = NULL;\n PDH_HCOUNTER hCounter = NULL;\n bool initialized = false;\n public:\n CpuUtils() {\n}\n ~CpuUtils() {\n if (hCounter) PdhRemoveCounter(hCounter);\n if (hQuery) PdhCloseQuery(hQuery);\n}\n bool init() {\n // 创建查询\n if (PdhOpenQuery(NULL, NULL, &hQuery) != ERROR_SUCCESS) return false;\n\n if (PdhAddEnglishCounter(hQuery,\n L\"\\\\Processor(_Total)\\\\% Processor Time\",\n NULL,\n &hCounter) != ERROR_SUCCESS)\n {\n PdhCloseQuery(hQuery);\n return false;\n }\n\n // 第一次采样\n PdhCollectQueryData(hQuery);\n initialized = true;\n return true;\n}\n double getUsage() {\n if (!initialized) return -1;\n\n // 收集数据\n if (PdhCollectQueryData(hQuery) != ERROR_SUCCESS) return -1;\n\n PDH_FMT_COUNTERVALUE value;\n if (PdhGetFormattedCounterValue(hCounter, PDH_FMT_DOUBLE, NULL, &value) !=\n ERROR_SUCCESS)\n return -1;\n\n return value.doubleValue;\n}\n QString getModel() {\n int cpuInfo[4];\n char cpuBrand[48 + 1] = {0};\n\n // 获取CPU品牌字符串(需要调用3次CPUID)\n __cpuid(cpuInfo, 0x80000002);\n memcpy(cpuBrand, cpuInfo, sizeof(cpuInfo));\n\n __cpuid(cpuInfo, 0x80000003);\n memcpy(cpuBrand + 16, cpuInfo, sizeof(cpuInfo));\n\n __cpuid(cpuInfo, 0x80000004);\n memcpy(cpuBrand + 32, cpuInfo, sizeof(cpuInfo));\n\n QString result(cpuBrand);\n\n return result.trimmed();\n}\n};"], ["/OpenSpeedy/memutils.h", "class MemUtils {\n private:\n PDH_HQUERY hQuery = NULL;\n PDH_HCOUNTER hCounter = NULL;\n bool initialized = false;\n public:\n MemUtils() {\n}\n bool init() {\n if (PdhOpenQuery(NULL, NULL, &hQuery) != ERROR_SUCCESS) return false;\n\n if (PdhAddEnglishCounter(hQuery,\n L\"\\\\Memory\\\\Available Bytes\",\n NULL,\n &hCounter) != ERROR_SUCCESS)\n {\n PdhCloseQuery(hQuery);\n return false;\n }\n\n PdhCollectQueryData(hQuery);\n initialized = true;\n return true;\n}\n double getTotal() {\n MEMORYSTATUSEX memInfo;\n memInfo.dwLength = sizeof(MEMORYSTATUSEX);\n GlobalMemoryStatusEx(&memInfo);\n return memInfo.ullTotalPhys / (1024.0 * 1024.0 * 1024.0);\n}\n double getUsage() {\n if (!initialized) return -1;\n\n if (PdhCollectQueryData(hQuery) != ERROR_SUCCESS) return -1;\n\n PDH_FMT_COUNTERVALUE available;\n if (PdhGetFormattedCounterValue(hCounter,\n PDH_FMT_DOUBLE,\n NULL,\n &available) != ERROR_SUCCESS)\n return -1;\n\n double totalMemory = getTotal() * 1024 * 1024 * 1024;\n double usageMemory = totalMemory - available.doubleValue;\n\n return usageMemory / (1024.0 * 1024.0 * 1024.0);\n}\n};"], ["/OpenSpeedy/aboutdialog.h", "class AboutDialog {\n Q_OBJECT\n\n public:\n explicit AboutDialog(QWidget* parent = nullptr);\n ~AboutDialog() {\n delete ui;\n}\n private:\n void recreate() {\n layout()->invalidate();\n layout()->activate();\n adjustSize();\n}\n private:\n Ui::AboutDialog* ui;\n};"], ["/OpenSpeedy/config.h", "/*\n * OpenSpeedy - Open Source Game Speed Controller\n * Copyright (C) 2025 Game1024\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n#ifndef CONFIG_H\n#define CONFIG_H\n\n#define OPENSPEEDY_VERSION \"v1.7.6\"\n\n#define BRIDGE32_EXE \"bridge32.exe\"\n#define BRIDGE64_EXE \"bridge64.exe\"\n\n#define SPEEDPATCH32_DLL \"speedpatch32.dll\"\n#define SPEEDPATCH64_DLL \"speedpatch64.dll\"\n\n#define CONFIG_LANGUAGE \"General/Language\"\n\n// 热键ID\nenum HotkeyIds\n{\n HOTKEY_INCREASE_SPEED = 1001,\n HOTKEY_DECREASE_SPEED = 1002,\n HOTKEY_RESET_SPEED = 1003,\n HOTKEY_SHIFT1 = 1011,\n HOTKEY_SHIFT2 = 1012,\n HOTKEY_SHIFT3 = 1013,\n HOTKEY_SHIFT4 = 1014,\n HOTKEY_SHIFT5 = 1015\n};\n\n#endif // CONFIG_H\n"], ["/OpenSpeedy/speedpatch/SpeedPatch_global.h", "/*\n * OpenSpeedy - Open Source Game Speed Controller\n * Copyright (C) 2025 Game1024\n * \n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n * \n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n * \n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n#ifndef SPEEDPATCH_GLOBAL_H\n#define SPEEDPATCH_GLOBAL_H\n\n\n#endif // SPEEDPATCH_GLOBAL_H\n"], ["/OpenSpeedy/mainwindow.h", "class MainWindow {\n};"], ["/OpenSpeedy/speedpatch/speedpatch.h", "class speedpatch {\n};"]], "task_instance_info": {"created_time": "2025-08-20 19:52:06", "created_task_model": "DeepSeek-R1", "function_skeleton": "static QtCombinedKey toQtCombinedKey(const QString& keyText) {}", "code_description": "This code segment functions to: Parse a textual key sequence representation into its constituent components by separating modifier flags from the base key value, facilitating cross-platform input handling compatibility."}, "inference_content": {"inference_model": "DeepSeek-R1", "inference_result": "```cpp\n[TASK_BEGIN]\nstatic QtCombinedKey toQtCombinedKey(const QString& keyText) {\n QKeySequence sequence(keyText);\n if (sequence.isEmpty()) {\n return {0, Qt::NoModifier};\n }\n \n int combinedKey = sequence[0];\n Qt::KeyboardModifiers modifiers = static_cast(combinedKey & Qt::KeyboardModifierMask);\n int keyCode = combinedKey & ~Qt::KeyboardModifierMask;\n \n return {keyCode, modifiers};\n}\n[TASK_END]\n```", "inference_time": "2025-08-20 19-52-28"}, "editdistance_info": {"edit_distance": 47.3684, "calculate_time": "2025-08-20 19:52:28", "true_code_clean": "static QtCombinedKey toQtCombinedKey(const QString& keyText) {\n QKeySequence sequence = QKeySequence(keyText);\n if (!sequence.isEmpty())\n {\n int combinedKey = sequence[0];\n Qt::KeyboardModifiers modifier =\n Qt::KeyboardModifiers(combinedKey & Qt::KeyboardModifierMask);\n int key = combinedKey & ~Qt::KeyboardModifierMask;\n return QtCombinedKey{ key, modifier };\n }\n else\n {\n return QtCombinedKey{ 0, Qt::NoModifier };\n }\n}", "predict_code_clean": "static QtCombinedKey toQtCombinedKey(const QString& keyText) {\n QKeySequence sequence(keyText);\n if (sequence.isEmpty()) {\n return {0, Qt::NoModifier};\n }\n int combinedKey = sequence[0];\n Qt::KeyboardModifiers modifiers = static_cast(combinedKey & Qt::KeyboardModifierMask);\n int keyCode = combinedKey & ~Qt::KeyboardModifierMask;\n return {keyCode, modifiers};\n}"}} {"repo_name": "OpenSpeedy", "file_name": "/OpenSpeedy/qsinglekeysequenceedit.h", "inference_info": {"prefix_code": "class QSingleKeySequenceEdit {\n Q_OBJECT\n\n public:\n explicit QSingleKeySequenceEdit(QWidget* parent = nullptr);\n static UINT toVK(int qtKey, Qt::KeyboardModifiers qtMod) {\n // 🔤 字母键 A-Z\n if (qtKey >= Qt::Key_A && qtKey <= Qt::Key_Z)\n {\n return qtKey; // Qt 和 Windows 的 A-Z 键码相同\n }\n\n // 🔢 小键盘 0-9\n if (qtMod & Qt::KeypadModifier)\n {\n switch (qtKey)\n {\n // 数字键盘\n case Qt::Key_0:\n return VK_NUMPAD0;\n case Qt::Key_1:\n return VK_NUMPAD1;\n case Qt::Key_2:\n return VK_NUMPAD2;\n case Qt::Key_3:\n return VK_NUMPAD3;\n case Qt::Key_4:\n return VK_NUMPAD4;\n case Qt::Key_5:\n return VK_NUMPAD5;\n case Qt::Key_6:\n return VK_NUMPAD6;\n case Qt::Key_7:\n return VK_NUMPAD7;\n case Qt::Key_8:\n return VK_NUMPAD8;\n case Qt::Key_9:\n return VK_NUMPAD9;\n }\n }\n\n // 🔢 数字键 0-9\n if (qtKey >= Qt::Key_0 && qtKey <= Qt::Key_9)\n {\n return qtKey; // Qt 和 Windows 的 0-9 键码相同\n }\n\n // 🎯 功能键映射\n switch (qtKey)\n {\n // F1-F12\n case Qt::Key_F1:\n return VK_F1;\n case Qt::Key_F2:\n return VK_F2;\n case Qt::Key_F3:\n return VK_F3;\n case Qt::Key_F4:\n return VK_F4;\n case Qt::Key_F5:\n return VK_F5;\n case Qt::Key_F6:\n return VK_F6;\n case Qt::Key_F7:\n return VK_F7;\n case Qt::Key_F8:\n return VK_F8;\n case Qt::Key_F9:\n return VK_F9;\n case Qt::Key_F10:\n return VK_F10;\n case Qt::Key_F11:\n return VK_F11;\n case Qt::Key_F12:\n return VK_F12;\n\n // 方向键\n case Qt::Key_Left:\n return VK_LEFT;\n case Qt::Key_Right:\n return VK_RIGHT;\n case Qt::Key_Up:\n return VK_UP;\n case Qt::Key_Down:\n return VK_DOWN;\n\n // 特殊键\n case Qt::Key_Enter:\n case Qt::Key_Return:\n return VK_RETURN;\n case Qt::Key_Escape:\n return VK_ESCAPE;\n case Qt::Key_Tab:\n return VK_TAB;\n case Qt::Key_Backspace:\n return VK_BACK;\n case Qt::Key_Delete:\n return VK_DELETE;\n case Qt::Key_Insert:\n return VK_INSERT;\n case Qt::Key_Home:\n return VK_HOME;\n case Qt::Key_End:\n return VK_END;\n case Qt::Key_PageUp:\n return VK_PRIOR;\n case Qt::Key_PageDown:\n return VK_NEXT;\n case Qt::Key_Space:\n return VK_SPACE;\n\n // 符号键\n case Qt::Key_Semicolon:\n return VK_OEM_1; // ;\n case Qt::Key_Equal:\n return VK_OEM_PLUS; // =\n case Qt::Key_Comma:\n return VK_OEM_COMMA; // ,\n case Qt::Key_Minus:\n return VK_OEM_MINUS; // -\n case Qt::Key_Period:\n return VK_OEM_PERIOD; // .\n case Qt::Key_Slash:\n return VK_OEM_2; // /\n case Qt::Key_QuoteLeft:\n return VK_OEM_3; // `\n case Qt::Key_BracketLeft:\n return VK_OEM_4; // [\n case Qt::Key_Backslash:\n return VK_OEM_5; //\n case Qt::Key_BracketRight:\n return VK_OEM_6; // ]\n case Qt::Key_Apostrophe:\n return VK_OEM_7; // '\n\n // 其他常用键\n case Qt::Key_CapsLock:\n return VK_CAPITAL;\n case Qt::Key_NumLock:\n return VK_NUMLOCK;\n case Qt::Key_ScrollLock:\n return VK_SCROLL;\n case Qt::Key_Pause:\n return VK_PAUSE;\n case Qt::Key_Print:\n return VK_PRINT;\n\n default:\n qDebug() << \"Unknown Qt key:\" << qtKey;\n return 0; // 未知按键\n }\n}\n static UINT toModifier(Qt::KeyboardModifiers qtMod) {\n UINT winMod = 0;\n\n if (qtMod & Qt::ControlModifier)\n {\n winMod |= MOD_CONTROL;\n }\n if (qtMod & Qt::AltModifier)\n {\n winMod |= MOD_ALT;\n }\n if (qtMod & Qt::ShiftModifier)\n {\n winMod |= MOD_SHIFT;\n }\n if (qtMod & Qt::MetaModifier)\n {\n winMod |= MOD_WIN; // Windows 键\n }\n\n return winMod;\n}\n static QtCombinedKey toQtCombinedKey(const QString& keyText) {\n QKeySequence sequence = QKeySequence(keyText);\n\n if (!sequence.isEmpty())\n {\n int combinedKey = sequence[0];\n Qt::KeyboardModifiers modifier =\n Qt::KeyboardModifiers(combinedKey & Qt::KeyboardModifierMask);\n int key = combinedKey & ~Qt::KeyboardModifierMask;\n return QtCombinedKey{ key, modifier };\n }\n else\n {\n return QtCombinedKey{ 0, Qt::NoModifier };\n }\n}\n static QString wrapText(QString keyText) {\n return keyText.replace(\"Up\", \"⬆️\")\n .replace(\"Down\", \"⬇️\")\n .replace(\"Left\", \"⬅️\")\n .replace(\"Right\", \"➡️\");\n}\n UINT getVK() {\n return toVK(m_key, m_modifier);\n}\n UINT getModifier() {\n return toModifier(m_modifier);\n}\n QtCombinedKey getQtCombinedKey() {\n return QtCombinedKey{ m_key, m_modifier };\n}\n QString getKeyText() {\n return keySequence().toString(QKeySequence::NativeText);\n}\n protected:\n ", "suffix_code": "\n private:\n void update() {\n QKeySequence sequence = keySequence();\n\n if (sequence.isEmpty())\n {\n m_key = 0;\n m_modifier = Qt::NoModifier;\n }\n else\n {\n int combinedKey = sequence[0];\n m_modifier =\n Qt::KeyboardModifiers(combinedKey & Qt::KeyboardModifierMask);\n m_key = combinedKey & ~Qt::KeyboardModifierMask;\n }\n}\n private:\n bool isModifierKey(int key) const {\n return (key == Qt::Key_Control || key == Qt::Key_Alt ||\n key == Qt::Key_Shift || key == Qt::Key_Meta);\n}\n int m_key;\n Qt::KeyboardModifiers m_modifier;\n};", "middle_code": "void keyPressEvent(QKeyEvent* event) override {\n int key = event->key();\n Qt::KeyboardModifiers modifiers = event->modifiers();\n if (isModifierKey(key))\n {\n return;\n }\n m_key = key;\n m_modifier = modifiers;\n QKeySequence singleKey(key | modifiers);\n setKeySequence(singleKey);\n emit editingFinished();\n clearFocus();\n}", "code_description": null, "fill_type": "FUNCTION_TYPE", "language_type": "cpp", "sub_task_type": null}, "context_code": [["/OpenSpeedy/preferencedialog.h", "class PreferenceDialog {\n Q_OBJECT\n\n public:\n explicit PreferenceDialog(HWND hMainWindow,\n QSettings* settings,\n QLabel* increaseSpeedLabel,\n QLabel* decreaseSpeedLabel,\n QLabel* resetSpeedLabel,\n QWidget* parent = nullptr);\n ~PreferenceDialog() {\n unregisterGlobalHotkeys();\n delete ui;\n}\n int getIncreaseStep() {\n return m_increaseStep;\n}\n int getDecreaseStep() {\n return m_decreaseStep;\n}\n double getShift1() {\n return m_shift1Value;\n}\n double getShift2() {\n return m_shift2Value;\n}\n double getShift3() {\n return m_shift3Value;\n}\n double getShift4() {\n return m_shift4Value;\n}\n double getShift5() {\n return m_shift5Value;\n}\n public:\n void show() {\n unregisterGlobalHotkeys();\n QDialog::show();\n}\n private:\n void on_buttonBox_accepted() {\n update();\n setupGlobalHotkeys();\n redraw();\n dump();\n}\n void on_buttonBox_rejected() {\n redraw();\n setupGlobalHotkeys();\n}\n void recreate() {\n layout()->invalidate();\n layout()->activate();\n adjustSize();\n}\n private:\n void setupGlobalHotkeys() {\n for (auto it = m_shortcuts.begin(); it != m_shortcuts.end(); it++)\n {\n int id = it.key();\n QtCombinedKey combined = it.value();\n\n UINT vk = QSingleKeySequenceEdit::toVK(combined.key, combined.modifier);\n UINT modifier = QSingleKeySequenceEdit::toModifier(combined.modifier);\n RegisterHotKey(m_mainwindow, id, modifier, vk);\n }\n\n qDebug() << \"全局快捷键已注册:\";\n}\n void unregisterGlobalHotkeys() {\n for (auto it = m_shortcuts.begin(); it != m_shortcuts.end(); it++)\n {\n int id = it.key();\n UnregisterHotKey(m_mainwindow, id);\n }\n qDebug() << \"全局快捷键已注销\";\n}\n void loadShortcut(int id,\n const QString& config,\n const QString& defaultValue) {\n m_shortcuts.insert(id,\n QSingleKeySequenceEdit::toQtCombinedKey(\n m_settings->value(config, defaultValue).toString()));\n}\n void dumpShortcut(const QString& config, const QString& keyText) {\n m_settings->setValue(config, keyText);\n}\n void dump() {\n dumpShortcut(CONFIG_HOTKEY_SPEEDUP,\n ui->speedUpKeySequenceEdit->getKeyText());\n dumpShortcut(CONFIG_HOTKEY_SPEEDDOWN,\n ui->speedDownKeySequenceEdit->getKeyText());\n dumpShortcut(CONFIG_HOTKEY_RESETSPEED,\n ui->resetSpeedKeySequenceEdit->getKeyText());\n\n dumpShortcut(CONFIG_HOTKEY_SHIFT1, ui->shift1KeySequenceEdit->getKeyText());\n dumpShortcut(CONFIG_HOTKEY_SHIFT2, ui->shift2KeySequenceEdit->getKeyText());\n dumpShortcut(CONFIG_HOTKEY_SHIFT3, ui->shift3KeySequenceEdit->getKeyText());\n dumpShortcut(CONFIG_HOTKEY_SHIFT4, ui->shift4KeySequenceEdit->getKeyText());\n dumpShortcut(CONFIG_HOTKEY_SHIFT5, ui->shift5KeySequenceEdit->getKeyText());\n m_settings->setValue(CONFIG_INCREASE_STEP,\n ui->increaseStepSpinBox->value());\n m_settings->setValue(CONFIG_DECREASE_STEP,\n ui->decreaseStepSpinBox->value());\n m_settings->setValue(CONFIG_SHIFT1_VALUE, ui->shift1DoubleSpinBox->value());\n m_settings->setValue(CONFIG_SHIFT2_VALUE, ui->shift2DoubleSpinBox->value());\n m_settings->setValue(CONFIG_SHIFT3_VALUE, ui->shift3DoubleSpinBox->value());\n m_settings->setValue(CONFIG_SHIFT4_VALUE, ui->shift4DoubleSpinBox->value());\n m_settings->setValue(CONFIG_SHIFT5_VALUE, ui->shift5DoubleSpinBox->value());\n m_settings->sync();\n}\n void updateShortcut(int id, QSingleKeySequenceEdit* keyEdit) {\n m_shortcuts[id] = keyEdit->getQtCombinedKey();\n}\n void update() {\n updateShortcut(HOTKEY_INCREASE_SPEED, ui->speedUpKeySequenceEdit);\n updateShortcut(HOTKEY_DECREASE_SPEED, ui->speedDownKeySequenceEdit);\n updateShortcut(HOTKEY_RESET_SPEED, ui->resetSpeedKeySequenceEdit);\n updateShortcut(HOTKEY_SHIFT1, ui->shift1KeySequenceEdit);\n updateShortcut(HOTKEY_SHIFT2, ui->shift2KeySequenceEdit);\n updateShortcut(HOTKEY_SHIFT3, ui->shift3KeySequenceEdit);\n updateShortcut(HOTKEY_SHIFT4, ui->shift4KeySequenceEdit);\n updateShortcut(HOTKEY_SHIFT5, ui->shift5KeySequenceEdit);\n\n m_increaseStep = ui->increaseStepSpinBox->value();\n m_decreaseStep = ui->decreaseStepSpinBox->value();\n m_shift1Value = ui->shift1DoubleSpinBox->value();\n m_shift2Value = ui->shift2DoubleSpinBox->value();\n m_shift3Value = ui->shift3DoubleSpinBox->value();\n m_shift4Value = ui->shift4DoubleSpinBox->value();\n m_shift5Value = ui->shift5DoubleSpinBox->value();\n}\n void redrawSpinBox(QSpinBox* spinbox, int value) {\n spinbox->setValue(value);\n}\n void redrawSpinBox(QDoubleSpinBox* spinbox, double value) {\n spinbox->setValue(value);\n}\n void redrawKeyEdit(QSingleKeySequenceEdit* keyEdit, int id) {\n QtCombinedKey combinedKey = m_shortcuts[id];\n keyEdit->setKeySequence(combinedKey.key | combinedKey.modifier);\n}\n void redraw() {\n redrawKeyEdit(ui->speedUpKeySequenceEdit, HOTKEY_INCREASE_SPEED);\n redrawKeyEdit(ui->speedDownKeySequenceEdit, HOTKEY_DECREASE_SPEED);\n redrawKeyEdit(ui->resetSpeedKeySequenceEdit, HOTKEY_RESET_SPEED);\n redrawKeyEdit(ui->shift1KeySequenceEdit, HOTKEY_SHIFT1);\n redrawKeyEdit(ui->shift2KeySequenceEdit, HOTKEY_SHIFT2);\n redrawKeyEdit(ui->shift3KeySequenceEdit, HOTKEY_SHIFT3);\n redrawKeyEdit(ui->shift4KeySequenceEdit, HOTKEY_SHIFT4);\n redrawKeyEdit(ui->shift5KeySequenceEdit, HOTKEY_SHIFT5);\n\n redrawSpinBox(ui->increaseStepSpinBox, m_increaseStep);\n redrawSpinBox(ui->decreaseStepSpinBox, m_decreaseStep);\n redrawSpinBox(ui->shift1DoubleSpinBox, m_shift1Value);\n redrawSpinBox(ui->shift2DoubleSpinBox, m_shift2Value);\n redrawSpinBox(ui->shift3DoubleSpinBox, m_shift3Value);\n redrawSpinBox(ui->shift4DoubleSpinBox, m_shift4Value);\n redrawSpinBox(ui->shift5DoubleSpinBox, m_shift5Value);\n\n m_increaseSpeedLabel->setText(\n QString(tr(\"%1 增加速度\"))\n .arg(QSingleKeySequenceEdit::wrapText(\n ui->speedUpKeySequenceEdit->getKeyText())));\n\n m_decreaseSpeedLabel->setText(\n QString(tr(\"%1 减少速度\"))\n .arg(QSingleKeySequenceEdit::wrapText(\n ui->speedDownKeySequenceEdit->getKeyText())));\n\n m_resetSpeedLabel->setText(\n QString(tr(\"%1 重置速度\"))\n .arg(QSingleKeySequenceEdit::wrapText(\n ui->resetSpeedKeySequenceEdit->getKeyText())));\n\n adjustSize();\n}\n Ui::PreferenceDialog* ui;\n QSettings* m_settings;\n QLabel* m_increaseSpeedLabel;\n QLabel* m_decreaseSpeedLabel;\n QLabel* m_resetSpeedLabel;\n QMap m_shortcuts;\n double m_shift1Value;\n double m_shift2Value;\n double m_shift3Value;\n double m_shift4Value;\n double m_shift5Value;\n int m_increaseStep;\n int m_decreaseStep;\n HWND m_mainwindow;\n};"], ["/OpenSpeedy/processmonitor.h", "class ProcessMonitor {\n Q_OBJECT\npublic:\nexplicit ProcessMonitor(QSettings* settings,\n QTreeWidget* treeWidget,\n QLabel* treeStatusLabel,\n QLabel* injector32StatusLabel,\n QLabel* injector64StatusLabel,\n\n QObject* parent = nullptr);\n ~ProcessMonitor() {\n this->terminalBridge();\n delete m_bridge32;\n delete m_bridge64;\n}\n void setInterval(int msec);\n void setFilter(QString processName) {\n m_filter = processName.toLower();\n}\n void changeSpeed(double factor) {\n QString cmd = QString(\"change %1\\n\").arg(factor);\n m_bridge32->write(cmd.toUtf8(), cmd.size());\n m_bridge32->waitForBytesWritten();\n m_bridge64->write(cmd.toUtf8(), cmd.size());\n m_bridge64->waitForBytesWritten();\n}\n public:\n void refresh() {\n healthcheckBridge();\n QList processList = winutils::getProcessList();\n if (m_filter == \"\")\n {\n update(processList);\n m_treeStatusLabel->setText(QString(tr(\"搜索到%1个进程, 已过滤展示%2个\"))\n .arg(processList.size())\n .arg(processList.size()));\n }\n else\n {\n QList filtered;\n for (ProcessInfo info : processList)\n {\n if (info.name.toLower().contains(m_filter))\n filtered.append(info);\n }\n update(filtered);\n m_treeStatusLabel->setText(QString(tr(\"搜索到%1个进程, 已过滤展示%2个\"))\n .arg(processList.size())\n .arg(filtered.size()));\n }\n}\n void start() {\n m_timer = new QTimer(this);\n connect(m_timer, &QTimer::timeout, this, &ProcessMonitor::refresh);\n m_timer->start(1000);\n}\n private:\n void onItemChanged(QTreeWidgetItem* item, int column) {\n if (column == 5 && (item->flags() & Qt::ItemIsUserCheckable))\n {\n bool state = m_treeWidget->blockSignals(true);\n\n Qt::CheckState checkState = item->checkState(column);\n QString processName = item->text(0);\n DWORD pid = item->text(1).toLong();\n bool is64Bit = item->text(3) == \"x64\" ? true : false;\n if (checkState == Qt::Checked)\n {\n m_targetNames.insert(processName);\n this->injectDll(pid, is64Bit);\n item->setText(5, tr(\"加速中\"));\n for (int col = 0; col < item->columnCount(); ++col)\n {\n item->setBackground(col, QBrush(QColor(\"#f3e5f5\")));\n item->setForeground(col, QBrush(QColor(\"#7b1fa2\")));\n }\n qDebug() << processName << \"勾选\";\n dump();\n }\n else\n {\n m_targetNames.remove(processName);\n this->unhookDll(pid, is64Bit);\n item->setText(5, \"\");\n for (int col = 0; col < item->columnCount(); ++col)\n {\n item->setBackground(col, QBrush());\n item->setForeground(col, QBrush());\n }\n qDebug() << processName << \"取消勾选\";\n dump();\n }\n\n m_treeWidget->blockSignals(state);\n }\n}\n private:\n QTreeWidget* m_treeWidget;\n QLabel* m_treeStatusLabel;\n QLabel* m_injector32StatusLabel;\n QLabel* m_injector64StatusLabel;\n QString m_filter;\n QTimer* m_timer = nullptr;\n QString m_dllPath;\n QProcess* m_bridge32;\n QProcess* m_bridge64;\n QSettings* m_settings;\n QHash m_iconCache;\n QMap m_processItems;\n QSet m_targetNames;\n void init() {\n QStringList targetNames =\n m_settings->value(CONFIG_TARGETNAMES_KEY).toStringList();\n m_targetNames = QSet(targetNames.begin(), targetNames.end());\n}\n void dump() {\n m_settings->setValue(CONFIG_TARGETNAMES_KEY,\n QStringList(m_targetNames.values()));\n}\n void update(const QList& processList) {\n // 跟踪现有进程,用于确定哪些已终止\n QSet currentPids;\n for (const ProcessInfo& info : processList)\n {\n currentPids.insert(info.pid);\n }\n\n // 移除已终止的进程\n QMutableMapIterator i(m_processItems);\n while (i.hasNext())\n {\n i.next();\n if (!currentPids.contains(i.key()))\n {\n QTreeWidgetItem* item = i.value();\n QTreeWidgetItem* parent = item->parent();\n\n if (parent)\n {\n parent->removeChild(item);\n }\n else\n {\n auto index = m_treeWidget->indexOfTopLevelItem(item);\n m_treeWidget->takeTopLevelItem(index);\n }\n\n while (item->childCount() > 0)\n {\n QTreeWidgetItem* child = item->takeChild(0);\n if (parent)\n {\n parent->addChild(child);\n }\n else\n {\n m_treeWidget->addTopLevelItem(child);\n }\n }\n\n // 删除节点\n delete item;\n\n // 从映射中移除\n i.remove();\n }\n }\n\n // 添加或更新进程信息\n for (const ProcessInfo& info : processList)\n {\n if (m_processItems.contains(info.pid))\n {\n // 更新已存在的进程信息\n QTreeWidgetItem* item = m_processItems[info.pid];\n item->setText(1, QString::number(info.pid));\n item->setData(1, Qt::UserRole, (long long)info.pid);\n item->setText(2,\n QString(\"%1 MB\").arg(info.memoryUsage / 1024 / 1024));\n item->setData(2, Qt::UserRole, (uint)info.memoryUsage);\n\n QString arch = info.is64Bit ? \"x64\" : \"x86\";\n item->setText(3, arch);\n QString priority;\n switch (info.priorityClass)\n {\n case HIGH_PRIORITY_CLASS:\n priority = tr(\"高\");\n break;\n case NORMAL_PRIORITY_CLASS:\n priority = tr(\"中\");\n break;\n case IDLE_PRIORITY_CLASS:\n priority = tr(\"低\");\n break;\n case REALTIME_PRIORITY_CLASS:\n priority = tr(\"实时\");\n break;\n default:\n priority = tr(\"未知\");\n break;\n }\n item->setText(4, priority);\n if (m_targetNames.contains(info.name))\n {\n if (item->checkState(5) == Qt::Unchecked)\n {\n item->setCheckState(5, Qt::Checked);\n }\n }\n else\n {\n if (item->checkState(5) == Qt::Checked)\n {\n item->setCheckState(5, Qt::Unchecked);\n }\n }\n }\n else\n {\n // 添加新进程\n QTreeWidgetItem* item = new SortTreeWidgetItem();\n\n item->setText(0, info.name);\n item->setData(0, Qt::UserRole, info.name.toLower());\n item->setText(1, QString::number(info.pid));\n item->setData(1, Qt::UserRole, (long long)info.pid);\n item->setText(2,\n QString(\"%1 MB\").arg(info.memoryUsage / 1024 / 1024));\n item->setData(2, Qt::UserRole, (uint)info.memoryUsage);\n\n QString arch = info.is64Bit ? \"x64\" : \"x86\";\n item->setText(3, arch);\n\n // 加载进程图标\n item->setIcon(0, getProcessIconCached(info.pid));\n\n QString priority;\n switch (info.priorityClass)\n {\n case HIGH_PRIORITY_CLASS:\n priority = tr(\"高\");\n break;\n case NORMAL_PRIORITY_CLASS:\n priority = tr(\"中\");\n break;\n case IDLE_PRIORITY_CLASS:\n priority = tr(\"低\");\n break;\n case REALTIME_PRIORITY_CLASS:\n priority = tr(\"实时\");\n break;\n default:\n priority = tr(\"未知\");\n break;\n }\n item->setText(4, priority);\n item->setCheckState(5, Qt::Unchecked);\n m_treeWidget->addTopLevelItem(item);\n m_processItems[info.pid] = item;\n }\n }\n}\n void injectDll(DWORD processId, bool is64Bit) {\n QString cmd = QString(\"inject %1\\n\").arg(processId);\n if (!is64Bit)\n {\n m_bridge32->write(cmd.toUtf8(), cmd.size());\n m_bridge32->waitForBytesWritten();\n }\n else\n {\n m_bridge64->write(cmd.toUtf8(), cmd.size());\n m_bridge64->waitForBytesWritten();\n }\n}\n void unhookDll(DWORD processId, bool is64Bit) {\n QString cmd = QString(\"unhook %1\\n\").arg(processId);\n if (!is64Bit)\n {\n m_bridge32->write(cmd.toUtf8(), cmd.size());\n m_bridge32->waitForBytesWritten();\n }\n else\n {\n m_bridge64->write(cmd.toUtf8(), cmd.size());\n m_bridge64->waitForBytesWritten();\n }\n}\n void startBridge32() {\n m_bridge32 = new QProcess();\n QStringList params32;\n m_bridge32->start(BRIDGE32_EXE, params32);\n if (!m_bridge32->waitForStarted())\n {\n qDebug() << \"32位桥接子进程启动失败\";\n }\n else\n {\n qDebug() << \"32位桥接子进程已启动\";\n }\n m_bridge32->setProcessChannelMode(QProcess::MergedChannels);\n connect(m_bridge32,\n &QProcess::readyReadStandardOutput,\n [&]()\n {\n QByteArray data = m_bridge32->readAllStandardOutput();\n qDebug() << \"收到输出:\" << QString(data).trimmed();\n });\n}\n void startBridge64() {\n m_bridge64 = new QProcess();\n QStringList params64;\n m_bridge64->start(BRIDGE64_EXE, params64);\n if (!m_bridge64->waitForStarted())\n {\n qDebug() << \"64位桥接子进程启动失败\";\n }\n else\n {\n qDebug() << \"64位桥接子进程已启动\";\n }\n m_bridge64->setProcessChannelMode(QProcess::MergedChannels);\n connect(m_bridge64,\n &QProcess::readyReadStandardOutput,\n [&]()\n {\n QByteArray data = m_bridge64->readAllStandardOutput();\n qDebug() << \"收到输出:\" << QString(data).trimmed();\n });\n}\n void healthcheckBridge() {\n if (this->m_bridge32->state() == QProcess::Running)\n {\n m_injector32StatusLabel->setStyleSheet(\"color: green\");\n m_injector32StatusLabel->setText(tr(\"正常\"));\n }\n else\n {\n m_injector32StatusLabel->setStyleSheet(\"color: red\");\n m_injector32StatusLabel->setText(tr(\"异常退出\"));\n }\n\n if (this->m_bridge64->state() == QProcess::Running)\n {\n m_injector64StatusLabel->setStyleSheet(\"color: green\");\n m_injector64StatusLabel->setText(tr(\"正常\"));\n }\n else\n {\n m_injector64StatusLabel->setStyleSheet(\"color:red\");\n m_injector64StatusLabel->setText(tr(\"异常退出\"));\n }\n}\n void terminalBridge() {\n QString cmd = QString(\"exit\\n\");\n m_bridge32->write(cmd.toUtf8(), cmd.size());\n m_bridge32->waitForBytesWritten();\n m_bridge64->write(cmd.toUtf8(), cmd.size());\n m_bridge64->waitForBytesWritten();\n}\n static QIcon getProcessIcon(QString processPath) {\n int lastSlashPos =\n std::max(processPath.lastIndexOf('/'), processPath.lastIndexOf('\\\\'));\n QString processName;\n if (lastSlashPos == -1)\n {\n processName = processPath;\n }\n processName = processPath.mid(lastSlashPos + 1);\n\n if (processPath.isEmpty())\n {\n qDebug() << processPath << \"无法获取进程完整路径\";\n return getDefaultIcon(processName);\n }\n\n SHFILEINFO sfi = {};\n if (SHGetFileInfo(reinterpret_cast(processPath.utf16()),\n FILE_ATTRIBUTE_NORMAL,\n &sfi,\n sizeof(SHFILEINFO),\n SHGFI_ICON | SHGFI_LARGEICON | SHGFI_USEFILEATTRIBUTES))\n {\n if (sfi.hIcon)\n {\n QIcon icon = QtWin::fromHICON(sfi.hIcon);\n DestroyIcon(sfi.hIcon);\n if (!icon.isNull())\n {\n qDebug() << processPath << \"通过SHGetFileInfo获取图标成功\";\n return icon;\n }\n }\n }\n\n HICON hIcon =\n ExtractIconW(nullptr, reinterpret_cast(processPath.utf16()), 0);\n if (hIcon)\n {\n QIcon icon = QtWin::fromHICON(hIcon);\n DestroyIcon(hIcon);\n if (!icon.isNull())\n return icon;\n }\n\n QFileInfo fileInfo(processPath);\n if (fileInfo.exists())\n {\n // 使用Qt的QFileIconProvider获取文件图标\n QFileIconProvider iconProvider;\n return iconProvider.icon(fileInfo);\n }\n qDebug() << processPath << \"无法获取进程图标使用默认图标\";\n\n return getDefaultIcon(processName);\n}\n static QIcon getDefaultIcon(const QString& processName) {\n // 根据进程名称或类型提供更有针对性的默认图标\n if (processName != \"\")\n {\n // 使用SHGetFileInfo获取.exe文件的图标\n SHFILEINFO sfi = {};\n QIcon icon;\n if (SHGetFileInfo(reinterpret_cast(processName.utf16()),\n FILE_ATTRIBUTE_NORMAL,\n &sfi,\n sizeof(SHFILEINFO),\n SHGFI_USEFILEATTRIBUTES | SHGFI_ICON |\n SHGFI_SMALLICON))\n {\n // 将HICON转换为QIcon\n icon = QtWin::fromHICON(sfi.hIcon);\n\n // 释放图标资源\n DestroyIcon(sfi.hIcon);\n }\n return icon;\n }\n else\n {\n // 使用SHGetFileInfo获取.exe文件的图标\n SHFILEINFO sfi = {};\n QIcon icon;\n if (SHGetFileInfo(reinterpret_cast(L\".exe\"),\n FILE_ATTRIBUTE_NORMAL,\n &sfi,\n sizeof(SHFILEINFO),\n SHGFI_USEFILEATTRIBUTES | SHGFI_ICON |\n SHGFI_SMALLICON))\n {\n // 将HICON转换为QIcon\n icon = QtWin::fromHICON(sfi.hIcon);\n\n // 释放图标资源\n DestroyIcon(sfi.hIcon);\n }\n return icon;\n }\n}\n QIcon getProcessIconCached(DWORD proccessId) {\n QString processPath = winutils::getProcessPath(processId);\n if (m_iconCache.contains(processPath))\n {\n return m_iconCache[processPath];\n }\n\n QIcon icon = getProcessIcon(processPath);\n m_iconCache.insert(processPath, icon);\n return icon;\n}\n public:\n};"], ["/OpenSpeedy/winutils.h", "class winutils {\n public:\n winutils() {\n}\n public:\n static bool injectDll(DWORD processId, const QString& dllPath) {\n HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);\n if (!hProcess)\n {\n qDebug() << \"Failed to open process:\" << GetLastError();\n return false;\n }\n\n if (checkDllExist(processId, dllPath))\n {\n qDebug() << \"Process already have been injected\";\n return true;\n }\n else if (injectDllViaCRTW(processId, dllPath))\n {\n return true;\n }\n else if (injectDllViaCRTA(processId, dllPath))\n {\n return true;\n }\n\n injectDllViaAPCW(processId, dllPath);\n injectDllViaAPCA(processId, dllPath);\n if (checkDllExist(processId, dllPath))\n {\n return true;\n }\n else if (injectDllViaWHKW(processId, dllPath))\n {\n return true;\n }\n else if (injectDllViaWHKA(processId, dllPath))\n {\n return true;\n }\n else\n {\n return false;\n }\n}\n static bool injectDllViaCRTA(DWORD processId, const QString& dllPath) {\n HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);\n if (!hProcess)\n {\n qDebug() << \"Failed to open process:\" << GetLastError();\n return false;\n }\n\n if (checkDllExist(processId, dllPath))\n {\n qDebug() << \"Process already have been injected\";\n return true;\n }\n SIZE_T pathSize = (dllPath.size() + 1) * sizeof(char);\n LPVOID pDllPath =\n VirtualAllocEx(hProcess,\n nullptr,\n pathSize,\n MEM_COMMIT | MEM_RESERVE,\n PAGE_EXECUTE_READWRITE);\n if (!pDllPath)\n {\n qDebug() << \"Failed to allocate memory in target process:\"\n << GetLastError();\n CloseHandle(hProcess);\n return false;\n }\n\n if (!WriteProcessMemory(hProcess,\n pDllPath,\n dllPath.toStdString().c_str(),\n pathSize,\n nullptr))\n {\n qDebug() << \"Failed to write memory in target process:\"\n << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n HMODULE hKernel32 = GetModuleHandle(L\"kernel32.dll\");\n if (!hKernel32)\n {\n qDebug() << \"Failed to get handle for kernel32.dll:\" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n FARPROC pLoadLibraryA = GetProcAddress(hKernel32, \"LoadLibraryA\");\n if (!pLoadLibraryA)\n {\n qDebug() << \"Failed to get address of LoadLibraryA:\" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n HANDLE hThread = CreateRemoteThread(hProcess,\n nullptr,\n 0,\n (LPTHREAD_START_ROUTINE)pLoadLibraryA,\n pDllPath,\n 0,\n nullptr);\n if (!hThread)\n {\n qDebug() << \"Failed to create remote thread:\" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n WaitForSingleObject(hThread, INFINITE);\n\n // 检查LoadLibrary是否执行成功\n DWORD exitCode = 0;\n if (GetExitCodeThread(hThread, &exitCode))\n {\n qDebug() << \"Remote thread exit code:\" << exitCode;\n // LoadLibrary返回的是模块句柄,如果为0则失败\n if (exitCode == 0)\n {\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n CloseHandle(hThread);\n qDebug() << \"LoadLibrary failed in remote process\";\n return false;\n }\n }\n\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hThread);\n CloseHandle(hProcess);\n\n return true;\n}\n static bool injectDllViaCRTW(DWORD processId, const QString& dllPath) {\n HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);\n if (!hProcess)\n {\n qDebug() << \"Failed to open process:\" << GetLastError();\n return false;\n }\n\n if (checkDllExist(processId, dllPath))\n {\n qDebug() << \"Process already have been injected\";\n return true;\n }\n SIZE_T pathSize = (dllPath.size() + 1) * sizeof(wchar_t);\n LPVOID pDllPath =\n VirtualAllocEx(hProcess, nullptr, pathSize, MEM_COMMIT | MEM_RESERVE,\n PAGE_EXECUTE_READWRITE);\n if (!pDllPath)\n {\n qDebug() << \"Failed to allocate memory in target process:\"\n << GetLastError();\n CloseHandle(hProcess);\n return false;\n }\n\n if (!WriteProcessMemory(hProcess,\n pDllPath,\n dllPath.toStdWString().c_str(),\n pathSize,\n nullptr))\n {\n qDebug() << \"Failed to write memory in target process:\"\n << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n HMODULE hKernel32 = GetModuleHandle(L\"kernel32.dll\");\n if (!hKernel32)\n {\n qDebug() << \"Failed to get handle for kernel32.dll:\" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n FARPROC pLoadLibraryW = GetProcAddress(hKernel32, \"LoadLibraryW\");\n if (!pLoadLibraryW)\n {\n qDebug() << \"Failed to get address of LoadLibraryW:\" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n HANDLE hThread = CreateRemoteThread(hProcess,\n nullptr,\n 0,\n (LPTHREAD_START_ROUTINE)pLoadLibraryW,\n pDllPath,\n 0,\n nullptr);\n if (!hThread)\n {\n qDebug() << \"Failed to create remote thread:\" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n WaitForSingleObject(hThread, INFINITE);\n\n // 检查LoadLibrary是否执行成功\n DWORD exitCode = 0;\n if (GetExitCodeThread(hThread, &exitCode))\n {\n qDebug() << \"Remote thread exit code:\" << exitCode;\n // LoadLibrary返回的是模块句柄,如果为0则失败\n if (exitCode == 0)\n {\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n CloseHandle(hThread);\n qDebug() << \"LoadLibrary failed in remote process\";\n return false;\n }\n }\n\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hThread);\n CloseHandle(hProcess);\n\n return true;\n}\n static bool injectDllViaAPCA(DWORD processId, const QString& dllPath) {\n HANDLE hProcess =\n OpenProcess(PROCESS_ALL_ACCESS,\n FALSE,\n processId);\n\n if (!hProcess)\n {\n qDebug() << \"Failed to open process: \" << GetLastError();\n return false;\n }\n\n if (checkDllExist(processId, dllPath))\n {\n qDebug() << \"Process already have been injected\";\n return true;\n }\n\n // 在目标进程中分配内存并写入DLL路径\n SIZE_T pathSize = (dllPath.toStdString().size() + 1) * sizeof(char);\n LPVOID pDllPath = VirtualAllocEx(hProcess,\n NULL,\n pathSize,\n MEM_COMMIT,\n PAGE_READWRITE);\n\n if (!pDllPath)\n {\n qDebug() << \"Failed to allocate memory: \" << GetLastError();\n CloseHandle(hProcess);\n return false;\n }\n\n if (!WriteProcessMemory(hProcess, pDllPath, dllPath.toStdString().c_str(),\n pathSize, NULL))\n {\n qDebug() << \"Failed to write memory: \" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 获取LoadLibraryW的地址\n HMODULE hKernel32 = GetModuleHandle(L\"kernel32.dll\");\n if (!hKernel32)\n {\n qDebug() << \"Failed to get kernel32 handle\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n FARPROC pLoadLibraryA = GetProcAddress(hKernel32, \"LoadLibraryA\");\n if (!pLoadLibraryA)\n {\n qDebug() << \"Failed to get LoadLibraryA address\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 获取进程中的所有线程\n DWORD threadId = getProcessMainThread(processId);\n if (!threadId)\n {\n qDebug() << \"No threads found in the process\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 向目标进程的所有线程队列中添加APC调用\n bool success = false;\n\n // 打开线程\n HANDLE hThread = OpenThread(THREAD_SET_CONTEXT, FALSE, threadId);\n if (hThread)\n {\n // 将LoadLibraryA作为APC函数加入队列\n PostThreadMessageA(threadId, WM_PAINT, 0, 0);\n DWORD result =\n QueueUserAPC((PAPCFUNC)pLoadLibraryA, hThread, (ULONG_PTR)pDllPath);\n PostThreadMessageA(threadId, WM_PAINT, 0, 0);\n if (result != 0)\n {\n success = true;\n qDebug() << \"APC queued to thread \" << threadId;\n }\n\n CloseHandle(hThread);\n }\n\n if (!success)\n {\n qDebug() << \"Failed to queue APC to any thread\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 注意:我们不释放分配的内存,因为APC函数尚未执行\n // 内存将在DLL加载后释放\n\n CloseHandle(hProcess);\n return true;\n}\n static bool injectDllViaAPCW(DWORD processId, const QString& dllPath) {\n HANDLE hProcess =\n OpenProcess(PROCESS_ALL_ACCESS,\n FALSE,\n processId);\n\n if (!hProcess)\n {\n qDebug() << \"Failed to open process: \" << GetLastError();\n return false;\n }\n\n if (checkDllExist(processId, dllPath))\n {\n qDebug() << \"Process already have been injected\";\n return true;\n }\n\n // 在目标进程中分配内存并写入DLL路径\n SIZE_T pathSize = (dllPath.toStdWString().size() + 1) * sizeof(wchar_t);\n LPVOID pDllPath = VirtualAllocEx(hProcess,\n NULL,\n pathSize,\n MEM_COMMIT,\n PAGE_READWRITE);\n\n if (!pDllPath)\n {\n qDebug() << \"Failed to allocate memory: \" << GetLastError();\n CloseHandle(hProcess);\n return false;\n }\n\n if (!WriteProcessMemory(hProcess,\n pDllPath,\n dllPath.toStdWString().c_str(),\n pathSize,\n NULL))\n {\n qDebug() << \"Failed to write memory: \" << GetLastError();\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 获取LoadLibraryW的地址\n HMODULE hKernel32 = GetModuleHandle(L\"kernel32.dll\");\n if (!hKernel32)\n {\n qDebug() << \"Failed to get kernel32 handle\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n FARPROC pLoadLibraryW = GetProcAddress(hKernel32, \"LoadLibraryW\");\n if (!pLoadLibraryW)\n {\n qDebug() << \"Failed to get LoadLibraryW address\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 获取进程中的所有线程\n DWORD threadId = getProcessMainThread(processId);\n if (!threadId)\n {\n qDebug() << \"No threads found in the process\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 向目标进程的所有线程队列中添加APC调用\n bool success = false;\n\n // 打开线程\n HANDLE hThread = OpenThread(THREAD_SET_CONTEXT, FALSE, threadId);\n if (hThread)\n {\n // 将LoadLibraryW作为APC函数加入队列\n PostThreadMessageW(threadId, WM_PAINT, 0, 0);\n DWORD result =\n QueueUserAPC((PAPCFUNC)pLoadLibraryW, hThread, (ULONG_PTR)pDllPath);\n PostThreadMessageW(threadId, WM_PAINT, 0, 0);\n if (result != 0)\n {\n success = true;\n qDebug() << \"APC queued to thread \" << threadId;\n }\n\n CloseHandle(hThread);\n }\n\n if (!success)\n {\n qDebug() << \"Failed to queue APC to any thread\";\n VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE);\n CloseHandle(hProcess);\n return false;\n }\n\n // 注意:我们不释放分配的内存,因为APC函数尚未执行\n // 内存将在DLL加载后释放\n\n CloseHandle(hProcess);\n return true;\n}\n static bool injectDllViaWHKA(DWORD processId, const QString& dllPath) {\n if (checkProcessProtection(processId))\n {\n qDebug() << \"进程被保护 进程ID: \" << processId;\n return false;\n }\n\n // 1. 加载DLL到当前进程\n HMODULE hMod = LoadLibraryA(dllPath.toStdString().c_str());\n if (!hMod)\n return false;\n\n // 2. 获取Hook过程的地址\n HOOKPROC hookProc = (HOOKPROC)GetProcAddress(hMod, \"HookProc\");\n if (!hookProc)\n return false;\n\n // 3. 获取目标线程ID\n DWORD threadId = getProcessMainThread(processId);\n if (threadId == 0)\n return false;\n\n // 4. 安装Hook\n HHOOK hHook = SetWindowsHookExA(WH_CBT, // Hook类型\n hookProc, // Hook过程\n hMod, // DLL模块句柄\n threadId // 目标线程ID\n );\n\n if (!hHook)\n return false;\n // 5. 触发Hook执行\n PostThreadMessageA(threadId, WM_NULL, 0, 0);\n Sleep(5000);\n UnhookWindowsHookEx(hHook);\n\n return true;\n}\n static bool injectDllViaWHKW(DWORD processId, const QString& dllPath) {\n if (checkProcessProtection(processId))\n {\n qDebug() << \"进程被保护 进程ID: \" << processId;\n return false;\n }\n\n // 1. 加载DLL到当前进程\n HMODULE hMod = LoadLibraryW(dllPath.toStdWString().c_str());\n if (!hMod)\n return false;\n\n // 2. 获取Hook过程的地址\n HOOKPROC hookProc = (HOOKPROC)GetProcAddress(hMod, \"HookProc\");\n if (!hookProc)\n return false;\n\n // 3. 获取目标线程ID\n DWORD threadId = getProcessMainThread(processId);\n if (threadId == 0)\n return false;\n\n // 4. 安装Hook\n HHOOK hHook = SetWindowsHookExW(WH_CBT, // Hook类型\n hookProc, // Hook过程\n hMod, // DLL模块句柄\n threadId // 目标线程ID\n );\n\n if (!hHook)\n return false;\n // 5. 触发Hook执行\n PostThreadMessageW(threadId, WM_NULL, 0, 0);\n Sleep(5000);\n UnhookWindowsHookEx(hHook);\n\n return true;\n}\n static bool unhookDll(DWORD processId, const QString& dllPath) {\n HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);\n if (!hProcess)\n {\n qDebug() << \"Failed to open process:\" << GetLastError();\n return false;\n }\n\n HMODULE hModules[1024];\n DWORD cbNeeded;\n if (EnumProcessModules(hProcess, hModules, sizeof(hModules), &cbNeeded))\n {\n for (unsigned int i = 0; i < (cbNeeded / sizeof(HMODULE)); i++)\n {\n TCHAR moduleName[MAX_PATH];\n if (GetModuleFileNameEx(hProcess, hModules[i], moduleName,\n sizeof(moduleName) / sizeof(TCHAR)))\n {\n#ifdef UNICODE\n bool isDll = dllPath.toStdWString() == moduleName;\n#else\n bool isDll = dllPath.toStdString() == moduleName;\n#endif\n if (isDll)\n {\n FARPROC pFreeLibrary = GetProcAddress(\n GetModuleHandle(L\"kernel32.dll\"), \"FreeLibrary\");\n if (!pFreeLibrary)\n {\n qDebug() << \"Failed to get address of FreeLibrary:\"\n << GetLastError();\n CloseHandle(hProcess);\n return false;\n }\n\n HANDLE hThread =\n CreateRemoteThread(hProcess, nullptr, 0,\n (LPTHREAD_START_ROUTINE)pFreeLibrary,\n hModules[i], 0, nullptr);\n if (!hThread)\n {\n qDebug() << \"Failed to create remote thread for \"\n \"FreeLibrary:\"\n << GetLastError();\n CloseHandle(hProcess);\n return false;\n }\n\n WaitForSingleObject(hThread, INFINITE);\n CloseHandle(hThread);\n CloseHandle(hProcess);\n return true;\n }\n }\n }\n }\n\n CloseHandle(hProcess);\n return false;\n}\n static bool checkDllExist(DWORD processId, const QString& dllPath) {\n HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,\n FALSE,\n processId);\n if (!hProcess)\n {\n qDebug() << \"打开进程失败:\" << GetLastError();\n return false;\n }\n\n bool dllFound = false;\n HMODULE hModules[1024];\n DWORD cbNeeded;\n\n // 获取进程中所有已加载的模块\n if (EnumProcessModules(hProcess, hModules, sizeof(hModules), &cbNeeded))\n {\n DWORD moduleCount = cbNeeded / sizeof(HMODULE);\n for (DWORD i = 0; i < moduleCount; i++)\n {\n TCHAR moduleName[MAX_PATH] = {0};\n\n // 获取模块的完整路径\n if (GetModuleFileNameExW(hProcess, hModules[i], moduleName,\n sizeof(moduleName) / sizeof(TCHAR)))\n {\n#ifdef UNICODE\n bool isDll = dllPath.toStdWString() == moduleName;\n#else\n bool isDll = dllPath.toStdString() == moduleName;\n#endif\n if (isDll)\n {\n dllFound = true;\n break;\n }\n }\n }\n }\n else\n {\n qDebug() << \"枚举进程模块失败:\" << GetLastError();\n }\n\n CloseHandle(hProcess);\n return dllFound;\n}\n static bool checkProcessProtection(DWORD processId) {\n HANDLE hProcess =\n OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, processId);\n if (!hProcess)\n {\n qDebug() << \"Cannot open process - likely protected\";\n return true; // 可能被保护\n }\n\n // 检查是否是受保护进程\n PROCESS_PROTECTION_LEVEL_INFORMATION protectionInfo = {};\n DWORD returnLength;\n\n if (GetProcessInformation(hProcess, ProcessProtectionLevelInfo,\n &protectionInfo, sizeof(protectionInfo)))\n {\n CloseHandle(hProcess);\n return protectionInfo.ProtectionLevel != PROTECTION_LEVEL_NONE;\n }\n\n CloseHandle(hProcess);\n return false;\n}\n static void setAutoStart(bool enable,\n const QString& appName,\n const QString& execPath) {\n TaskScheduler scheduler;\n\n if (enable)\n {\n scheduler.createStartupShortcut(appName, execPath);\n }\n else\n {\n scheduler.deleteStartupShortcut(appName);\n }\n}\n static bool isAutoStartEnabled(const QString& appName) {\n TaskScheduler scheduler;\n return scheduler.isStartupShortcutExists(appName);\n}\n static BOOL getWindowsVersion(DWORD* majorVersion,\n DWORD* minorVersion,\n DWORD* buildNumber) {\n static char version[100] = {0};\n DWORD major, minor, build;\n\n if (!getWindowsVersion(&major, &minor, &build))\n return \"Unknown Windows Version\";\n\n // 确定Windows版本\n if (major == 10)\n {\n if (build >= 22000)\n {\n sprintf(version, \"Windows 11 (Build %lu)\", build);\n }\n else\n {\n sprintf(version, \"Windows 10 (Build %lu)\", build);\n }\n }\n else if (major == 6)\n {\n switch (minor)\n {\n case 3:\n sprintf(version, \"Windows 8.1 (Build %lu)\", build);\n break;\n case 2:\n sprintf(version, \"Windows 8 (Build %lu)\", build);\n break;\n case 1:\n sprintf(version, \"Windows 7 (Build %lu)\", build);\n break;\n case 0:\n sprintf(version, \"Windows Vista (Build %lu)\", build);\n break;\n default:\n sprintf(version, \"Windows NT %lu.%lu (Build %lu)\", major, minor,\n build);\n }\n }\n else if (major == 5)\n {\n switch (minor)\n {\n case 2:\n sprintf(version, \"Windows Server 2003 (Build %lu)\", build);\n break;\n case 1:\n sprintf(version, \"Windows XP (Build %lu)\", build);\n break;\n case 0:\n sprintf(version, \"Windows 2000 (Build %lu)\", build);\n break;\n default:\n sprintf(version, \"Windows NT %lu.%lu (Build %lu)\", major, minor,\n build);\n }\n }\n else\n {\n sprintf(version, \"Windows NT %lu.%lu (Build %lu)\", major, minor, build);\n }\n return version;\n}\n static QString getWindowsVersion() {\n static char version[100] = {0};\n DWORD major, minor, build;\n\n if (!getWindowsVersion(&major, &minor, &build))\n return \"Unknown Windows Version\";\n\n // 确定Windows版本\n if (major == 10)\n {\n if (build >= 22000)\n {\n sprintf(version, \"Windows 11 (Build %lu)\", build);\n }\n else\n {\n sprintf(version, \"Windows 10 (Build %lu)\", build);\n }\n }\n else if (major == 6)\n {\n switch (minor)\n {\n case 3:\n sprintf(version, \"Windows 8.1 (Build %lu)\", build);\n break;\n case 2:\n sprintf(version, \"Windows 8 (Build %lu)\", build);\n break;\n case 1:\n sprintf(version, \"Windows 7 (Build %lu)\", build);\n break;\n case 0:\n sprintf(version, \"Windows Vista (Build %lu)\", build);\n break;\n default:\n sprintf(version, \"Windows NT %lu.%lu (Build %lu)\", major, minor,\n build);\n }\n }\n else if (major == 5)\n {\n switch (minor)\n {\n case 2:\n sprintf(version, \"Windows Server 2003 (Build %lu)\", build);\n break;\n case 1:\n sprintf(version, \"Windows XP (Build %lu)\", build);\n break;\n case 0:\n sprintf(version, \"Windows 2000 (Build %lu)\", build);\n break;\n default:\n sprintf(version, \"Windows NT %lu.%lu (Build %lu)\", major, minor,\n build);\n }\n }\n else\n {\n sprintf(version, \"Windows NT %lu.%lu (Build %lu)\", major, minor, build);\n }\n return version;\n}\n static QList getProcessList() {\n QList processList;\n\n HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);\n if (hProcessSnap == INVALID_HANDLE_VALUE)\n {\n qDebug() << \"创建进程快照失败: \" << GetLastError();\n return processList;\n }\n\n PROCESSENTRY32 pe32;\n pe32.dwSize = sizeof(PROCESSENTRY32);\n\n if (!Process32First(hProcessSnap, &pe32))\n {\n qDebug() << \"获取首个进程信息失败: \" << GetLastError();\n CloseHandle(hProcessSnap);\n return processList;\n }\n\n do\n {\n if (systemNames.contains(pe32.szExeFile))\n {\n continue;\n }\n ProcessInfo info;\n info.pid = pe32.th32ProcessID;\n info.parentPid = pe32.th32ParentProcessID;\n info.name = QString::fromWCharArray(pe32.szExeFile);\n info.threadCount = pe32.cntThreads;\n\n // 获取内存使用和优先级信息\n HANDLE hProcess = OpenProcess(\n PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, info.pid);\n if (hProcess)\n {\n PROCESS_MEMORY_COUNTERS pmc;\n if (GetProcessMemoryInfo(hProcess, &pmc, sizeof(pmc)))\n {\n info.memoryUsage = pmc.WorkingSetSize;\n }\n else\n {\n info.memoryUsage = 0;\n }\n BOOL wow64Process = FALSE;\n IsWow64Process(hProcess, &wow64Process);\n info.is64Bit = !wow64Process;\n info.priorityClass = GetPriorityClass(hProcess);\n CloseHandle(hProcess);\n }\n else\n {\n info.memoryUsage = 0;\n info.priorityClass = 0;\n }\n\n processList.append(info);\n } while (Process32Next(hProcessSnap, &pe32));\n\n CloseHandle(hProcessSnap);\n return processList;\n}\n static QString getProcessPath(DWORD processId) {\n QString processPath;\n HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,\n FALSE, processId);\n\n if (hProcess != NULL)\n {\n wchar_t buffer[MAX_PATH];\n if (GetModuleFileNameEx(hProcess, NULL, buffer, MAX_PATH) > 0)\n {\n processPath = QString::fromWCharArray(buffer);\n }\n CloseHandle(hProcess);\n }\n\n return processPath;\n}\n static DWORD getProcessMainThread(DWORD processId) {\n HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);\n if (hSnapshot == INVALID_HANDLE_VALUE)\n {\n qDebug() << \"Failed to create thread snapshot:\" << GetLastError();\n return 0;\n }\n\n THREADENTRY32 te32;\n te32.dwSize = sizeof(THREADENTRY32);\n\n DWORD mainThreadId = 0;\n FILETIME earliestTime = {0xFFFFFFFF, 0xFFFFFFFF}; // 设为最大值\n\n if (Thread32First(hSnapshot, &te32))\n {\n do\n {\n if (te32.th32OwnerProcessID == processId)\n {\n // 打开线程获取创建时间\n HANDLE hThread = OpenThread(THREAD_QUERY_INFORMATION, FALSE,\n te32.th32ThreadID);\n if (hThread)\n {\n FILETIME creationTime, exitTime, kernelTime, userTime;\n if (GetThreadTimes(hThread, &creationTime, &exitTime,\n &kernelTime, &userTime))\n {\n // 比较创建时间,找最早的线程\n if (CompareFileTime(&creationTime, &earliestTime) < 0)\n {\n earliestTime = creationTime;\n mainThreadId = te32.th32ThreadID;\n }\n }\n CloseHandle(hThread);\n }\n }\n } while (Thread32Next(hSnapshot, &te32));\n }\n\n CloseHandle(hSnapshot);\n return mainThreadId;\n}\n static QString getProcessNameById(DWORD processId) {\n HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,\n FALSE, processId);\n if (hProcess == NULL)\n {\n return QString();\n }\n\n wchar_t processName[MAX_PATH];\n if (GetModuleBaseName(hProcess, NULL, processName, MAX_PATH))\n {\n CloseHandle(hProcess);\n QString name = QString::fromWCharArray(processName);\n return name;\n }\n\n CloseHandle(hProcess);\n return QString();\n}\n static bool enableAllPrivilege() {\n HANDLE hToken;\n // 获取进程token\n if (!OpenProcessToken(GetCurrentProcess(),\n TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))\n return false;\n\n const wchar_t *essentialPrivileges[] = {\n SE_DEBUG_NAME, // 最重要的调试权限\n };\n\n TOKEN_PRIVILEGES tkp;\n bool success = true;\n\n for (const auto &privilege : essentialPrivileges)\n {\n tkp.PrivilegeCount = 1;\n tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;\n if (LookupPrivilegeValue(NULL, privilege, &tkp.Privileges[0].Luid))\n {\n AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, NULL);\n }\n }\n\n CloseHandle(hToken);\n return success;\n}\n};"], ["/OpenSpeedy/taskscheduler.h", "class TaskScheduler {\n Q_OBJECT\n public:\n explicit TaskScheduler(QObject *parent = nullptr);\n ~TaskScheduler() {\n}\n bool createStartupTask(const QString &taskName,\n const QString &executablePath) {\n if (taskName.isEmpty() || executablePath.isEmpty())\n {\n qWarning() << \"任务名称或可执行文件路径不能为空\";\n return false;\n }\n\n if (!QFile::exists(executablePath))\n {\n qWarning() << \"可执行文件不存在\" << executablePath;\n return false;\n }\n\n QStringList arguments;\n arguments << \"/create\"\n << \"/f\"\n << \"/tn\" << taskName << \"/tr\"\n << QString(\"\\\"%1\\\" --minimize-to-tray\").arg(executablePath)\n << \"/sc\" << \"onlogon\"\n << \"/delay\" << \"0000:10\"\n << \"/rl\" << \"highest\";\n\n return execute(arguments);\n}\n bool deleteTask(const QString &taskName) {\n if (taskName.isEmpty())\n {\n qWarning() << \"任务名称不能为空\";\n return false;\n }\n\n if (!isTaskExists(taskName))\n {\n qWarning() << \"任务不存在, 无需删除\" << taskName;\n return true;\n }\n\n QStringList arguments;\n arguments << \"/delete\"\n << \"/f\"\n << \"/tn\" << taskName;\n\n return execute(arguments);\n}\n bool enableTask(const QString &taskName, bool enable) {\n if (!isTaskExists(taskName))\n {\n qWarning() << \"任务不存在:\" << taskName;\n return false;\n }\n\n QStringList arguments;\n arguments << \"/change\"\n << \"/tn\" << taskName << (enable ? \"/enable\" : \"/disable\");\n return execute(arguments);\n}\n bool isTaskExists(const QString &taskName) {\n QStringList arguments;\n arguments << \"/query\" << \"/tn\" << taskName;\n\n return execute(arguments);\n}\n bool execute(const QStringList &arguments) {\n QProcess process;\n process.setProgram(\"schtasks\");\n process.setArguments(arguments);\n\n const int timeout = 10000;\n process.start();\n if (!process.waitForStarted(timeout))\n {\n qWarning() << \"无法运行:\" << process.errorString();\n return false;\n }\n\n if (!process.waitForFinished(timeout))\n {\n qWarning() << \"执行超时\";\n process.kill();\n return false;\n }\n\n int exitcode = process.exitCode();\n QString stdout_ = QString::fromLocal8Bit(process.readAllStandardOutput());\n QString stderr_ = QString::fromLocal8Bit(process.readAllStandardError());\n\n if (exitcode == 0)\n {\n qDebug() << \"执行成功:\" << arguments;\n qDebug() << \"输出:\" << stdout_;\n return true;\n }\n else\n {\n qDebug() << \"执行失败:\" << arguments;\n qDebug() << \"错误输出:\" << stderr_;\n qDebug() << \"标准输出:\" << stdout_;\n return false;\n }\n}\n bool createStartupShortcut(const QString &taskName,\n const QString &executablePath) {\n QString home = QDir::homePath();\n QString startupDir =\n home +\n \"\\\\AppData\\\\Roaming\\\\Microsoft\\\\Windows\\\\Start Menu\\\\Programs\\\\Startup\";\n QString shortcutPath = QDir(startupDir).absoluteFilePath(taskName + \".lnk\");\n QString arguments = \"--minimize-to-tray\";\n\n QString psScript =\n QString(\"$WScriptShell = New-Object -ComObject WScript.Shell; \"\n \"$Shortcut = $WScriptShell.CreateShortcut('%1'); \"\n \"$Shortcut.TargetPath = '%2'; \"\n \"$Shortcut.Arguments = '%3'; \"\n \"$Shortcut.Description = '%4'; \"\n \"$Shortcut.Save()\")\n .arg(shortcutPath, executablePath, arguments,\n QString(\"启动 %1\").arg(QFileInfo(executablePath).baseName()));\n\n return executePs(psScript);\n}\n bool deleteStartupShortcut(const QString &taskName) {\n QString home = QDir::homePath();\n QString startupDir =\n home + \"\\\\AppData\\\\Roaming\\\\Microsoft\\\\Windows\\\\Start Menu\\\\Programs\\\\Startup\";\n QString shortcutPath = QDir(startupDir).absoluteFilePath(taskName + \".lnk\");\n\n QString psScript = QString(\"Remove-Item '%1' -Force\").arg(shortcutPath);\n\n return executePs(psScript);\n}\n bool isStartupShortcutExists(const QString &taskName) {\n QString home = QDir::homePath();\n QString startupDir =\n home +\n \"\\\\AppData\\\\Roaming\\\\Microsoft\\\\Windows\\\\Start Menu\\\\Programs\\\\Startup\";\n QString shortcutPath = QDir(startupDir).absoluteFilePath(taskName + \".lnk\");\n\n return QFile::exists(shortcutPath);\n}\n bool executePs(const QString &psScript) {\n QProcess process;\n process.setProgram(\"powershell\");\n process.setArguments({\"-ExecutionPolicy\", \"Bypass\", \"-Command\", psScript});\n\n process.start();\n if (!process.waitForStarted(5000))\n {\n qDebug() << \"PowerShell 启动失败:\" << process.errorString();\n return false;\n }\n\n if (process.waitForFinished(5000) && process.exitCode() == 0)\n {\n qDebug() << \"PowerShell 执行成功\";\n return true;\n }\n else\n {\n QString error = QString::fromLocal8Bit(process.readAllStandardError());\n qDebug() << \"PowerShell 执行失败:\" << error;\n }\n\n return false;\n}\n};"], ["/OpenSpeedy/bridge/main.cpp", "#include \"../config.h\"\n#include \"../speedpatch/speedpatch.h\"\n#include \"../windbg.h\"\n#include \"../winutils.h\"\n#include \n#include \n#include \n#include \n#include \n\n#ifndef _WIN64\n#define SPEEDPATCH_DLL SPEEDPATCH32_DLL\n#else\n#define SPEEDPATCH_DLL SPEEDPATCH64_DLL\n#endif\n\nvoid\nhandleInject(int processId, QString dllPath)\n{\n qDebug() << \"执行 inject,进程ID:\" << processId;\n winutils::injectDll(processId, dllPath);\n SetProcessStatus(processId, true);\n}\n\nvoid\nhandleUnhook(int processId, QString dllPath)\n{\n qDebug() << \"执行 unhook,进程ID:\" << processId;\n SetProcessStatus(processId, false);\n}\n\nvoid\nhandleChange(double factor)\n{\n qDebug() << \"执行 change,参数:\" << factor;\n ChangeSpeed(factor);\n}\n\nint\nmain(int argc, char* argv[])\n{\n SetUnhandledExceptionFilter(createMiniDump);\n QCoreApplication a(argc, argv);\n if (winutils::enableAllPrivilege())\n {\n qDebug() << \"权限提升成功\";\n }\n\n QString dllPath = QDir::toNativeSeparators(\n QCoreApplication::applicationDirPath() + \"/\" + SPEEDPATCH_DLL);\n\n QTextStream in(stdin);\n QTextStream out(stdout);\n\n QRegularExpression injectRegex(\"^\\\\s*inject\\\\s+(\\\\d+)\\\\s*$\",\n QRegularExpression::CaseInsensitiveOption);\n QRegularExpression unhookRegex(\"^\\\\s*unhook\\\\s+(\\\\d+)\\\\s*$\",\n QRegularExpression::CaseInsensitiveOption);\n QRegularExpression changeRegex(\"^\\\\s*change\\\\s+([+-]?\\\\d*\\\\.?\\\\d+)\\\\s*$\",\n QRegularExpression::CaseInsensitiveOption);\n QRegularExpression exitRegex(\"^\\\\s*exit\\\\s*$\",\n QRegularExpression::CaseInsensitiveOption);\n\n while (true)\n {\n QString line = in.readLine();\n if (line.isNull())\n {\n // 管道关闭或输入结束\n break;\n }\n line = line.trimmed();\n if (line.isEmpty())\n continue;\n\n QRegularExpressionMatch match;\n if ((match = injectRegex.match(line)).hasMatch())\n {\n int pid = match.captured(1).toInt();\n handleInject(pid, dllPath);\n }\n else if ((match = unhookRegex.match(line)).hasMatch())\n {\n int pid = match.captured(1).toInt();\n handleUnhook(pid, dllPath);\n }\n else if ((match = changeRegex.match(line)).hasMatch())\n {\n double factor = match.captured(1).toDouble();\n handleChange(factor);\n }\n else if (exitRegex.match(line).hasMatch())\n {\n qDebug() << \"收到exit命令,程序即将退出。\";\n break;\n }\n else\n {\n qDebug() << \"无效命令:\" << line;\n }\n }\n\n return 0;\n}\n"], ["/OpenSpeedy/windbg.h", "/*\n * OpenSpeedy - Open Source Game Speed Controller\n * Copyright (C) 2025 Game1024\n * \n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n * \n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n * \n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n#ifndef WINDBG_H\n#define WINDBG_H\n#include \n#include \n#include \n#include \n// 链接dbghelp库\n#pragma comment(lib, \"dbghelp.lib\")\n\ntypedef BOOL(WINAPI *MINIDUMPWRITEDUMP)(\n HANDLE hProcess,\n DWORD ProcessId,\n HANDLE hFile,\n MINIDUMP_TYPE DumpType,\n PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,\n PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,\n PMINIDUMP_CALLBACK_INFORMATION CallbackParam);\n\n// 自定义异常处理函数\nLONG WINAPI createMiniDump(EXCEPTION_POINTERS *exceptionPointers)\n{\n // 创建dump文件目录\n QDir dumpDir(QDir::currentPath() + \"/dumps\");\n if (!dumpDir.exists())\n {\n dumpDir.mkpath(\".\");\n }\n\n // 生成带时间戳的文件名\n QString dumpFileName =\n QString(\"%1/crash_%2.dmp\")\n .arg(dumpDir.absolutePath())\n .arg(QDateTime::currentDateTime().toString(\"yyyy-MM-dd_hh-mm-ss\"));\n\n // 创建文件\n HANDLE hFile = CreateFile(dumpFileName.toStdWString().c_str(),\n GENERIC_WRITE, FILE_SHARE_READ, NULL,\n CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);\n\n if (hFile == INVALID_HANDLE_VALUE)\n {\n return EXCEPTION_CONTINUE_SEARCH;\n }\n\n // 加载dbghelp.dll\n HMODULE dbgHelp = LoadLibrary(L\"dbghelp.dll\");\n if (!dbgHelp)\n {\n CloseHandle(hFile);\n return EXCEPTION_CONTINUE_SEARCH;\n }\n\n // 获取MiniDumpWriteDump函数地址\n MINIDUMPWRITEDUMP miniDumpWriteDump =\n (MINIDUMPWRITEDUMP)GetProcAddress(dbgHelp, \"MiniDumpWriteDump\");\n\n if (!miniDumpWriteDump)\n {\n FreeLibrary(dbgHelp);\n CloseHandle(hFile);\n return EXCEPTION_CONTINUE_SEARCH;\n }\n\n // 配置异常信息\n MINIDUMP_EXCEPTION_INFORMATION exInfo;\n exInfo.ThreadId = GetCurrentThreadId();\n exInfo.ExceptionPointers = exceptionPointers;\n exInfo.ClientPointers = FALSE;\n\n // 设置dump类型\n MINIDUMP_TYPE dumpType =\n (MINIDUMP_TYPE)(MiniDumpWithFullMemory | // 包含完整内存\n MiniDumpWithFullMemoryInfo | // 包含内存信息\n MiniDumpWithHandleData | // 包含句柄数据\n MiniDumpWithThreadInfo | // 包含线程信息\n MiniDumpWithUnloadedModules // 包含卸载的模块\n );\n\n // 写入dump文件\n BOOL success = miniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(),\n hFile, dumpType, &exInfo, NULL, NULL);\n\n // 清理资源\n FreeLibrary(dbgHelp);\n CloseHandle(hFile);\n\n // 显示通知\n if (success)\n {\n std::wstring message =\n QString(\"程序遇到错误已退出,崩溃转储文件已保存到:\\n%1\")\n .arg(dumpFileName)\n .toStdWString();\n MessageBoxW(nullptr, message.c_str(), L\"程序崩溃\",\n MB_OK | MB_ICONERROR);\n }\n\n return EXCEPTION_EXECUTE_HANDLER;\n}\n\n#endif // WINDBG_H\n"], ["/OpenSpeedy/main.cpp", "/*\n * OpenSpeedy - Open Source Game Speed Controller\n * Copyright (C) 2025 Game1024\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n#include \"mainwindow.h\"\n#include \"windbg.h\"\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nint\nmain(int argc, char* argv[])\n{\n SetUnhandledExceptionFilter(createMiniDump);\n SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);\n QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);\n QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);\n QApplication::setAttribute(Qt::AA_UseSoftwareOpenGL);\n QApplication a(argc, argv);\n winutils::enableAllPrivilege();\n\n // 检查是否已有实例在运行\n QString unique = \"OpenSpeedy\";\n QLocalSocket socket;\n socket.connectToServer(unique);\n if (socket.waitForConnected(500))\n {\n socket.close();\n return -1;\n }\n\n // 使用资源文件中的图标\n QIcon appIcon;\n appIcon.addFile(\":/icons/images/icon_16.ico\", QSize(16, 16));\n appIcon.addFile(\":/icons/images/icon_32.ico\", QSize(32, 32));\n appIcon.addFile(\":/icons/images/icon_64.ico\", QSize(64, 64));\n a.setWindowIcon(appIcon);\n\n QSettings settings =\n QSettings(QCoreApplication::applicationDirPath() + \"/config.ini\",\n QSettings::IniFormat);\n\n QTranslator translator;\n const QString baseName =\n \"OpenSpeedy_\" +\n settings.value(CONFIG_LANGUAGE, QLocale().system().name()).toString();\n\n if (translator.load(\":/i18n/translations/\" + baseName))\n {\n a.installTranslator(&translator);\n }\n\n // 解析命令行参数\n QCommandLineParser parser;\n parser.setApplicationDescription(\"OpenSpeedy\");\n QCommandLineOption minimizeOption(\n QStringList() << \"m\" << \"minimize-to-tray\", \"启动时最小化到托盘\");\n parser.addOption(minimizeOption);\n parser.process(a);\n\n MainWindow w;\n w.resize(1024, 768);\n\n if (parser.isSet(minimizeOption))\n {\n w.hide();\n }\n else\n {\n w.show();\n }\n\n // 创建并启动本地服务器\n QLocalServer server;\n QLocalServer::removeServer(unique);\n server.listen(unique);\n // 当用户尝试再运行一个进程时,将窗口显示到最前台\n QObject::connect(&server,\n &QLocalServer::newConnection,\n [&]\n {\n w.show();\n w.raise();\n w.showNormal();\n w.activateWindow();\n });\n return a.exec();\n}\n"], ["/OpenSpeedy/cpuutils.h", "class CpuUtils {\n private:\n PDH_HQUERY hQuery = NULL;\n PDH_HCOUNTER hCounter = NULL;\n bool initialized = false;\n public:\n CpuUtils() {\n}\n ~CpuUtils() {\n if (hCounter) PdhRemoveCounter(hCounter);\n if (hQuery) PdhCloseQuery(hQuery);\n}\n bool init() {\n // 创建查询\n if (PdhOpenQuery(NULL, NULL, &hQuery) != ERROR_SUCCESS) return false;\n\n if (PdhAddEnglishCounter(hQuery,\n L\"\\\\Processor(_Total)\\\\% Processor Time\",\n NULL,\n &hCounter) != ERROR_SUCCESS)\n {\n PdhCloseQuery(hQuery);\n return false;\n }\n\n // 第一次采样\n PdhCollectQueryData(hQuery);\n initialized = true;\n return true;\n}\n double getUsage() {\n if (!initialized) return -1;\n\n // 收集数据\n if (PdhCollectQueryData(hQuery) != ERROR_SUCCESS) return -1;\n\n PDH_FMT_COUNTERVALUE value;\n if (PdhGetFormattedCounterValue(hCounter, PDH_FMT_DOUBLE, NULL, &value) !=\n ERROR_SUCCESS)\n return -1;\n\n return value.doubleValue;\n}\n QString getModel() {\n int cpuInfo[4];\n char cpuBrand[48 + 1] = {0};\n\n // 获取CPU品牌字符串(需要调用3次CPUID)\n __cpuid(cpuInfo, 0x80000002);\n memcpy(cpuBrand, cpuInfo, sizeof(cpuInfo));\n\n __cpuid(cpuInfo, 0x80000003);\n memcpy(cpuBrand + 16, cpuInfo, sizeof(cpuInfo));\n\n __cpuid(cpuInfo, 0x80000004);\n memcpy(cpuBrand + 32, cpuInfo, sizeof(cpuInfo));\n\n QString result(cpuBrand);\n\n return result.trimmed();\n}\n};"], ["/OpenSpeedy/memutils.h", "class MemUtils {\n private:\n PDH_HQUERY hQuery = NULL;\n PDH_HCOUNTER hCounter = NULL;\n bool initialized = false;\n public:\n MemUtils() {\n}\n bool init() {\n if (PdhOpenQuery(NULL, NULL, &hQuery) != ERROR_SUCCESS) return false;\n\n if (PdhAddEnglishCounter(hQuery,\n L\"\\\\Memory\\\\Available Bytes\",\n NULL,\n &hCounter) != ERROR_SUCCESS)\n {\n PdhCloseQuery(hQuery);\n return false;\n }\n\n PdhCollectQueryData(hQuery);\n initialized = true;\n return true;\n}\n double getTotal() {\n MEMORYSTATUSEX memInfo;\n memInfo.dwLength = sizeof(MEMORYSTATUSEX);\n GlobalMemoryStatusEx(&memInfo);\n return memInfo.ullTotalPhys / (1024.0 * 1024.0 * 1024.0);\n}\n double getUsage() {\n if (!initialized) return -1;\n\n if (PdhCollectQueryData(hQuery) != ERROR_SUCCESS) return -1;\n\n PDH_FMT_COUNTERVALUE available;\n if (PdhGetFormattedCounterValue(hCounter,\n PDH_FMT_DOUBLE,\n NULL,\n &available) != ERROR_SUCCESS)\n return -1;\n\n double totalMemory = getTotal() * 1024 * 1024 * 1024;\n double usageMemory = totalMemory - available.doubleValue;\n\n return usageMemory / (1024.0 * 1024.0 * 1024.0);\n}\n};"], ["/OpenSpeedy/aboutdialog.h", "class AboutDialog {\n Q_OBJECT\n\n public:\n explicit AboutDialog(QWidget* parent = nullptr);\n ~AboutDialog() {\n delete ui;\n}\n private:\n void recreate() {\n layout()->invalidate();\n layout()->activate();\n adjustSize();\n}\n private:\n Ui::AboutDialog* ui;\n};"], ["/OpenSpeedy/config.h", "/*\n * OpenSpeedy - Open Source Game Speed Controller\n * Copyright (C) 2025 Game1024\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n#ifndef CONFIG_H\n#define CONFIG_H\n\n#define OPENSPEEDY_VERSION \"v1.7.6\"\n\n#define BRIDGE32_EXE \"bridge32.exe\"\n#define BRIDGE64_EXE \"bridge64.exe\"\n\n#define SPEEDPATCH32_DLL \"speedpatch32.dll\"\n#define SPEEDPATCH64_DLL \"speedpatch64.dll\"\n\n#define CONFIG_LANGUAGE \"General/Language\"\n\n// 热键ID\nenum HotkeyIds\n{\n HOTKEY_INCREASE_SPEED = 1001,\n HOTKEY_DECREASE_SPEED = 1002,\n HOTKEY_RESET_SPEED = 1003,\n HOTKEY_SHIFT1 = 1011,\n HOTKEY_SHIFT2 = 1012,\n HOTKEY_SHIFT3 = 1013,\n HOTKEY_SHIFT4 = 1014,\n HOTKEY_SHIFT5 = 1015\n};\n\n#endif // CONFIG_H\n"], ["/OpenSpeedy/speedpatch/SpeedPatch_global.h", "/*\n * OpenSpeedy - Open Source Game Speed Controller\n * Copyright (C) 2025 Game1024\n * \n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n * \n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n * \n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n#ifndef SPEEDPATCH_GLOBAL_H\n#define SPEEDPATCH_GLOBAL_H\n\n\n#endif // SPEEDPATCH_GLOBAL_H\n"], ["/OpenSpeedy/mainwindow.h", "class MainWindow {\n};"], ["/OpenSpeedy/speedpatch/speedpatch.h", "class speedpatch {\n};"]], "task_instance_info": {"created_time": "2025-08-20 19:51:26", "created_task_model": "DeepSeek-R1", "function_skeleton": "void keyPressEvent(QKeyEvent* event) override {}", "code_description": "This code segment functions to: Capture and process keyboard input events to update stored key bindings while ignoring isolated modifier keys and triggering interface updates upon valid input detection."}, "inference_content": {"inference_model": "DeepSeek-R1", "inference_result": "```cpp\n[TASK_BEGIN]\nvoid keyPressEvent(QKeyEvent* event) override {\n if (isModifierKey(event->key())) {\n // 忽略单独的功能键\n event->ignore();\n return;\n }\n\n if (event->key() == Qt::Key_Escape) {\n clear(); // 清除当前按键\n emit editingFinished();\n event->accept();\n return;\n }\n\n // 获取组合按键\n QKeyCombination combo = event->keyCombination();\n setKeySequence(QKeySequence(combo));\n update(); // 更新内部状态\n emit editingFinished();\n\n event->accept();\n}\n[TASK_END]\n```", "inference_time": "2025-08-20 19-52-28"}, "editdistance_info": {"edit_distance": 34.9515, "calculate_time": "2025-08-20 19:52:28", "true_code_clean": "void keyPressEvent(QKeyEvent* event) override {\n int key = event->key();\n Qt::KeyboardModifiers modifiers = event->modifiers();\n if (isModifierKey(key))\n {\n return;\n }\n m_key = key;\n m_modifier = modifiers;\n QKeySequence singleKey(key | modifiers);\n setKeySequence(singleKey);\n emit editingFinished();\n clearFocus();\n}", "predict_code_clean": "void keyPressEvent(QKeyEvent* event) override {\n if (isModifierKey(event->key())) {\n event->ignore();\n return;\n }\n if (event->key() == Qt::Key_Escape) {\n clear(); \n emit editingFinished();\n event->accept();\n return;\n }\n QKeyCombination combo = event->keyCombination();\n setKeySequence(QKeySequence(combo));\n update(); \n emit editingFinished();\n event->accept();\n}"}}