Jump to content
Tuts 4 You

How to get variables and their values with dnlib


Mahmoudnia

Recommended Posts

Posted

Follow the code so let's say the variable id is 0 and type is string 

 

so in the ilcode it will look like 

 

ldstr "string value"

stloc.0

 

 

Posted (edited)

Thanks for reply.

I think the problem is not about target's ilcode
https://l72i.imgup.net/38055.png

maybe I have mistake in my code for example

I use this code in foreach loop

foreach (TypeDef type in mod.GetTypes())
{
	if (type.BaseType != null)
		if (type.BaseType.ToString() == "System.Windows.Forms.Form")
		{
			Console.WriteLine("  Name: {0}", type.FullName);
			Console.WriteLine("  Methods: {0}", type.Methods.Count);
			Console.WriteLine("  Fields: {0}", type.Fields.Count);
			Console.WriteLine();

			foreach (MethodDef method in type.Methods)
			{
				Console.WriteLine(method.Body.Variables);
			}
		}
}

 

 

Edited by Mahmoudnia
Posted

So, there is no solution at all ? I changed code to this but vr.Name has still null value .

foreach (MethodDef method in type.Methods)
{
    //my commands

    if (method.HasBody && method.Body.HasVariables)
    {
        foreach (var vr in method.Body.Variables)
        {
            vr.Name = GenerateName();
        }
    }
} 

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...