I inject a DLL into a process, then I want to overwrite a string in this running EXE...

This is my code so far... but it does not work:

szPosition DD 1343571524 ; hex = 50154644
szToWrite DB "newstring123", 0

invoke GetCurrentProcessId
mov hHandle, eax
invoke WriteProcessMemory, hHandle, ADDR szPosition, ADDR szToWrite, 12, ADDR nWritten
invoke CloseHandle, hHandle

I tried to unprotect the memory position, change the GetCurrentProcessId with GetCurrentThreadId, changing the parameters in OpenProcess....

I don't want to use FindWindow is something like that, I need change it in the running process which my DLL is attached to
Posted on 2004-07-27 18:58:41 by flapper
I find it amazing that the majority of programmers do not insert a simple GetLastError in their code and even when they do they ignore the value it returns. Try to find out which function fails by it's return value then use GetLastError/FormatMessage to find out why. It is very difficult to diagnose problems with remote processes when we don't have the target process to test with.

By the way you use hHandle for the Process ID then don't redefine it when you WriteProcessMemory which requires a handle not a PID. This would have been obvious from the "The handle is invalid." error message that it returns.
Posted on 2004-07-27 19:11:46 by donkey
Sorry, you can delete this thread, I do it like this now:

mov eax, dword ptr
mov byte ptr , "n"

Posted on 2004-07-27 19:29:54 by flapper
Here is a proc which handles the whole GetLastError & FormatMessage thing and displays the error in a messagebox.

Posted on 2004-07-27 19:31:33 by JimmyClif