Hi, you guys. I'm making a obfuscator, and I need to know how to get all variables, classes, functions, etc, from a .NET program. I know how to get assembly info, which is quite easy.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using System.Diagnostics;

        string asm()
        {
            FileVersionInfo inf = FileVersionInfo.GetVersionInfo(Application.ExecutablePath);
            string sht = "";
            foreach (PropertyInfo p in inf.GetType().GetProperties())
                sht += p.Name + "   " + p.GetValue(inf, null) + Environment.NewLine;
            return sht;
        }

Thanks you guys, I can't get anything from it, but assembly information.

Once you have an Assembly object to work with (for example, loaded with Assembly.Load), then you can call GetTypes on the assembly object to get all of the classes and structs defined in the assembly. Then you call GetMembers on each type to get its constructors, events, fields, methods, properties, &c.

Once you have an Assembly object to work with (for example, loaded with Assembly.Load), then you can call GetTypes on the assembly object to get all of the classes and structs defined in the assembly. Then you call GetMembers on each type to get its constructors, events, fields, methods, properties, &c.

Thank you so much for this. I made a function which got all functions from a console application. Do you know how to do this with a Forms application? Thanks so much, man. I can get the functions, if they're private, but it returns other functions that I don't even have.

Hey, I found out how to do that. Do you know how I can get all variables within the namespace, class, function, etc?

I can get the functions, if they're private, but it returns other functions that I don't even have.

Which methods are showing up? They are probably inherited from other classes. If you use the overload of Type.GetMembers that takes a BindingFlags parameter, you can include BindingFlags.DeclaredOnly to only get members that were declared by that type.

I made a function which got all functions from a console application. Do you know how to do this with a Forms application?

Hey, I found out how to do that. Do you know how I can get all variables within the namespace, class, function, etc?

Namespaces don't directly contain storage, so there's nothing I can think of that you could call a "variable" to get from there.

You can use Type.GetFields to get variables that are declared as members of a class or structure.

For methods... this may not be exactly what you're looking for, but you could use the MethodInfo.GetMethodBody method and the MethodBody.LocalVariables property to get variables that are local to a method.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.