Пример #1
0
        public static UnitorMethod ToUnitorMethod(this MethodDef method, UnitorModel lookupModel)
        {
            if (method == null)
            {
                return(new UnitorMethod(lookupModel));
            }

            List <UnitorType> ParameterList = new List <UnitorType>();

            foreach (Parameter param in method.Parameters)
            {
                if (param.Type.IsTypeDefOrRef)
                {
                    ParameterList.Add(param.Type.TryGetTypeDef()?.ToUnitorType(lookupModel, false) ?? new UnitorType(lookupModel));
                }
            }
            UnitorMethod m = new UnitorMethod(lookupModel)
            {
                DeclaringType = method.DeclaringType.ToUnitorType(lookupModel, false),
                ReturnType    = method.ReturnType.TryGetTypeDef()?.ToUnitorType(lookupModel, false) ?? new UnitorType(lookupModel),
                ParameterList = ParameterList,
                MonoMethod    = method
            };

            return(m);
        }
Пример #2
0
        public static UnitorMethod ToUnitorMethod(this MethodInfo method, UnitorModel lookupModel)
        {
            if (method == null)
            {
                return(new UnitorMethod(lookupModel));
            }

            List <UnitorType> ParameterList = new List <UnitorType>();

            ParameterList.AddRange(method.DeclaredParameters.Select(p => p.ParameterType.ToUnitorType(lookupModel, false)));

            UnitorMethod m = new UnitorMethod(lookupModel)
            {
                DeclaringType = method.DeclaringType.ToUnitorType(lookupModel, false),
                ParameterList = ParameterList,
                ReturnType    = method.ReturnType.ToUnitorType(lookupModel, false),
                Il2CppMethod  = method
            };

            return(m);
        }
Пример #3
0
        public void Analyse()
        {
            if (IsEmpty)
            {
                return;
            }
            if (Il2CppMethod != null)
            {
                if (!Il2CppMethod.VirtualAddress.HasValue)
                {
                    return;
                }

                X86DisassembleMode      mode         = Owner.AppModel.Image.Arch == "x64" ? X86DisassembleMode.Bit64 : X86DisassembleMode.Bit32;
                CapstoneX86Disassembler disassembler = CapstoneDisassembler.CreateX86Disassembler(mode);
                disassembler.EnableInstructionDetails = true;

                var asm = disassembler.Disassemble(Il2CppMethod.GetMethodBody(), (long)Il2CppMethod.VirtualAddress.Value.Start);
                foreach (X86Instruction ins in asm)
                {
                    if (Dissasembler.ShouldCheckInstruction(ins.Id))
                    {
                        UnitorMethod m = Dissasembler.GetMethodFromInstruction(ins, Owner);
                        if (m != null)
                        {
                            MethodCalls.Add(m);
                            Owner.MethodReferences.AddOrUpdate(m, new List <UnitorMethod>(), (key, references) => { references.Add(this); return(references); });
                        }
                        var s = Dissasembler.GetStringFromInstruction(ins, Owner.StringTable);
                        if (!string.IsNullOrEmpty(s.Item2))
                        {
                            Strings.Add(new KeyValuePair <ulong, string>(s.Item1, s.Item2));
                        }
                    }
                }
                disassembler.Dispose();
            }
            else
            {
                if (!MonoMethod.HasBody)
                {
                    return;
                }

                foreach (Instruction ins in MonoMethod.Body.Instructions)
                {
                    if ((ins.OpCode.Code == Code.Call || ins.OpCode.Code == Code.Calli || ins.OpCode.Code == Code.Callvirt) && ins.Operand is MethodDef calledMethod)
                    {
                        if (Owner.MonoTypeMatches.TryGetValue(calledMethod.DeclaringType, out UnitorType type))
                        {
                            if (type.Methods == null)
                            {
                                continue;
                            }
                            UnitorMethod method = type.Methods.FirstOrDefault(m => calledMethod.Name == m.Name);
                            MethodCalls.Add(method);
                            Owner.MethodReferences.AddOrUpdate(method, new List <UnitorMethod>(), (key, references) => { references.Add(this); return(references); });
                        }
                    }
                    if (ins.OpCode.Code == Code.Ldstr && ins.Operand is string s)
                    {
                        Strings.Add(new KeyValuePair <ulong, string>((ulong)(MonoMethod.RVA + ins.Offset), s));
                    }
                }
            }
        }