Beispiel #1
0
        static void Main(string[] args)
        {
            PdbReader pdbReader = new PdbReader(@"D:\Honzik\Desktop\Mandelbrot\Mandelbrot\bin\Debug\Mandelbrot.exe");
            IModule   module    = pdbReader.Module;

            foreach (var namedTypeDefinition in module.GetAllTypes())
            {
                PropertyInfo propertyInfo2 = namedTypeDefinition.GetType().GetProperty("TokenValue", BindingFlags.NonPublic | BindingFlags.Instance);
                uint         value2        = (uint)propertyInfo2.GetValue(namedTypeDefinition, null);

                foreach (var methodDefinition in namedTypeDefinition.Methods)
                {
                    Console.WriteLine(methodDefinition.Name);

                    PropertyInfo propertyInfo = methodDefinition.GetType().GetProperty("TokenValue", BindingFlags.NonPublic | BindingFlags.Instance);
                    uint         value        = (uint)propertyInfo.GetValue(methodDefinition, null);
                    foreach (var location in methodDefinition.Locations)
                    {
                        foreach (var primarySourceLocation in pdbReader.GetAllPrimarySourceLocationsFor(location))
                        {
                            if (primarySourceLocation != null)
                            {
                                Console.WriteLine("line {0}, {1}:{2}", primarySourceLocation.StartLine,
                                                  primarySourceLocation.StartColumn, primarySourceLocation.EndColumn);
                            }
                        }
                    }
                }
            }
        }
        private void PopulateSourceLocations()
        {
            IModule module = PdbReader.Module;

            foreach (INamedTypeDefinition namedTypeDefinition in module.GetAllTypes())
            {
                foreach (IMethodDefinition methodDefinition in namedTypeDefinition.Methods)
                {
                    PropertyInfo propertyInfo = methodDefinition.GetType().GetProperty("TokenValue",
                                                                                       BindingFlags.NonPublic |
                                                                                       BindingFlags.Instance);
                    var methodMdToken          = (uint)propertyInfo.GetValue(methodDefinition, null);
                    var primarySourceLocations = new List <IPrimarySourceLocation>();
                    foreach (ILocation location in methodDefinition.Locations)
                    {
                        IEnumerable <IPrimarySourceLocation> notNullLocations =
                            PdbReader.GetAllPrimarySourceLocationsFor(location).Where(sl => sl != null);
                        primarySourceLocations.AddRange(notNullLocations);
                    }

                    IEnumerable <CciMethodLine> cciMethodLines =
                        primarySourceLocations.Where(sl => sl.StartLine < MaxSourceLineLength).Select(sl => new CciMethodLine(sl));
                    LocationsByToken[methodMdToken] = cciMethodLines;
                }
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            if (args == null || args.Length == 0)
            {
                Console.WriteLine("usage: peToText [path]fileName.ext");
                return;
            }

            PdbReader pdbReader = new PdbReader(args[0]);
            IModule   module    = pdbReader.Module;

            foreach (var namedTypeDefinition in module.GetAllTypes())
            {
                PropertyInfo propertyInfo2 = namedTypeDefinition.GetType().GetProperty("TokenValue", BindingFlags.NonPublic | BindingFlags.Instance);
                uint         value2        = (uint)propertyInfo2.GetValue(namedTypeDefinition, null);

                foreach (var methodDefinition in namedTypeDefinition.Methods)
                {
                    Console.WriteLine(methodDefinition.Name);

                    PropertyInfo propertyInfo = methodDefinition.GetType().GetProperty("TokenValue", BindingFlags.NonPublic | BindingFlags.Instance);
                    uint         value        = (uint)propertyInfo.GetValue(methodDefinition, null);
                    foreach (var location in methodDefinition.Locations)
                    {
                        foreach (var primarySourceLocation in pdbReader.GetAllPrimarySourceLocationsFor(location))
                        {
                            if (primarySourceLocation != null)
                            {
                                Console.WriteLine("line {0}, {1}:{2}", primarySourceLocation.StartLine,
                                                  primarySourceLocation.StartColumn, primarySourceLocation.EndColumn);
                            }
                        }
                    }
                }
            }
        }