Valhalla Legends Forums Archive | .NET Platform | Request

AuthorMessageTime
shout
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.
October 30, 2004, 12:13 AM
St0rm.iD
Yeah I wish I could do that too.
November 1, 2004, 8:36 PM
shout
Mabye I could do something like...
[code]
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);
}
}
[/code]

...except have all the methods I need to inject a DLL.

Would that work? Or is there things that will create stupid errors?
November 4, 2004, 2:59 PM
Myndfyr
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.
[code]
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));
}
[/code]

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.
November 4, 2004, 6:33 PM
shout
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
November 5, 2004, 4:44 AM
K
if you have the detours library, which is really swell, you can use the functions DetourContinueProcessWithDll and DetourCreateProcessWithDll.  Doesn't get much easier with that.
November 19, 2004, 11:16 PM
shout
Thank you! My kittens love you forever!
November 23, 2004, 8:52 PM

Search