R
R
Riketta2014-08-09 20:28:53
Microsoft
Riketta, 2014-08-09 20:28:53

How to make a dynamic call to an obfuscated DLL (all in C#)?

There is a library that I need to dynamically call from the application.
The library is obfuscated through ConfuserEx.
Only the namespace, the class and the main function that I will call are not obfuscated (not renamed).
I call the method (which is not renamed by the obfuscator) like this:

Assembly A = Assembly.LoadFrom(".\Example.dll");
Type ClassType = A.GetType("Namespace.Class", true);
object Obj = Activator.CreateInstance(ClassType);
System.Reflection.MethodInfo MI = ClassType.GetMethod("Main");
MI.Invoke(Obj, null);

Everything works, but on Invoke, I don’t understand where the TypeLoadException comes from.
As I understand it, this happens already in the Main method itself, which calls already obfuscated methods.
Exception example:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeLoadException: A type load exception has occurred.
  at ZMLoader.Loader.Main () [0x00000] in <filename unknown>:0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <filename unknown>:0 
  at ACZM.Module.Initialize () [0x00000] in <filename unknown>:0

How to fix this and get a working call to the Main function?
I will also be happy with alternative ways to achieve my goal, if any.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Tsiren Naimanov, 2014-08-10
@ImmortalCAT

MI.Invoke(Obj, null);
check if null is needed there

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question