Пример #1
0
        public CallManagedFunctionAction(MethodAnalysis context, Instruction instruction) : base(context, instruction)
        {
            var jumpTarget = instruction.NearBranchTarget;
            var objectMethodBeingCalledOn = context.GetLocalInReg("rcx");
            var listOfCallableMethods     = LibCpp2IlMain.GetManagedMethodImplementationsAtAddress(jumpTarget);

            if (listOfCallableMethods == null)
            {
                return;
            }

            Il2CppMethodDefinition possibleTarget = null;

            if (objectMethodBeingCalledOn?.Type != null)
            {
                //Direct instance methods take priority
                possibleTarget = listOfCallableMethods.FirstOrDefault(m => !m.IsStatic && Utils.AreManagedAndCppTypesEqual(LibCpp2ILUtils.WrapType(m.DeclaringType !), objectMethodBeingCalledOn.Type) && CheckParameters(m, context, true));

                //todo check args and null out

                if (possibleTarget == null)
                {
                    //Base class instance methods
                    possibleTarget = listOfCallableMethods.FirstOrDefault(m => !m.IsStatic && Utils.IsManagedTypeAnInstanceOfCppOne(LibCpp2ILUtils.WrapType(m.DeclaringType !), objectMethodBeingCalledOn.Type) && CheckParameters(m, context, true));
                }

                //check args again.
            }

            //Check static methods
            if (possibleTarget == null)
            {
                possibleTarget = listOfCallableMethods.FirstOrDefault(m => m.IsStatic && CheckParameters(m, context, false));
            }


            if (possibleTarget != null)
            {
                target = SharedState.UnmanagedToManagedMethods[possibleTarget];
                return;
            }

            // SharedState.MethodsByAddress.TryGetValue(jumpTarget, out target);
        }
Пример #2
0
        public CallManagedFunctionInRegAction(MethodAnalysis context, Instruction instruction) : base(context, instruction)
        {
            var regName = Utils.GetRegisterNameNew(instruction.MemoryBase);
            var operand = context.GetConstantInReg(regName);

            _targetMethod = (MethodDefinition)operand.Value;

            if (!_targetMethod.IsStatic)
            {
                _instanceCalledOn = context.GetLocalInReg("rcx");
                if (_instanceCalledOn == null)
                {
                    var cons = context.GetConstantInReg("rcx");
                    if (cons?.Value is NewSafeCastResult castResult)
                    {
                        _instanceCalledOn = castResult.original;
                    }
                }
            }
        }
Пример #3
0
        public CallVirtualMethodAction(MethodAnalysis context, Instruction instruction) : base(context, instruction)
        {
            var inReg = context.GetOperandInRegister(Utils.GetRegisterNameNew(instruction.MemoryBase));

            if (!(inReg is ConstantDefinition cons) || !(cons.Value is Il2CppClassIdentifier klass))
            {
                return;
            }

            var classReadFrom = klass.backingType;

            var readOffset = instruction.MemoryDisplacement;

            Called = Utils.GetMethodFromReadKlassOffset((int)readOffset);

            if (Called == null)
            {
                return;
            }

            CalledOn = context.GetLocalInReg("rcx");
        }