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); } } }
public bool Transform(Dex target, MethodBody body) { #if DEBUG //return; #endif return(DoOptimization(body)); }
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()); } } } } }
static void Main() { var dex = Dex.Read("classes.dex"); dex.Write("output.dex"); Console.ReadLine(); }
/// <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); } }
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); } } }
// Use this for initialization void Start() { Aex.SetActive(false); Bex.SetActive(false); Cex.SetActive(false); Dex.SetActive(false); }
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); }
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; } } }
public void ClickD() { Aex.SetActive(false); Bex.SetActive(false); Cex.SetActive(false); Dex.SetActive(true); }
/// <summary> /// Verify all methods /// </summary> private void VerifyMethods(Dex dex) { foreach (var @class in dex.Classes) { VerifyClass(@class); } }
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; } }
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; }
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)))); }
/// <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); } }
/// <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); } }
/// <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; }
public virtual void LoadXML(XmlElement ele) { Str.LoadXML(ele); Dex.LoadXML(ele); End.LoadXML(ele); Int.LoadXML(ele); Edu.LoadXML(ele); Soc.LoadXML(ele); }
public virtual void SaveXML(XmlElement ele) { Str.SaveXML(ele); Dex.SaveXML(ele); End.SaveXML(ele); Int.SaveXML(ele); Edu.SaveXML(ele); Soc.SaveXML(ele); }
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; }
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); }
public async Task <IActionResult> Pokerandom() { Dex dex = new Dex(); Pokemon pokemon = await dex.GetRandomPokemon(); ViewBag.Pokemon = pokemon; ViewData["Sprites"] = pokemon.sprites; return(View()); }
public bool Transform(Dex target, MethodBody body) { bool hasChanges = false; var registerUsage = new RegisterUsageMap2(body); hasChanges = InlineIntConstsIntoBinOp(registerUsage); return(hasChanges); }
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..."); }
/// <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); }
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(); }
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)); } }
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(); }
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; }
private void DEX_Click(object sender, RoutedEventArgs e) { string filepath = ChoosedPath.Text; Dex aa = new Dex(filepath); aa.Show(); }