Speicher auslesen eines programmes



  • Huhu
    ich hab mir ein kleines Taschenrechner programm geschrieben und von diesem möchte ich nun versuchen die Werte im arbeitsspeicher auszulesen bzw verändern
    ich hab in einem Tutorial das so gesehen:

    #include <windows.h> 
    #include <iostream> 
    
    using namespace std; 
    
    typedef unsigned int uint; 
    
    void GetMemMinMax(void); 
    void ScanMem(DWORD start, DWORD end); 
    
    HANDLE hproc; 
    DWORD procid; 
    
    int main(void) 
    { 
        HWND hWnd; 
    
        hWnd = FindWindow(0,"Taschenrechner"); 
        if(!hWnd) 
            return 0; 
    
        GetWindowThreadProcessId(hWnd, &procid); 
        hproc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, procid); 
        GetMemMinMax(); 
        CloseHandle(hproc);//<-- Wichtig! 
        return 0; 
    } 
    
    void GetMemMinMax(void) 
    { 
        MEMORY_BASIC_INFORMATION mbi; 
        unsigned int adress = 0x400000; 
        do 
        { 
            VirtualQueryEx( 
                            hproc, 
                            (void*)adress, 
                            &mbi, 
                            sizeof(MEMORY_BASIC_INFORMATION) 
                        ); 
    
            if((mbi.State == MEM_COMMIT)&& 
               (mbi.Protect == PAGE_READWRITE)&& 
               (mbi.Type == MEM_PRIVATE)) 
            { 
                uint start = (uint)mbi.BaseAddress; 
                uint end = (uint)mbi.BaseAddress+mbi.RegionSize; 
    
                cout << "Bereich: " << 
                                hex << start << " - " << 
                                hex << end; 
    
                ScanMem(start,end); 
            } 
    
            adress += mbi.RegionSize; 
        } while(adress < 0x80000000); 
    } 
    
    void ScanMem(DWORD start, DWORD end) 
    { 
        cout << " Bereich wird gescannt... 
    "; 
        DWORD read = 0; 
        int buffer = 0; 
        for(start;start<end;start++) 
        { 
            ReadProcessMemory( 
                                hproc, 
                                (void*)start, 
                                &buffer, 
                                sizeof(int), 
                                &read 
                            ); 
            if(buffer == 15) 
            { 
                cout << "Wert an " << hex << start << " gefunden!"; 
                char choice; 
                cout << "Abbrechen? [j,n]"; 
                cin >> choice; 
                if(choice == 'j') 
                    return; 
            } 
        } 
    }
    

    leider öffnet sich das programm nur so 2 sekunden und beendet sich dann von
    selber. Um zu testen ob das handle nicht funktioniert habe ich if(!hWnd) eingebaut aber es funktioniert. Hat einer eine Idee warum das nicht klappt?
    danke


Anmelden zum Antworten