c# - How do I invoke .getmethodinfo? -


i have started read how open source encryption program works.

the problem is, i'm stuck here on these 2 lines of code can't understand @ all, have looked @ msdn doesn't me @ understand these 2 lines do.

methodinfo run = assembly.load(injres).gettype("resource.reflect").getmethod("run"); bool inj = (bool)run.invoke(null, new object[] { assembly.getexecutingassembly().location, "", payloadres, false }); 

i'm trying figure out way accomplish same thing, there way invoke .getmethod?

this basic "reflection" in .net.

basically happens here is:

  • loads .net assembly indicated injres
  • inside assembly, type definition resource.reflect (which class)
  • inside resource.reflect type, run method , save variable run
  • invoke (in other works, "execute") run() function on null instance (which means run() static method) parameters (assembly.getexecutingassembly().location, "", payloadres, false)

more simply, these lines translate "regular old c#" looks like:

bool inj = resource.reflect.run(assembly.getexecutingassembly().location, "", payloadres, false); 

but original author couldn't have written simple 1 line above because either:

  • the assembly wasn't referenced @ build-time, compiler doesn't know resouce namespace have thrown compile error
  • or resouce.reflect class or run method isn't public couldn't have been called normally. reflection can bypass limitation.

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -