ReadProcessMemory faster

2020-03-31 04:32发布

问题:

I'm making an application that will simulate an action using mouse/keyboard (macro) deppending on the value of a variable.

Here I have de scanning code that I made:

void ReadMemory(int value){
        DWORD primeiroAddress = 0x000000;
        DWORD finalAddress = 0xFFFFFF;
        DWORD address=0;
        std::ostringstream ss;
        int i=0;
        TListItem *ListIt;
        int valor;
        HANDLE phandle = OpenProcess(PROCESS_VM_READ,0,TargetPID);
        if(!phandle){
                ShowMessage("Não encoutrou o processo");
        }else{
                for(address=primeiroAddress;address<=finalAddress;address+=sizeof(valor)){
                        ReadProcessMemory(phandle,(void*)address,&valor,sizeof(valor),0);
                        if(valor==value){
                                i++;
                                ss << std::hex << address;
                                Form1->Label5->Caption=i;
                                ListIt = Form1->ListView1->Items->Add();
                                ListIt->Caption = AnsiString(ss.str().c_str()).UpperCase();
                                ListIt->SubItems->Add(IntToStr(valor));
                                ss.str(std::string());
                        }
                }
        }
}

I was wondering what I could make to make the scanning faster

回答1:

You're reading one int at a time. Instead call ReadProcessMemory once, reading the 16MB in one swoop, then scan the memory in your own process. It'll be a lot faster.