Ejemplo n.º 1
0
        public TPIHashReader(IServiceContainer ctx, byte[] hashData) : base(hashData)
        {
            TPIReader tpi  = ctx.GetService <TPIReader>();
            TPIHash   hash = tpi.Header.Hash;

            switch (hash.HashKeySize)
            {
            case sizeof(UInt16):
            case sizeof(UInt32):
                break;

            default:
                throw new InvalidDataException();
            }

            if (hash.TypeOffsets.Size > 0)
            {
                Position = hash.TypeOffsets.Offset;
                uint NumTiPairs = (uint)(hash.TypeOffsets.Size / Marshal.SizeOf <TIOffset>());
                for (int i = 1; i < NumTiPairs; i++)
                {
                    TIOffset tiOff = Read <TIOffset>();
                    TypeIndexToOffset.Add(tiOff.TypeIndex, tiOff.Offset);
                }
            }

            if (hash.HashValues.Size > 0)
            {
                Position = hash.HashValues.Offset;
                uint NumHashValues = hash.HashValues.Size / sizeof(UInt32);
                RecordHashValues = PerformAt(hash.HashValues.Offset, () => {
                    return(Enumerable.Range(1, (int)NumHashValues)
                           .Select(_ => ReadUInt32())
                           .ToArray());
                });
            }

            if (hash.HashHeadList.Size > 0)
            {
                Position             = hash.HashHeadList.Offset;
                NameIndexToTypeIndex = Deserializers.ReadMap <UInt32, UInt32>(this);
            }
        }
Ejemplo n.º 2
0
        public UdtNameTableReader(IServiceContainer ctx, byte[] namesData) : base(namesData)
        {
            this.Tpi      = ctx.GetService <TPIReader>();
            this.resolver = ctx.GetService <TypeResolver>();

            Magic = ReadUInt32();
            if (Magic != MAGIC)
            {
                throw new InvalidDataException();
            }

            Version = ReadEnum <UdtNameTableVersion>();

            data = Deserializers.ReadBuffer(this);
            rdr  = new SpanStream(data);

            NameIndices         = Deserializers.ReadArray <uint>(this);
            NumberOfNameIndices = ReadUInt32();

            //BuildTypeMap();
        }
Ejemplo n.º 3
0
        public HashDataReader(TPIReader tpi, Stream stream) : base(stream)
        {
            TPIHash hash       = tpi.Header.Hash;
            uint    NumTiPairs = (uint)(hash.TypeOffsets.Size / Marshal.SizeOf <TPISlice>());

            PerformAt(hash.TypeOffsets.Offset, () => {
                for (int i = 1; i < NumTiPairs; i++)
                {
                    TIOffset tiOff = ReadStruct <TIOffset>();
                    TypeIndexToOffset.Add(tiOff.TypeIndex, tiOff.Offset);
                }
            });

            uint NumHashValues = (uint)(hash.HashValues.Size / sizeof(UInt32));

            RecordHashValues = PerformAt(hash.HashValues.Offset, () => {
                return(Enumerable.Range(1, (int)NumHashValues)
                       .Select(_ => ReadUInt32())
                       .ToArray());
            });
        }
Ejemplo n.º 4
0
 public HasherV2(IServiceContainer ctx)
 {
     this.Tpi = ctx.GetService <TPIReader>();
 }
Ejemplo n.º 5
0
        public PDBFile(FileStream stream)
        {
            this.fs          = stream;
            this.StreamTable = Services.GetService <StreamTableReader>();

            this.mf       = MemoryMappedFile.CreateFromFile(stream, null, 0, MemoryMappedFileAccess.Read, HandleInheritability.Inheritable, true);
            this.FileType = DetectPdbType();

            Services.AddService <PDBFile>(this);

            //$TODO
            if (this.FileType == PDBType.Small)
            {
                throw new NotImplementedException($"Small/Old/JG PDBs not supported/tested yet");
            }


            MSFReader msf = new MSFReader(mf, stream.Length);

            Services.AddService <MSFReader>(msf);

            StreamTableReader streamTable;

            // init stream table
            {
                byte[] streamTableData = msf.StreamTable();
                streamTable = new StreamTableReader(Services, streamTableData);
            }
            Services.AddService <StreamTableReader>(streamTable);

            DBIReader dbi;

            // init DBI
            {
                byte[] dbiData = streamTable.GetStream(DefaultStreams.DBI);
                dbi = new DBIReader(Services, dbiData);
                OnDbiInit?.Invoke(dbi);
            }
            Services.AddService <DBIReader>(dbi);

            TPIReader tpi;

            // init TPI
            {
                byte[] tpiData = streamTable.GetStream(DefaultStreams.TPI);
                tpi = new TPIReader(Services, new SpanStream(tpiData));
                OnTpiInit?.Invoke(tpi);
            }
            Services.AddService <TPIReader>(tpi);

            TPIHashReader tpiHash = null;

            // init TPIHash
            if (tpi.Header.Hash.StreamNumber != -1)
            {
                byte[] tpiHashData = streamTable.GetStream(tpi.Header.Hash.StreamNumber);
                tpiHash = new TPIHashReader(Services, tpiHashData);
                Services.AddService <TPIHashReader>(tpiHash);
            }

            // init resolver
            TypeResolver resolver = new TypeResolver(Services);

            Services.AddService <TypeResolver>(resolver);


            // init Hasher
            HasherV2 hasher = new HasherV2(Services);

            Services.AddService <HasherV2>(hasher);

            PdbStreamReader nameMap;

            // init NameMap
            {
                byte[] nameMapData = streamTable.GetStream(DefaultStreams.PDB);
                nameMap = new PdbStreamReader(nameMapData);
            }
            Services.AddService <PdbStreamReader>(nameMap);

            NamedStreamTableReader namedStreamTable = new NamedStreamTableReader(Services);

            Services.AddService <NamedStreamTableReader>(namedStreamTable);

            UdtNameTableReader udtNameTable = null;
            // init UdtNameMap
            {
                byte[] namesData = namedStreamTable.GetStreamByName("/names");
                if (namesData != null)
                {
                    udtNameTable = new UdtNameTableReader(Services, namesData);
                    Services.AddService <UdtNameTableReader>(udtNameTable);
                }
            }
        }
