コード例 #1
0
        public Analyzer(string TargetPath)
        {
            BindingOperations.CollectionRegistering += BindingOperations_CollectionRegistering;
            targetPath = TargetPath;

            View   = new MyToolkit.Collections.ObservableCollectionView <aPart>();
            aParts = new System.Collections.ObjectModel.ObservableCollection <aPart>();
        }
コード例 #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());
        }
コード例 #3
0
        private string analyze(string assemblyPath, bool WithTrace = false)
        {
            AssemblyDefinition asmDef;

            string fileName = Path.GetFileName(assemblyPath);

            StringBuilder ReturnString = new StringBuilder();

            string s = String.Empty;

            // Load assembly
            asmDef = AssemblyDefinition.ReadAssembly(assemblyPath);

            foreach (ModuleDefinition modDef in asmDef.Modules)
            {
                s = modDef.Name + "  (" + modDef.MetadataToken.RID + ")" + NewLine;
                ReturnString.Append(s);
                if (WithTrace)
                {
                    Trace.WriteLine(s);
                }

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

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

                aParts.Add(a);

                foreach (TypeDefinition typDef in modDef.Types)
                {
                    s = "    " + typDef.Name + "  (" + typDef.MetadataToken.RID + ")" + NewLine;
                    ReturnString.Append(s);
                    if (WithTrace)
                    {
                        Trace.WriteLine(s);
                    }

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

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

                    aParts.Add(a);

                    foreach (MethodDefinition metDef in typDef.Methods)
                    {
                        s = "        " + metDef.Name + "  (" + metDef.MetadataToken.RID + ")" + NewLine;
                        ReturnString.Append(s);
                        if (WithTrace)
                        {
                            Trace.WriteLine(s);
                        }

                        a          = new aPart();
                        a.Name     = s;
                        a.Token    = metDef.MetadataToken.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 (ParameterDefinition param in metDef.Parameters)
                            {
                                s  = "            Type: " + param.ParameterType.ToString() + " Name: " + param.Name + NewLine;
                                s += "            Attributes: " + param.Attributes.ToString();
                                ReturnString.Append(s);
                                if (WithTrace)
                                {
                                    Trace.WriteLine(s);
                                }

                                a          = new aPart();
                                a.Name     = s;
                                a.Token    = param.MetadataToken.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 (VariableDefinition variable in metDef.Body.Variables)
                            {
                                s  = "            Type: " + variable.VariableType.ToString() + " Name: " + variable.Name + NewLine;
                                s += "            Index: " + variable.Index.ToString();
                                ReturnString.Append(s);
                                if (WithTrace)
                                {
                                    Trace.WriteLine(s);
                                }

                                a          = new aPart();
                                a.Name     = 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());
        }