ArrayDataMethodItem.java revision 74c14ffcca0ff4f8f3e66e66022894cd7b0b8540
1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* 2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * [The "BSD licence"] 3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Copyright (c) 2010 Ben Gruver (JesusFreke) 4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * All rights reserved. 5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Redistribution and use in source and binary forms, with or without 7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * modification, are permitted provided that the following conditions 8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * are met: 9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 1. Redistributions of source code must retain the above copyright 10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * notice, this list of conditions and the following disclaimer. 11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 2. Redistributions in binary form must reproduce the above copyright 12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * notice, this list of conditions and the following disclaimer in the 13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * documentation and/or other materials provided with the distribution. 14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 3. The name of the author may not be used to endorse or promote products 15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * derived from this software without specific prior written permission. 16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgpackage org.jf.baksmali.Adaptors.Format; 30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgimport org.jf.util.IndentingWriter; 32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgimport org.jf.baksmali.Renderers.ByteRenderer; 33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgimport org.jf.dexlib.Code.Format.ArrayDataPseudoInstruction; 34f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgimport org.jf.dexlib.CodeItem; 35f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 36f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgimport java.io.IOException; 37f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgimport java.util.Iterator; 38f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 39f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgpublic class ArrayDataMethodItem extends InstructionMethodItem<ArrayDataPseudoInstruction> { 40f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public ArrayDataMethodItem(CodeItem codeItem, int codeAddress, ArrayDataPseudoInstruction instruction) { 41f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org super(codeItem, codeAddress, instruction); 42f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 43f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 44f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org public boolean writeTo(IndentingWriter writer) throws IOException { 45f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org writer.write(".array-data 0x"); 46f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org writer.printUnsignedLongAsHex(instruction.getElementWidth()); 47f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org writer.write('\n'); 48f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 49f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org writer.indent(4); 50f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org Iterator<ArrayDataPseudoInstruction.ArrayElement> iterator = instruction.getElements(); 51f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org while (iterator.hasNext()) { 52f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org ArrayDataPseudoInstruction.ArrayElement element = iterator.next(); 53f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 54f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org for (int i=0; i<element.elementWidth; i++) { 55f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (i!=0) { 56f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org writer.write(' '); 57f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 58f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org ByteRenderer.writeUnsignedTo(writer, element.buffer[element.bufferIndex+i]); 59f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 60f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org writer.write('\n'); 61f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 62f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org writer.deindent(4); 63 writer.write(".end array-data"); 64 return true; 65 } 66} 67