Exemplo n.º 1
0
        private static void FindCurrentScoreField(ClassObj @class, IList <Instruction> instructions)
        {
            if (@class.GetField("CurrentScore").IsPresent())
            {
                return;
            }
            if (instructions.Count < 15)
            {
                return;
            }

            for (var i = 2; i < instructions.Count - 1; i++)
            {
                var prevPrevInsn = instructions[i - 2];
                var prevInsn     = instructions[i - 1];
                var insn         = instructions[i];
                var nextInsn     = instructions[i + 1];

                if (prevPrevInsn.OpCode != OpCodes.Call || prevInsn.OpCode != OpCodes.Ldsfld ||
                    nextInsn.OpCode != OpCodes.Ret || !(prevInsn.Operand is IField))
                {
                    continue;
                }

                var ldsfld = (IField)prevInsn.Operand;
                @class.AddField("CurrentScore", ldsfld.Name);
            }
        }
Exemplo n.º 2
0
        private void FindFields(ClassObj @class, IList <MethodDef> methodDefs)
        {
            foreach (var method in methodDefs)
            {
                if (!HasStrings(method,
                                "{0}:{1}:{2}:{3}:{4}:{5}:{6}:{7}:{8}:{9}:{10}:{11}:{12}:{13}:{14}:{15}:{16:yyMMddHHmmss}:{17}"))
                {
                    continue;
                }

                int addedFields = 0;
                foreach (var insn in method.Body.Instructions)
                {
                    if (insn.OpCode != OpCodes.Ldfld || !(insn.Operand is IField))
                    {
                        continue;
                    }

                    var field     = (IField)insn.Operand;
                    var fieldType = field.FieldSig.Type;
                    if (fieldType == Program.osu_exe.CorLibTypes.UInt16 ||
                        fieldType == Program.osu_exe.CorLibTypes.Int32)
                    {
                        //TODO: Doesn't get TotalScore because it's a 'callvirt' and not a 'Ldfld'
                        switch (addedFields)
                        {
                        case 0:
                            @class.AddField("Count300", field.Name);
                            break;

                        case 1:
                            @class.AddField("Count100", field.Name);
                            break;

                        case 2:
                            @class.AddField("Count50", field.Name);
                            break;

                        case 3:
                            @class.AddField("CountGeki", field.Name);
                            break;

                        case 4:
                            @class.AddField("CountKatu", field.Name);
                            break;

                        case 5:
                            @class.AddField("CountMiss", field.Name);
                            break;

                        case 6:
                            @class.AddField("CountMaxCombo", field.Name);
                            break;
                        }
                        addedFields++;
                    }
                }
            }
        }
Exemplo n.º 3
0
 private void FindComponentList(ClassObj clazz, IList <FieldDef> typeFields)
 {
     foreach (var typeField in typeFields)
     {
         if (!typeField.FullName.Contains("Generic.List"))
         {
             continue;
         }
         clazz.AddField("ComponentList", typeField.Name);
         return;
     }
 }
        private void FindValueField(ClassObj clazz, IList <MethodDef> methodDefs)
        {
            var methodContaingValueFld = methodDefs.First(m => ClrHelper.MatchesSig(m, "Double", "Boolean", "Boolean"));
            var pattern = GetOpcodePattern(methodContaingValueFld, 1, OpCodes.Ldarg_0, OpCodes.Ldfld, OpCodes.Ldarg_1, OpCodes.Beq_S);

            if (!pattern.IsPresent())
            {
                Console.WriteLine("Pattern not found while finding valueFld");
                return;
            }

            clazz.AddField("SliderValue", (pattern.Get().Operand as FieldDef).Name);
        }
        public override void GetMethods(string className, TypeDef type, IList <MethodDef> methodDefs)
        {
            var sigCheck = methodDefs.Where(m =>
                                            ClrHelper.MatchesSig(m, "?", "Double", "Double", "Double", "Vector2", "Int32")).ToList();

            if (!sigCheck.Any())
            {
                return;
            }

            var clazz = new ClassObj(UnobfuscatedName, className);

            MappingManager.AddClass(clazz);

            var callbackSearch = methodDefs
                                 .Where(m => ClrHelper.MatchesSig(m, "Object", "EventArgs")).ToList();

            if (!callbackSearch.Any())
            {
                return;
            }

            foreach (var methodDef in callbackSearch)
            {
                var insn = GetOpcodePattern(methodDef, 0, OpCodes.Ldfld, OpCodes.Brfalse_S, OpCodes.Ldarg_0,
                                            OpCodes.Ldfld, OpCodes.Ldc_I4_1, OpCodes.Callvirt);

                if (!insn.IsPresent())
                {
                    continue;
                }

                var i        = insn.Get();
                var fieldDef = i.Operand as FieldDef;
                clazz.AddField("SliderCallbacks", fieldDef.Name);

                var sliderChangeClass = new ClassObj("SliderChanged", fieldDef.FieldType.FullName);
                MappingManager.AddClass(sliderChangeClass);
            }

            FindSetTooltip(clazz, methodDefs);
            FindValueField(clazz, methodDefs);
        }
        private void FindComponentManager(IList <MethodDef> methodDefs, ClassObj @class)
        {
            var ctorList = methodDefs.Where(i => i.Name == ".ctor");

            if (!ctorList.Any())
            {
                return;
            }
            var ctor = ctorList.First();

            var insnOpt = GetOpcodePattern(ctor, 4, OpCodes.Newobj, OpCodes.Dup, OpCodes.Ldc_I4_0, OpCodes.Stfld,
                                           OpCodes.Stfld);

            insnOpt.IfPresent(insn =>
            {
                if (!(insn.Operand is FieldDef field))
                {
                    return;
                }

                @class.AddField("componentManagerFld", field.Name);
                AddComponentManagerClass(field);
            });
        }