Exemple #1
0
        private unsafe bool SendManifest(byte[] rawManifest, EventProviderDataStream outputStream)
        {
            fixed(byte *numRef = rawManifest)
            {
                EventDescriptorInternal eventDescriptor = new EventDescriptorInternal(0xfffe, 1, 0, 0, 0xfe, 0, -1L);
                ManifestEnvelope        envelope        = new ManifestEnvelope {
                    Format       = ManifestEnvelope.ManifestFormats.SimpleXmlFormat,
                    MajorVersion = 1,
                    MinorVersion = 0,
                    Magic        = 0x5b
                };
                int length = rawManifest.Length;

                envelope.TotalChunks = (ushort)((length + 0xfeff) / 0xff00);
                envelope.ChunkNumber = 0;
                EventProvider.EventData *dataPtr = (EventProvider.EventData *) stackalloc byte[(((IntPtr)2) * sizeof(EventProvider.EventData))];
                dataPtr->Ptr        = (ulong)((IntPtr) & envelope);
                dataPtr->Size       = (uint)sizeof(ManifestEnvelope);
                dataPtr->Reserved   = 0;
                dataPtr[1].Ptr      = (ulong)numRef;
                dataPtr[1].Reserved = 0;
                bool flag = true;

                while (length > 0)
                {
                    dataPtr[1].Size = (uint)Math.Min(length, 0xff00);
                    if (((outputStream == null) && (this.m_provider != null)) && !this.m_provider.WriteEvent(ref eventDescriptor, 2, (IntPtr)dataPtr))
                    {
                        flag = false;
                    }
                    if (outputStream != null)
                    {
                        byte[] destination = null;
                        byte[] buffer2     = null;
                        if (destination == null)
                        {
                            destination = new byte[dataPtr->Size];
                            buffer2     = new byte[dataPtr[1].Size];
                        }
                        Marshal.Copy((IntPtr)dataPtr->Ptr, destination, 0, (int)dataPtr->Size);
                        Marshal.Copy((IntPtr)dataPtr[1].Ptr, buffer2, 0, (int)dataPtr[1].Size);
                        this.m_eventCallbackArgs.EventId = eventDescriptor.EventId;
                        this.m_eventCallbackArgs.Payload = new object[] { destination, buffer2 };
                        outputStream.m_Callback(this.m_eventCallbackArgs);
                    }
                    length -= 0xff00;
                    envelope.ChunkNumber = (ushort)(envelope.ChunkNumber + 1);
                }
                return(flag);
            }
        }
        private unsafe bool SendManifest(byte[] rawManifest, EventProviderDataStream outputStream) 
        { 
            fixed (byte* dataPtr = rawManifest)
            { 
                EventDescriptorInternal manifestDescr = new EventDescriptorInternal(0xFFFE, 1, 0, 0, 0xFE, 0, -1);
                ManifestEnvelope envelope = new ManifestEnvelope();

                envelope.Format = ManifestEnvelope.ManifestFormats.SimpleXmlFormat; 
                envelope.MajorVersion = 1;
                envelope.MinorVersion = 0; 
                envelope.Magic = 0x5B;              // An unusual number that can be checked for consistancy. 
                int dataLeft = rawManifest.Length;
                envelope.TotalChunks = (ushort)((dataLeft + (ManifestEnvelope.MaxChunkSize - 1)) / ManifestEnvelope.MaxChunkSize); 
                envelope.ChunkNumber = 0;

                EventProvider.EventData* dataDescrs = stackalloc EventProvider.EventData[2];
                dataDescrs[0].Ptr = (ulong)&envelope; 
                dataDescrs[0].Size = (uint)sizeof(ManifestEnvelope);
                dataDescrs[0].Reserved = 0; 
 
                dataDescrs[1].Ptr = (ulong)dataPtr;
                dataDescrs[1].Reserved = 0; 

                bool success = true;
                while (dataLeft > 0)
                { 
                    dataDescrs[1].Size = (uint)Math.Min(dataLeft, ManifestEnvelope.MaxChunkSize);
#if ETW_SUPPORTED 
                    if (outputStream == null && m_provider != null && !m_provider.WriteEvent(ref manifestDescr, 2, (IntPtr)dataDescrs)) 
                        success = false;
#endif 
                    if (outputStream != null)
                    {
                        byte[] envelopeBlob = null;
                        byte[] manifestBlob = null; 
                        if (envelopeBlob == null)
                        { 
                            envelopeBlob = new byte[dataDescrs[0].Size]; 
                            manifestBlob = new byte[dataDescrs[1].Size];
                        } 
                        System.Runtime.InteropServices.Marshal.Copy((IntPtr)dataDescrs[0].Ptr, envelopeBlob, 0, (int)dataDescrs[0].Size);
                        System.Runtime.InteropServices.Marshal.Copy((IntPtr)dataDescrs[1].Ptr, manifestBlob, 0, (int)dataDescrs[1].Size);

                        m_eventCallbackArgs.EventId = manifestDescr.EventId; 
                        m_eventCallbackArgs.Payload = new object[] { envelopeBlob, manifestBlob };
                        outputStream.m_Callback(m_eventCallbackArgs); 
                    } 

                    dataLeft -= ManifestEnvelope.MaxChunkSize; 
                    envelope.ChunkNumber++;
                }
                return success;
            } 
        }
 private unsafe bool SendManifest(byte[] rawManifest, EventProviderDataStream outputStream)
 {
     fixed (byte* numRef = rawManifest)
     {
         EventDescriptorInternal eventDescriptor = new EventDescriptorInternal(0xfffe, 1, 0, 0, 0xfe, 0, -1L);
         ManifestEnvelope envelope = new ManifestEnvelope {
             Format = ManifestEnvelope.ManifestFormats.SimpleXmlFormat,
             MajorVersion = 1,
             MinorVersion = 0,
             Magic = 0x5b
         };
         int length = rawManifest.Length;
         envelope.TotalChunks = (ushort) ((length + 0xfeff) / 0xff00);
         envelope.ChunkNumber = 0;
         EventProvider.EventData* dataPtr = (EventProvider.EventData*) stackalloc byte[(((IntPtr) 2) * sizeof(EventProvider.EventData))];
         dataPtr->Ptr = (ulong) ((IntPtr) &envelope);
         dataPtr->Size = (uint) sizeof(ManifestEnvelope);
         dataPtr->Reserved = 0;
         dataPtr[1].Ptr = (ulong) numRef;
         dataPtr[1].Reserved = 0;
         bool flag = true;
         while (length > 0)
         {
             dataPtr[1].Size = (uint) Math.Min(length, 0xff00);
             if (((outputStream == null) && (this.m_provider != null)) && !this.m_provider.WriteEvent(ref eventDescriptor, 2, (IntPtr) dataPtr))
             {
                 flag = false;
             }
             if (outputStream != null)
             {
                 byte[] destination = null;
                 byte[] buffer2 = null;
                 if (destination == null)
                 {
                     destination = new byte[dataPtr->Size];
                     buffer2 = new byte[dataPtr[1].Size];
                 }
                 Marshal.Copy((IntPtr) dataPtr->Ptr, destination, 0, (int) dataPtr->Size);
                 Marshal.Copy((IntPtr) dataPtr[1].Ptr, buffer2, 0, (int) dataPtr[1].Size);
                 this.m_eventCallbackArgs.EventId = eventDescriptor.EventId;
                 this.m_eventCallbackArgs.Payload = new object[] { destination, buffer2 };
                 outputStream.m_Callback(this.m_eventCallbackArgs);
             }
             length -= 0xff00;
             envelope.ChunkNumber = (ushort) (envelope.ChunkNumber + 1);
         }
         return flag;
     }
 }