Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions cpuutils.cpp
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/
#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;
Expand Down
18 changes: 12 additions & 6 deletions memutils.cpp
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/
#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);
Expand All @@ -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;

Expand Down
15 changes: 9 additions & 6 deletions taskscheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@
#include <QDebug>
#include <QDir>
#include <QProcess>
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)
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down
71 changes: 49 additions & 22 deletions winutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand Down