Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

How to get variables and their values with dnlib

Featured Replies

Posted

Hello
I have some issue with dnlib when I want to get variables and their values in C#
I can get variable count for example in Form1_Load and other methods but variable's name have null values.

https://j00i.imgup.net/17563.png
https://m07i.imgup.net/20e1a.png

What can I do ?

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

 

 

  • Author

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

  • Author

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.