Пример #1
0
        private static void PatchMethods(Collection <MethodDefinition> methods, PatchCollection <MethodPatch> patches)
        {
            int count = 0;

            foreach (MethodDefinition method in methods)
            {
                MethodPatch patch = patches.FindBySource(method.Name);
                if (patch == null)
                {
                    continue;
                }

                bool?result = IsApplicable(method, patch);
                if (result == false)
                {
                    continue;
                }

                if (result == true)
                {
                    patch.Patch(method);
                    Changed = true;
                }

                if (++count >= patches.Count)
                {
                    break;
                }
            }
        }
Пример #2
0
 private void SetTargetMethod(MethodPatch patch)
 {
     if (patch.TargetName != null)
     {
         patch.TargetMethod = TargetType.GetMethod(patch.TargetName);
     }
 }
Пример #3
0
        private static bool?IsApplicable(MethodDefinition method, MethodPatch patch)
        {
            if (method.ReturnType.FullName != patch.ExpectedReturnType)
            {
                return(false);
            }

            if (method.HasParameters)
            {
                if (patch.ExpectedParameterTypes.IsNullOrEmpty())
                {
                    return(false);
                }

                if (method.Parameters.Count != patch.ExpectedParameterTypes.Length)
                {
                    return(false);
                }

                for (int i = 0; i < method.Parameters.Count; i++)
                {
                    if (method.Parameters[i].ParameterType.FullName != patch.ExpectedParameterTypes[i])
                    {
                        return(false);
                    }
                }
            }
            else if (!patch.ExpectedParameterTypes.IsNullOrEmpty())
            {
                return(false);
            }

            Collection <Instruction> instructions = method.Body.Instructions;

            return((instructions.Count < 1 || instructions[0].Operand as String != patch.Label) ? (bool?)true : null);
        }