Exemple #1
0
        private void WriteUnresolvedMethodBody(MethodDefinition method)
        {
            CodeReader    codeReader = this.metadata.module.Read <MethodDefinition, CodeReader>(method, (MethodDefinition _, MetadataReader reader) => reader.code);
            MethodSymbols methodSymbols;
            ByteBuffer    buffer = codeReader.PatchRawMethodBody(method, this, out methodSymbols);

            base.WriteBytes(buffer);
            if (methodSymbols.instructions.IsNullOrEmpty <InstructionSymbol>())
            {
                return;
            }
            methodSymbols.method_token    = method.token;
            methodSymbols.local_var_token = CodeWriter.GetLocalVarToken(buffer, methodSymbols);
            ISymbolWriter symbol_writer = this.metadata.symbol_writer;

            if (symbol_writer != null)
            {
                symbol_writer.Write(methodSymbols);
            }
        }
Exemple #2
0
        public ByteBuffer PatchRawMethodBody(MethodDefinition method, CodeWriter writer, out MethodSymbols symbols)
        {
            ByteBuffer byteBuffer = new ByteBuffer();

            symbols             = new MethodSymbols(method.Name);
            this.method         = method;
            this.reader.context = method;
            this.MoveTo(method.RVA);
            byte          b = base.ReadByte();
            MetadataToken zero;

            switch (b & 3)
            {
            case 2:
                byteBuffer.WriteByte(b);
                zero = MetadataToken.Zero;
                symbols.code_size = b >> 2;
                this.PatchRawCode(byteBuffer, symbols.code_size, writer);
                break;

            case 3:
                this.position--;
                this.PatchRawFatMethod(byteBuffer, symbols, writer, out zero);
                break;

            default:
                throw new NotSupportedException();
            }
            ISymbolReader symbol_reader = this.reader.module.symbol_reader;

            if (symbol_reader != null && writer.metadata.write_symbols)
            {
                symbols.method_token    = CodeReader.GetOriginalToken(writer.metadata, method);
                symbols.local_var_token = zero;
                symbol_reader.Read(symbols);
            }
            return(byteBuffer);
        }
Exemple #3
0
 private Instruction GetInstruction(int offset)
 {
     return(CodeReader.GetInstruction(this.body.Instructions, offset));
 }