Ejemplo n.º 6
0
 public TypeResolver(IServiceContainer ctx)
 {
     tpi     = ctx.GetService <TPIReader>();
     tpiHash = ctx.GetService <TPIHashReader>();
 }
Ejemplo n.º 7
0
        public PDBFile(FileStream stream)
        {
            this.fs      = stream;
            this.mf      = MemoryMappedFile.CreateFromFile(stream, null, 0, MemoryMappedFileAccess.Read, HandleInheritability.Inheritable, true);
            this.memSpan = new MemoryMappedSpan <byte>(mf, (int)fs.Length);

            this.StreamTable = Services.GetService <StreamTableReader>();
            Services.AddService <PDBFile>(this);

            this.Type = MSFReader.DetectPdbType(memSpan.GetSpan());

            MSFReader         msf         = null;
            StreamTableReader streamTable = null;

            if (Type != PDBType.Old)
            {
                switch (Type)
                {
                case PDBType.Big:
                    msf = new MSFReaderDS(memSpan.Memory);
                    break;

                case PDBType.Small:
                    msf = new MSFReaderJG(memSpan.Memory);
                    break;

                default:
                    throw new InvalidOperationException();
                }
                Services.AddService <MSFReader>(msf);

                // init stream table
                {
                    byte[] streamTableData = msf.StreamTable();
                    streamTable = new StreamTableReader(Services, streamTableData);
                }
                Services.AddService <StreamTableReader>(streamTable);

                DBIReader dbi;
                // init DBI
                {
                    byte[] dbiData = streamTable.GetStream(DefaultStreams.DBI);
                    dbi = new DBIReader(Services, dbiData);
                    OnDbiInit?.Invoke(dbi);
                }
                Services.AddService <DBIReader>(dbi);
            }

            TPIReader tpi;

            // init TPI
            {
                SpanStream tpiStream;
                if (Type != PDBType.Old)
                {
                    byte[] tpiData = streamTable.GetStream(DefaultStreams.TPI);
                    tpiStream = new SpanStream(tpiData);
                }
                else
                {
                    Span <byte> span   = memSpan.GetSpan();
                    JGHeaderOld header = span.Read <JGHeaderOld>(0);
                    // $TODO: the MSFReader interface should be abstracted into a more generic PDBHeader
                    Services.AddService <JGHeaderOld>(header);

                    tpiStream = new SpanStream(span.Slice(header.SIZE).ToArray());
                }
                tpi = new TPIReader(Services, tpiStream);
                OnTpiInit?.Invoke(tpi);
            }
            Services.AddService <TPIReader>(tpi);

            TPIHashReader tpiHash = null;

            // init TPIHash
            if (Type != PDBType.Old && tpi.Header.Hash.StreamNumber != -1)
            {
                byte[] tpiHashData = streamTable.GetStream(tpi.Header.Hash.StreamNumber);
                tpiHash = new TPIHashReader(Services, tpiHashData);
                Services.AddService <TPIHashReader>(tpiHash);
            }

            // init resolver
            TypeResolver resolver = new TypeResolver(Services);

            Services.AddService <TypeResolver>(resolver);


            // init Hasher
            HasherV2 hasher = new HasherV2(Services);

            Services.AddService <HasherV2>(hasher);

            if (Type != PDBType.Old)
            {
                {                 // init NameMap
                    byte[] nameMapData = streamTable.GetStream(DefaultStreams.PDB);

                    PdbStreamReader nameMap = new PdbStreamReader(nameMapData);
                    Services.AddService <PdbStreamReader>(nameMap);
                }

                NamedStreamTableReader namedStreamTable = new NamedStreamTableReader(Services);
                Services.AddService <NamedStreamTableReader>(namedStreamTable);

                {                 // init UdtNameMap
                    byte[] namesData = namedStreamTable.GetStreamByName("/names");
                    if (namesData != null)
                    {
                        UdtNameTableReader udtNameTable = new UdtNameTableReader(Services, namesData);
                        Services.AddService <UdtNameTableReader>(udtNameTable);
                    }
                }
            }
        }