Could someone make me a simple C++.net DLL that injects a DLL into a process?
If anyone could do that I would be greatful.
Thx.
Yeah I wish I could do that too.
Mabye I could do something like...
public __gc class Functions
{
public bool _WriteProcessMemory(HANDLE hProcess, LPVOID lpBaseAddress, LPCVOID lpBuffer, SIZE_T nSize, SIZE_T* lpNumberOfBytesWritten);
public bool _WriteProcessMemory(HANDLE hProcess, LPVOID lpBaseAddress, LPCVOID lpBuffer, SIZE_T nSize, SIZE_T* lpNumberOfBytesWritten)
{
public bool WriteProcessMemory(HANDLE hProcess, LPVOID lpBaseAddress, LPCVOID lpBuffer, SIZE_T nSize, SIZE_T* lpNumberOfBytesWritten);
}
}
...except have all the methods I need to inject a DLL.
Would that work? Or is there things that will create stupid errors?
Okay, let's think about this process.
When a library is loaded, the image is processed through the PE interpreter, which checks for a flag to see whether or not the library contains managed entry points. If so, they are mapped to the CLR.
What you're asking to do, though, is to write a managed library that loads a library and writes code into another process. Well, you won't be able to write managed code into a process, because it needs to be compiled by the CLR, and (even if the native image has already been generated), garbage collection has to occur; if the process isn't owned by the CLR, garbage collection will fail.
If you're talking about injecting a regular DLL into a process.... WHY DO YOU WANT AN MC++ DLL TO DO THAT?!? THAT'S RETARDED! Just make a regular DLL to do it....
Your code is wrong.
public __gc class Functions
{
public:
__gc System::Boolean _WriteProcessMemory(System::IntPtr hProcess, System::IntPtr lpBaseAddress, System::IntPtr lpBuffer, System::IntPtr nSize, System::IntPtr* lpNumberOfBytesWritten);
}
__gc System::Boolean Functions::_WriteProcessMemory(System::IntPtr hProcess, System::IntPtr lpBaseAddress, System::IntPtr lpBuffer, System::IntPtr nSize, System::IntPtr* lpNumberOfBytesWritten)
{
// WTF were you thinking with "public bool" INSIDE of a function?!?
// when you're writing the function implementation you don't make
// identifier modifiers.
// You don't make type declarations of the prototype either!
WriteProcessMemory( static_cast<HANDLE>(hProcess), static_cast<LPVOID>(lpBaseAddress), static_cast<LPCVOID>(lpBuffer), static_cast<SIZE_T>(nSize), static_cast<SIZE_T*>(lpNumberOfBytesWritten));
}
Also, why are you people calling a class "Functions"? There is something wrong with either your design or your head if you're calling it "Functions." There has GOT to be a more effective way of naming your types.
Just thinking, I dont know anything about C++ or injecting DLLs or any of that. And I did that in notepad at school. Just thinking about things above my ability level.
Sorry for making your BP rise MyndFyre ;D
if you have the detours (http://research.microsoft.com/sn/detours/) library, which is really swell, you can use the functions DetourContinueProcessWithDll and DetourCreateProcessWithDll. Doesn't get much easier with that.
Thank you! My kittens love you forever!