コード例 #1
0
ファイル: PatchProcessor.cs プロジェクト: 5l1v3r1/Harmony-1
        /// <summary>Returns the methods unmodified list of code instructions</summary>
        /// <param name="original">The original method/constructor</param>
        /// <param name="generator">A new generator that now contains all local variables and labels contained in the result</param>
        /// <returns>A list containing all the original <see cref="CodeInstruction"/></returns>
        ///
        public static List <CodeInstruction> GetOriginalInstructions(MethodBase original, out ILGenerator generator)
        {
            generator = CreateILGenerator();
            var reader = MethodBodyReader.GetInstructions(generator, original);

            return(reader.Select(ins => ins.GetCodeInstruction()).ToList());
        }
コード例 #2
0
ファイル: PatchProcessor.cs プロジェクト: walterhcain/Harmony
        /// <summary>A low level way to read the body of a method. Used for quick searching in methods</summary>
        /// <param name="method">The original method</param>
        /// <returns>All instructions as opcode/operand pairs</returns>
        ///
        public static IEnumerable <KeyValuePair <OpCode, object> > ReadMethodBody(MethodBase method)
        {
            var dummyMethod = new DynamicMethodDefinition($"{method.Name}_Dummy{Guid.NewGuid()}", typeof(void), new Type[0]);

            return(MethodBodyReader.GetInstructions(dummyMethod.GetILGenerator(), method)
                   .Select(instr => new KeyValuePair <OpCode, object>(instr.opcode, instr.operand)));
        }
コード例 #3
0
        /// <summary>Returns the methods unmodified list of CodeInstructions</summary>
        /// <param name="original">The original method</param>
        /// <param name="generator">The generator that now contains all local variables and labels contained in the result</param>
        /// <returns>A list containing all the original CodeInstructions</returns>
        public static List <CodeInstruction> GetOriginalInstructions(MethodBase original, out ILGenerator generator)
        {
            var patch = DynamicTools.CreateDynamicMethod(original, $"_Copy{Guid.NewGuid()}");

            generator = patch.GetILGenerator();
            var reader = MethodBodyReader.GetInstructions(generator, original);

            return(reader.Select(ins => ins.GetCodeInstruction()).ToList());
        }
コード例 #4
0
ファイル: PatchProcessor.cs プロジェクト: walterhcain/Harmony
        /// <summary>Returns the methods unmodified list of code instructions</summary>
        /// <param name="original">The original method/constructor</param>
        /// <param name="generator">A new generator that now contains all local variables and labels contained in the result</param>
        /// <returns>A list containing all the original <see cref="CodeInstruction"/></returns>
        ///
        public static List <CodeInstruction> GetOriginalInstructions(MethodBase original, out ILGenerator generator)
        {
            var method = new DynamicMethodDefinition($"{original.Name}_Dummy{Guid.NewGuid()}", typeof(void), new Type[0]);

            generator = method.GetILGenerator();
            var reader = MethodBodyReader.GetInstructions(generator, original);

            return(reader.Select(ins => ins.GetCodeInstruction()).ToList());
        }
コード例 #5
0
        /// <summary>Returns the methods unmodified list of CodeInstructions</summary>
        /// <param name="original">The original method</param>
        /// <param name="generator">Optionally an existing generator that will be used to create all local variables and labels contained in the result (if not specified, an internal generator is used)</param>
        /// <returns>A list containing all the original CodeInstructions</returns>
        public static List <CodeInstruction> GetOriginalInstructions(MethodBase original, ILGenerator generator = null)
        {
            var patch = MethodPatcher.CreateDynamicMethod(original, $"_Copy{Guid.NewGuid()}", Harmony.DEBUG);

            generator = generator ?? patch.GetILGenerator();
            var reader = MethodBodyReader.GetInstructions(generator, original);

            return(reader.Select(ins => ins.GetCodeInstruction()).ToList());
        }
コード例 #6
0
ファイル: PatchProcessor.cs プロジェクト: 5l1v3r1/Harmony-1
 /// <summary>A low level way to read the body of a method. Used for quick searching in methods</summary>
 /// <param name="method">The original method</param>
 /// <param name="generator">An existing generator that will be used to create all local variables and labels contained in the result</param>
 /// <returns>All instructions as opcode/operand pairs</returns>
 ///
 public static IEnumerable <KeyValuePair <OpCode, object> > ReadMethodBody(MethodBase method, ILGenerator generator)
 {
     return(MethodBodyReader.GetInstructions(generator, method)
            .Select(instr => new KeyValuePair <OpCode, object>(instr.opcode, instr.operand)));
 }
コード例 #7
0
 /// <summary>Gets all instructions from a method</summary>
 /// <param name="generator">The generator (for defining labels)</param>
 /// <param name="method">The original method</param>
 /// <returns>The instructions</returns>
 ///
 public static List <ILInstruction> GetInstructions(ILGenerator generator, MethodBase method)
 {
     return(MethodBodyReader.GetInstructions(generator, method));
 }