所以我用C++检查csgo脚本,一切都很顺利,但当我完成Bhop代码时,我发现"字符串1";是";const char";以及";字符串2";是CCD_ 1。我试着修复,我搜索了Credit,youtube上的所有内容,但我无法修复。
#include "memory.h"
#include <TlHelp32.h>
Memory :: Memory(const char* processName)
{
PROCESSENTRY32 entry;
entry.dwSize = sizeof(PROCESSENTRY32);
const auto snapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
while (Process32Next(snapShot, &entry))
{
if (!strcmp(processName, entry.szExeFile))
{
this->id = entry.th32ProcessID;
this->process = OpenProcess(PROCESS_ALL_ACCESS, FALSE, this->id);
break;
}
}
if (snapShot)
CloseHandle(this->process);
}
Memory :: ~Memory()
{
if (this->process)
CloseHandle(this->process);
}
DWORD Memory :: GetProcessId()
{
return this->id;
}
HANDLE Memory :: GetProcessHandle()
{
return this->process;
}
uintptr_t Memory :: GetModuleAdress(const char* moduleName)
{
MODULEENTRY32 entry;
entry.dwSize = sizeof(MODULEENTRY32);
const auto snapShot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, this->id);
uintptr_t result = 0;
while (Module32Next(snapShot, &entry))
{
if (!strcmp(moduleName, entry.szModule))
{
result = reinterpret_cast<uintptr_t>(entry.modBaseAddr);
break;
}
}
if (snapShot)
CloseHandle(snapShot);
return result;
}
错误出现在CCD_ 2上,其中CCD_;const char";并且CCD_ 4是"0";wchar";。请告诉我如何解决我的问题因为我一无所知。
您正在使用基于TCHAR
的Win32 API宏,并且您正在编译定义了UNICODE
的项目,因此宏将解析为wchar_t
版本的API。但是您在代码的其余部分使用char
数据,因此需要显式使用API的ANSI(char
(版本。
此外,您的代码中还有其他错误。也就是说,忽略进程和模块列表中的第一个条目。而您的构造函数正在关闭错误的wchar
0。
试试这个:
Memory :: Memory(const char* processName)
{
PROCESSENTRY32A entry;
entry.dwSize = sizeof(entry);
const auto snapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (Process32FirstA(snapShot, &entry))
{
do
{
if (strcmp(processName, entry.szExeFile) == 0)
{
this->id = entry.th32ProcessID;
this->process = OpenProcess(PROCESS_ALL_ACCESS, FALSE, this->id);
break;
}
}
while (Process32NextA(snapShot, &entry));
}
if (snapShot)
CloseHandle(snapShot);
}
uintptr_t Memory :: GetModuleAdress(const char* moduleName)
{
MODULEENTRY32A entry;
entry.dwSize = sizeof(entry);
const auto snapShot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, this->id);
uintptr_t result = 0;
if (Module32FirstA(snapShot, &entry))
{
do
{
if (strcmp(moduleName, entry.szModule) == 0)
{
result = reinterpret_cast<uintptr_t>(entry.modBaseAddr);
break;
}
}
while (Module32NextA(snapShot, &entry));
}
if (snapShot)
CloseHandle(snapShot);
return result;
}