コード例 #1
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.symbol_reader;
            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;
        }
コード例 #2
0
        static MetadataToken GetLocalVarToken(ByteBuffer buffer, MethodSymbols symbols)
        {
            if (symbols.variables.IsNullOrEmpty())
                return MetadataToken.Zero;

            buffer.position = 8;
            return new MetadataToken(buffer.ReadUInt32());
        }
コード例 #3
0
        void PatchRawFatMethod(ByteBuffer buffer, MethodSymbols symbols, CodeWriter writer, out MetadataToken local_var_token)
        {
            var flags = ReadUInt16();
            buffer.WriteUInt16(flags);
            buffer.WriteUInt16(ReadUInt16());
            symbols.code_size = ReadInt32();
            buffer.WriteInt32(symbols.code_size);
            local_var_token = ReadToken();

            if (local_var_token.RID > 0)
            {
                var variables = symbols.variables = ReadVariables(local_var_token);
                buffer.WriteUInt32(variables != null
                    ? writer.GetStandAloneSignature(symbols.variables).ToUInt32()
                    : 0);
            }
            else
                buffer.WriteUInt32(0);

            PatchRawCode(buffer, symbols.code_size, writer);

            if ((flags & 0x8) != 0)
                PatchRawSection(buffer, writer.metadata);
        }