Mahmoudnia Posted March 30, 2017 Posted March 30, 2017 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.pnghttps://m07i.imgup.net/20e1a.png What can I do ?
cawk Posted March 30, 2017 Posted March 30, 2017 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
Mahmoudnia Posted March 30, 2017 Author Posted March 30, 2017 (edited) Thanks for reply. I think the problem is not about target's ilcodehttps://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 March 30, 2017 by Mahmoudnia
Mahmoudnia Posted April 1, 2017 Author Posted April 1, 2017 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(); } } }
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now