HelpMemory scanner

Posts 14 of 4 · Page 1 of 1
Memory scanner
My memory scanner don't found my variable in my test application and I don't understand why (but it found correct variable that I can find with cheat engine). I don't understand why I can't find the variable so please help me.... My code :
Code:
#include <windows.h>
#include <stdio.h>
#include <iostream>

int founded = 0;
int total = 0;

// Below are helper functions
BOOL DoRtlAdjustPrivilege()
{
    #define SE_DEBUG_PRIVILEGE  20L
    #define AdjustCurrentProcess    0
    BOOL bPrev = FALSE;
    LONG (WINAPI *RtlAdjustPrivilege)(DWORD, BOOL, INT, PBOOL);
    *(FARPROC *)&RtlAdjustPrivilege = GetProcAddress(GetModuleHandle("ntdll.dll"), "RtlAdjustPrivilege");
    if(!RtlAdjustPrivilege) return FALSE;
    RtlAdjustPrivilege(SE_DEBUG_PRIVILEGE, TRUE, AdjustCurrentProcess, &bPrev);
    return TRUE;
}

typedef BOOL (CALLBACK *LPENUMADDRESSES)(LPBYTE lpAddress, DWORD dwSize, DWORD dwState, DWORD dwType, DWORD dwProtect);
BOOL EnumProcessAddresses(HANDLE hProcess, LPENUMADDRESSES lpCallback)
{
    MEMORY_BASIC_INFORMATION mbi;
    SYSTEM_INFO msi;
    ZeroMemory(&mbi, sizeof(mbi));
    GetSystemInfo(&msi);
    for(LPBYTE lpAddress = (LPBYTE)msi.lpMinimumApplicationAddress;
        lpAddress <= (LPBYTE)msi.lpMaximumApplicationAddress;
        lpAddress += mbi.RegionSize){
        if(VirtualQueryEx(hProcess, lpAddress, &mbi, sizeof(mbi))){
            if(lpCallback && !lpCallback((LPBYTE)mbi.BaseAddress, mbi.RegionSize,
                mbi.State, mbi.Type, mbi.Protect)) return FALSE;
        } else break;
    }
    return TRUE;
}

// Below is actual code --
BOOL CALLBACK DoSomethingForAddress(LPBYTE lpAddress, DWORD dwSize, DWORD dwState, DWORD dwType, DWORD dwProtect)
{
    int value = 0;
    HWND hWnd = FindWindow(0, "Sandbox 2");
    DWORD proccess_ID;
    GetWindowThreadProcessId(hWnd, &proccess_ID);
    HANDLE phandle = OpenProcess(PROCESS_VM_READ,0,proccess_ID);
    ReadProcessMemory(phandle,(void*)lpAddress,&value,sizeof(value),0);
    printf("0x%08X - 0x%08X (0x%08X) : ", lpAddress, (lpAddress + dwSize), dwSize);
    printf("(%d)", value);
    if (value == 5462)
        {
            founded += 1;
           printf(" FOUND !");
    }
    total += 1;
    printf("\n");
    return TRUE;
}

int main(int argc, char **argv)
{
    if(!DoRtlAdjustPrivilege()) return 1;// Error 1
   HWND hWnd = FindWindow(0, "Sandbox 2");
   DWORD proccess_ID;
    GetWindowThreadProcessId(hWnd, &proccess_ID);
    HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, proccess_ID);
    if(hProcess == NULL) return 2; // Error 2
    printf("=====SCAN BEGIN===== \n");
    EnumProcessAddresses(hProcess, DoSomethingForAddress);
    CloseHandle(hProcess);
    printf("=====END OF THE SCAN===== \n");
    printf("Found : %d\n", founded);
    printf("Total : %d", total);

    return 0;
}
what exactly does not work? you might want to check some of the error codes! Esp. try to call GetLastError for the ReadProcessMemory call. it might additionally require the PROCESS_VM_OPERATION.
The programme don't show a variable that I can find with cheat engine and It found only 130 variables (153 000 with cheat engine)...
With the perm PROCESS_VM_OPERATION ---> 0 result
The last error is :
ERROR_PARTIAL_COPY

299 (0x12B)

Only part of a ReadProcessMemory or WriteProcessMemory request was completed.

and this error :
ERROR_FILE_NOT_FOUND

2 (0x2)

The system cannot find the file specified.
Your function gets passed the dwSize of the memory region but you only read the first four bytes, then move onto the next region..

OL CALLBACK DoSomethingForAddress(LPBYTE lpAddress, DWORD dwSize, DWORD dwState, DWORD dwType, DWORD dwProtect)
{
int value = 0;
HWND hWnd = FindWindow(0, "Sandbox 2");
DWORD proccess_ID;
GetWindowThreadProcessId(hWnd, &proccess_ID);
HANDLE phandle = OpenProcess(PROCESS_VM_READ,0,proccess_ID);
ReadProcessMemory(phandle,(void*)lpAddress,&value,sizeof(value),0);
printf("0x%08X - 0x%08X (0x%08X) : ", lpAddress, (lpAddress + dwSize), dwSize);
printf("(%d)", value);
if (value == 5462)
{
founded += 1;
printf(" FOUND !");
}
total += 1;
printf("\n");
return TRUE;
}
Why are you using a callback..is this copied from someone else?
And calling openprocess() for each region..?
Posts 14 of 4 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?