InstructionTransformer.java revision 081c7142b29ccd6e1744b26e097b6a4d7c12f2bd
1081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson/* 2081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson * Copyright (C) 2011 The Android Open Source Project 3081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson * 4081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson * Licensed under the Apache License, Version 2.0 (the "License"); 5081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson * you may not use this file except in compliance with the License. 6081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson * You may obtain a copy of the License at 7081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson * 8081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson * http://www.apache.org/licenses/LICENSE-2.0 9081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson * 10081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson * Unless required by applicable law or agreed to in writing, software 11081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson * distributed under the License is distributed on an "AS IS" BASIS, 12081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson * See the License for the specific language governing permissions and 14081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson * limitations under the License. 15081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson */ 16081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 17081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilsonpackage com.android.dx.merge; 18081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 19081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilsonimport com.android.dx.dex.DexException; 20081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilsonimport java.util.BitSet; 21081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 22081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson/** 23081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson * Adjusts a block of instructions to a new index. 24081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson */ 25081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilsonpublic final class InstructionTransformer { 26081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 27081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson private static final Instruction[] INSTRUCTIONS = new Instruction[] { 28081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson // 0x00...0x0f 29081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "nop"), 30081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "move vA, vB"), 31081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "move/from vAA, vBBBB"), 32081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(3, "move/16 vAAAA, vBBBB"), 33081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "move-wide, vA, vB"), 34081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "move-wide/from16 vAA, vBBBB"), 35081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(3, "move-wide/from16 vAAAA, vBBBB"), 36081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "move-object vA, vB"), 37081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "move-object/from16 vAA, vBBBB"), 38081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(3, "move-object/16 vAAAA, vBBBB"), 39081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "move-result vAA"), 40081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "move-result-wide vAA"), 41081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "move-result-object vAA"), 42081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "move-exception vAA"), 43081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "return void"), 44081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "return vAA"), 45081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 46081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson // 0x10...0x1f 47081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "return-wide vAA"), 48081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "return-object vAA"), 49081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "const/4 vA, #+B"), 50081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "const/16 vAA, #+BBBB"), 51081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(3, "const vAA, #+BBBBBBBB"), 52081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "const/high16 vAA, #+BBBB0000"), 53081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "const-wide/16 vAA, #+BBBB"), 54081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(3, "const-wide/32 vAA, #+BBBBBBBB"), 55081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(5, "const-wide vAA, #+BBBBBBBBBBBBBBBB"), 56081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "const-wide/high16 vAA, #+BBBB000000000000"), 57081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new StringInstruction(2, "const-string vAA, string@BBBB"), 58081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new JumboStringInstruction(3, "const-string/jumbo vAA, string@BBBBBBBB"), 59081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new TypeInstruction(2, "const-class vAA, type@BBBB"), 60081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "monitor-enter vAA"), 61081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "monitor-exit vAA"), 62081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new TypeInstruction(2, "check-cast vAA type@BBBB"), 63081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 64081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson // 0x20...0x2f 65081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new TypeInstruction(2, "instance-of vA, vB, type@CCCC"), 66081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "array-length vA, vB"), 67081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new TypeInstruction(2, "new-instance vAA, type@BBBB"), 68081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new TypeInstruction(2, "new-array vA, vB, type@CCCC"), 69081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new TypeInstruction(3, "filled-new-array {vD, vE, vF, vG, vA}, type@CCCC"), 70081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new TypeInstruction(3, "filled-new-array/range {vCCCC..vNNNN}, type@BBBB"), 71081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new FillArrayInstruction(3, "fill-array-data vAA, +BBBBBBBB"), 72081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "throw vAA"), 73081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "goto +AA"), 74081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "goto/16 +AAAA"), 75081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(3, "goto/32 +AAAAAAAA"), 76081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new PackedSwitchInstruction(3, "packed-switch vAA, +BBBBBBBB"), 77081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new SparseSwitchInstruction(3, "sparse-switch vAA, +BBBBBBBB"), 78081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "cmpl-float vAA, vBB, vCC"), 79081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "cmpg-float vAA, vBB, vCC"), 80081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "cmpl-double vAA, vBB, vCC"), 81081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 82081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson // 0x30...0x3f 83081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "cmpg-double vAA, vBB, vCC"), 84081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "cmp-long vAA, vBB, vCC"), 85081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "if-eq vA, vB, +CCCC"), 86081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "if-ne vA, vB, +CCCC"), 87081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "if-lt vA, vB, +CCCC"), 88081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "if-ge vA, vB, +CCCC"), 89081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "if-gt vA, vB, +CCCC"), 90081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "if-le vA, vB, +CCCC"), 91081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "if-eqz vAA, +BBBB"), 92081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "if-nez vAA, +BBBB"), 93081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "if-ltz vAA, +BBBB"), 94081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "if-gez vAA, +BBBB"), 95081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "if-gtz vAA, +BBBB"), 96081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "if-lez vAA, +BBBB"), 97081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new UnusedInstruction(), 98081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new UnusedInstruction(), 99081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 100081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson // 0x40...0x4f 101081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new UnusedInstruction(), 102081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new UnusedInstruction(), 103081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new UnusedInstruction(), 104081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new UnusedInstruction(), 105081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "aget vAA, vBB, vCC"), 106081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "aget-wide vAA, vBB, vCC"), 107081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "aget-object vAA, vBB, vCC"), 108081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "aget-boolean vAA, vBB, vCC"), 109081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "aget-byte vAA, vBB, vCC"), 110081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "aget-char vAA, vBB, vCC"), 111081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "aget-short vAA, vBB, vCC"), 112081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "aput vAA, vBB, vCC"), 113081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "aput-wide vAA, vBB, vCC"), 114081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "aput-object vAA, vBB, vCC"), 115081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "aput-boolean vAA, vBB, vCC"), 116081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "aput-byte vAA, vBB, vCC"), 117081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 118081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson // 0x50...0x5f 119081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "aput-char vAA, vBB, vCC"), 120081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "aput-short vAA, vBB, vCC"), 121081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new FieldInstruction(2, "iget vA, vB, field@CCCC"), 122081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new FieldInstruction(2, "iget-wide vA, vB, field@CCCC"), 123081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new FieldInstruction(2, "iget-object vA, vB, field@CCCC"), 124081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new FieldInstruction(2, "iget-boolean vA, vB, field@CCCC"), 125081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new FieldInstruction(2, "iget-byte vA, vB, field@CCCC"), 126081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new FieldInstruction(2, "iget-char vA, vB, field@CCCC"), 127081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new FieldInstruction(2, "iget-short vA, vB, field@CCCC"), 128081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new FieldInstruction(2, "iput vA, vB, field@CCCC"), 129081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new FieldInstruction(2, "iput-wide vA, vB, field@CCCC"), 130081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new FieldInstruction(2, "iput-object vA, vB, field@CCCC"), 131081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new FieldInstruction(2, "iput-boolean vA, vB, field@CCCC"), 132081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new FieldInstruction(2, "iput-byte vA, vB, field@CCCC"), 133081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new FieldInstruction(2, "iput-char vA, vB, field@CCCC"), 134081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new FieldInstruction(2, "iput-short vA, vB, field@CCCC"), 135081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 136081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson // 0x60...0x6f 137081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new FieldInstruction(2, "sget vAA, field@BBBB"), 138081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new FieldInstruction(2, "sget-wide vAA, field@BBBB"), 139081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new FieldInstruction(2, "sget-object vAA, field@BBBB"), 140081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new FieldInstruction(2, "sget-boolean vAA, field@BBBB"), 141081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new FieldInstruction(2, "sget-byte vAA, field@BBBB"), 142081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new FieldInstruction(2, "sget-char vAA, field@BBBB"), 143081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new FieldInstruction(2, "sget-short vAA, field@BBBB"), 144081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new FieldInstruction(2, "sput vAA, field@BBBB"), 145081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new FieldInstruction(2, "sput-wide vAA, field@BBBB"), 146081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new FieldInstruction(2, "sput-object vAA, field@BBBB"), 147081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new FieldInstruction(2, "sput-boolean vAA, field@BBBB"), 148081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new FieldInstruction(2, "sput-byte vAA, field@BBBB"), 149081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new FieldInstruction(2, "sput-char vAA, field@BBBB"), 150081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new FieldInstruction(2, "sput-short vAA, field@BBBB"), 151081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new MethodInstruction(3, "invoke-virtual {vD, vE, vF, vG, vA}, meth@CCCC"), 152081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new MethodInstruction(3, "invoke-super {vD, vE, vF, vG, vA}, meth@CCCC"), 153081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 154081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson // 0x70...0x7f 155081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new MethodInstruction(3, "invoke-direct {vD, vE, vF, vG, vA}, meth@CCCC"), 156081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new MethodInstruction(3, "invoke-static {vD, vE, vF, vG, vA}, meth@CCCC"), 157081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new MethodInstruction(3, "invoke-interface {vD, vE, vF, vG, vA}, meth@CCCC"), 158081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new UnusedInstruction(), 159081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new MethodInstruction(3, "invoke-virtual/range {vCCCC..vNNNN}, meth@BBBB"), 160081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new MethodInstruction(3, "invoke-super/range {vCCCC..vNNNN}, meth@BBBB"), 161081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new MethodInstruction(3, "invoke-direct/range {vCCCC..vNNNN}, meth@BBBB"), 162081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new MethodInstruction(3, "invoke-static/range {vCCCC..vNNNN}, meth@BBBB"), 163081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new MethodInstruction(3, "invoke-interface/range {vCCCC..vNNNN}, meth@BBBB"), 164081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new UnusedInstruction(), 165081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new UnusedInstruction(), 166081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "neg-int vA, vB"), 167081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "not-int vA, vB"), 168081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "neg-long vA, vB"), 169081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "not-long vA, vB"), 170081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "neg-float vA, vB"), 171081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 172081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson // 0x80...0x8f 173081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "neg-double vA, vB"), 174081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "int-to-long vA, vB"), 175081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "int-to-float vA, vB"), 176081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "int-to-double vA, vB"), 177081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "long-to-int vA, vB"), 178081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "long-to-float vA, vB"), 179081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "long-to-double vA, vB"), 180081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "float-to-int vA, vB"), 181081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "float-to-long vA, vB"), 182081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "float-to-double vA, vB"), 183081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "double-to-int vA, vB"), 184081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "double-to-long vA, vB"), 185081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "double-to-float vA, vB"), 186081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "int-to-byte vA, vB"), 187081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "int-to-char vA, vB"), 188081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "int-to-short vA, vB"), 189081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 190081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson // 0x90...0x9f 191081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "add-int vAA, vBB, vCC"), 192081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "sub-int vAA, vBB, vCC"), 193081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "mul-int vAA, vBB, vCC"), 194081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "div-int vAA, vBB, vCC"), 195081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "rem-int vAA, vBB, vCC"), 196081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "and-int vAA, vBB, vCC"), 197081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "or-int vAA, vBB, vCC"), 198081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "xor-int vAA, vBB, vCC"), 199081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "shl-int vAA, vBB, vCC"), 200081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "shr-int vAA, vBB, vCC"), 201081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "ushr-int vAA, vBB, vCC"), 202081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "add-long vAA, vBB, vCC"), 203081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "sub-long vAA, vBB, vCC"), 204081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "mul-long vAA, vBB, vCC"), 205081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "div-long vAA, vBB, vCC"), 206081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "rem-long vAA, vBB, vCC"), 207081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 208081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson // 0xa0...0xaf 209081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "and-long vAA, vBB, vCC"), 210081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "or-long vAA, vBB, vCC"), 211081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "xor-long vAA, vBB, vCC"), 212081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "shl-long vAA, vBB, vCC"), 213081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "shr-long vAA, vBB, vCC"), 214081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "ushr-long vAA, vBB, vCC"), 215081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "add-float vAA, vBB, vCC"), 216081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "sub-float vAA, vBB, vCC"), 217081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "mul-float vAA, vBB, vCC"), 218081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "div-float vAA, vBB, vCC"), 219081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "rem-float vAA, vBB, vCC"), 220081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "add-double vAA, vBB, vCC"), 221081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "sub-double vAA, vBB, vCC"), 222081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "mul-double vAA, vBB, vCC"), 223081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "div-double vAA, vBB, vCC"), 224081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "rem-double vAA, vBB, vCC"), 225081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 226081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson // 0xb0..0xbf 227081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "add-int/2addr vA, vB"), 228081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "sub-int/2addr vA, vB"), 229081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "mul-int/2addr vA, vB"), 230081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "div-int/2addr vA, vB"), 231081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "rem-int/2addr vA, vB"), 232081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "and-int/2addr vA, vB"), 233081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "or-int/2addr vA, vB"), 234081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "xor-int/2addr vA, vB"), 235081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "shl-int/2addr vA, vB"), 236081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "shr-int/2addr vA, vB"), 237081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "ushr-int/2addr vA, vB"), 238081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "add-long/2addr vA, vB"), 239081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "sub-long/2addr vA, vB"), 240081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "mul-long/2addr vA, vB"), 241081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "div-long/2addr vA, vB"), 242081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "rem-long/2addr vA, vB"), 243081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 244081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson // 0xc0...0xcf 245081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "and-long/2addr vA, vB"), 246081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "or-long/2addr vA, vB"), 247081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "xor-long/2addr vA, vB"), 248081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "shl-long/2addr vA, vB"), 249081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "shr-long/2addr vA, vB"), 250081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "ushr-long/2addr vA, vB"), 251081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "add-float/2addr vA, vB"), 252081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "sub-float/2addr vA, vB"), 253081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "mul-float/2addr vA, vB"), 254081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "div-float/2addr vA, vB"), 255081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "rem-float/2addr vA, vB"), 256081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "add-double/2addr vA, vB"), 257081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "sub-double/2addr vA, vB"), 258081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "mul-double/2addr vA, vB"), 259081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "div-double/2addr vA, vB"), 260081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(1, "rem-double/2addr vA, vB"), 261081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 262081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson // 0xd0...0xdf 263081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "add-int/lit16 vA, vB, #+CCCC"), 264081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "rsub-int (reverse subtract) vA, vB, #+CCCC"), 265081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "mul-int/lit16 vA, vB, #+CCCC"), 266081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "div-int/lit16 vA, vB, #+CCCC"), 267081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "rem-int/lit16 vA, vB, #+CCCC"), 268081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "and-int/lit16 vA, vB, #+CCCC"), 269081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "or-int/lit16 vA, vB, #+CCCC"), 270081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "xor-int/lit16 vA, vB, #+CCCC"), 271081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "add-int/lit8 vAA, vBB, #+CC"), 272081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "rsub-int/lit8 vAA, vBB, #+CC"), 273081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "mul-int/lit8 vAA, vBB, #+CC"), 274081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "div-int/lit8 vAA, vBB, #+CC"), 275081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "rem-int/lit8 vAA, vBB, #+CC"), 276081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "and-int/lit8 vAA, vBB, #+CC"), 277081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "or-int/lit8 vAA, vBB, #+CC"), 278081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "xor-int/lit8 vAA, vBB, #+CC"), 279081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 280081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson // 0xe0...0xef 281081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "shl-int/lit8 vAA, vBB, #+CC"), 282081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "shr-int/lit8 vAA, vBB, #+CC"), 283081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson new Instruction(2, "ushr-int/lit8 vAA, vBB, #+CC"), 284081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson }; 285081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 286081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson private final IndexMap indexMap; 287081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 288081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson public InstructionTransformer(IndexMap indexMap) { 289081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson this.indexMap = indexMap; 290081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 291081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 292081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson public short[] transform(short[] instructions) throws DexException { 293081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson instructions = instructions.clone(); 294081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson BitSet skippedInstructions = new BitSet(); 295081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 296081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson for (int i = 0; i < instructions.length; ) { 297081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson if (skippedInstructions.get(i)) { 298081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson i++; 299081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson continue; 300081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 301081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 302081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson int index = instructions[i] & 0xFF; 303081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson if (index < 0 || index >= INSTRUCTIONS.length) { 304081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson throw new DexException("Unhandled instruction at " + i 305081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson + ": " + Integer.toHexString(index)); 306081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 307081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 308081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson Instruction instruction = INSTRUCTIONS[index]; 309081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson instruction.transform(instructions, i, indexMap, skippedInstructions); 310081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson i += instruction.codeUnits; 311081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 312081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 313081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson return instructions; 314081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 315081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 316081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson private static class Instruction { 317081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson private final String name; 318081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson private final int codeUnits; 319081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson Instruction(int codeUnits, String name) { 320081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson this.name = name; 321081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson this.codeUnits = codeUnits; 322081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 323081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 324081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson public void transform(short[] instructions, int i, IndexMap indexMap, 325081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson BitSet skippedInstructions) throws DexException {} 326081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 327081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson @Override public String toString() { 328081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson return name; 329081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 330081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 331081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 332081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson private static class UnusedInstruction extends Instruction { 333081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson UnusedInstruction() { 334081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson super(1, "unused"); 335081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 336081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 337081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 338081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson private static class StringInstruction extends Instruction { 339081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson StringInstruction(int codeUnits, String name) { 340081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson super(codeUnits, name); 341081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 342081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson @Override public void transform(short[] instructions, int i, IndexMap indexMap, 343081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson BitSet skippedInstructions) throws DexException { 344081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson int stringIndex = instructions[i + 1] & 0xFFFF; 345081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson int mappedIndex = indexMap.stringIds[stringIndex]; 346081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson if (mappedIndex > 0xFFFF) { 347081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson throw new DexException("Cannot convert string to jumbo string!"); 348081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 349081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson instructions[i + 1] = (short) mappedIndex; 350081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 351081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 352081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 353081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson private static class JumboStringInstruction extends Instruction { 354081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson JumboStringInstruction(int codeUnits, String name) { 355081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson super(codeUnits, name); 356081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 357081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson @Override public void transform(short[] instructions, int i, IndexMap indexMap, 358081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson BitSet skippedInstructions) throws DexException { 359081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson throw new UnsupportedOperationException("Jumbo strings not implemented. " 360081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson + "Due to a lack of dex files requiring jumbo strings, this class doesn't " 361081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson + "bother to support jumbo strings!"); 362081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 363081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 364081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 365081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson private static class FieldInstruction extends Instruction { 366081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson FieldInstruction(int codeUnits, String name) { 367081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson super(codeUnits, name); 368081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 369081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson @Override public void transform(short[] instructions, int i, IndexMap indexMap, 370081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson BitSet skippedInstructions) throws DexException { 371081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson short field = instructions[i + 1]; 372081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson instructions[i + 1] = (short) indexMap.fieldIds[field]; 373081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 374081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 375081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 376081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson private static class TypeInstruction extends Instruction { 377081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson TypeInstruction(int codeUnits, String name) { 378081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson super(codeUnits, name); 379081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 380081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson @Override public void transform(short[] instructions, int i, IndexMap indexMap, 381081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson BitSet skippedInstructions) throws DexException { 382081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson short type = instructions[i + 1]; 383081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson instructions[i + 1] = (short) indexMap.typeIds[type]; 384081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 385081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 386081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 387081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson private static class MethodInstruction extends Instruction { 388081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson MethodInstruction(int codeUnits, String name) { 389081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson super(codeUnits, name); 390081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 391081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson @Override public void transform(short[] instructions, int i, IndexMap indexMap, 392081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson BitSet skippedInstructions) throws DexException { 393081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson short method = instructions[i + 1]; 394081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson instructions[i + 1] = (short) indexMap.methodIds[method]; 395081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 396081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 397081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 398081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson private static class PackedSwitchInstruction extends Instruction { 399081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson public PackedSwitchInstruction(int codeUnits, String name) { 400081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson super(codeUnits, name); 401081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 402081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson @Override public void transform(short[] instructions, int i, IndexMap indexMap, 403081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson BitSet skippedInstructions) throws DexException { 404081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson int offset = (instructions[i + 1] & 0xFFFF) 405081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson + ((instructions[i + 2] & 0xFFFF) << 16); 406081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson if (instructions[i + offset] != 0x100) { 407081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson throw new DexException("Expected packed-switch pseudo-opcode but was 0x" 408081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson + Integer.toHexString(instructions[i + offset])); 409081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 410081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson short size = instructions[i + offset + 1]; 411081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson skippedInstructions.set(i + offset, i + offset + 4 + (size * 2)); 412081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 413081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 414081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 415081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson private static class SparseSwitchInstruction extends Instruction { 416081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson public SparseSwitchInstruction(int codeUnits, String name) { 417081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson super(codeUnits, name); 418081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 419081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson @Override public void transform(short[] instructions, int i, IndexMap indexMap, 420081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson BitSet skippedInstructions) throws DexException { 421081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson int offset = (instructions[i + 1] & 0xFFFF) 422081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson + ((instructions[i + 2] & 0xFFFF) << 16); 423081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson if (instructions[i + offset] != 0x200) { 424081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson throw new DexException("Expected sparse-switch pseudo-opcode but was 0x" 425081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson + Integer.toHexString(instructions[i + offset])); 426081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 427081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson short size = instructions[i + offset + 1]; 428081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson skippedInstructions.set(i + offset, i + offset + 2 + (size * 4)); 429081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 430081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 431081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson 432081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson private static class FillArrayInstruction extends Instruction { 433081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson public FillArrayInstruction(int codeUnits, String name) { 434081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson super(codeUnits, name); 435081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 436081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson @Override public void transform(short[] instructions, int i, IndexMap indexMap, 437081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson BitSet skippedInstructions) throws DexException { 438081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson int offset = (instructions[i + 1] & 0xFFFF) 439081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson + ((instructions[i + 2] & 0xFFFF) << 16); 440081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson if (instructions[i + offset] != 0x300) { 441081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson throw new DexException("Expected fill-array-data pseudo-opcode but was 0x" 442081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson + Integer.toHexString(instructions[i + offset])); 443081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 444081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson int bytesPerElement = instructions[i + offset + 1]; 445081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson int size = (instructions[i + offset + 2] & 0xFFFF) 446081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson + ((instructions[i + offset + 3] & 0xFFFF) << 4); 447081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson int totalBytes = size * bytesPerElement; 448081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson int totalShorts = (totalBytes + 1) / 2; // round up! 449081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson skippedInstructions.set(i + offset, i + offset + 4 + totalShorts); 450081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 451081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson } 452081c7142b29ccd6e1744b26e097b6a4d7c12f2bdJesse Wilson} 453