/// <summary>
        /// Handles replacing code for most method calling OpCodes
        /// </summary>
        /// <param name="actualClass">instance</param>
        /// <param name="instruction">instance </param>
        /// <param name="classObj">Class Object </param>
        private void HandleGeneralMethodCall(TypeDef actualClass, Instruction instruction, ClassObj classObj)
        {
            var operandCast = (MethodDef)instruction.Operand;
            var methodName  = operandCast.Name;

            if (methodName == ".ctor")
            {
                HandleCtor(actualClass, instruction);
                return;
            }

            var methodObjOpt = classObj.GetMethod(methodName);

            if (!methodObjOpt.IsPresent())
            {
                Console.WriteLine("!! [Genera] Method Object is missing for: " + actualClass.Name + "." +
                                  operandCast.Name);
                return;
            }

            var methodObj = methodObjOpt.Get();
            //Todo: Make this use a MethodSig for finding the method
            //Finds the obfuscated class' method's MethodDef
            var actualMethod = actualClass.FindMethod(methodObj.ObfName);

            //Sets the instructions operand to our new one
            instruction.Operand = instruction.OpCode.ToInstruction(actualMethod).Operand;
        }
Exemplo n.º 2
0
        private void InjectMethods(TypeDef type)
        {
            foreach (var methodDef in type.Methods)
            {
                _methodInjectors.ForEach(m =>
                {
                    var methodObjOpt = ClassObj.GetMethod(m.Item1);
                    if (!methodObjOpt.IsPresent() || !methodObjOpt.Get().ObfName.Equals(methodDef.Name))
                    {
                        return;
                    }

                    m.Item2.Invoke(methodDef);
                    Console.WriteLine("... Method Injected: " + methodObjOpt.Get().Name);
                });
            }
        }