Search code examples
c#dll-injection

Can Reflection help me call a function in an injected DLL?


I have injected a managed .NET DLL into a .NET process.
I've seen some people here on StackOverflow say that you can then call the functions of the injected DLL by using Reflection. This is apparently the technique that Snoop uses.
Is this correct? If so, exactly how could it be done?
Thank you in advance.


Solution

  • You could use reflection. Here's an example:

    class Program
    {
        static void Main()
        {
            var assembly = Assembly.Load("System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
            var serverType = assembly.GetType("System.Web.HttpUtility", true);
            var method = serverType.GetMethod("HtmlEncode", BindingFlags.Static | BindingFlags.Public, null, new[] { typeof(string) }, null);
            var result = method.Invoke(null, new[] { "<some value>" });
            Console.WriteLine(result);
        }
    }