Is it possible to extract the header from a DLL? If so, how?

Asked

Viewed 81 times

1

It is possible to extract header of a dll? Is this practice possible? If so, how can I?

  • By header do you mean signing methods? Metadata? Or details like application name?

  • That, the method signatures. But the more information you can extract, the better.

1 answer

0

If you are using C#, use the class FileVersionInfo:

myFileVersionInfo = FileVersionInfo.GetVersionInfo("dll-alvo.dll");

Instance properties expose compilation details - for example CompanyName, ProductName and ProductVersion.

To extract classes from a data Assembly, you will need to use Reflection:

Assembly assembly = Assembly.ReflectionOnlyLoadFrom("dll-alvo.dll");

foreach (Type tc in assembly .GetTypes())
{
    Console.WriteLine(tc.FullName);
}

And finally listing all methods of a given class:

    foreach (Type tc in assembly .GetTypes())
        {
            if (tc.IsAbstract)
            {
                Console.WriteLine("Abstract Class : " + tc.Name);
            }
            else if (tc.IsPublic)
            {
                Console.WriteLine("Public Class : " + tc.Name);
            }
            else if (tc.IsSealed)
            {
                Console.WriteLine("Sealed Class : " + tc.Name);
            }  

            //Obtém lista de nomes de métodos
            MemberInfo[] methodName = tc.GetMethods();

            foreach (MemberInfo method in methodName)
            {
                if (method.ReflectedType.IsPublic)
                {
                    Console.WriteLine("Método público : " + method.Name.ToString());
                }
                else
                {
                    Console.WriteLine("Método não público : " + method.Name.ToString());
                }
            }
        }

Sources: 1, 2.

  • So @lbotinelly, I tried using your example of reflection but it didn’t work when trying to carry a dll for example, the following message appeared: An unhandled Exception of type 'System.Badimageformatexception' occurred in mscorlib.dll . The command I used was: Assembly assembly = Assembly.ReflectionOnlyLoadFrom("C:\\Users\\Eduardo\\Desktop\\winusb.dll");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.