Ejemplo n.º 1
0
        public void TestGlobalSort <T>(Func <Dex, List <T> > provider, IComparer <T> comparer)
        {
            foreach (var file in GetTestFiles())
            {
                TestContext.WriteLine("Testing {0}", file);

                var dex   = Dex.Read(file);
                var list  = provider(dex);
                var items = new List <T>(list);
                items.Shuffle();
                items.Sort(comparer);

                if (comparer is IPartialComparer <T> partialComparer)
                {
                    var tsorter = new TopologicalSorter();
                    items = new List <T>(tsorter.TopologicalSort(items, partialComparer));
                }

                if (Extralog)
                {
                    DumpList(string.Concat(file, comparer.ToString(), ".expected.txt"), items);
                    DumpList(string.Concat(file, comparer.ToString(), ".actual.txt"), list);
                }

                for (var i = 0; i < items.Count; i++)
                {
                    var expected = items[i];
                    var actual   = list[i];

                    Assert.AreEqual(expected, actual);
                }
            }
        }
Ejemplo n.º 2
0
        public bool Transform(Dex target, MethodBody body)
        {
#if DEBUG
            //return;
#endif
            return(DoOptimization(body));
        }
Ejemplo n.º 3
0
        public void TestAnnotationSort()
        {
            foreach (var file in GetTestFiles())
            {
                TestContext.WriteLine("Testing {0}", file);
                var dex = Dex.Read(file);

                foreach (var @class in dex.Classes)
                {
                    SortAndCheck(@class.Annotations, new AnnotationComparer());

                    foreach (var field in @class.Fields)
                    {
                        SortAndCheck(field.Annotations, new AnnotationComparer());
                    }

                    foreach (var method in @class.Methods)
                    {
                        SortAndCheck(method.Annotations, new AnnotationComparer());

                        foreach (var parameter in method.Prototype.Parameters)
                        {
                            SortAndCheck(parameter.Annotations, new AnnotationComparer());
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        static void Main()
        {
            var dex = Dex.Read("classes.dex");

            dex.Write("output.dex");
            Console.ReadLine();
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Transform the given body towards Dex compilation.
 /// </summary>
 internal static void Transform(Dex target, MethodBody body)
 {
     foreach (var transformation in optimizations)
     {
         transformation.Transform(target, body);
     }
 }
Ejemplo n.º 6
0
        private void TestReadWrite(string file, out DexReader dexreader, out DexWriter dexwriter)
        {
            TestContext.WriteLine("Testing {0}", file);


            using (Stream fs = new FileStream(file, FileMode.Open))
            {
                var dex = new Dex(fs);
                dexreader = new DexReader(dex);

                var reader = new BinaryReader(dex.buffer);
                dexreader.ReadFrom(reader);

                dexwriter = new DexWriter(dex);

                if (Extralog)
                {
                    using (Stream ofs = new FileStream(file + ".out", FileMode.Create))
                        using (var writer = new BinaryWriter(ofs))
                            dexwriter.WriteTo(writer);
                }
                else
                {
                    using (Stream ofs = new MemoryStream())
                        using (var writer = new BinaryWriter(ofs))
                            dexwriter.WriteTo(writer);
                }
            }
        }
Ejemplo n.º 7
0
 // Use this for initialization
 void Start()
 {
     Aex.SetActive(false);
     Bex.SetActive(false);
     Cex.SetActive(false);
     Dex.SetActive(false);
 }
Ejemplo n.º 8
0
    public void LoadStatus(SaveData LoadData)
    {
        Name      = new Name(LoadData.Name);
        Lv        = new Lv(LoadData.Lv);
        Hp        = new Hp(LoadData.MaxHp, LoadData.CurrentHp);
        Mp        = new Mp(LoadData.MaxMp, LoadData.CurrentMp);
        Str       = new Str(LoadData.Str);
        Vit       = new Vit(LoadData.Vit);
        Dex       = new Dex(LoadData.Dex);
        Int       = new Int(LoadData.Int);
        Exp       = new Exp(LoadData.NextExp, LoadData.CurrentExp);
        MoveSpeed = new MoveSpeed(3, 1);

        Direction = new Direction(Animator);

        ChargeSkill = new SwordChargeAtack();
        NormalAtack = new SwordNomalAtack();
        Skill       = NormalAtack;
        Charge      = GameObject.transform.Find("tame").GetComponent <Charge>();
        Weapon      = (GameObject)Resources.Load("prefab/Weapon/Sword");
        Equip       = new Equip();

        Equip.Weapon(LoadData.EquipWeapon);
        Equip.Head(LoadData.EquipHead);
        Equip.Body(LoadData.EquipBody);
        Equip.Hand(LoadData.EquipHand);
        Equip.Foot(LoadData.EquipFoot);
        Equip.Accessory(LoadData.EquipAccessory);
    }
Ejemplo n.º 9
0
        internal static void Fill(string tdString, TypeReference item, Dex context)
        {
            if (!string.IsNullOrEmpty(tdString))
            {
                char prefix = tdString[0];
                var  td     = (TypeDescriptors)prefix;
                switch (td)
                {
                case TypeDescriptors.Array:
                    var atype = (ArrayType)item;

                    TypeReference elementType = Allocate(tdString.Substring(1));
                    Fill(tdString.Substring(1), elementType, context);

                    /* All types are already allocated
                     * We want to reuse object reference if already in type repository
                     * BUT if not, we don't want to add a new reference to this type:
                     * it's a 'transient' type only used in the Dexer object model but
                     * not persisted in dex file.
                     */
                    atype.ElementType = context.Import(elementType, false);

                    break;

                case TypeDescriptors.FullyQualifiedName:
                    var cref = (ClassReference)item;
                    cref.Fullname = tdString.Substring(1, tdString.Length - 2);
                    break;
                }
            }
        }
Ejemplo n.º 10
0
 public void ClickD()
 {
     Aex.SetActive(false);
     Bex.SetActive(false);
     Cex.SetActive(false);
     Dex.SetActive(true);
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Verify all methods
 /// </summary>
 private void VerifyMethods(Dex dex)
 {
     foreach (var @class in dex.Classes)
     {
         VerifyClass(@class);
     }
 }
Ejemplo n.º 12
0
        private void Boost(AbilityScoreSelection boost, string name, int value)
        {
            switch (boost)
            {
            case AbilityScoreSelection.Str:
                Str.Add(name, value);
                break;

            case AbilityScoreSelection.Dex:
                Dex.Add(name, value);
                break;

            case AbilityScoreSelection.Con:
                Con.Add(name, value);
                break;

            case AbilityScoreSelection.Wis:
                Wis.Add(name, value);
                break;

            case AbilityScoreSelection.Int:
                Int.Add(name, value);
                break;

            case AbilityScoreSelection.Cha:
                Cha.Add(name, value);
                break;
            }
        }
Ejemplo n.º 13
0
        public SAV_PokedexSM(SaveFile sav)
        {
            InitializeComponent();
            WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
            SAV = (SAV7)(Origin = sav).Clone();
            Dex = SAV.Zukan;
            CP  = new[] { CHK_P1, CHK_P2, CHK_P3, CHK_P4, CHK_P5, CHK_P6, CHK_P7, CHK_P8, CHK_P9 };
            CL  = new[] { CHK_L1, CHK_L2, CHK_L3, CHK_L4, CHK_L5, CHK_L6, CHK_L7, CHK_L8, CHK_L9 };

            editing = true;
            // Clear Listbox and ComboBox
            LB_Species.Items.Clear();
            CB_Species.Items.Clear();
            LB_Forms.Items.Clear();

            // Fill List
            CB_Species.InitializeBinding();
            CB_Species.DataSource = new BindingSource(GameInfo.FilteredSources.Species.Skip(1).ToList(), null);

            var Species = GameInfo.Strings.Species;
            var names   = Dex.GetEntryNames(Species);

            foreach (var n in names)
            {
                LB_Species.Items.Add(n);
            }

            editing = false;
            LB_Species.SelectedIndex = 0;
            CB_Species.KeyDown      += WinFormsUtil.RemoveDropCB;
        }
Ejemplo n.º 14
0
        public SAV_PokedexGG(SaveFile sav)
        {
            InitializeComponent();
            WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
            SAV = (SAV7b)(Origin = sav).Clone();
            CP  = new[] { CHK_P1, CHK_P2, CHK_P3, CHK_P4, CHK_P5, CHK_P6, CHK_P7, CHK_P8, CHK_P9, };
            CL  = new[] { CHK_L1, CHK_L2, CHK_L3, CHK_L4, CHK_L5, CHK_L6, CHK_L7, CHK_L8, CHK_L9, };

            editing = true;
            // Clear Listbox and ComboBox
            LB_Species.Items.Clear();
            CB_Species.Items.Clear();

            // Fill List
            CB_Species.InitializeBinding();
            CB_Species.DataSource = new BindingSource(GameInfo.SpeciesDataSource.Skip(1).ToList(), null);

            Dex = SAV.Blocks.Zukan;

            var Species = GameInfo.Strings.Species;
            var names   = Dex.GetEntryNames(Species);

            foreach (var n in names)
            {
                LB_Species.Items.Add(n);
            }

            RecordUsed   = new[] { CHK_RMinHeight, CHK_RMaxHeight, CHK_RMinWeight, CHK_RMaxWeight };
            RecordHeight = new[] { NUD_RHeightMin, NUD_RHeightMax, NUD_RWeightMinHeight, NUD_RWeightMaxHeight };
            RecordWeight = new[] { NUD_RHeightMinWeight, NUD_RHeightMaxWeight, NUD_RWeightMin, NUD_RWeightMax };

            editing = false;
            LB_Species.SelectedIndex = 0;
            CB_Species.KeyDown      += WinFormsUtil.RemoveDropCB;
        }
        public bool Transform(Dex target, MethodBody body)
        {
            bool hasChanges = false;

#if DEBUG
            //return;
#endif
            var instructions = body.Instructions;

            bool[] reachable = new bool[instructions.Count];

            MarkReachable(0, instructions, reachable, body);

            for (int i = instructions.Count - 1; i > 0; --i)
            {
                // the nop-remover will also correcly remove exception handlers.
                if (!reachable[i] && instructions[i].Code != RCode.Nop)
                {
                    instructions[i].ConvertToNop();
                    hasChanges = true;
                }
            }

            return(hasChanges);
        }
        private DexLookup LoadDex()
        {
            var apk = new ApkFile(_apkPath);
            var dex = apk.Load("classes.dex");

            return(new DexLookup(Dex.Read(new MemoryStream(dex))));
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Transform the given body.
 /// </summary>
 public void Transform(Dex target, MethodBody body)
 {
     foreach (var ins in body.Instructions)
     {
         switch (ins.Code)
         {
         case RCode.Invoke_direct:
         case RCode.Invoke_virtual:
         case RCode.Invoke_interface:
             MethodDefinition method;
             if (((MethodReference)ins.Operand).TryResolve(target, out method))
             {
                 if (method.Owner.IsInterface)
                 {
                     ins.Code = RCode.Invoke_interface;
                 }
                 else if (method.IsDirect)
                 {
                     ins.Code = RCode.Invoke_direct;
                 }
                 else
                 {
                     ins.Code = RCode.Invoke_virtual;
                 }
             }
             break;
         }
     }
 }
    public void DiceRoll()
    {
        float first = 0, second = 0, third = 0;

        for (int i = 0; i < 5; i++)
        {
            Roll[i] = Random.Range(1, 7);
        }
        for (int j = 0; j < 5; j++)
        {
            if (Roll[j] > first)
            {
                third  = second;
                second = first;
                first  = Roll[j];
            }
            else if (Roll[j] > second)
            {
                third  = second;
                second = Roll[j];
            }
            else if (Roll[j] > third)
            {
                third = Roll[j];
            }
        }

        total = first + second + third;
        if (Total.Count < 6)
        {
            Total.Add(total);
            Output1.text     = Roll[0].ToString();
            Output2.text     = Roll[1].ToString();
            Output3.text     = Roll[2].ToString();
            Output4.text     = Roll[3].ToString();
            Output5.text     = Roll[4].ToString();
            OutputTotal.text = total.ToString();
        }

        StrMod.text = "+2";
        DexMod.text = "+2";
        ConMod.text = "+2";
        IntMod.text = "+2";
        WisMod.text = "+2";
        ChaMod.text = "+2";

        List <string> options = new List <string>();

        if (Str.options.Count < 6)
        {
            options.Add(Total[Total.Count - 1].ToString());
            Str.AddOptions(options);
            Dex.AddOptions(options);
            Con.AddOptions(options);
            Int.AddOptions(options);
            Wis.AddOptions(options);
            Cha.AddOptions(options);
        }
    }
Ejemplo n.º 19
0
 /// <summary>
 /// Add references to all implemented interfaces.
 /// </summary>
 protected virtual void ImplementInterfaces(Dex target, NameConverter nsConverter)
 {
     // Implement interfaces
     foreach (var intf in typeDef.Interfaces.Select(x => new ClassReference(x.ClassName)))
     {
         classDef.Interfaces.Add(intf);
     }
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Resolve the given method to a method definition.
 /// </summary>
 public static bool TryResolve(this MethodReference methodRef, Dex target, out MethodDefinition result)
 {
     result = methodRef as MethodDefinition;
     if (result != null)
         return true;
     result = target.GetMethod((ClassReference)methodRef.Owner, methodRef.Name, methodRef.Prototype);
     return result != null;
 }
Ejemplo n.º 21
0
 public virtual void LoadXML(XmlElement ele)
 {
     Str.LoadXML(ele);
     Dex.LoadXML(ele);
     End.LoadXML(ele);
     Int.LoadXML(ele);
     Edu.LoadXML(ele);
     Soc.LoadXML(ele);
 }
Ejemplo n.º 22
0
 public virtual void SaveXML(XmlElement ele)
 {
     Str.SaveXML(ele);
     Dex.SaveXML(ele);
     End.SaveXML(ele);
     Int.SaveXML(ele);
     Edu.SaveXML(ele);
     Soc.SaveXML(ele);
 }
Ejemplo n.º 23
0
        internal Dictionary <int, Instruction> LookupLast;        // instructions by ending offset

        public InstructionReader(Dex dex, MethodDefinition mdef)
        {
            Dex = dex;
            MethodDefinition        = mdef;
            Lookup                  = new Dictionary <int, Instruction>();
            LookupLast              = new Dictionary <int, Instruction>();
            LazyInstructionsSetters = new List <Action>();
            _ip = 0;
        }
Ejemplo n.º 24
0
        public bool Transform(Dex target, MethodBody body)
        {
            bool hasChanges = false;

#if DEBUG
            //return;
#endif
            var instructions = body.Instructions;
            var hasNops      = instructions.Any(x => x.Code == RCode.Nop);
            if (!hasNops)
            {
                return(false);
            }

            var rerouter = new BranchReRouter(body);
            var i        = 0;
            while (i < instructions.Count)
            {
                var inst = instructions[i];
                if (inst.Code != RCode.Nop)
                {
                    i++;
                    continue;
                }
                if (body.Exceptions.Count > 0)
                {
                    foreach (var ex in body.Exceptions.Where(x => x.TryEnd == inst).ToList())
                    {
                        var exTryEnd = ex.TryEnd;
                        if (exTryEnd.Index > ex.TryStart.Index)
                        {
                            exTryEnd = exTryEnd.Previous;
                        }

                        if (exTryEnd == ex.TryStart)
                        {
                            // empty exception handler -- remove.
                            body.Exceptions.Remove(ex);
                        }
                        else
                        {
                            ex.TryEnd = exTryEnd;
                        }
                    }
                }

                if (i < instructions.Count - 1)
                {
                    var next = instructions[i + 1];
                    rerouter.Reroute(inst, next);
                }
                instructions.RemoveAt(i);
                hasChanges = true;
            }

            return(hasChanges);
        }
Ejemplo n.º 25
0
        public async Task <IActionResult> Pokerandom()
        {
            Dex     dex     = new Dex();
            Pokemon pokemon = await dex.GetRandomPokemon();

            ViewBag.Pokemon     = pokemon;
            ViewData["Sprites"] = pokemon.sprites;
            return(View());
        }
Ejemplo n.º 26
0
        public bool Transform(Dex target, MethodBody body)
        {
            bool hasChanges = false;

            var registerUsage = new RegisterUsageMap2(body);

            hasChanges = InlineIntConstsIntoBinOp(registerUsage);

            return(hasChanges);
        }
Ejemplo n.º 27
0
        public DalvikCPU(Dex d, string pName, EmuPage hostPg)
        {
            dex         = d;
            packageName = pName;
            hostPage    = hostPg;
            da          = hostPage.RunningApp;
            da.cpu      = this;

            hostPage.setPreloadStatusText("Setting up app environment...");
        }
Ejemplo n.º 28
0
 /// <summary>
 /// Resolve the given method to a method definition.
 /// </summary>
 public static bool TryResolve(this MethodReference methodRef, Dex target, out MethodDefinition result)
 {
     result = methodRef as MethodDefinition;
     if (result != null)
     {
         return(true);
     }
     result = target.GetMethod((ClassReference)methodRef.Owner, methodRef.Name, methodRef.Prototype);
     return(result != null);
 }
Ejemplo n.º 29
0
 private void UpdateUI()
 {
     lblRaceName.Text    = currentRace.Name;
     lblRaceBenefit.Text = Benefit;
     lblHitPoints.Text   = HitPoints.ToString();
     lblDex.Text         = Dex.ToString();
     lblInt.Text         = Int.ToString();
     lblStrength.Text    = Strength.ToString();
     lblMana.Text        = Mana.ToString();
 }
Ejemplo n.º 30
0
        public void TestUpdateInstructionOffsets()
        {
            var coverage = new Dictionary <OpCodes, int>();

            foreach (var file in GetTestFiles())
            {
                TestContext.WriteLine("Testing {0}", file);

                var dex = Dex.Read(file);

                foreach (var @class in dex.Classes)
                {
                    foreach (var method in @class.Methods)
                    {
                        if (method.Body == null)
                        {
                            continue;
                        }

                        var offsets = new List <int>();
                        foreach (var ins in method.Body.Instructions)
                        {
                            if (!coverage.ContainsKey(ins.OpCode))
                            {
                                coverage.Add(ins.OpCode, 0);
                            }
                            offsets.Add(ins.Offset);
                            coverage[ins.OpCode]++;
                        }

                        method.Body.UpdateInstructionOffsets();
                        for (var i = 0; i < offsets.Count; i++)
                        {
                            Assert.AreEqual(offsets[i], method.Body.Instructions[i].Offset, "Check OpCode {0}", method.Body.Instructions[i == 0 ? i : i - 1].OpCode);
                        }
                    }
                }
            }

            bool isInconclusive = false;

            foreach (OpCodes opcode in Enum.GetValues(typeof(OpCodes)))
            {
                if (!coverage.ContainsKey(opcode))
                {
                    isInconclusive = true;
                    TestContext.WriteLine("OpCode {0} was not covered", opcode);
                }
            }

            if (isInconclusive)
            {
                Assert.Inconclusive("Some OpCode(s) were not covered ({0:P} coverage) , see test details", ((double)coverage.Count) / (Enum.GetNames(typeof(OpCodes)).Length));
            }
        }
Ejemplo n.º 31
0
 public void LvUp()
 {
     Lv.LvUp();
     Hp.LvUp(10);
     Mp.LvUp(5);
     Str.LvUp(5);
     Vit.LvUp(5);
     Dex.LvUp(3);
     Int.LvUp(1);
     DataManager.Save();
 }
Ejemplo n.º 32
0
        internal Dex ReadFrom(BinaryReader reader)
        {
            ReadHeader(reader);
            ReadMapList(reader);
            ReadStrings(reader);

            PrefetchTypeReferences(reader);
            PrefetchClassDefinitions(reader, false);

            ReadTypesReferences(reader);
            ReadPrototypes(reader);
            ReadFieldReferences(reader);
            ReadMethodReferences(reader);

            PrefetchClassDefinitions(reader, true);
            ReadClassDefinitions(reader);

            var topLevelClasses = ClassDefinition.Hierarchicalize(classes);
            var dex = new Dex();
            dex.AddRange(topLevelClasses);
            return dex;
        }
Ejemplo n.º 33
0
 private void DEX_Click(object sender, RoutedEventArgs e)
 {
     string filepath = ChoosedPath.Text;
     Dex aa = new Dex(filepath);
     aa.Show(); 
 }