这个程序一开始就能工作,但在几个循环之后就出错了。
我在ReadProcessMemory上遇到了麻烦。它在我的程序开始时工作,并以大字符串读取,但它停止正确地更新值。例如,它将保留前一个字符串,并保留该字符串作为程序的其余部分,否则在我关闭程序之前,它将在字符串中完全没有任何内容。这是在前两次之后随机发生的,它起作用。在游戏中,基本地址通过悬停效果包含一个项目的文本串。然而,readprocessmemory内存似乎在几次之后就停止工作了,我已经多次检查地址是否仍然在通过欺骗引擎更新正确的值,而且确实如此,但是它在程序中并没有正确地更新。我知道代码写得不好,我应该使用向量等.
问题发生在这里:
while(temp.size() < 150 ){
do{
// memset(&buffer[0], 0, sizeof(buffer));
ReadProcessMemory(hProcHandle, (LPCVOID)myaddr, &buffer, sizeof(buffer), NULL);
temp = std::string((char*)buffer);
}
while(temp == previous);
std:: cout << temp.size() << std::endl;
}上面的代码以前不是循环,我试着再一次回忆它,直到它有了新的值或null为止,但是一旦程序停止使用坏的值,不管我调用它多少次,它仍然停留在循环中,但是相同地址在欺骗引擎中同时被更新,我已经重复检查过了。这个循环中的主要问题是,readprocessmemory仍然具有与以前调用相同的值,并且一直保持这种状态直到程序关闭。此地址正在游戏中更新,此时正在运行。
#include <iostream>
#include <Windows.h>
#include <string>
#include <ctime>
#include <sstream>
#include <algorithm>
#include <vector>
DWORD ariaBase = 0x400000 + 0x009B5A20;
std::string teatime[] = {" + 5 E"," + 6 Acc"," + 5 Acc"," + 6 Acc"," + 5 Acc"," + 7 Crit"," + 6 Damage"," + 5 Damage"," + 4 Damage"," + 3 Crit"};
unsigned char* buffer[800] = {0};
std::string temp = "";
std::string previous = "";
int myaddr = 0;
bool match[5];
DWORD aOffset[] = {0x724, 0x37C, 0x0, 0xAC, 0x50};
int count = 0;
std::vector<std::string> stats;
bool statsFound = false;
void WriteToMemory(HANDLE hProcHandle){
stats.clear();
temp = "";
while(temp.size() < 150 ){
do{
// memset(&buffer[0], 0, sizeof(buffer));
ReadProcessMemory(hProcHandle, (LPCVOID)myaddr, &buffer, sizeof(buffer), NULL);
temp = std::string((char*)buffer);
}
while(temp == previous);
std:: cout << temp.size() << std::endl;
}
previous = temp;
std::replace( temp.begin(), temp.end(),(char)'\\', '*');
stats = findStats(temp);
//for( std::vector<std::string>::const_iterator i = stats.begin(); i != stats.end(); ++i)std::cout << *i << ' ' << std::endl;
}
int main(){
...code...
...code...
...code...
...code...
while(statsFound == false){
round++;
checkItem();
Sleep(2000);
WriteToMemory(hProcHandle);
std::cout << round << std::endl;
for( std::vector<std::string>::const_iterator i = stats.begin(); i != stats.end(); ++i)std::cout << *i << ' ' << std::endl;
for(int i = 0; i < stats.size();i++){
for(int j = 0; j < 10;j++){
if(("Identified Attribute:" + teatime[j]) == stats[i])match[i] = true;
}
}
count = 0;
for(int i = 0; i < stats.size();i++){
if(match[i] != true)statsFound = false;
else count++;
if(count == stats.size())statsFound = true;
}
match[0] = false;
match[1] = false;
match[2] = false;
match[3] = false;
if(statsFound == false)MouseStart();
}
...code...
...code...
...code...
}发布于 2013-11-12 05:19:11
您能说出在读取数据的目标进程的内存中驻留了什么吗?你听说过GetLastError函数吗?在ReadProcessMemory返回后立即调用它,这可能会提供一个线索。
https://stackoverflow.com/questions/19921330
复制相似问题