[Resovled] VirtualAllocEx help...
OK...I have no idea how to use this function in C#, I know it's possible...I'd really appreciate it if someone would show me how to SIMPLY do it...like in notepad...positive rating to all whom help. For those who don't know what it is..it is an API call used to allocate memory in an external process all allocated addresses have the memory value of 0 but they are non-static. Thanks in advanced...and if you have any questions or I didn't make my self clear (it's quite possible) let me know!
Re: [2.0] VirtualAllocEx help...
Hi there,
You'll use the DllImportAttribute class to provide the information needed to call the function from the DLL. According to pinvoke.net the signature looks like this:
Code:
[DllImport("kernel32.dll")]
static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress,
uint dwSize, uint flAllocationType, uint flProtect);
After that is in your class, you can call VirtualAllocEx, pass it the arguments and your off.
A search for DllImport will turn up plenty of help. Good luck!
Re: [2.0] VirtualAllocEx help...
one last question...exactly how would i pass the hProcess argument when i call VirtualAllocEx? Is it possible for it to be process name?
Edit:Grammatical errors...didn't see them when i was writing it the first time...:ehh:
Re: [2.0] VirtualAllocEx help...
The name won't work. You'll need an IntPtr to your process's handle and then you can pass that.
Re: [2.0] VirtualAllocEx help...
For the first parameter of VirtualAllocEx, you need to pass a handle to an external process that has been opened for read/write via an OpenProcess call (search pinvoke.net for it as well).
Generally, you will find the hWnd of a window using FindWindow, get its ProcessID using GetWindowThreadProcessId, call OpenProcess with the PID, and then pass the return of that OpenProcess call as the first parameter for VirtualAllocEx. All of these have to be imported ala nmadd's suggestion so look them up on pinvoke.net.
Re: [2.0] VirtualAllocEx help...
I haven't used VirtualAllocEx before, but if all you need is a handle of a process, you can try something like this:
Code:
Process[] p = Process.GetProcessesByName("firefox");
if (p.Length > 0)
{
IntPtr hFF = p[0].Handle;
MessageBox.Show("FireFox handle: " + hFF.ToString());
}
Re: [2.0] VirtualAllocEx help...
If p[0] holds the ProcessID, that can be passed directly to OpenProcess without the need for a FindWindow or GetWindowThreadProcessId call. I forgot about the Process object.
Re: [2.0] VirtualAllocEx help...
Quote:
Originally Posted by nmadd
I haven't used VirtualAllocEx before, but if all you need is a handle of a process, you can try something like this:
Code:
Process[] p = Process.GetProcessesByName("firefox");
if (p.Length > 0)
{
IntPtr hFF = p[0].Handle;
MessageBox.Show("FireFox handle: " + hFF.ToString());
}
great! thanks that worked, if i could give two reps...i would, thanks. also thanks to the other guy...
Re: [2.0] VirtualAllocEx help...
Glad to help. :)
If you're all done with this question, you can mark this thread as "Resolved" and let everybody know. Good luck with your project.