Hi, I have been making a program that searches in another process's memory for a value from the user. It works, but it's very slow. I have used other searchers like TSearch that are really fast. If anyone has a way to make it faster, please help.:-/

Here's my code

#include <windows.h>
#include <iostream>
using namespace std;

int Memory(HWND MyWindow, int long Address, int Value, bool _w)
{
    DWORD PROC_ID;
    HANDLE PROC_HANDLE;

    GetWindowThreadProcessId(MyWindow, &PROC_ID);
    PROC_HANDLE = OpenProcess(PROCESS_ALL_ACCESS, false, PROC_ID);
    if(_w)
        WriteProcessMemory(PROC_HANDLE, (LPVOID)Address, &Value, sizeof(long int), NULL);
    else
        ReadProcessMemory(PROC_HANDLE, (LPVOID)Address, &Value, sizeof(long int), NULL);
    CloseHandle(PROC_HANDLE);
    return Value;
}

int main()
{
    SetConsoleTitle("Memory Search");
    unsigned long long int x;
    LPVOID MyLPVOID;
    
    char Caption[1000];
    cout << "Enter the caption of the window: ";
    cin.getline(Caption, 1000);
    HWND Test = FindWindow(NULL, Caption);
    if (!Test)
    {
    cout << "\nCannot find window \"" << Caption << "\"!";
    cin.get();
    return 0;
    }
    
    LPVOID Address;
    cout << "\nEnter the address to start at: ";
    cin >> Address;
    
    int WhatToFind;

    cout << "\nWhat number are you trying to find: ";
    cin >> WhatToFind;
    
    for (x = 0; x < 2000000000; x++)
    {
    int AtAddress = Memory(Test, ((int long)Address + x), 0, false);
    if (AtAddress == WhatToFind)
    {
    cout << "\n\nFound it at address: " << (LPVOID)((int long)Address + x);
    cin.ignore();
    cin.ignore();
    }
    }
    cout << "\nDone!";
    cin.ignore();
    cin.ignore();
    return 0;
}

You thing that for (x = 0; x < 2000000000; x++)
will work quickly??? Mad boy. If you start this loop without any operations it will be VERY long....

You thing that for (x = 0; x < 2000000000; x++)
will work quickly??? Mad boy. If you start this loop without any operations it will be VERY long....

Please define "VERY long"

Pentium D 3.2GHz (one core tied up with other processing) took 8 seconds to run the loop with empty body.

As to the OP's program, I find it doesn't compile in Visual C++ 2005 as written. When corrected, it won't find the target app window, much less search in memory. So the loop is moot at this point, for me.

What compiler are you using?
I tried using Dev-C++ and I got a nearly endless list of errors

What compiler are you using?
I tried using Dev-C++ and I got a nearly endless list of errors

Such as?

Such as?

A quick C,P,&C:

---------- Build Project: 'C++.vpj' - 'Debug' ---------- VSLICKERRORPATH="d:\scratch"
main.cpp
     ****** {BD Software Proxy c++ v3.43a for gcc} STL Message Decryption is Off ******
