Beispiel #1
0
 // a bit slow if many items
 public void SelectAllMethodDefinitions()
 {
     if (lstBoxAnalyze.SelectedItems.Count > 0)
     {
         lstBoxAnalyze.UnselectAll();
     }
     else
     {
         int i = 0;
         while (i < lstBoxAnalyze.Items.Count)
         {
             ListBoxItem lbi = (ListBoxItem)lstBoxAnalyze.ItemContainerGenerator.ContainerFromIndex(i);
             aPart       a   = lstBoxAnalyze.Items[i] as aPart;
             if (a.Editible)
             {
                 lstBoxAnalyze.SelectedItems.Add(lstBoxAnalyze.Items.GetItemAt(i));
             }
             i++;
         }
     }
 }
Beispiel #2
0
        private string analyze(string assemblyPath, bool WithTrace = false)
        {
            string fileName = Path.GetFileName(assemblyPath);

            StringBuilder ReturnString = new StringBuilder();

            string s = String.Empty;

            // Load assembly
            AssemblyDef asmDef = AssemblyDef.Load(assemblyPath);
            ModuleDefMD mod    = ModuleDefMD.Load(assemblyPath);

            // check references

            foreach (ModuleDef modDef in asmDef.Modules)
            {
                s = modDef.Name + "  (" + modDef.MDToken.Rid + ")" + NewLine;
                ReturnString.Append(s);
                if (WithTrace)
                {
                    Trace.WriteLine(s);
                }

                aPart a = new aPart();
                a.Name        = modDef.Name;
                a.VirtualName = s;
                a.Token       = modDef.MDToken.ToString();
                a.Type        = aPart.Types.ModuleDefinition;
                a.Editible    = false;

                // Icon
                GenerateImage("MoImage");
                a.Image = _tempImage;

                aParts.Add(a);


                foreach (var assemRef in modDef.GetAssemblyRefs())
                {
                    s = assemRef.Name + "  (" + assemRef.MDToken.Rid + ")" + NewLine;
                    ReturnString.Append(s);
                    if (WithTrace)
                    {
                        Trace.WriteLine(s);
                    }

                    a             = new aPart();
                    a.Name        = assemRef.Name;
                    a.VirtualName = s;
                    a.Token       = assemRef.MDToken.ToString();
                    a.Type        = aPart.Types.AssemblyReference;
                    a.Editible    = false;

                    // Icon
                    GenerateImage("ReImage");
                    a.Image = _tempImage;

                    aParts.Add(a);
                }


                foreach (TypeDef typDef in modDef.Types)
                {
                    s = "    " + typDef.Name + "  (" + typDef.MDToken.Rid + ")" + NewLine;
                    ReturnString.Append(s);
                    if (WithTrace)
                    {
                        Trace.WriteLine(s);
                    }

                    a             = new aPart();
                    a.Name        = typDef.Name;
                    a.VirtualName = s;
                    a.Token       = typDef.MDToken.ToString();
                    a.Type        = aPart.Types.TypeDefinition;
                    a.Editible    = false;

                    // Icon
                    GenerateImage("TyImage");
                    a.Image = _tempImage;

                    aParts.Add(a);

                    foreach (MethodDef metDef in typDef.Methods)
                    {
                        s = "        " + metDef.Name + "  (" + metDef.MDToken.Rid + ")" + NewLine;
                        ReturnString.Append(s);
                        if (WithTrace)
                        {
                            Trace.WriteLine(s);
                        }

                        a             = new aPart();
                        a.Name        = metDef.Name;
                        a.VirtualName = s;
                        a.Token       = metDef.MDToken.ToString();
                        a.Type        = aPart.Types.MethodDefinition;
                        a.Editible    = true;

                        // Icon
                        GenerateImage("MeImage");
                        a.Image = _tempImage;

                        aParts.Add(a);

                        if (metDef.Parameters != null && metDef.Parameters.Count > 0)
                        {
                            foreach (Parameter param in metDef.Parameters)
                            {
                                //s = "            Type: " + param.ParamDef.ElementType.ToString() + " Name: " + param.Name + NewLine;
                                s = "             Name: " + param.Name + NewLine;
                                if (param.ParamDef != null)
                                {
                                    s += "            Attributes: " + param.ParamDef.Attributes.ToString();
                                }
                                ReturnString.Append(s);
                                if (WithTrace)
                                {
                                    Trace.WriteLine(s);
                                }

                                a             = new aPart();
                                a.Name        = param.Name;
                                a.VirtualName = s;
                                if (param.ParamDef != null)
                                {
                                    a.Token = param.ParamDef.MDToken.ToString();
                                }
                                a.Type     = aPart.Types.ParameterDefinition;
                                a.Editible = false;

                                // Icon
                                GenerateImage("PaImage");
                                a.Image = _tempImage;

                                aParts.Add(a);
                            }
                        }

                        if (metDef.Body != null && metDef.Body.Variables != null && metDef.Body.Variables.Count > 0)
                        {
                            foreach (dnlib.DotNet.Emit.Local variable in metDef.Body.Variables)
                            {
                                s  = "            Type: " + variable.Type.ToString() + " Name: " + variable.Name + NewLine;
                                s += "            Index: " + variable.Index.ToString();
                                ReturnString.Append(s);
                                if (WithTrace)
                                {
                                    Trace.WriteLine(s);
                                }

                                a             = new aPart();
                                a.Name        = variable.Name;
                                a.VirtualName = s;
                                a.Type        = aPart.Types.VariableDefinition;
                                a.Editible    = false;

                                // Icon
                                GenerateImage("PaImage");
                                a.Image = _tempImage;

                                aParts.Add(a);
                            }
                        }
                    }
                }
            }

            TextView = ReturnString.ToString();
            View     = new MyToolkit.Collections.ObservableCollectionView <aPart>(aParts);
            UpdateFilter();

            return(ReturnString.ToString());
        }