diff --git a/cpuutils.cpp b/cpuutils.cpp index 135ad4a..3de803e 100644 --- a/cpuutils.cpp +++ b/cpuutils.cpp @@ -1,31 +1,35 @@ /* * OpenSpeedy - Open Source Game Speed Controller * Copyright (C) 2025 Game1024 - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "cpuutils.h" -CpuUtils::CpuUtils() {} +CpuUtils::CpuUtils() +{ +} bool CpuUtils::init() { // 创建查询 if (PdhOpenQuery(NULL, NULL, &hQuery) != ERROR_SUCCESS) return false; - if (PdhAddEnglishCounter(hQuery, L"\\Processor(_Total)\\% Processor Time", - NULL, &hCounter) != ERROR_SUCCESS) + if (PdhAddEnglishCounter(hQuery, + L"\\Processor(_Total)\\% Processor Time", + NULL, + &hCounter) != ERROR_SUCCESS) { PdhCloseQuery(hQuery); return false; diff --git a/memutils.cpp b/memutils.cpp index 3ffd0b6..20c0567 100644 --- a/memutils.cpp +++ b/memutils.cpp @@ -1,29 +1,33 @@ /* * OpenSpeedy - Open Source Game Speed Controller * Copyright (C) 2025 Game1024 - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "memutils.h" -MemUtils::MemUtils() {} +MemUtils::MemUtils() +{ +} bool MemUtils::init() { if (PdhOpenQuery(NULL, NULL, &hQuery) != ERROR_SUCCESS) return false; - if (PdhAddEnglishCounter(hQuery, L"\\Memory\\Available Bytes", NULL, + if (PdhAddEnglishCounter(hQuery, + L"\\Memory\\Available Bytes", + NULL, &hCounter) != ERROR_SUCCESS) { PdhCloseQuery(hQuery); @@ -50,7 +54,9 @@ double MemUtils::getUsage() if (PdhCollectQueryData(hQuery) != ERROR_SUCCESS) return -1; PDH_FMT_COUNTERVALUE available; - if (PdhGetFormattedCounterValue(hCounter, PDH_FMT_DOUBLE, NULL, + if (PdhGetFormattedCounterValue(hCounter, + PDH_FMT_DOUBLE, + NULL, &available) != ERROR_SUCCESS) return -1; diff --git a/taskscheduler.cpp b/taskscheduler.cpp index 11cd859..97bc92a 100644 --- a/taskscheduler.cpp +++ b/taskscheduler.cpp @@ -19,9 +19,13 @@ #include #include #include -TaskScheduler::TaskScheduler(QObject *parent) : QObject{parent} {} +TaskScheduler::TaskScheduler(QObject *parent) : QObject{parent} +{ +} -TaskScheduler::~TaskScheduler() {} +TaskScheduler::~TaskScheduler() +{ +} bool TaskScheduler::createStartupTask(const QString &taskName, const QString &executablePath) @@ -151,8 +155,8 @@ bool TaskScheduler::createStartupShortcut(const QString &taskName, "$Shortcut.Arguments = '%3'; " "$Shortcut.Description = '%4'; " "$Shortcut.Save()") - .arg(shortcutPath, executablePath, arguments, - QString("启动 %1").arg(QFileInfo(executablePath).baseName())); + .arg(shortcutPath, executablePath, arguments, + QString("启动 %1").arg(QFileInfo(executablePath).baseName())); return executePs(psScript); } @@ -161,8 +165,7 @@ bool TaskScheduler::deleteStartupShortcut(const QString &taskName) { QString home = QDir::homePath(); QString startupDir = - home + - "\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup"; + home + "\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup"; QString shortcutPath = QDir(startupDir).absoluteFilePath(taskName + ".lnk"); QString psScript = QString("Remove-Item '%1' -Force").arg(shortcutPath); diff --git a/winutils.cpp b/winutils.cpp index 43efcf8..8072325 100644 --- a/winutils.cpp +++ b/winutils.cpp @@ -92,7 +92,10 @@ bool winutils::injectDllViaCRTA(DWORD processId, const QString &dllPath) } SIZE_T pathSize = (dllPath.size() + 1) * sizeof(char); LPVOID pDllPath = - VirtualAllocEx(hProcess, nullptr, pathSize, MEM_COMMIT | MEM_RESERVE, + VirtualAllocEx(hProcess, + nullptr, + pathSize, + MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); if (!pDllPath) { @@ -102,8 +105,11 @@ bool winutils::injectDllViaCRTA(DWORD processId, const QString &dllPath) return false; } - if (!WriteProcessMemory(hProcess, pDllPath, dllPath.toStdString().c_str(), - pathSize, nullptr)) + if (!WriteProcessMemory(hProcess, + pDllPath, + dllPath.toStdString().c_str(), + pathSize, + nullptr)) { qDebug() << "Failed to write memory in target process:" << GetLastError(); @@ -130,9 +136,13 @@ bool winutils::injectDllViaCRTA(DWORD processId, const QString &dllPath) return false; } - HANDLE hThread = CreateRemoteThread(hProcess, nullptr, 0, + HANDLE hThread = CreateRemoteThread(hProcess, + nullptr, + 0, (LPTHREAD_START_ROUTINE)pLoadLibraryA, - pDllPath, 0, nullptr); + pDllPath, + 0, + nullptr); if (!hThread) { qDebug() << "Failed to create remote thread:" << GetLastError(); @@ -192,8 +202,11 @@ bool winutils::injectDllViaCRTW(DWORD processId, const QString &dllPath) return false; } - if (!WriteProcessMemory(hProcess, pDllPath, dllPath.toStdWString().c_str(), - pathSize, nullptr)) + if (!WriteProcessMemory(hProcess, + pDllPath, + dllPath.toStdWString().c_str(), + pathSize, + nullptr)) { qDebug() << "Failed to write memory in target process:" << GetLastError(); @@ -220,9 +233,13 @@ bool winutils::injectDllViaCRTW(DWORD processId, const QString &dllPath) return false; } - HANDLE hThread = CreateRemoteThread(hProcess, nullptr, 0, + HANDLE hThread = CreateRemoteThread(hProcess, + nullptr, + 0, (LPTHREAD_START_ROUTINE)pLoadLibraryW, - pDllPath, 0, nullptr); + pDllPath, + 0, + nullptr); if (!hThread) { qDebug() << "Failed to create remote thread:" << GetLastError(); @@ -259,9 +276,9 @@ bool winutils::injectDllViaCRTW(DWORD processId, const QString &dllPath) bool winutils::injectDllViaAPCA(DWORD processId, const QString &dllPath) { HANDLE hProcess = - OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ | - PROCESS_QUERY_INFORMATION, - FALSE, processId); + OpenProcess(PROCESS_ALL_ACCESS, + FALSE, + processId); if (!hProcess) { @@ -277,8 +294,11 @@ bool winutils::injectDllViaAPCA(DWORD processId, const QString &dllPath) // 在目标进程中分配内存并写入DLL路径 SIZE_T pathSize = (dllPath.toStdString().size() + 1) * sizeof(char); - LPVOID pDllPath = - VirtualAllocEx(hProcess, NULL, pathSize, MEM_COMMIT, PAGE_READWRITE); + LPVOID pDllPath = VirtualAllocEx(hProcess, + NULL, + pathSize, + MEM_COMMIT, + PAGE_READWRITE); if (!pDllPath) { @@ -364,9 +384,9 @@ bool winutils::injectDllViaAPCA(DWORD processId, const QString &dllPath) bool winutils::injectDllViaAPCW(DWORD processId, const QString &dllPath) { HANDLE hProcess = - OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ | - PROCESS_QUERY_INFORMATION, - FALSE, processId); + OpenProcess(PROCESS_ALL_ACCESS, + FALSE, + processId); if (!hProcess) { @@ -382,8 +402,11 @@ bool winutils::injectDllViaAPCW(DWORD processId, const QString &dllPath) // 在目标进程中分配内存并写入DLL路径 SIZE_T pathSize = (dllPath.toStdWString().size() + 1) * sizeof(wchar_t); - LPVOID pDllPath = - VirtualAllocEx(hProcess, NULL, pathSize, MEM_COMMIT, PAGE_READWRITE); + LPVOID pDllPath = VirtualAllocEx(hProcess, + NULL, + pathSize, + MEM_COMMIT, + PAGE_READWRITE); if (!pDllPath) { @@ -392,8 +415,11 @@ bool winutils::injectDllViaAPCW(DWORD processId, const QString &dllPath) return false; } - if (!WriteProcessMemory(hProcess, pDllPath, dllPath.toStdWString().c_str(), - pathSize, NULL)) + if (!WriteProcessMemory(hProcess, + pDllPath, + dllPath.toStdWString().c_str(), + pathSize, + NULL)) { qDebug() << "Failed to write memory: " << GetLastError(); VirtualFreeEx(hProcess, pDllPath, 0, MEM_RELEASE); @@ -611,7 +637,8 @@ bool winutils::unhookDll(DWORD processId, const QString &dllPath) bool winutils::checkDllExist(DWORD processId, const QString &dllPath) { HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, - FALSE, processId); + FALSE, + processId); if (!hProcess) { qDebug() << "打开进程失败:" << GetLastError();