WriteByte() public method

public WriteByte ( byte value ) : void
value byte
return void
Example #1
0
        void PatchRawSmallSection(ByteBuffer buffer, MetadataBuilder metadata)
        {
            var length = ReadByte ();
            buffer.WriteByte (length);
            Advance (2);

            buffer.WriteUInt16 (0);

            var count = length / 12;

            PatchRawExceptionHandlers (buffer, metadata, count, false);
        }
Example #2
0
        void PatchRawSection(ByteBuffer buffer, MetadataBuilder metadata)
        {
            var position = base.position;
            Align (4);
            buffer.WriteBytes (base.position - position);

            const byte fat_format = 0x40;
            const byte more_sects = 0x80;

            var flags = ReadByte ();
            if ((flags & fat_format) == 0) {
                buffer.WriteByte (flags);
                PatchRawSmallSection (buffer, metadata);
            } else
                PatchRawFatSection (buffer, metadata);

            if ((flags & more_sects) != 0)
                PatchRawSection (buffer, metadata);
        }
Example #3
0
        public ByteBuffer PatchRawMethodBody(MethodDefinition method, CodeWriter writer, out int code_size, out MetadataToken local_var_token)
        {
            var position = MoveTo (method);

            var buffer = new ByteBuffer ();

            var flags = ReadByte ();

            switch (flags & 0x3) {
            case 0x2: // tiny
                buffer.WriteByte (flags);
                local_var_token = MetadataToken.Zero;
                code_size = flags >> 2;
                PatchRawCode (buffer, code_size, writer);
                break;
            case 0x3: // fat
                Advance (-1);
                PatchRawFatMethod (buffer, writer, out code_size, out local_var_token);
                break;
            default:
                throw new NotSupportedException ();
            }

            MoveBackTo (position);

            return buffer;
        }
Example #4
0
        public ByteBuffer PatchRawMethodBody(MethodDefinition method, CodeWriter writer, out MethodSymbols symbols)
        {
            var buffer = new ByteBuffer ();
            symbols = new MethodSymbols (method.Name);

            this.method = method;
            reader.context = method;

            MoveTo (method.RVA);

            var flags = ReadByte ();

            MetadataToken local_var_token;

            switch (flags & 0x3) {
            case 0x2: // tiny
                buffer.WriteByte (flags);
                local_var_token = MetadataToken.Zero;
                symbols.code_size = flags >> 2;
                PatchRawCode (buffer, symbols.code_size, writer);
                break;
            case 0x3: // fat
                base.position--;

                PatchRawFatMethod (buffer, symbols, writer, out local_var_token);
                break;
            default:
                throw new NotSupportedException ();
            }

            var symbol_reader = reader.module.SymbolReader;
            if (symbol_reader != null && writer.metadata.write_symbols) {
                symbols.method_token = GetOriginalToken (writer.metadata, method);
                symbols.local_var_token = local_var_token;
                symbol_reader.Read (symbols);
            }

            return buffer;
        }
Example #5
0
        public bool GetDebugHeader(out ImageDebugDirectory directory, out byte [] header)
        {
            if (IsEmbedded) {
                directory = new ImageDebugDirectory ();
                header = Empty<byte>.Array;
                return false;
            }

            directory = new ImageDebugDirectory () {
                MajorVersion = 256,
                MinorVersion = 20577,
                Type = 2,
            };

            var buffer = new ByteBuffer ();
            // RSDS
            buffer.WriteUInt32 (0x53445352);
            // Module ID
            buffer.WriteBytes (module.Mvid.ToByteArray ());
            // PDB Age
            buffer.WriteUInt32 (1);
            // PDB Path
            buffer.WriteBytes (System.Text.Encoding.UTF8.GetBytes (writer.BaseStream.GetFileName ()));
            buffer.WriteByte (0);

            header = new byte [buffer.length];
            Buffer.BlockCopy (buffer.buffer, 0, header, 0, buffer.length);
            directory.SizeOfData = header.Length;
            return true;
        }