C# [HELP] auto load dll function on injection

Stato
Discussione chiusa ad ulteriori risposte.

tdr

Utente Silver
25 Agosto 2010
12
4
0
56
I have a dll(made by me in c#) and I want to auto load a function when it is injected into a process. How can I do this? An little example would be perfect for me.

PS: Sorry for my english..
 
Ultima modifica:
In Windows there's a special function on DLLs that is called when the DLL is loaded. The function must have the name "DllMain". When the library is loaded, this function will be called. But this is only for native DLLs.
Anyway, there's a way to do this in .NET. But note that you shouldn't do that... Why you need this? .NET assemblies are different from native assemblies: they can't be injected in the same way you inject a native DLL. Are you sure about what you're doing? In which process you want to inject the DLL?
If you want to run some code the first time anybody calls a static method or property of your class or constructs an instance of your class, give your class a static constructor and do your initialization there.
If you want to inject the DLL into a native process, you should use a native DLL.
 
I want to inject the dll into a game process(metin2). I think it is a native process.
Why shouldn't I inject the .net dll into a native process? I don't know so much c++ so I can't make a native (c++) dll...

edit: can you give me a source of a empty c++ native dll that only show a message(MessageBox) when it is injected?
 
I want to inject the dll into a game process(metin2). I think it is a native process.
Yes, Metin2 is native.
Why shouldn't I inject the .net dll into a native process? I don't know so much c++ so I can't make a native (c++) dll...
When you compile a project (DLL or EXE) in .NET, it's translated into MSIL (MicroSoft Intermediate Language) and when you execute the project, the CLR (Common Language Runtime) translates the MSIL into machine language (binary), comprehensible by the CPU, and run it. Native DLLs are compiled directly in machine language. So, if you want to inject a .NET assembly in a native process, you need first to translate it in machine language calling the CLR from a native DLL (the injector injects the native DLL that loads the .NET DLL calling the CLR). You can found an example of native/managed DLL injection here: http://www.inforge.net/community/i-vostri-programmi/288869-dll-injector-native-managed-code.html (downloading the injector, you will also download the source code).
edit: can you give me a source of a empty c++ native dll that only show a message(MessageBox) when it is injected?
I don't know C++...but if you google the web, you can found a lot of examples in C++ using DllMain.
 
Ultima modifica:
If you want to load the dll file automatically, you will first download dll and the file will automatically be uploaded to your computer.
 
Stato
Discussione chiusa ad ulteriori risposte.