Probing Dlls through Reflection in ASP .Net
I have been trying to find more information on the technique of dll and exe discovery by way of writing programs using ASP .Net and reflection(?). I haven't been able to find anything.
I know there are dissassemblers but I am not interested in running other tools and disassembling code per say, I am more interested in understanding how to write a program that takes an unknown file or executable and determines the properties and methods within that are public.
I am just starting on my search for this and was wondering of any good resources to jumpstart the learning开发者_如何学JAVA process.
I am more interested in understanding how to write a program that takes an unknown file or executable and determines the properties and methods within that are public.
Reflection is a good way to do that. Here are a few tips if you don't want a full code explanation.
You could use the
Assembly.ReflectionOnlyLoad
to load an existing assembly. This will only work for .NET assemblies. The difference betweenLoad
andReflectionOnlyLoad
is thatLoad
loads an assembly that allows you to use it, like executing a method on a type in that assembly.ReflectionOnlyLoad
is useful when you only want to look at what is in the assembly without executing any code. The other advantage ofReflectionOnlyLoad
is that it doesn't care what platform the assembly was compiled for.Once you have the assembly, you can use a method like
GetExportedTypes
to get a list of all of the public types. If you want to get the public and non-public, you can use justGetTypes
().So now we have our assembly loaded, and a list of all of the types. The
Type
class has several members for working with that type. GetMethods and GetProperties come to mind.
You can refer to this MSDN article for a more general overview of Reflection.
精彩评论