Thread: WriteProcessMemory failing with GetLastError 87

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    319

    WriteProcessMemory failing with GetLastError 87

    Code:
    if (!WriteProccessMemory(hProc, pAddr, (LPVOID)GenerateLetters, dwProcSize, &dwWr)
    {
    cout << "WriteProcess Failed" << " " << GetLastError() << endl; //this says 87 which is invalid paramater , i dont know how to fix this after 10 hours
    }
    
    DWORD WINAPI GenerateLetters(LPVOID param)
    {
    return 0;
    }
    VirtualAlloc returns fine and pAddr is correct as well
    thanks if you can help....

  2. #2
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    It depends on what hProc, pAddr, dwProcSize, and dwWr are when you call the function. It's impossible to tell from that. Also, it's infinitely easier to deduce problems and it produces less false positives if you copy and paste what you've got rather than retyping it. Anyway, writing a function pointer into a remote process will rarely bring any joy. If you've got a dll you don't need to write the pointer into the process like that, if you haven't then the pointer is genereally pretty worthless.

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by adeyblue View Post
    It depends on what hProc, pAddr, dwProcSize, and dwWr are when you call the function. It's impossible to tell from that. Also, it's infinitely easier to deduce problems and it produces less false positives if you copy and paste what you've got rather than retyping it. Anyway, writing a function pointer into a remote process will rarely bring any joy. If you've got a dll you don't need to write the pointer into the process like that, if you haven't then the pointer is genereally pretty worthless.
    Windows will not rebase a DLL unless it has to. If both processes don't already have something loaded in their virtual address spaces at the DLL's preferred base address, then the function pointer will be valid in both processes.

    In the case of a system DLL, Windows will NEVER rebase it. The address of a function in ntdll.dll, for instance, is the same for every process in the system.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> In the case of a system DLL, Windows will NEVER rebase it. The address of a function in ntdll.dll, for instance, is the same for every process in the system.

    In newer versions of windows, this isn't guaranteed.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  5. #5
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Sebastiani View Post
    >> In the case of a system DLL, Windows will NEVER rebase it. The address of a function in ntdll.dll, for instance, is the same for every process in the system.

    In newer versions of windows, this isn't guaranteed.
    Yet another reason I need to get Win7 installed at work so I can start hammering it.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  6. #6
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    Quote Originally Posted by Anddos View Post
    Code:
    if (!WriteProccessMemory(hProc, pAddr, (LPVOID)GenerateLetters, dwProcSize, &dwWr)
    {
    cout << "WriteProcess Failed" << " " << GetLastError() << endl; //this says 87 which is invalid paramater , i dont know how to fix this after 10 hours
    }
    
    DWORD WINAPI GenerateLetters(LPVOID param)
    {
    return 0;
    }
    VirtualAlloc returns fine and pAddr is correct as well
    thanks if you can help....
    If reasonable, post your code for review.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 09-23-2008, 03:32 AM
  2. pointer comparison failing
    By Bleech in forum C Programming
    Replies: 4
    Last Post: 08-11-2007, 06:33 PM
  3. CreateDevice failing
    By MadCow257 in forum Game Programming
    Replies: 6
    Last Post: 03-14-2006, 09:03 PM
  4. initializes all components of failing to false
    By romeoz in forum C++ Programming
    Replies: 21
    Last Post: 08-01-2003, 09:30 PM
  5. WriteProcessMemory
    By cppdude in forum Windows Programming
    Replies: 3
    Last Post: 04-12-2002, 08:31 AM