public void Throws_Exception_If_Invalid_Features_Response_Received()
        {
            MessageSender.SendTransportMessage(TransportMessage.Opened);
            MessageSender.SendToReceivePipe(StreamHeader.Client());

            Assert.Throws <XmppException>(() => MessageSender.SendToReceivePipe(new XmlElement("stream:feature")));
        }
Esempio n. 2
0
        /// <summary>
        /// Reads stream headers described in ECMA-335 24.2.2 Stream header
        /// </summary>
        private StreamHeader[] ReadStreamHeaders(ref BlobReader memReader)
        {
            // storage header:
            memReader.ReadUInt16();
            int streamCount = memReader.ReadInt16();

            var streamHeaders = new StreamHeader[streamCount];

            for (int i = 0; i < streamHeaders.Length; i++)
            {
                if (memReader.RemainingBytes < COR20Constants.MinimumSizeofStreamHeader)
                {
                    throw new BadImageFormatException("StreamHeaderTooSmall");
                }

                streamHeaders[i].Offset = memReader.ReadUInt32();
                streamHeaders[i].Size   = memReader.ReadInt32();
                streamHeaders[i].Name   = memReader.ReadUtf8NullTerminated();
                bool aligned = memReader.TryAlign(4);

                if (!aligned || memReader.RemainingBytes == 0)
                {
                    throw new BadImageFormatException("NotEnoughSpaceForStreamHeaderName");
                }
            }

            return(streamHeaders);
        }
