Hack Forums
[.NET] How to get variables and values of method using mono.cecil? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] How to get variables and values of method using mono.cecil? (/showthread.php?tid=5993919)



How to get variables and values of method using mono.cecil? - mutchim - Jul 28, 2019

My code get
Code
 
Imports Mono.Cecil
Imports Mono.Cecil.Cil
Dim nasm As AssemblyDefinition  
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim assembly As AssemblyDefinition = AssemblyDefinition.ReadAssembly(TextBox1.Text)

       For Each t As TypeDefinition In Assembly.MainModule.Types

           For Each f As FieldDefinition In t.Fields
               TextBox2.Text = TextBox2.Text & f.Name & vbNewLine
           Next

           For Each l As PropertyDefinition In t.Properties
               TextBox3.Text = TextBox3.Text & l.Name & vbNewLine
           Next



           For Each x As TypeDefinition In t.NestedTypes
               TextBox4.Text = TextBox4.Text & x.Name & vbNewLine
           Next

         

           For Each m As MethodDefinition In t.Methods

               For Each v As GenericParameter In m.GenericParameters
                   TextBox5.Text = TextBox5.Text & v.Name & vbNewLine
               Next

               For Each c As ParameterDefinition In m.Parameters
                   TextBox6.Text = TextBox6.Text & c.Name & vbNewLine
               Next

               If m.IsConstructor = False Then
                   TextBox7.Text = TextBox7.Text & m.Name & vbNewLine
               End If
               For Each c1 As VariableDefinition In m.Body.Variables
                   TextBox8.Text = TextBox8.Text & c1.Name & vbNewLine
               Next
         
           Next
Next
End Sub
End Class

My Code Test
Code
Module Module1
   Dim a1 As String = "eeee"
   Dim a2 As Integer = 1
   Sub main()
       Dim a33 As String = "3333"
       MsgBox(aaa(1, 2))
   End Sub
   Public Function aaa(ByVal b As Integer, ByVal c As Integer) As Integer
       Dim d As Integer = 222
       Return b + c + d
   End Function
End Module
Help me get the variables names and value  in my code Test after compiling to .exe
I want get a33,"3333",d,222

Thank you so much


RE: How to get variables and values of method using mono.cecil? - gigajew - Jul 28, 2019

Here's a way in c#, but I recommend switching to dnlib because it has a lot of features already built in.



RE: How to get variables and values of method using mono.cecil? - mutchim - Jul 29, 2019

thank you so much,let me test it


RE: How to get variables and values of method using mono.cecil? - mutchim - Aug 6, 2019

(Jul 29, 2019 06:53 AM)mutchim Wrote:  The above code works incorrectly to my requirements


help me for my VB .NET code works,thank you so much