Ejemplo n.º 1
0
        public TypeNode AddDependency(ILeafContainer type)
        {
            TypeNode node = new TypeNode(type);

            TypeDependencies.Add(node);
            return(node);
        }
Ejemplo n.º 2
0
        private TypeNode AddDependency(ILeafContainer leaf)
        {
            TypeNode node = new TypeNode(leaf);

            TypeDependencies.Add(node);
            return(node);
        }
Ejemplo n.º 3
0
        private void WriteType(ILeafContainer leafc)
        {
            switch (leafc.Type)
            {
            case LeafType.SPECIAL_BUILTIN:
                BuiltinTypeLeaf builtin = leafc.Data as BuiltinTypeLeaf;
                itw.Write(SpecialTypeMaps[builtin.SpecialType]);
                if (builtin.TypeMode != SpecialTypeMode.Direct)
                {
                    itw.Write('*');
                }
                break;

            case LeafType.LF_ARGLIST:
                LF_ARGLIST lfArgList = leafc.Data as LF_ARGLIST;
                itw.Write('(');
                for (int i = 0; i < lfArgList.NumberOfArguments; i++)
                {
                    WriteType(lfArgList.ArgumentTypes[i]);
                    if (lfArgList.ArgumentTypes[i].Data is BuiltinTypeLeaf bt &&
                        i + 1 == lfArgList.NumberOfArguments &&
                        bt.SpecialType == SpecialType.None &&
                        bt.TypeMode == SpecialTypeMode.Direct
                        )
                    {
                        itw.Write("...");
                    }
Ejemplo n.º 4
0
        public override void Read()
        {
            TypeDataReader r = CreateReader();

            NumElements = r.ReadUInt16();
            Bases       = r.ReadIndexedType16Lazy();
        }
Ejemplo n.º 5
0
        //$TODO(work in progress): fix the NI -> TI mapping
        private void BuildTypeMap()
        {
            uint minTi = Tpi.Header.MinTypeIndex;
            uint maxTi = minTi + Tpi.Header.MaxTypeIndex - 1;

            for (uint ti = minTi; ti <= maxTi; ti++)
            {
                ILeafContainer leafC = resolver.GetTypeByIndex(ti);
                if (leafC == null || !(leafC.Data is LeafBase leaf))
                {
                    continue;
                }

                if (!leaf.IsDefnUdt)
                {
                    continue;
                }

                string typeName = leaf.UdtName;

                if (leaf.IsLocalDefnUdtWithUniqueName)
                {
                    throw new NotImplementedException();
                }

                if (!GetIndex(typeName, out uint nameIndex))
                {
                    //$TODO: how do i handle this?
                    continue;
                }

                NameIndex_TypeIndex.Add(nameIndex, ti);
            }
        }
Ejemplo n.º 6
0
        public override void Read()
        {
            TypeDataReader r = CreateReader();

            r.ReadUInt16();             //padding
            PointerType = r.ReadIndexedTypeLazy();
        }
Ejemplo n.º 7
0
        public override void Read()
        {
            TypeDataReader r = CreateReader();

            Attributes   = r.ReadFlagsEnum <CVModifier>();
            ModifiedType = r.ReadIndexedType16Lazy();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Read a varying ILeaf which can be either a ILeaf type or a raw data marker
        /// </summary>
        /// <param name="dataSize"></param>
        /// <param name="leafType"></param>
        /// <returns>true if we found a ILeaf, false if we found raw data marker</returns>
        public ILeafContainer ReadVaryingType(out uint dataSize)
        {
            UInt16 leafValue = ReadUInt16();

            if (leafValue < (ushort)LeafType.LF_NUMERIC)
            {
                // $TODO: ILeafValue is not a ILeaf marker, but it's still a valid ushort
                // do we need to save this?
                dataSize = 0;
                return(null);
            }

            if (!Enum.IsDefined(typeof(LeafType), leafValue))
            {
                throw new InvalidDataException($"Unknown ILeaf type {leafValue} while computing ILeaf data size");
            }

            LeafType leafType = (LeafType)leafValue;

            dataSize = PrimitiveDataSizes[leafType];
            Seek(-2, SeekOrigin.Current);

            TypeDataReader rdr  = new TypeDataReader(ctx, this);
            ILeafContainer leaf = rdr.ReadTypeDirect(hasSize: false);

            //ILeafContainer leaf = new TypeDataReader(ctx, this).ReadTypeDirect(hasSize: false);

            // add leaf size
            this.Position += rdr.Position;

            return(leaf);
        }
Ejemplo n.º 9
0
        public override void Read()
        {
            TypeDataReader r = CreateReader();

            Attributes = new FieldAttributes(r.ReadUInt16());
            Value      = r.ReadVaryingType(out uint ILeafSize);
            FieldName  = r.ReadCString();
        }
Ejemplo n.º 10
0
        public override void Read()
        {
            TypeDataReader r = CreateReader();

            Attributes    = new FieldAttributes(r.ReadUInt16());
            BaseClassType = r.ReadIndexedType32Lazy();

            Offset = r.ReadVaryingType(out uint dataSize);
        }
Ejemplo n.º 11
0
        public void WriteVaryingType(ILeafContainer leaf)
        {
            if ((ushort)leaf.Type < (ushort)LeafType.LF_NUMERIC)
            {
                throw new NotImplementedException();
            }

            leaf.Data.Write();
        }
Ejemplo n.º 12
0
        public override void Read()
        {
            var r = CreateReader();

            Offset       = r.ReadUInt32();
            SectionIndex = r.ReadUInt16();
            r.ReadUInt16();             //padding
            Type = r.ReadIndexedTypeLazy();
        }
Ejemplo n.º 13
0
        public override void Read()
        {
            var r = CreateReader();

            InlinerParentOffset = r.ReadUInt32();
            Inliner             = r.ReadSymbol(Module, InlinerParentOffset);
            End               = r.ReadUInt32();
            Inlinee           = r.ReadIndexedTypeLazy();
            BinaryAnnotations = r.ReadRemaining();
        }
Ejemplo n.º 14
0
        public override void Read()
        {
            TypeDataReader r = CreateReader();

            ReturnValueType   = r.ReadIndexedType32Lazy();
            CallingConvention = r.ReadEnum <CallingConvention>();
            r.ReadByte();             //reserved
            NumberOfParameters = r.ReadUInt16();
            ArgumentListType   = r.ReadIndexedType32Lazy();
        }
Ejemplo n.º 15
0
        public override void Read()
        {
            var r = CreateReader();

            CallSiteOffset = r.ReadUInt32();

            SectionIndex = r.ReadUInt16();
            HeapAllocationInstructionSize = r.ReadUInt16();

            FunctionSignature = r.ReadIndexedType32Lazy();
        }
Ejemplo n.º 16
0
        public override void Read()
        {
            TypeDataReader r = CreateReader();

            Attributes             = new FieldAttributes(r.ReadUInt16());
            VirtualBaseClassType   = r.ReadIndexedTypeLazy();
            VirtualBasePointerType = r.ReadIndexedTypeLazy();


            //virtual base pointer offset from address point
            OffsetFromAddress = r.ReadVaryingType(out uint dynSize1);
            //virtual base offset from vbtable
            OffsetFromTable = r.ReadVaryingType(out uint dynSize2);
        }
Ejemplo n.º 17
0
        private ILeafContainer ReadTypeOld(out long dataSize)
        {
            uint hash = ReadUInt32();

            // we have no length, so we just pass all memory (after the hash)
            SpanStream     memStream = new SpanStream(Memory.Slice((int)Position));
            TypeDataReader rdr       = new TypeDataReader(ctx, memStream);

            // without a length, and with a small amount of data, we can just read this directly
            ILeafContainer leaf = rdr.ReadTypeDirect(false);

            // hash + type data
            dataSize = Position + rdr.Position;

            Position += rdr.Position;
            return(leaf);
        }
Ejemplo n.º 18
0
        public override void Read()
        {
            var r = CreateReader();

            ParentOffset = r.ReadUInt32();
            ParentSymbol = r.ReadSymbol(Module, ParentOffset);

            End        = r.ReadUInt32();
            NextOffset = r.ReadUInt32();
            NextSymbol = r.ReadSymbol(Module, NextOffset);

            Length           = r.ReadUInt32();
            DebugStartOffset = r.ReadUInt32();
            DebugEndOffset   = r.ReadUInt32();
            Type             = r.ReadIndexedType32Lazy();
            Offset           = r.ReadUInt32();
            Segment          = r.ReadUInt16();
            Flags            = r.ReadFlagsEnum <CV_PROCFLAGS>();
            Name             = r.ReadSymbolString();
        }
Ejemplo n.º 19
0
        public static long LeafDecimalValue(this ILeafContainer leaf)
        {
            switch (leaf.Data)
            {
            case LF_CHAR lfChar:
                return(lfChar.Value);

            case LF_SHORT lfShort:
                return(lfShort.Value);

            case LF_USHORT lfUShort:
                return(lfUShort.Value);

            case LF_LONG lfLong:
                return(lfLong.Value);

            case LF_ULONG lfULong:
                return(lfULong.Value);

            default:
                throw new NotSupportedException($"Cannot get numeric decimal value for leaf {leaf.Type}");
            }
        }
Ejemplo n.º 20
0
        public override void Read()
        {
            var r = CreateReader();

            ItemID = r.ReadIndexedTypeLazy();
        }
Ejemplo n.º 21
0
 public TypeNode(ILeafContainer leaf)
 {
     this.Type = leaf;
     this.HandleType();
 }
Ejemplo n.º 22
0
        static void Main(string[] args)
        {
            ParseArguments(args);

            if (PdbFilePath == null)
            {
                Console.Error.WriteLine(@"PDBSharp.Dumper
  Usage: PDBSharp.Dumper <options> <file.pdb>
    [-dump]            Save individual PDB Streams to files
    [-dump-modules]    Verbose output for DBI Modules
    [-dump-leaves]     Verbose output for TPI Leaves
    [-dump-syms]       Verbose output for DBI Symbols
    [-print]           Extract and print type definitions");
                Environment.Exit(1);
            }

#if PERF
            Console.WriteLine("Starting...");
            Stopwatch sw = new Stopwatch();
            sw.Start();
#endif

            PDBFile           pdb = PDBFile.Open(PdbFilePath);
            IServiceContainer sc  = pdb.Services;

            DBIReader         dbi         = sc.GetService <DBIReader>();
            TPIReader         tpi         = sc.GetService <TPIReader>();
            StreamTableReader streamTable = sc.GetService <StreamTableReader>();

            if (OptPrintDecls)
            {
                var        tree = new GraphBuilder(sc).Build();
                CodeWriter cw   = new CodeWriter(tree);
#if !PERF
                cw.Write(Console.Out);
#endif
            }

            if (OptDumpLeaves)
            {
                pdb.OnTpiInit += Pdb_OnTpiInit;
            }
            if (OptDumpModules || OptDumpSymbols)
            {
                pdb.OnDbiInit += Pdb_OnDbiInit;
            }

            if (OptDumpStreams)
            {
                DirectoryInfo dumpDir = Directory.CreateDirectory(Path.GetFileNameWithoutExtension(PdbFilePath));
                for (int i = 1; i < streamTable.NumStreams; i++)
                {
                    string dumpPath = Path.Combine(dumpDir.ToString(), $"stream{i}.bin");

                    byte[] stream = streamTable.GetStream(i);
                    File.WriteAllBytes(dumpPath, stream);
                }
            }

            /*
             * foreach(var type in ctx.TpiReader.Types) {
             *      //Console.WriteLine(type);
             * }*/

            TPIHashReader      tpiHash      = sc.GetService <TPIHashReader>();
            UdtNameTableReader udtNameTable = sc.GetService <UdtNameTableReader>();
            TypeResolver       resolver     = sc.GetService <TypeResolver>();
            if (tpiHash != null && udtNameTable != null)
            {
                foreach (var pair in tpiHash.NameIndexToTypeIndex)
                {
                    string         name = udtNameTable.GetString(pair.Key);
                    ILeafContainer leaf = resolver.GetTypeByIndex(pair.Value);
#if !PERF
                    Console.WriteLine($"=> {name} [NI={pair.Key}] [TI={pair.Value}]");
                    Console.WriteLine(leaf.Data.GetType().Name);
#endif
                }
            }

            foreach (var contrib in dbi.SectionContribs.SectionContribs)
            {
#if !PERF
                ObjectDumper.Dump(contrib);
#endif
            }

            DebugReader debug = dbi.DebugInfo;
            if (debug != null && debug.FPO != null)
            {
                foreach (var frame in debug.FPO.Frames)
                {
#if !PERF
                    ObjectDumper.Dump(frame);
#endif
                }
            }

            foreach (var container in dbi.Modules)
            {
#if !PERF
                Console.WriteLine($"[MODULE => {container.Info.ModuleName}]");
                Console.WriteLine($"[OBJECT => {container.Info.ObjectFileName}]");
                Console.WriteLine($"[SRC    => {container.Info.SourceFileName}]");
                if (container.Module != null)
                {
                    Console.WriteLine($"[TYPE   => {container.Module.GetType().Name}");
                }
                Console.WriteLine();
#endif

                IModule mod = container.Module;
                if (mod != null)
                {
                    foreach (var sym in mod.Symbols)
                    {
#if !PERF
                        Console.WriteLine(sym);
#endif
                    }
                }
            }

            foreach (var type in tpi.Types)
            {
#if !PERF
                Console.WriteLine(type);
#endif
            }

#if !PERF
            Console.WriteLine("Press Enter to continue...");
            Console.ReadLine();
#else
            sw.Stop();
            Console.WriteLine($"Finished in {sw.Elapsed.TotalSeconds} seconds");
#endif
        }
Ejemplo n.º 23
0
        public override void Read()
        {
            TypeDataReader r = CreateReader();

            Referenced = r.ReadIndexedTypeLazy();
        }
Ejemplo n.º 24
0
 public void WriteIndexedType16(ILeafContainer leaf)
 {
     WriteUInt16((ushort)leaf.TypeIndex);
     leaf.Data.Write();
 }
Ejemplo n.º 25
0
 public void WriteIndexedType(ILeafContainer leaf)
 {
     WriteUInt32(leaf.TypeIndex);
     leaf.Data.Write();
 }