i have some problem using VirtualAllocEx function. it allways return?  ERROR_INVALID_HANDLE, but that handle i pushing in function is seems to be valid
this the code i use to get process HANDLE by it name:


invoke CreateToolhelp32Snapshot, TH32CS_SNAPPROCESS, 0
mov hsnapshot, eax
mov ps.dwSize, sizeof PROCESSENTRY32
invoke Process32First, hsnapshot, addr ps
next:
invoke cmpstr, addr ps.szExeFile, addr target
test eax, eax
jne found
invoke Process32Next, hsnapshot, addr ps
test eax, eax
jne next
jmp exit
found:
......


and now i trying to allocate memory in that process

invoke	VirtualAllocEx,ps.th32ProcessID, 0, sizeof Inject,MEM_COMMIT, PAGE_EXECUTE_READWRITE


but it return ERROR_INVALID_HANDLE

help me please, what I'm doing wrong?
Posted on 2006-06-22 15:30:10 by SET
To modify virtual memory of another process the process must have been created with the PROCESS_VM_OPERATION flag set.

Try OpenProcess with this flag before using VirtualAllocEx.
Posted on 2006-06-22 16:27:35 by arafel
Yes, you need an hProcess handle to work with VirtualAllocEx, not just the process ID number.
Posted on 2006-06-22 17:54:11 by comrade
okay, now it works fine )

invoke OpenProcess,PROCESS_VM_OPERATION, 1, ps.th32ProcessID
mov var1, eax
invoke VirtualAllocEx,var1, 0, sizeof Inject,MEM_COMMIT, PAGE_EXECUTE_READWRITE

thanks to u arafe
Posted on 2006-06-22 18:09:17 by SET