Esempio n. 3
0
        Task IPreprocessingStep.Execute(IPreprocessingStepCallback callback)
        {
            var header             = new StreamHeader(sourceFile.Location);
            var detectedFormatStep = extentions.Items.Select(d => d.DetectFormat(sourceFile, header)).FirstOrDefault(x => x != null);

            if (detectedFormatStep != null)
            {
                callback.YieldNextStep(detectedFormatStep);
            }
            else if (IsZip(sourceFile, header))
            {
                callback.YieldNextStep(preprocessingStepsFactory.CreateUnpackingStep(sourceFile));
            }
            else if (IsGzip(sourceFile, header))
            {
                callback.YieldNextStep(preprocessingStepsFactory.CreateGunzippingStep(sourceFile));
            }
            else if (IsTar(sourceFile, header))
            {
                callback.YieldNextStep(preprocessingStepsFactory.CreateUntarStep(sourceFile));
            }
            else
            {
                AutodetectFormatAndYield(sourceFile, callback);
            }
            return(Task.FromResult(0));
        }
        //-------------------------------------------------
        private bool ReadFormatControl(Stream Stream_in)
        {
            if ((Stream_in == null))
            {
                return(false);
            }
            if ((this._Blocks == null))
            {
                return(false);
            }
            BinaryFormatter bf = new BinaryFormatter();

            try
            {
                Stream_in.Seek(0, SeekOrigin.Begin);
                this._Header = (StreamHeader)bf.Deserialize(Stream_in);
                Stream_in.Seek((this._Header.DataOffset + this._Header.DataSize), SeekOrigin.Begin);
                byte[] inbytes = new byte[Convert.ToInt32((Stream_in.Length - Stream_in.Position) - 1) + 1];
                Stream_in.Read(inbytes, 0, inbytes.Length);
                byte[] outbytes = { };
                if (!this._DecodeBytes(null, inbytes, ref outbytes))
                {
                    return(false);
                }
                MemoryStream ms = new MemoryStream(outbytes);
                this._Blocks = (ArrayList)bf.Deserialize(ms);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(true);
        }
        //-------------------------------------------------
        public Stream Close(bool Compact_in, bool CloseStream_in)
        {
            if ((this._Stream != null))
            {
                if (Compact_in)
                {
                    if (!this.Compact())
                    {
                        return(null);
                    }
                }
                if (this._BlocksDirty)
                {
                    if (!this.WriteFormatControl(this._Stream))
                    {
                        return(null);
                    }
                }
                if (CloseStream_in)
                {
                    if ((this._Stream != null))
                    {
                        this._Stream.Close();
                    }
                }
            }
            this._Header      = null;
            this._Blocks      = null;
            this._BlocksDirty = false;
            Stream stream = this._Stream;

            this._Stream = null;
            return(stream);
        }
Esempio n. 6
0
 private StreamBlock(short streamId, StreamHeader header, byte[] checksum, byte[] data)
 {
     _streamId = streamId;
     _header   = header;
     _checksum = checksum;
     _data     = data;
 }
Esempio n. 7
0
 private static void PrintStreamHeader(StreamHeader value, int indent)
 {
     PrintRawData(value, indent);
     Print($"Name: {value.DisplayName}", indent);
     Print($"Offset: {value.Offset:X8}", indent);
     Print($"Size: {value.Size:X8}", indent);
 }
Esempio n. 8
0
        public byte[] GetStreamBytes(BinaryReader reader, StreamHeader streamHeader, uint metadataDirectoryAddress, IEnumerable <Section> sections)
        {
            var rva        = metadataDirectoryAddress + streamHeader.Offset;
            var fileOffset = BinUtil.RVAToOffset(rva, sections);

            reader.BaseStream.Seek((long)fileOffset, SeekOrigin.Begin);
            return(reader.ReadBytes((int)streamHeader.Size));
        }
Esempio n. 9
0
        BlobChunkVerificationResultInfo WriteChunksWriteStart()
        {
            var result = VerifyEnoughBytesForChunkOrData(kHeaderSize);

            if (result.IsValid)
            {
                mHeader = new StreamHeader(mHeader.FileType);
                mHeader.Serialize(UnderlyingStream);
            }

            return(result);
        }
Esempio n. 10
0
        public void ModifyD3DTX(DDS_Master dds)                                                //ISSUE HERE WITH DXT5 AND MIP MAPS WITH UPSCALED TEXTURES
        {
            mWidth         = dds.header.dwWidth;                                               //this is correct
            mHeight        = dds.header.dwHeight;                                              //this is correct
            mSurfaceFormat = DDS_Functions.Get_T3Format_FromFourCC(dds.header.ddspf.dwFourCC); //this is correct
            mDepth         = dds.header.dwDepth;
            mNumMipLevels  = dds.header.dwMipMapCount;

            List <byte[]> ddsData = dds.textureData;

            ddsData.Reverse();

            mPixelData.Clear();   //this is correct
            mPixelData = ddsData; //this is correct


            StreamHeader newStreamHeader = new StreamHeader()
            {
                mRegionCount   = (int)dds.header.dwMipMapCount,                         //this is correct
                mAuxDataCount  = mStreamHeader.mAuxDataCount,                           //this is correct
                mTotalDataSize = (int)ByteFunctions.Get2DByteArrayTotalSize(mPixelData) //this is correct
            };

            mStreamHeader = newStreamHeader;                                                //this is correct

            List <RegionStreamHeader> regionStreamHeader = new List <RegionStreamHeader>(); //this is correct

            uint[,] mipMapResolutions = DDS_Functions.DDS_CalculateMipResolutions(mNumMipLevels, mWidth, mHeight);
            bool blockSizeDouble = DDS_Functions.DDS_CompressionBool(dds.header);

            for (int i = 0; i < mStreamHeader.mRegionCount; i++)
            {
                RegionStreamHeader region = new RegionStreamHeader()
                {
                    mDataSize   = (uint)mPixelData[i].Length,
                    mFaceIndex  = 0,                                                                                                          //NOTE: for cubemap textures this will need to change
                    mMipCount   = 1,                                                                                                          //NOTE: for cubemap textures this will need to change
                    mMipIndex   = (mStreamHeader.mRegionCount - 1) - i,
                    mPitch      = DDS_Functions.DDS_ComputePitchValue(mipMapResolutions[mStreamHeader.mRegionCount - i, 0], blockSizeDouble), //this is correct
                    mSlicePitch = mPixelData[i].Length,                                                                                       //this is correct
                };

                regionStreamHeader.Add(region);
            }

            regionStreamHeader.Reverse();
            mRegionHeaders = regionStreamHeader.ToArray();

            UpdateArrayCapacities();
            PrintConsole();
        }
Esempio n. 11
0
        public StorageStreamNode(HexDocument doc, StreamHeader sh, int streamNumber, DotNetStream knownStream, IMetaData md)
            : base((ulong)sh.StartOffset, (ulong)sh.EndOffset - 1)
        {
            this.StreamNumber      = streamNumber;
            this.StorageStreamType = GetStorageStreamType(knownStream);
            this.storageStreamVM   = new StorageStreamVM(this, doc, StartOffset, (int)(EndOffset - StartOffset + 1 - 8));

            var tblStream = knownStream as TablesStream;

            if (tblStream != null)
            {
                this.newChild = new TablesStreamNode(doc, tblStream, md);
            }
        }
Esempio n. 12
0
        public StorageStreamNode(HexBuffer buffer, StreamHeader sh, int streamNumber, DotNetStream knownStream, IMetaData md)
            : base(HexSpan.FromBounds((ulong)sh.StartOffset, (ulong)sh.EndOffset))
        {
            StreamNumber      = streamNumber;
            StorageStreamType = GetStorageStreamType(knownStream);
            storageStreamVM   = new StorageStreamVM(this, buffer, Span.Start, (int)(Span.Length - 8).ToUInt64());

            var tblStream = knownStream as TablesStream;

            if (tblStream != null)
            {
                newChild = new TablesStreamNode(buffer, tblStream, md);
            }
        }
        public void ModifyD3DTX(DDS_Master dds)
        {
            mWidth         = dds.header.dwWidth;
            mHeight        = dds.header.dwHeight;
            mSurfaceFormat = DDS_Functions.Get_T3Format_FromFourCC(dds.header.ddspf.dwFourCC);
            mDepth         = dds.header.dwDepth;
            mNumMipLevels  = dds.header.dwMipMapCount;

            List <byte[]> ddsData = new List <byte[]>(dds.textureData); //this is correct

            ddsData.Reverse();                                          //this is correct

            mPixelData.Clear();                                         //this is correct
            mPixelData = ddsData;                                       //this is correct

            StreamHeader newStreamHeader = new StreamHeader()
            {
                mRegionCount   = (int)dds.header.dwMipMapCount,
                mAuxDataCount  = mStreamHeader.mAuxDataCount,
                mTotalDataSize = (int)ByteFunctions.Get2DByteArrayTotalSize(mPixelData) //this is correct
            };

            mStreamHeader = newStreamHeader;

            RegionStreamHeader[] regionStreamHeader = new RegionStreamHeader[mStreamHeader.mRegionCount];
            uint[,] mipMapResolutions = DDS_Functions.DDS_CalculateMipResolutions(mNumMipLevels, mWidth, mHeight);
            bool blockSizeDouble = DDS_Functions.DDS_CompressionBool(dds.header);

            for (int i = 0; i < regionStreamHeader.Length; i++)
            {
                regionStreamHeader[i] = new RegionStreamHeader()
                {
                    mDataSize   = (uint)mPixelData[i].Length,
                    mFaceIndex  = 0,                                                                                                         //NOTE: for cubemap textures this will need to change
                    mMipCount   = 1,                                                                                                         //NOTE: for cubemap textures this will need to change
                    mMipIndex   = (regionStreamHeader.Length - 1) - i,                                                                       //mMipIndex = (regionStreamHeader.Length - 1) - i,
                    mPitch      = DDS_Functions.DDS_ComputePitchValue(mipMapResolutions[regionStreamHeader.Length - i, 0], blockSizeDouble), //this is correct
                    mSlicePitch = mPixelData[i].Length,                                                                                      //this is correct
                };
            }

            mRegionHeaders = regionStreamHeader;

            UpdateArrayCapacities();
            //PrintConsole();
        }
        //-------------------------------------------------
        public bool CreateMemoryStream()
        {
            this.Close();
            this._Header = new StreamHeader();
            this._Blocks = new ArrayList();
            MemoryStream STM = new MemoryStream();

            if (!this.WriteFormatControl(STM))
            {
                return(false);
            }
            if (!this.OpenStream(STM))
            {
                return(false);
            }
            return(true);
        }
        public void Can_Negotiate_Tls_Feature()
        {
            XmlElement sentElement      = default;
            bool?      setTlsSend       = default;
            var        featuresResponse = new XmlElement("stream:features", new XmlElement("starttls").Xmlns(XmppNamespaces.Tls));

            HandlersRegistry.RegisterTransmitPipeHandler <XmlElement>(request => sentElement           = request);
            HandlersRegistry.RegisterTransportMessageHandler(TransportMessage.SetTls, () => setTlsSend = true);

            MessageSender.SendTransportMessage(TransportMessage.Opened);
            MessageSender.SendToReceivePipe(StreamHeader.Client());
            MessageSender.SendToReceivePipe(featuresResponse);

            Assert.Equal("starttls", sentElement.Name);

            MessageSender.SendToReceivePipe(new XmlElement("proceed").Xmlns(XmppNamespaces.Tls));
            Assert.True(setTlsSend);
        }
Esempio n. 16
0
        protected static StreamBlock BuildBlock(byte[] rawBlock)
        {
            StreamHeader header   = (StreamHeader)rawBlock.Skip(HEADER_OFFSET).Take(HEADER_LENGTH).First();
            short        streamId = BitConverter.ToInt16(rawBlock.Skip(STREAM_ID_OFFSET).Take(STREAM_ID_LENGTH).ToArray(), 0);

            byte[] checksum = rawBlock.Skip(CHECKSUM_OFFSET).Take(CHECKSUM_LENGTH).ToArray();
            if (header.HasFlag(StreamHeader.CACHEABLE))
            {
                StreamBlock block = StreamCache.GetCache(checksum);
                if (block != null)
                {
                    return(block);
                }
            }
            MD5 md5 = MD5.Create();

            byte[] data = rawBlock.Skip(DATA_OFFSET).ToArray();
            byte[] calculatedChecksum = md5.ComputeHash(data);
            if (!calculatedChecksum.SequenceEqual(checksum))
            {
                throw new InvalidDataException("Checksums did not match when checking data in BuildBlock routine! Calculated: " + BitConverter.ToString(calculatedChecksum) + " | Stored: " + BitConverter.ToString(checksum));
            }
            if (header.HasFlag(StreamHeader.GZIPPED))
            {
                using (GZipStream stream = new GZipStream(new MemoryStream(data), CompressionMode.Decompress))
                {
                    byte[] buffer = new byte[256];
                    using (MemoryStream memory = new MemoryStream())
                    {
                        int count = 0;
                        do
                        {
                            count = stream.Read(buffer, 0, buffer.Length);
                            if (count > 0)
                            {
                                memory.Write(buffer, 0, count);
                            }
                        }while (count > 0);
                        data = memory.ToArray();
                    }
                }
            }
            return(new StreamBlock(streamId, header, checksum, data));
        }
Esempio n. 17
0
        public byte[] GetStreamBytes(string streamName, BinaryReader r)
        {
            StreamHeader hdr = null;

            foreach (var item in Streams)
            {
                if (item.Name == streamName)
                {
                    hdr = item;
                    break;
                }
            }
            if (hdr == null)
            {
                return(null);
            }

            return(GetStreamBytes(r, hdr, ClrHeader.MetaDataDirectoryAddress, PeHeader.Sections));
        }
 //-------------------------------------------------
 public bool OpenStream(Stream Stream_in)
 {
     this.Close();
     if (!Stream_in.CanSeek)
     {
         return(false);
     }
     if (!Stream_in.CanRead)
     {
         return(false);
     }
     this._Header = new StreamHeader();
     this._Blocks = new ArrayList();
     if (!this.ReadFormatControl(Stream_in))
     {
         this.Close();
         return(false);
     }
     this._Stream = Stream_in;
     return(true);
 }
 //-------------------------------------------------
 public bool CreateInStream(Stream Stream_in)
 {
     this.Close();
     this._Header = new StreamHeader();
     this._Blocks = new ArrayList();
     if (!Stream_in.CanSeek)
     {
         return(false);
     }
     if (!Stream_in.CanRead)
     {
         return(false);
     }
     if (!this.WriteFormatControl(Stream_in))
     {
         return(false);
     }
     if (!this.OpenStream(Stream_in))
     {
         return(false);
     }
     return(true);
 }
Esempio n. 20
0
        private void Init(byte[] data)
        {
            #region Parse PE Header
            RawFile = new BinaryReader(new MemoryStream(data));
            BinaryReader r = new BinaryReader(new MemoryStream(data));

            DosHeader = ReadDOSHeader(r);
            PeHeader  = ReadPEHeader(DosHeader.COFFHeaderAddress, r);

            //Read all of the data
            PeHeader.Directories = ReadDirectoriesList(PeHeader.DirectoryLength, r);
            PeHeader.Sections    = ReadSectionsList(PeHeader.NumberOfSections, r);
            #endregion
            #region Parse Clr header & Strong name hash
            try
            {
                ClrHeader = ReadCLRHeader(r, PeHeader);
            }
            catch
            {
                Console.WriteLine("No clr header!");
                ContainsMetadata = false;
                return;
            }

            //Read the strong name hash
            ClrStrongNameHash = ReadStrongNameHash(r, ClrHeader.StrongNameSignatureAddress, ClrHeader.StrongNameSignatureSize, PeHeader.Sections);
            #endregion
            #region Parse Metadata header

            //Skip past all of the IL Code, and get tto the metadata header
            long pos = (long)BinUtil.RVAToOffset(ClrHeader.MetaDataDirectoryAddress, PeHeader.Sections);
            r.BaseStream.Position = pos;


            ClrMetaDataHeader                     = new MetadataHeader();
            ClrMetaDataHeader.Signature           = r.ReadUInt32();
            ClrMetaDataHeader.MajorVersion        = r.ReadUInt16();
            ClrMetaDataHeader.MinorVersion        = r.ReadUInt16();
            ClrMetaDataHeader.Reserved1           = r.ReadUInt32();
            ClrMetaDataHeader.VersionStringLength = r.ReadUInt32();
            ClrMetaDataHeader.VersionString       = r.ReadNullTermString((int)ClrMetaDataHeader.VersionStringLength);
            ClrMetaDataHeader.Flags               = r.ReadUInt16(); //reserved
            ClrMetaDataHeader.NumberOfStreams     = r.ReadUInt16();

            //Simple checks
            //Debug.Assert(ClrMetaDataHeader.Signature == 0x424A5342);
            //Debug.Assert(ClrMetaDataHeader.Reserved1 == 0);
            //Debug.Assert(ClrMetaDataHeader.Flags == 0);
            #endregion
            #region Parse Streams

            //Parse the StreamHeader(s)
            for (int i = 0; i < ClrMetaDataHeader.NumberOfStreams; i++)
            {
                var hdr = new StreamHeader();

                hdr.Offset = r.ReadUInt32();
                hdr.Size   = r.ReadUInt32();
                hdr.Name   = r.ReadNullTermFourByteAlignedString();

                Streams.Add(hdr);
            }

            //Parse the #String stream
            var bytes = GetStreamBytes("#Strings", r);
            ClrStringsStream = new StringsStream(bytes);

            //Parse the #US Stream
            var bytes2 = GetStreamBytes("#US", r);
            //File.WriteAllBytes("strings", bytes2);
            ClrUsStream = new USStreamReader(bytes2).Read();


            #endregion
            #region Parse #~ Stream aka Tabels stream
            //Parse the #~ stream
            BinaryReader TableStreamR = new BinaryReader(new MemoryStream(GetStreamBytes("#~", r)));
            ClrMetaDataStreamHeader = ReadHeader(TableStreamR);

            //Parse the tabels data
            var numberOfTables = GetTableCount(ClrMetaDataStreamHeader.TablesFlags);
            ClrMetaDataStreamHeader.TableSizes = new uint[numberOfTables];

            for (var i = 0; i < numberOfTables; i++)
            {
                ClrMetaDataStreamHeader.TableSizes[i] = TableStreamR.ReadUInt32();
            }

            MetadataReader = new MetadataReader(TableStreamR.BaseStream);
            BlobStream     = GetStreamBytes("#Blob", r);

            //Parse the tabels
            Tabels = new Tabels(this);
            #endregion
        }
Esempio n. 21
0
        private void Init(byte[] data)
        {
            #region Parse PE & Strong name hash
            RawFile = new BinaryReader(new MemoryStream(data));
            BinaryReader r = new BinaryReader(new MemoryStream(data));

            DosHeader = ReadDOSHeader(r);
            PeHeader  = ReadPEHeader(DosHeader.COFFHeaderAddress, r);

            //Read all of the data
            PeHeader.Directories = ReadDirectoriesList(PeHeader.DirectoryLength, r);
            PeHeader.Sections    = ReadSectionsList(PeHeader.NumberOfSections, r);

            try
            {
                ClrHeader = ReadCLRHeader(r, PeHeader);
            }
            catch (Exception ex)
            {
                throw new Exception("Error: Invaild metadata: " + ex.Message);
            }

            //Read the strong name hash
            ClrStrongNameHash = ReadStrongNameHash(r, ClrHeader.StrongNameSignatureAddress, ClrHeader.StrongNameSignatureSize, PeHeader.Sections);
            #endregion
            #region Parse metadata header

            //Skip past all of the IL Code, and get tto the metadata header
            long pos = (long)RelativeVirtualAddressToFileOffset(ClrHeader.MetaDataDirectoryAddress, PeHeader.Sections);
            r.BaseStream.Position = pos;


            ClrMetaDataHeader = new MetadataHeader();

            ClrMetaDataHeader.Signature           = r.ReadUInt32();
            ClrMetaDataHeader.MajorVersion        = r.ReadUInt16();
            ClrMetaDataHeader.MinorVersion        = r.ReadUInt16();
            ClrMetaDataHeader.Reserved1           = r.ReadUInt32();
            ClrMetaDataHeader.VersionStringLength = r.ReadUInt32();
            ClrMetaDataHeader.VersionString       = r.ReadNullTermString((int)ClrMetaDataHeader.VersionStringLength);
            ClrMetaDataHeader.Flags           = r.ReadUInt16(); //reserved
            ClrMetaDataHeader.NumberOfStreams = r.ReadUInt16();

            //Simple checks
            //Debug.Assert(ClrMetaDataHeader.Signature == 0x424A5342);
            //Debug.Assert(ClrMetaDataHeader.Reserved1 == 0);
            //Debug.Assert(ClrMetaDataHeader.Flags == 0);
            #endregion
            #region Parse streams

            //Read all of the tabels
            List <StreamHeader> Streams = new List <StreamHeader>();

            //Parse the StreamHeader(s)
            for (int i = 0; i < ClrMetaDataHeader.NumberOfStreams; i++)
            {
                var hdr = new StreamHeader();

                hdr.Offset = r.ReadUInt32();
                hdr.Size   = r.ReadUInt32();
                hdr.Name   = r.ReadNullTermString();

                //#~ Stream
                if (hdr.Name.Length == 2)
                {
                    r.BaseStream.Position += 1; //Skip past the 4 zeros
                }
                //#Strings stream
                else if (hdr.Name.Length == 8)
                {
                    r.BaseStream.Position += 3;
                }
                //#US Stream
                else if (hdr.Name.Length == 3)
                {
                }
                //#GUID Stream
                else if (hdr.Name.Length == 5)
                {
                    r.BaseStream.Position += 2;
                }

                Console.WriteLine("Stream: " + hdr.Name + " Size: " + hdr.Size + " Offset: " + hdr.Offset);
                Streams.Add(hdr);
            }

            //Parse the #String stream
            var bytes = GetStreamBytes(r, Streams[1], ClrHeader.MetaDataDirectoryAddress, PeHeader.Sections);
            ClrStringsStream = new StringsStreamReader(bytes).Read();

            //Parse the #US Stream
            var bytes2 = GetStreamBytes(r, Streams[2], ClrHeader.MetaDataDirectoryAddress, PeHeader.Sections);
            ClrUsStream = new USStreamReader(bytes2).Read();

            #endregion
            #region Parse #~ Stream
            //Parse the #~ stream
            BinaryReader TableStreamR = new BinaryReader(new MemoryStream(
                                                             GetStreamBytes(r, Streams[0], ClrHeader.MetaDataDirectoryAddress, PeHeader.Sections)));

            ClrMetaDataStreamHeader = ReadHeader(TableStreamR);

            //Parse the tabels data
            var numberOfTables = GetTableCount(ClrMetaDataStreamHeader.TablesFlags);
            ClrMetaDataStreamHeader.TableSizes = new uint[numberOfTables];

            for (var i = 0; i < numberOfTables; i++)
            {
                ClrMetaDataStreamHeader.TableSizes[i] = TableStreamR.ReadUInt32();
            }

            MetadataReader = new MetadataReader(TableStreamR.BaseStream);
            //Parse the tabels
            tabels = new Tabels(this);
            #endregion
        }
Esempio n. 22
0
        public void Start(string folder, bool writeStock, bool writeOrders,
                          bool writeTrades, bool writeMessages, HashSet <Security> ticks, int rk)
        {
            try
            {
                lock (pLock)
                {
                    // ---------------------------------------------------

                    if (IsRecording)
                    {
                        Status = "Запись уже ведется";
                        return;
                    }

                    // ---------------------------------------------------

                    streamsCount = 0;

                    if (writeStock)
                    {
                        streamsCount++;
                    }

                    if (writeOrders)
                    {
                        streamsCount++;
                    }

                    if (writeTrades)
                    {
                        streamsCount++;
                    }

                    if (writeMessages)
                    {
                        streamsCount++;
                    }

                    streamsCount += ticks.Count;

                    if (streamsCount == 0)
                    {
                        throw new Exception("Не заданы потоки для записи");
                    }

                    // ---------------------------------------------------

                    WrittenCount = 0;
                    LastDateTime = DateTime.MinValue;

                    // ---------------------------------------------------

                    baseDateTime = DateTime.UtcNow;
                    if (rk == 0)
                    {
                        FileName = string.Format(FileNameFormat0, baseDateTime.ToLocalTime(), cfg.HistoryFileExt);
                    }
                    if (rk == 1)
                    {
                        FileName = string.Format(FileNameFormat1, baseDateTime.ToLocalTime(), cfg.HistoryFileExt);
                    }
                    if (rk == 2)
                    {
                        FileName = string.Format(FileNameFormat2, baseDateTime.ToLocalTime(), cfg.HistoryFileExt);
                    }


                    fs = new FileStream(folder + "\\" + FileName, FileMode.Create, FileAccess.Write);
                    bw = new BinaryWriter(new DeflateStream(fs, CompressionMode.Compress));

                    DataFile.WriteHeader(bw, new DataFileHeader(
                                             cfg.FullProgName, string.Empty, baseDateTime, streamsCount));

                    // ---------------------------------------------------

                    streamsCount = 0;

                    StreamHeader sh = new StreamHeader(StreamType.Stock,
                                                       new Security(cfg.u.SecCode, cfg.u.ClassCode),
                                                       cfg.u.PriceRatio, cfg.u.PriceStep);

                    if (writeStock)
                    {
                        stockId = streamsCount++;
                        DataFile.WriteStreamHeader(bw, sh);

                        lastQuotes      = new Quote[0];
                        this.writeStock = true;
                    }

                    if (writeOrders)
                    {
                        orderId = streamsCount++;
                        sh.Type = StreamType.Orders;
                        DataFile.WriteStreamHeader(bw, sh);

                        this.writeOrders = true;
                    }

                    if (writeTrades)
                    {
                        tradeId = streamsCount++;
                        sh.Type = StreamType.Trades;
                        DataFile.WriteStreamHeader(bw, sh);

                        this.writeTrades = true;
                    }

                    if (writeMessages)
                    {
                        msgId   = streamsCount++;
                        sh.Type = StreamType.Messages;
                        DataFile.WriteStreamHeader(bw, sh);

                        this.writeMessages = true;
                    }

                    if (ticks.Count > 0)
                    {
                        tickIds = new Dictionary <int, int>(ticks.Count);
                        sh      = new StreamHeader(StreamType.Ticks);

                        foreach (Security s in ticks)
                        {
                            tickIds.Add(s.GetKey(), streamsCount++);

                            sh.Security = s;
                            DataFile.WriteStreamHeader(bw, sh);
                        }
                    }

                    // ---------------------------------------------------
                }

                Status      = "Запись...";
                IsRecording = true;
            }
            catch (Exception e)
            {
                SetError(e.Message);
            }
        }
        /// <summary>
        /// Deserializes a D3DTX Object from a byte array.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="bytePointerPosition"></param>
        public D3DTX_V7(BinaryReader reader, bool showConsole = false)
        {
            mVersion = reader.ReadInt32();                      //mVersion [4 bytes]
            mSamplerState_BlockSize = reader.ReadInt32();       //mSamplerState Block Size [4 bytes]
            mSamplerState           = new T3SamplerStateBlock() //mSamplerState [4 bytes]
            {
                mData = reader.ReadUInt32()
            };
            mPlatform_BlockSize = reader.ReadInt32();                                   //mPlatform Block Size [4 bytes]
            mPlatform           = EnumPlatformType.GetPlatformType(reader.ReadInt32()); //mPlatform [4 bytes]
            mName_BlockSize     = reader.ReadInt32();                                   //mName Block Size [4 bytes] //mName block size (size + string len)
            mName = ByteFunctions.ReadString(reader);                                   //mName [x bytes]
            mImportName_BlockSize = reader.ReadInt32();                                 //mImportName Block Size [4 bytes] //mImportName block size (size + string len)
            mImportName           = ByteFunctions.ReadString(reader);                   //mImportName [x bytes] (this is always 0)
            mImportScale          = reader.ReadSingle();                                //mImportScale [4 bytes]
            mToolProps            = new ToolProps()                                     //mToolProps [1 byte]
            {
                mbHasProps = reader.ReadBoolean()
            };
            mNumMipLevels = reader.ReadUInt32();                                                     //mNumMipLevels [4 bytes]
            mWidth        = reader.ReadUInt32();                                                     //mWidth [4 bytes]
            mHeight       = reader.ReadUInt32();                                                     //mHeight [4 bytes]

            mSurfaceFormat      = T3TextureBase_Functions.GetSurfaceFormat(reader.ReadInt32());      //mSurfaceFormat [4 bytes]
            mTextureLayout      = T3TextureBase_Functions.GetTextureLayout(reader.ReadInt32());      //mTextureLayout [4 bytes]
            mSurfaceGamma       = T3TextureBase_Functions.GetSurfaceGamma(reader.ReadInt32());       //mSurfaceGamma [4 bytes]
            mSurfaceMultisample = T3TextureBase_Functions.GetSurfaceMultisample(reader.ReadInt32()); //mSurfaceMultisample [4 bytes]
            mResourceUsage      = T3TextureBase_Functions.GetResourceUsage(reader.ReadInt32());      //mResourceUsage [4 bytes]
            mType        = T3Texture_Functions.GetTextureType(reader.ReadInt32());                   //mType [4 bytes]
            mSwizzleSize = reader.ReadInt32();                                                       //mSwizzleSize [4 bytes]
            mSwizzle     = new RenderSwizzleParams()                                                 //mSwizzle [4 bytes]
            {
                mSwizzle1 = (char)reader.ReadByte(),
                mSwizzle2 = (char)reader.ReadByte(),
                mSwizzle3 = (char)reader.ReadByte(),
                mSwizzle4 = (char)reader.ReadByte()
            };
            mNormalMapFormat    = reader.ReadInt32();                                   //mNormalMapFormat [4 bytes]
            mHDRLightmapScale   = reader.ReadSingle();                                  //mHDRLightmapScale [4 bytes]
            mToonGradientCutoff = reader.ReadSingle();                                  //mToonGradientCutoff [4 bytes]
            mAlphaMode          = T3Texture_Functions.GetAlphaMode(reader.ReadInt32()); //mAlphaMode [4 bytes]
            mColorMode          = T3Texture_Functions.GetColorMode(reader.ReadInt32()); //mColorMode [4 bytes]
            mUVOffset           = new Vector2()                                         //mUVOffset [8 bytes]
            {
                x = reader.ReadSingle(),                                                //[4 bytes]
                y = reader.ReadSingle()                                                 //[4 bytes]
            };
            mUVScale = new Vector2()                                                    //mUVScale [8 bytes]
            {
                x = reader.ReadSingle(),                                                //[4 bytes]
                y = reader.ReadSingle()                                                 //[4 bytes]
            };

            //--------------------------mArrayFrameNames--------------------------
            mArrayFrameNames_ArrayCapacity = reader.ReadUInt32(); //mArrayFrameNames DCArray Capacity [4 bytes]
            mArrayFrameNames_ArrayLength   = reader.ReadInt32();  //mArrayFrameNames DCArray Length [4 bytes] //ADD 1 BECAUSE COUNTING STARTS AT 0
            mArrayFrameNames = new List <Symbol>();
            for (int i = 0; i < mArrayFrameNames_ArrayLength; i++)
            {
                Symbol newSymbol = new Symbol()
                {
                    mCrc64 = reader.ReadUInt64()
                };

                mArrayFrameNames.Add(newSymbol);
            }

            //--------------------------mToonRegions--------------------------
            mToonRegions_ArrayCapacity = reader.ReadUInt32(); //mToonRegions DCArray Capacity [4 bytes]
            mToonRegions_ArrayLength   = reader.ReadInt32();  //mToonRegions DCArray Length [4 bytes]
            mToonRegions = new T3ToonGradientRegion[mToonRegions_ArrayLength];

            for (int i = 0; i < mToonRegions_ArrayLength; i++)
            {
                mToonRegions[i] = new T3ToonGradientRegion()
                {
                    mColor = new Color()
                    {
                        r = reader.ReadSingle(), //[4 bytes]
                        g = reader.ReadSingle(), //[4 bytes]
                        b = reader.ReadSingle(), //[4 bytes]
                        a = reader.ReadSingle()  //[4 bytes]
                    },

                    mSize = reader.ReadSingle() //[4 bytes]
                };
            }

            //--------------------------StreamHeader--------------------------
            mStreamHeader = new StreamHeader()
            {
                mRegionCount   = reader.ReadInt32(), //[4 bytes]
                mAuxDataCount  = reader.ReadInt32(), //[4 bytes]
                mTotalDataSize = reader.ReadInt32()  //[4 bytes]
            };

            //--------------------------mRegionHeaders--------------------------
            mRegionHeaders = new RegionStreamHeader[mStreamHeader.mRegionCount];
            for (int i = 0; i < mStreamHeader.mRegionCount; i++)
            {
                mRegionHeaders[i] = new RegionStreamHeader()
                {
                    mFaceIndex  = reader.ReadInt32(),  //[4 bytes]
                    mMipIndex   = reader.ReadInt32(),  //[4 bytes]
                    mMipCount   = reader.ReadInt32(),  //[4 bytes]
                    mDataSize   = reader.ReadUInt32(), //[4 bytes]
                    mPitch      = reader.ReadInt32(),  //[4 bytes]
                    mSlicePitch = reader.ReadInt32()   //[4 bytes]
                };
            }
            //-----------------------------------------D3DTX HEADER END-----------------------------------------
            //--------------------------STORING D3DTX IMAGE DATA--------------------------
            mPixelData = new List <byte[]>();

            for (int i = 0; i < mStreamHeader.mRegionCount; i++)
            {
                int    dataSize  = (int)mRegionHeaders[i].mDataSize;
                byte[] imageData = reader.ReadBytes(dataSize);

                mPixelData.Add(imageData);
            }

            if (showConsole)
            {
                PrintConsole();
            }
        }
        FileInfo Get_FileInfo(string name)
        {
            foreach (var file in _directory.GetFiles())
                if (file.Name == name)
                    return file;

            var path = Path.Combine(_directory.FullName, name);

            using (var stream = File.Create(path))
            {
                var header = new StreamHeader
                {
                    Index = StreamHeader.SizeInBytes(),
                    Timestamp = DateTime.Now
                };

                using (var writer = new BinaryWriter(stream))
                    header.Serialize(writer);
            }
            return new FileInfo(path);
        }
Esempio n. 25
0
        static void Main(string[] args)
        {
            string dllPath = String.Empty;

            if (args.Length > 0)
            {
                dllPath = args[0];
                if (File.Exists(dllPath))
                {
                    ModuleContext context  = ModuleDef.CreateModuleContext();
                    ModuleDefMD   module   = ModuleDefMD.Load(dllPath);
                    Metadata      metadata = module.Metadata;
                    //MetaHeader
                    MetadataHeader metadataHeader = metadata.MetadataHeader;
                    //存储流Header数量
                    int count = metadataHeader.StreamHeaders.Count;
                    //Cor20头
                    ImageCor20Header imageCor20Header = metadata.ImageCor20Header;
                    int cbOffeset = 0x208;                                                       //cb偏移
                    int Metadata_VirtualAddress = (int)imageCor20Header.Metadata.VirtualAddress; //Metadata RVA
                    int MetadataOffeset         = Metadata_VirtualAddress - 0x1E00;              //metadata文件偏移
                    int stringHeaderSize        = 0;                                             //stringHeader size
                    int iMajorVerOffeset        = MetadataOffeset + 0x4;
                    int iMinorVerOffeset        = iMajorVerOffeset + 0x2;
                    int VersionStringLOffeset   = MetadataOffeset + 0xC;
                    int stringHeaderOffeset     = MetadataOffeset + 0x30;
                    int pe1 = 0x82;
                    int pe2 = 0x83;
                    int nrs = 0xF4;
                    for (int i = 0; i < count; i++)
                    {
                        StreamHeader header = metadataHeader.StreamHeaders[i];
                        if (header.Name.Contains("Strings"))
                        {
                            stringHeaderSize = (int)header.StreamSize;
                        }
                    }
                    byte[] buffer = File.ReadAllBytes(dllPath);
                    buffer[pe1]                   = 0x2E;
                    buffer[pe2]                   = 0x2E;
                    buffer[nrs]                   = 0xF;
                    buffer[cbOffeset]             = 0x88;
                    buffer[iMajorVerOffeset]      = 0x2;
                    buffer[iMinorVerOffeset]      = 0x2;
                    buffer[VersionStringLOffeset] = 0xB;
                    byte temp = buffer[stringHeaderOffeset];
                    buffer[stringHeaderOffeset]     = buffer[stringHeaderOffeset + 1];
                    buffer[stringHeaderOffeset + 1] = buffer[stringHeaderOffeset + 2];
                    buffer[stringHeaderOffeset + 2] = temp;
                    string savePath = dllPath.Replace(".dll", "_encrypt.dll");
                    File.WriteAllBytes(savePath, buffer);
                    Console.ReadKey();
                }
                else
                {
                    Console.WriteLine("文件不存在!\n按任意键退出!");
                    Console.ReadLine();
                }
            }
            else
            {
                Console.WriteLine("文件输入有误!\n按任意键退出!");
                Console.ReadLine();
            }
        }
Esempio n. 26
0
 private void OnStreamRecived(StreamHeader streamHeader, byte[] content)
 {
     throw new NotImplementedException();
 }
Esempio n. 27
0
 public void StreamEnqueue(StreamHeader streamHeader) => _streamHeaderQueue.Enqueue(streamHeader);
Esempio n. 28
0
 /// <summary>
 /// 构造器
 /// </summary>
 /// <param name="metadata">元数据</param>
 /// <param name="header">元数据流头</param>
 public UnknownHeap(IMetadata metadata, StreamHeader header) : base(metadata, header)
 {
 }
Esempio n. 29
0
 public BlobTransportStream(string fileType = "")
 {
     mHeader = new StreamHeader(fileType);
 }
        async Task WriteHeader(StreamHeader header, string name)
        {
            using (var buffer = CreateMemoryStream())
            {
                using (var writer = new BinaryWriter(buffer, Encoding.UTF8, true))
                {
                    header.Serialize(writer);
                    writer.Flush();
                }

                buffer.Seek(0, SeekOrigin.Begin);

                using (var stream = Open_Stream_For_Writing(name))
                {
                    await buffer.CopyToAsync(stream);
                    stream.Flush();
                }
            }
        }
Esempio n. 31
0
        public MetadataStream Parse(DataInterface file, AssemblyLoader al, bool fail_refs = true, bool is_pdb = false)
        {
            var m = new MetadataStream();

            m.al = al;

            long mroot_offset;

            if (is_pdb)
            {
                mroot_offset = 0;
                pdbf         = true;
            }
            else
            {
                pefh = new PE_File_Header();

                uint pefh_start = file.ReadUInt(0x3c) + 4;
                uint pesig      = file.ReadUInt((int)pefh_start - 4);
                System.Diagnostics.Debugger.Log(0, "metadata", "PEFile.Parse: PE Signature: " + pesig.ToString("X8"));
                pefh.NumberOfSections = file.ReadUShort((int)pefh_start + 2);
                pefh.Sections         = new SectionHeader[pefh.NumberOfSections];
                TimeSpan t = new TimeSpan(0, 0, (int)(file.ReadUInt((int)pefh_start + 4) & 0x7fffffff));    // csc /deterministic sets top bit - ignore for timestamp purposes
                System.Diagnostics.Debugger.Log(0, "metadata", "PEFile.Parse: t: " + ((int)file.ReadUInt((int)pefh_start + 4)).ToString());
                pefh.TimeDateStamp = new DateTime(1970, 1, 1) + t;
                pefh.OptHeaderSize = file.ReadUShort((int)pefh_start + 16);
                if (pefh.OptHeaderSize < 224)
                {
                    throw new Exception("PE optional header too small");
                }
                pefh.Chars = file.ReadUShort((int)pefh_start + 18);
                if ((pefh.Chars & 0x3) != 0x2)
                {
                    System.Diagnostics.Debugger.Log(0, "metadata", "PEFile.Parse: Invalid PE file header characteristics: " + pefh.Chars.ToString());
                    System.Diagnostics.Debugger.Break();
                    throw new Exception("Invalid PE file header characteristics");
                }

                int    pe32plusoffset = 0;
                ushort magic          = file.ReadUShort((int)pefh_start + 20);
                if (magic == 0x20b)
                {
                    pe32plusoffset = 16;
                }

                pefh.CliHeader      = new DataDir();
                pefh.CliHeader.RVA  = file.ReadUInt((int)pefh_start + 228 + pe32plusoffset);
                pefh.CliHeader.Size = file.ReadUInt((int)pefh_start + 232 + pe32plusoffset);

                // Read the section headers
                uint sections_start = pefh_start + 20 + pefh.OptHeaderSize;
                for (uint i = 0; i < pefh.NumberOfSections; i++)
                {
                    uint s_start = sections_start + i * 40;
                    pefh.Sections[i] = new SectionHeader();

                    char[] w_str = new char[9];
                    for (int j = 0; j < 8; j++)
                    {
                        w_str[j] = (char)file.ReadByte((int)s_start + j);
                    }
                    w_str[8] = '\0';

                    pefh.Sections[i].Name = new String(w_str);
                    pefh.Sections[i].Name = pefh.Sections[i].Name.Remove(pefh.Sections[i].Name.IndexOf("\0"));
                    System.Diagnostics.Debugger.Log(0, "metadata", "PEFile.Parse: section name: " + pefh.Sections[i].Name + "\n");

                    pefh.Sections[i].VSize    = file.ReadUInt((int)s_start + 8);
                    pefh.Sections[i].VAddress = file.ReadUInt((int)s_start + 12);
                    pefh.Sections[i].PSize    = file.ReadUInt((int)s_start + 16);
                    pefh.Sections[i].PAddress = file.ReadUInt((int)s_start + 20);

                    pefh.Sections[i].Chars = file.ReadUInt((int)s_start + 36);
                }

                // Read the Cli header
                if (pefh.CliHeader.RVA == 0)
                {
                    return(null);
                }
                long clih_offset = ResolveRVA(pefh.CliHeader.RVA);


                clih = new Cli_Header();
                clih.Metadata.RVA    = file.ReadUInt((int)clih_offset + 8);
                clih.Metadata.Size   = file.ReadUInt((int)clih_offset + 12);
                clih.EntryPointToken = file.ReadUInt((int)clih_offset + 20);
                clih.Resources.RVA   = file.ReadUInt((int)clih_offset + 24);
                clih.Resources.Size  = file.ReadUInt((int)clih_offset + 28);

                m.entry_point_token = clih.EntryPointToken;

                System.Diagnostics.Debugger.Log(0, "metadata", "PEFile.Parse: CLI header parsed");

                // First, read the metadata root
                mroot_offset = ResolveRVA(clih.Metadata.RVA);
            }
            uint sig = file.ReadUInt((int)mroot_offset);

            if (sig != 0x424A5342)
            {
                throw new Exception("Invalid metadata root");
            }
            uint vstr_len = file.ReadUInt((int)mroot_offset + 12);

            m.VersionString = ReadSZ(file, (int)mroot_offset + 16);
            ushort nstr = file.ReadUShort((int)mroot_offset + 16 +
                                          (int)vstr_len + 2);

            int cur_offset = (int)mroot_offset + 16 + (int)vstr_len + 4;

            // Now, read the stream headers
            for (ushort i = 0; i < nstr; i++)
            {
                StreamHeader sh = new StreamHeader();
                sh.Offset     = file.ReadUInt(cur_offset);
                sh.FileOffset = ResolveRVA((is_pdb ? 0 : clih.Metadata.RVA) + sh.Offset);
                sh.Size       = file.ReadUInt(cur_offset + 4);

                cur_offset += 8;
                StringBuilder sb = new StringBuilder();
                while (true)
                {
                    byte strb = file.ReadByte(cur_offset++);
                    if (strb == 0)
                    {
                        break;
                    }
                    else
                    {
                        sb.Append((char)strb);
                    }
                }
                while ((cur_offset & 0x3) != 0)
                {
                    cur_offset++;
                }

                sh.Name = sb.ToString();

                System.Diagnostics.Debugger.Log(0, "metadata", "PEFile.Parse: stream name: " + sh.Name);

                sh.di = file.Clone((int)sh.FileOffset);

                if (sh.Name == "#Strings")
                {
                    m.sh_string = sh;
                }
                else if (sh.Name == "#US")
                {
                    m.sh_us = sh;
                }
                else if (sh.Name == "#GUID")
                {
                    m.sh_guid = sh;
                }
                else if (sh.Name == "#Blob")
                {
                    m.sh_blob = sh;
                }
                else if (sh.Name == "#~")
                {
                    m.sh_tables = sh;
                }
                else if (sh.Name == "#Pdb")
                {
                    m.sh_pdb = sh;
                }
                else
                {
                    System.Diagnostics.Debugger.Log(0, "metadata", "PEFile.Parse: unknown table \"" + sh.Name + "\"");
                    throw new Exception("Unknown metadata table");
                }
            }

            // Parse tables
            if (m.sh_tables != null)
            {
                var di  = m.sh_tables.di;
                var maj = di.ReadByte(4);
                var min = di.ReadByte(5);
                System.Diagnostics.Debugger.Log(0, "metadata", "PEFile.Parse: parsing tables");
                System.Diagnostics.Debugger.Log(0, "metadata", "PEFile.Parse: metadata table schema v" + maj.ToString() + "." + min.ToString());

                // Determine size of indices into the heaps
                var heapsizes = di.ReadByte(6);
                if ((heapsizes & 0x1) == 0x1)
                {
                    m.wide_string = true;
                }
                if ((heapsizes & 0x2) == 0x2)
                {
                    m.wide_guid = true;
                }
                if ((heapsizes & 0x4) == 0x4)
                {
                    m.wide_blob = true;
                }

                // Get list of valid tables
                var        valid        = di.ReadULong(8);
                int        valid_count  = 0;
                List <int> valid_tables = new List <int>();
                for (int i = 0; i < 64; i++)
                {
                    if (((valid >> i) & 0x1) == 0x1)
                    {
                        m.valid_tables[i] = true;
                        valid_count++;
                        valid_tables.Add(i);
                    }
                }

                // Get number of rows in each table
                int table_id = 0;
                foreach (var valid_table in valid_tables)
                {
                    m.table_rows[valid_table] = (int)di.ReadUInt(24 + 4 * table_id++);
                }

                // Interpret the schema of each table
                foreach (var valid_table in valid_tables)
                {
                    InterpretSchema(valid_table, m);
                }

                // Determine start offsets of each table
                int offset = 24 + 4 * valid_count;
                foreach (var valid_table in valid_tables)
                {
                    m.table_offsets[valid_table] = offset;
                    offset += m.table_rows[valid_table] * m.table_entry_size[valid_table];
                }
            }

            m.pef  = this;
            m.file = file;

            /* Get this assembly name */
            if (m.table_rows[MetadataStream.tid_Assembly] == 1)
            {
                m.assemblyName = m.GetStringEntry(MetadataStream.tid_Assembly, 1, 7);

                // Handle dotnet coreclr mscorlib having a different name
                if (m.assemblyName == "System.Private.CoreLib")
                {
                    m.assemblyName = "mscorlib";
                }

                System.Diagnostics.Debugger.Log(0, "metadata", "PEFile.Parse: current assembly is " + m.assemblyName);
            }

            /* Load up all referenced assemblies */
            m.referenced_assemblies = new MetadataStream[m.table_rows[MetadataStream.tid_AssemblyRef]];
            for (int i = 1; i <= m.table_rows[MetadataStream.tid_AssemblyRef]; i++)
            {
                var ass_name = m.GetStringEntry(MetadataStream.tid_AssemblyRef, i, 6);
                var maj      = (int)m.GetIntEntry(MetadataStream.tid_AssemblyRef, i, 0);
                var min      = (int)m.GetIntEntry(MetadataStream.tid_AssemblyRef, i, 1);
                var build    = (int)m.GetIntEntry(MetadataStream.tid_AssemblyRef, i, 2);
                var rev      = (int)m.GetIntEntry(MetadataStream.tid_AssemblyRef, i, 3);

                if (ass_name == "netstandard")
                {
                    ass_name = "mscorlib";
                    maj      = -1;
                }

                System.Diagnostics.Debugger.Log(0, "metadata", "PEFile.Parse: loading referenced assembly " + ass_name);

                if ((m.referenced_assemblies[i - 1] = al.GetAssembly(ass_name, maj, min, build, rev)) == null && fail_refs)
                {
                    var ale = new AssemblyLoadException();
                    ale.ReferencedAssembly = new AssemblyLoadException.ALEAssembly
                    {
                        Name     = ass_name,
                        Major    = maj,
                        Minor    = min,
                        Revision = rev,
                        Build    = build
                    };
                    ale.CurrentAssembly = new AssemblyLoadException.ALEAssembly
                    {
                        Name     = m.AssemblyName,
                        Major    = m.MajorVersion,
                        Minor    = m.MinorVersion,
                        Revision = m.RevisionVersion,
                        Build    = m.BuildVersion
                    };

                    foreach (var la in al.LoadedAssemblies)
                    {
                        var cla = al.GetAssembly(la);

                        var clale = new AssemblyLoadException.ALEAssembly
                        {
                            Name     = cla.AssemblyName,
                            Major    = cla.MajorVersion,
                            Minor    = cla.MinorVersion,
                            Revision = cla.RevisionVersion,
                            Build    = cla.BuildVersion
                        };
                        ale.CurrentlyLoadedAssemblies.Add(clale);
                    }
                    throw ale;
                }
            }

            m.PatchMethodDefOwners();
            m.PatchFieldDefOwners();
            m.PatchFieldRVAs();
            m.PatchClassLayouts();
            m.PatchFieldConstants();
            m.PatchGTypes();
            if (m.assemblyName == "mscorlib")
            {
                m.is_corlib = true;
                m.PatchSimpleTypes();
            }
            m.PatchNestedTypes();
            m.PatchCustomAttrs();

            m.LoadBuiltinTypes();

            System.Diagnostics.Debugger.Log(0, "metadata", "PEFile.Parse: parsing complete");

            /* Load up a .pdb sidecar file if necessary */
            if (m.sh_pdb != null)
            {
                m.pdb = m;
            }
            else
            {
                var fname = file.Name;
                if (fname != null)
                {
                    if (fname.EndsWith(".dll") || fname.EndsWith(".exe"))
                    {
                        fname = fname.Substring(0, fname.Length - 4);
                    }
                    var pdbf = al.LoadAssembly(fname + ".pdb");
                    if (pdbf != null)
                    {
                        var pef = new metadata.PEFile();
                        try
                        {
                            m.pdb = pef.Parse(pdbf, al, true, true);
                        }
                        catch (Exception)
                        {
                            m.pdb = null;
                        }
                    }
                }
            }

            return(m);
        }
Esempio n. 32
0
		/// <summary>
		///    Reads the audio properties from the file represented by
		///    the current instance.
		/// </summary>
		/// <param name="start">
		///    A <see cref="long" /> value containing the seek position
		///    at which the tags end and the media data begins.
		/// </param>
		/// <param name="end">
		///    A <see cref="long" /> value containing the seek position
		///    at which the media data ends and the tags begin.
		/// </param>
		/// <param name="propertiesStyle">
		///    A <see cref="ReadStyle" /> value specifying at what level
		///    of accuracy to read the media properties, or <see
		///    cref="ReadStyle.None" /> to ignore the properties.
		/// </param>
		/// <returns>
		///    A <see cref="TagLib.Properties" /> object describing the
		///    media properties of the file represented by the current
		///    instance.
		/// </returns>
		protected override Properties ReadProperties (long start,
		                                              long end,
		                                              ReadStyle propertiesStyle)
		{
			StreamHeader header = new StreamHeader (header_block,
				end - start);
			return new Properties (TimeSpan.Zero, header);
		}
 public void ClientStreamEnqueue(ClientSocket clientSocket, StreamHeader streamHeader) => _ahemClients[clientSocket.IPAddress].StreamEnqueue(streamHeader);