Пример #1
0
 /// <inheritdoc/>
 public void Write(
     TinyBinaryWriter writer)
 {
     foreach (var item in _idsByStrings
              .OrderBy(item => item.Value)
              .Select(item => item.Key))
     {
         writer.WriteString(item);
     }
 }
        /// <summary>
        /// Writes header information into output stream (w/o CRC and table offsets/paddings).
        /// </summary>
        /// <param name="writer">Binary writer with correct endianness.</param>
        /// <param name="isPreAllocationCall">If true no assembly name will be written.</param>
        public void Write(
            TinyBinaryWriter writer,
            Boolean isPreAllocationCall)
        {
            writer.WriteString("MSSpot1");

            writer.WriteUInt32(0); // header CRC
            writer.WriteUInt32(0); // assembly CRC

            writer.WriteUInt32(writer.IsBigEndian ? FLAGS_BIG_ENDIAN : FLAGS_LITTLE_ENDIAN);

            // This CRC calculated only for BE assemblies!!!
            writer.WriteUInt32(writer.IsBigEndian ? _context.NativeMethodsCrc.Current : 0x00);
            writer.WriteUInt32(0xFFFFFFFF); // Native methods offset

            writer.WriteVersion(_context.AssemblyDefinition.Name.Version);

            writer.WriteUInt16(isPreAllocationCall
                ? (UInt16)0x0000
                : _context.StringTable.GetOrCreateStringId(_context.AssemblyDefinition.Name.Name));
            writer.WriteUInt16(1); // String table version

            if (isPreAllocationCall)
            {
                _tablesOffset = writer.BaseStream.Position;
                for (var i = 0; i < 16; ++i)
                {
                    writer.WriteUInt32(0);
                }

                writer.WriteUInt32(0); // Number of patched methods

                _paddingsOffset = writer.BaseStream.Position;
                for (var i = 0; i < 16; ++i)
                {
                    writer.WriteByte(0);
                }
            }
            else
            {
                writer.BaseStream.Seek(12, SeekOrigin.Begin);

                var assemblyCrc32 = ComputeCrc32(writer.BaseStream,
                                                 _paddingsOffset, writer.BaseStream.Length - _paddingsOffset);
                writer.WriteUInt32(assemblyCrc32);

                writer.BaseStream.Seek(8, SeekOrigin.Begin);

                var headerCrc32 = ComputeCrc32(writer.BaseStream, 0, _paddingsOffset);
                writer.WriteUInt32(headerCrc32);
            }
        }
        /// <summary>
        /// Writes header information into output stream (w/o CRC and table offsets/paddings).
        /// </summary>
        /// <param name="writer">Binary writer with correct endianness.</param>
        /// <param name="isPreAllocationCall">If true no assembly name will be written.</param>
        public void Write(
            TinyBinaryWriter writer,
            Boolean isPreAllocationCall)
        {
            writer.WriteString("MSSpot1");

            writer.WriteUInt32(0); // header CRC
            writer.WriteUInt32(0); // assembly CRC

            writer.WriteUInt32(writer.IsBigEndian ? FLAGS_BIG_ENDIAN : FLAGS_LITTLE_ENDIAN);

            // This CRC calculated only for BE assemblies!!!
            writer.WriteUInt32(writer.IsBigEndian ? _context.NativeMethodsCrc.Current : 0x00);
            writer.WriteUInt32(0xFFFFFFFF); // Native methods offset

            writer.WriteVersion(_context.AssemblyDefinition.Name.Version);

            writer.WriteUInt16(isPreAllocationCall
                ? (UInt16) 0x0000
                : _context.StringTable.GetOrCreateStringId(_context.AssemblyDefinition.Name.Name));
            writer.WriteUInt16(1); // String table version

            if (isPreAllocationCall)
            {
                _tablesOffset = writer.BaseStream.Position;
                for (var i = 0; i < 16; ++i)
                {
                    writer.WriteUInt32(0);
                }

                writer.WriteUInt32(0); // Number of patched methods

                _paddingsOffset = writer.BaseStream.Position;
                for (var i = 0; i < 16; ++i)
                {
                    writer.WriteByte(0);
                }
            }
            else
            {
                writer.BaseStream.Seek(12, SeekOrigin.Begin);

                var assemblyCrc32 = ComputeCrc32(writer.BaseStream,
                    _paddingsOffset, writer.BaseStream.Length - _paddingsOffset);
                writer.WriteUInt32(assemblyCrc32);

                writer.BaseStream.Seek(8, SeekOrigin.Begin);

                var headerCrc32 = ComputeCrc32(writer.BaseStream, 0, _paddingsOffset);
                writer.WriteUInt32(headerCrc32);
            }
        }
Пример #4
0
 /// <inheritdoc/>
 public void Write(
     TinyBinaryWriter writer)
 {
     foreach (var item in _idsByStrings
         .OrderBy(item => item.Value)
         .Select(item => item.Key))
     {
         writer.WriteString(item);
     }
 }