Thread: Write/ReadProcessMemory help

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    6

    Write/ReadProcessMemory help

    I want my program to read a pointer whose adress is 0x111111 then add 0x111 to the adress which the pointer holds and write 0x0 to the new adress how can i do that with write and readmemory apis

    i tried like that but could not succed what is the problem?
    Code:
    [LRESULT CALLBACK PencereProseduru (HWND AnaPencereTutmaci, UINT message, WPARAM wParam, LPARAM lParam)
    {   
            char Dugme1Ismi[256];
            HWND HedefTutmac;
            DWORD ProsesKimligi, Alan=0x111111, AlinanAlan, HedefAlan;
            HANDLE Islem;
            BYTE eDegistirilen[1]={0x0};
            BOOL a, b;
            
        switch (message)         
        {   case WM_COMMAND:
                 if(LOWORD(wParam) == 1 && HIWORD(wParam) == BN_CLICKED)
                        {
                            GetWindowText(Dugme1Tutmaci, Dugme1Ismi, sizeof(Dugme1Ismi));
                                if (strcmp(Dugme1Ismi, "Durdur")== 0) 
                                {SetWindowText (Dugme1Tutmaci,"Çalıştır");}
                                else
                                {SetWindowText (Dugme1Tutmaci, "Durdur");
                                 HedefTutmac = FindWindow (NULL,"sdsmnd");
                                      if (HedefTutmac == NULL)
                                      {MessageBox(0, "Pencere bulunamadı", "Olumsuz", MB_OK);}
                                      else
                                      {
                                       GetWindowThreadProcessId (HedefTutmac ,&ProsesKimligi);
                                       Islem = OpenProcess(PROCESS_ALL_ACCESS,0, ProsesKimligi);
                                           if (!Islem)
                                           {MessageBox (NULL,"Tutmac alınamadı", "Olumsuz", MB_OK);}
                                           else
                                           {
                                                if(ReadProcessMemory (Islem, (LPVOID)Alan, &AlinanAlan, 4, NULL))
                                                {
                                                  HedefAlan = AlinanAlan + 0x111;
                                                      if(WriteProcessMemory(Islem, (LPVOID)HedefAlan, &eDegistirilen, 4 , NULL))
                                                      {CloseHandle(Islem);}
                                                      else
                                                      {MessageBox (NULL,"Hafıza bölgesine yazılamadı", "Olumsuz", MB_OK);}
                                                }
                                                else
                                               {MessageBox (NULL, "Hafıza bölgesi okunamadı", "Olumsuz", MB_OK);}
                                           }
                                      }
                                }
                        }
                 break;                             
            case WM_DESTROY:
                PostQuitMessage (0);  
                break;
            default:  
                return DefWindowProc (AnaPencereTutmaci, message, wParam, lParam);
        }
    
        return 0;
    }
    Last edited by hileci555; 08-21-2008 at 10:57 AM.

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    You can do what you are wanting, however, you are not doing it the correct way. One major consideration to keep in mind is whether or not you need to gain privs to do this.

  3. #3
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    Possibly enabling the debug privileges before calling ReadProcessMemory and WriteProcessMemory.

Popular pages Recent additions subscribe to a feed