SparseSwitchMethodItem.java revision 7ab77bc90be62b0688c97d4476e3bd219eace0da
19bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com/* 29bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * [The "BSD licence"] 39bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * Copyright (c) 2009 Ben Gruver 49bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * All rights reserved. 59bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * 69bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * Redistribution and use in source and binary forms, with or without 79bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * modification, are permitted provided that the following conditions 89bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * are met: 99bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * 1. Redistributions of source code must retain the above copyright 109bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * notice, this list of conditions and the following disclaimer. 119bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * 2. Redistributions in binary form must reproduce the above copyright 129bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * notice, this list of conditions and the following disclaimer in the 139bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * documentation and/or other materials provided with the distribution. 149bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * 3. The name of the author may not be used to endorse or promote products 159bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * derived from this software without specific prior written permission. 169bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * 179bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 189bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 199bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 209bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 219bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 229bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 239bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 249bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 259bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 269bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 279bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com */ 289bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com 296ef13753e78bb7abc7e7683d5e533c3395d4a9b6JesusFreke@JesusFreke.compackage org.jf.baksmali.Adaptors.Format; 309bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com 31bf4ca730cc857f76ee703e9efa73ad3e408c6c37JesusFreke@JesusFreke.comimport org.jf.dexlib.Code.Format.SparseSwitchDataPseudoInstruction; 327ab77bc90be62b0688c97d4476e3bd219eace0daJesusFreke@JesusFreke.comimport org.antlr.stringtemplate.StringTemplateGroup; 337ab77bc90be62b0688c97d4476e3bd219eace0daJesusFreke@JesusFreke.comimport org.antlr.stringtemplate.StringTemplate; 349bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com 35cf6729c1ee64e732f28eb40386ecc69d4fb6b401JesusFreke@JesusFreke.comimport java.util.Iterator; 367ab77bc90be62b0688c97d4476e3bd219eace0daJesusFreke@JesusFreke.comimport java.util.List; 377ab77bc90be62b0688c97d4476e3bd219eace0daJesusFreke@JesusFreke.comimport java.util.ArrayList; 38cf6729c1ee64e732f28eb40386ecc69d4fb6b401JesusFreke@JesusFreke.com 399bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.compublic class SparseSwitchMethodItem extends InstructionFormatMethodItem<SparseSwitchDataPseudoInstruction> { 409bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com private int baseAddress; 419bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com 427ab77bc90be62b0688c97d4476e3bd219eace0daJesusFreke@JesusFreke.com public SparseSwitchMethodItem(int offset, StringTemplateGroup stg, SparseSwitchDataPseudoInstruction instruction, 437ab77bc90be62b0688c97d4476e3bd219eace0daJesusFreke@JesusFreke.com int baseAddress) { 447ab77bc90be62b0688c97d4476e3bd219eace0daJesusFreke@JesusFreke.com super(offset, stg, instruction); 459bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com this.baseAddress = baseAddress; 469bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com } 479bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com 487ab77bc90be62b0688c97d4476e3bd219eace0daJesusFreke@JesusFreke.com protected void setAttributes(StringTemplate template) { 497ab77bc90be62b0688c97d4476e3bd219eace0daJesusFreke@JesusFreke.com template.setAttribute("Targets", getTargets()); 507ab77bc90be62b0688c97d4476e3bd219eace0daJesusFreke@JesusFreke.com } 517ab77bc90be62b0688c97d4476e3bd219eace0daJesusFreke@JesusFreke.com 52cf6729c1ee64e732f28eb40386ecc69d4fb6b401JesusFreke@JesusFreke.com private static class SparseSwitchTarget { 53cf6729c1ee64e732f28eb40386ecc69d4fb6b401JesusFreke@JesusFreke.com public int Value; 54cf6729c1ee64e732f28eb40386ecc69d4fb6b401JesusFreke@JesusFreke.com public String Target; 559bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com } 569bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com 577ab77bc90be62b0688c97d4476e3bd219eace0daJesusFreke@JesusFreke.com private List<SparseSwitchTarget> getTargets() { 587ab77bc90be62b0688c97d4476e3bd219eace0daJesusFreke@JesusFreke.com List<SparseSwitchTarget> targets = new ArrayList<SparseSwitchTarget>(); 59cf6729c1ee64e732f28eb40386ecc69d4fb6b401JesusFreke@JesusFreke.com 607ab77bc90be62b0688c97d4476e3bd219eace0daJesusFreke@JesusFreke.com Iterator<SparseSwitchDataPseudoInstruction.SparseSwitchTarget> iterator = instruction.getTargets(); 619bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com 627ab77bc90be62b0688c97d4476e3bd219eace0daJesusFreke@JesusFreke.com while (iterator.hasNext()) { 637ab77bc90be62b0688c97d4476e3bd219eace0daJesusFreke@JesusFreke.com SparseSwitchDataPseudoInstruction.SparseSwitchTarget target = iterator.next(); 647ab77bc90be62b0688c97d4476e3bd219eace0daJesusFreke@JesusFreke.com SparseSwitchTarget sparseSwitchTarget = new SparseSwitchTarget(); 657ab77bc90be62b0688c97d4476e3bd219eace0daJesusFreke@JesusFreke.com sparseSwitchTarget.Value = target.value; 667ab77bc90be62b0688c97d4476e3bd219eace0daJesusFreke@JesusFreke.com sparseSwitchTarget.Target = Integer.toHexString(target.target + baseAddress); 677ab77bc90be62b0688c97d4476e3bd219eace0daJesusFreke@JesusFreke.com targets.add(sparseSwitchTarget); 687ab77bc90be62b0688c97d4476e3bd219eace0daJesusFreke@JesusFreke.com } 699bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com 707ab77bc90be62b0688c97d4476e3bd219eace0daJesusFreke@JesusFreke.com return targets; 719bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com } 729bc4978139ca38e422ae89065d3062146534132dJesusFreke@JesusFreke.com} 73