In file included from c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/windows.h:58,
                 from main.cpp:1:
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/winnls.h:571: error: expected `,' or `...' before '*' token
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/winnls.h:572: error: expected `,' or `...' before '*' token
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/winnls.h:588: error: expected `,' or `...' before '*' token
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/winnls.h:589: error: expected `,' or `...' before '*' token
In file included from c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/windows.h:67,
                 from main.cpp:1:
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/winreg.h:71: error: `PFILETIME' has not been declared
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/winreg.h:72: error: `PFILETIME' has not been declared
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/winreg.h:84: error: `PFILETIME' has not been declared
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/winreg.h:85: error: `PFILETIME' has not been declared
In file included from c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/windows.h:79,
                 from main.cpp:1:
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/lzexpand.h:25: error: `LPOFSTRUCT' has not been declared
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/lzexpand.h:26: error: `LPOFSTRUCT' has not been declared
In file included from c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/windows.h:84,
                 from main.cpp:1:
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/winperf.h:87: error: `SYSTEMTIME' does not name a type
In file included from c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/windows.h:87,
                 from main.cpp:1:
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/winspool.h:244: error: `SYSTEMTIME' does not name a type
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/winspool.h:259: error: `SYSTEMTIME' does not name a type
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/winspool.h:282: error: `SYSTEMTIME' does not name a type
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/winspool.h:307: error: `SYSTEMTIME' does not name a type
In file included from c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/objbase.h:74,
                 from c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/ole2.h:9,
                 from c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/windows.h:111,
                 from main.cpp:1:
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/objidl.h:13: error: `FILETIME' does not name a type
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/objidl.h:14: error: `FILETIME' does not name a type
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/objidl.h:15: error: `FILETIME' does not name a type
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/objidl.h:97: error: `FILETIME' does not name a type
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/objidl.h:98: error: `FILETIME' does not name a type
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/objidl.h:99: error: `FILETIME' does not name a type
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/objidl.h:283: error: expected `;' before '*' token
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/objidl.h:323: error: `FILETIME' does not name a type
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/objidl.h:576: error: `LPFILETIME' has not been declared
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/objidl.h:577: error: `LPFILETIME' has not been declared
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/objidl.h:622: error: `LPFILETIME' has not been declared
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/objidl.h:747: error: `FILETIME' has not been declared
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/objidl.h:747: error: `FILETIME' has not been declared
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/objidl.h:747: error: `FILETIME' has not been declared
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/objidl.h:912: error: `FILETIME' has not been declared
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/objidl.h:912: error: `FILETIME' has not been declared
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/objidl.h:912: error: `FILETIME' has not been declared
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/objidl.h:1136: error: `FILETIME' has not been declared
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/objidl.h:1138: error: `FILETIME' has not been declared
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/objidl.h:1168: error: `FILETIME' has not been declared
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/objidl.h:1244: error: expected `,' or `...' before '*' token
In file included from c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/ole2.h:9,
                 from c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/windows.h:111,
                 from main.cpp:1:
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/objbase.h:147: error: `FILETIME' was not declared in this scope
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/objbase.h:147: error: expected primary-expression before ',' token
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/objbase.h:147: error: expected primary-expression before ',' token
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/objbase.h:147: error: expected primary-expression before ')' token
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/objbase.h:147: error: initializer expression list treated as compound expression
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/objbase.h:148: error: `FILETIME' has not been declared
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/objbase.h:149: error: `FILETIME' was not declared in this scope
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/objbase.h:149: error: expected primary-expression before ')' token
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/objbase.h:168: error: `FILETIME' has not been declared
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/objbase.h:168: error: `FILETIME' has not been declared
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/objbase.h:168: error: `FILETIME' has not been declared
In file included from c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/ole2.h:11,
                 from c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/windows.h:111,
                 from main.cpp:1:
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/oleauto.h:185: error: `SYSTEMTIME' does not name a type
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/oleauto.h:208: error: `LPSYSTEMTIME' has not been declared
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/oleauto.h:209: error: `LPSYSTEMTIME' was not declared in this scope
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/oleauto.h:209: error: expected primary-expression before "double"
c:/progra~1/codeblocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/oleauto.h:209: error: initializer expression list treated as compound expression
main.cpp: In function `int Memory(HWND__*, long int, int, bool)':
main.cpp:10: error: `GetWindowThreadProcessId' undeclared (first use this function)
main.cpp:10: error: (Each undeclared identifier is reported only once for each function it appears in.)
main.cpp:11: error: `OpenProcess' undeclared (first use this function)
main.cpp:13: error: `WriteProcessMemory' undeclared (first use this function)
main.cpp:15: error: `ReadProcessMemory' undeclared (first use this function)
main.cpp:16: error: `CloseHandle' undeclared (first use this function)
main.cpp: In function `int main()':
main.cpp:51: warning: cast to pointer from integer of different size
*** Errors occurred during this build ***

Upshot: it has issues with SYSTEMTIME.

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Looks like something's not right with your windows include files. Not being a user of Dev-C++, I can't help here.

My winbase.h indeed appears quite hosed. C::B indicates they're close to a release -- I hope so, 'cuz the nightly builds don't freshen my hosed core.

Hi, i'm finally able to respond. I have a 2.50 mghz Intel Celeron CPU 479 mb ram. I am using Dev-C++ 4.9.9.2. Ill make the loop shorter, but how long does it need to be?

This article has been dead for over six months. Start a new discussion instead.