CInject.Engine/Utils/MethodInjector.cs

(开头部分) 3KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

#region GNU GPL Version 3 License

// Copyright 2011 Punit Ganshani
// 
// This file MonoExtensions.cs is part of CInject.
// 
// CInject is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
// 
// CInject is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License along with CInject. If not, see http://www.gnu.org/licenses/.
// 
// History:
// ______________________________________________________________
// Created        09-2011              Punit Ganshani

#endregion
using CInject.Engine.Extensions;
using Mono.Cecil.Cil;
using Mono.Cecil;

namespace CInject.Engine.Utils
{
    public class MethodInjector
    {
        private readonly ILProcessor _ilprocessor;
        private readonly MethodBody _methodBody;

        public MethodBody MethodBody
        {
            get { return _methodBody; }
        } 

        public MethodInjector(MethodDefinition method)
        {
            _methodBody = method.Body;
            _ilprocessor = method.Body.GetILProcessor();
        }

        public Instruction Create(OpCode opcode, VariableDefinition variable)
        {
            return _ilprocessor.Create(opcode, variable);
        }

        public void InsertBefore(Instruction target, Instruction instruction)
        {
            _ilprocessor.InsertBefore(target, instruction);
            UpdateReferences(target, instruction); // shift the instructions and offsets & handlers down
        }

        private void UpdateReferences(Instruction instruction, Instruction replaceBy)
        {
            if (_methodBody.Instructions.Count > 0)
                _methodBody.Instructions.UpdateReferences(instruction, replaceBy);

            if (_methodBody.ExceptionHandlers.Count > 0)
                _methodBody.ExceptionHandlers.UpdateReferences(instruction, replaceBy);
        }

        internal Instruction Create(OpCode opCode, ParameterDefinition parameterDefinition)
后面还有 46 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。