• Welcome to Valhalla Legends Archive.
 

Request

Started by shout, October 29, 2004, 07:13 PM

Previous topic - Next topic

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.

Banana fanna fo fanna

Yeah I wish I could do that too.

shout

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?

MyndFyre

#3
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.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

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

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.

shout

Thank you! My kittens love you forever!