1/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package dexfuzz.rawdex;
18
19import dexfuzz.Log;
20import dexfuzz.rawdex.formats.AbstractFormat;
21import dexfuzz.rawdex.formats.ContainsConst;
22import dexfuzz.rawdex.formats.ContainsPoolIndex;
23import dexfuzz.rawdex.formats.ContainsTarget;
24import dexfuzz.rawdex.formats.ContainsVRegs;
25import dexfuzz.rawdex.formats.Format10t;
26import dexfuzz.rawdex.formats.Format10x;
27import dexfuzz.rawdex.formats.Format11n;
28import dexfuzz.rawdex.formats.Format11x;
29import dexfuzz.rawdex.formats.Format12x;
30import dexfuzz.rawdex.formats.Format20t;
31import dexfuzz.rawdex.formats.Format21c;
32import dexfuzz.rawdex.formats.Format21h;
33import dexfuzz.rawdex.formats.Format21s;
34import dexfuzz.rawdex.formats.Format21t;
35import dexfuzz.rawdex.formats.Format22b;
36import dexfuzz.rawdex.formats.Format22c;
37import dexfuzz.rawdex.formats.Format22s;
38import dexfuzz.rawdex.formats.Format22t;
39import dexfuzz.rawdex.formats.Format22x;
40import dexfuzz.rawdex.formats.Format23x;
41import dexfuzz.rawdex.formats.Format30t;
42import dexfuzz.rawdex.formats.Format31c;
43import dexfuzz.rawdex.formats.Format31i;
44import dexfuzz.rawdex.formats.Format31t;
45import dexfuzz.rawdex.formats.Format32x;
46import dexfuzz.rawdex.formats.Format35c;
47import dexfuzz.rawdex.formats.Format3rc;
48import dexfuzz.rawdex.formats.Format51l;
49
50import java.io.IOException;
51import java.util.HashMap;
52import java.util.Map;
53
54public class Instruction implements RawDexObject {
55  // Only used by Format35* instructions
56  public static class InvokeFormatInfo {
57    public byte vregD;
58    public byte vregE;
59    public byte vregF;
60    public byte vregG;
61  }
62
63  // Immutable information about this class of instruction.
64  public OpcodeInfo info;
65
66  // The raw bytes of the instruction.
67  // Only used during reading, and writing out is done from the decoded instruction data.
68  //  Except in the case of the 3 "data" instructions.
69  public byte[] rawBytes;
70
71  public static final int RAW_TYPE_PACKED_SWITCH_DATA = 1;
72  public static final int RAW_TYPE_SPARSE_SWITCH_DATA = 2;
73  public static final int RAW_TYPE_FILL_ARRAY_DATA_DATA = 3;
74
75  public int rawType;
76  public boolean justRaw;
77  public int rawSize;
78
79  public long vregA = 0;
80  public long vregB = 0;
81  public long vregC = 0;
82
83  public InvokeFormatInfo invokeFormatInfo;
84
85  /**
86   * Clone an instruction.
87   */
88  public Instruction clone() {
89    Instruction newInsn = new Instruction();
90    // If we've generated a new instruction, we won't have calculated its raw array.
91    if (newInsn.rawBytes != null) {
92      newInsn.rawBytes = new byte[rawBytes.length];
93      for (int i = 0; i < rawBytes.length; i++) {
94        newInsn.rawBytes[i] = rawBytes[i];
95      }
96    }
97    newInsn.justRaw = justRaw;
98    newInsn.rawType = rawType;
99    newInsn.rawSize = rawSize;
100
101    newInsn.vregA = vregA;
102    newInsn.vregB = vregB;
103    newInsn.vregC = vregC;
104    newInsn.info = info;
105    if (invokeFormatInfo != null) {
106      newInsn.invokeFormatInfo = new InvokeFormatInfo();
107      newInsn.invokeFormatInfo.vregD = invokeFormatInfo.vregD;
108      newInsn.invokeFormatInfo.vregE = invokeFormatInfo.vregE;
109      newInsn.invokeFormatInfo.vregF = invokeFormatInfo.vregF;
110      newInsn.invokeFormatInfo.vregG = invokeFormatInfo.vregG;
111    }
112    return newInsn;
113  }
114
115  @Override
116  public void read(DexRandomAccessFile file) throws IOException {
117    // Remember the offset, so after reading the opcode, we can read the whole
118    // insn into raw_bytes.
119    long offset = file.getFilePointer();
120    int opcodeValue = readOpcode(file);
121    info = getOpcodeInfo(opcodeValue);
122    if (info == null) {
123      Log.errorAndQuit("Couldn't find OpcodeInfo for opcode with value: "
124          + opcodeValue);
125    }
126
127    rawBytes = new byte[2 * getSize()];
128    file.seek(offset);
129    file.read(rawBytes);
130
131    vregA = info.format.getA(rawBytes);
132    vregB = info.format.getB(rawBytes);
133    vregC = info.format.getC(rawBytes);
134
135    // Special case for 35* formats.
136    if (info.format.needsInvokeFormatInfo()) {
137      invokeFormatInfo = new InvokeFormatInfo();
138      invokeFormatInfo.vregD = (byte) (rawBytes[4] >> 4);
139      invokeFormatInfo.vregE = (byte) (rawBytes[5] & 0xf);
140      invokeFormatInfo.vregF = (byte) (rawBytes[5] >> 4);
141      invokeFormatInfo.vregG = (byte) (rawBytes[1] & 0xf);
142    }
143  }
144
145  @Override
146  public void write(DexRandomAccessFile file) throws IOException {
147    if (justRaw) {
148      // It is the responsibility of the CodeTranslator to make
149      // sure the raw bytes have been updated.
150      file.write(rawBytes);
151    } else {
152      info.format.writeToFile(file, this);
153    }
154  }
155
156  /**
157   * Get the size of an instruction, in code-words. (Code-words are 16-bits.)
158   */
159  public int getSize() {
160    if (justRaw) {
161      // It is the responsibility of the CodeTranslator to make sure
162      // the raw size has been updated.
163      return rawSize;
164    }
165    return info.format.getSize();
166  }
167
168  private int readOpcode(DexRandomAccessFile file) throws IOException {
169    short firstCodeWord = file.readUShort();
170    int opcode = (firstCodeWord & 0xff);
171    int upperBits = (firstCodeWord & 0xff00) >> 8;
172    if (opcode == 0x0 && upperBits != 0x0) {
173      justRaw = true;
174      rawType = upperBits;
175      // Need to calculate special sizes.
176      switch (rawType) {
177        case RAW_TYPE_PACKED_SWITCH_DATA:
178          rawSize = (file.readUShort() * 2) + 4;
179          break;
180        case RAW_TYPE_SPARSE_SWITCH_DATA:
181          rawSize = (file.readUShort() * 4) + 2;
182          break;
183        case RAW_TYPE_FILL_ARRAY_DATA_DATA:
184        {
185          int elementWidth = file.readUShort();
186          rawSize = ((file.readUInt() * elementWidth + 1) / 2) + 4;
187          break;
188        }
189        default:
190          Log.errorAndQuit("Unrecognised ident in data-payload instruction: " + rawType);
191      }
192    }
193    return opcode;
194  }
195
196  @Override
197  public String toString() {
198    if (justRaw) {
199      switch (rawType) {
200        case RAW_TYPE_PACKED_SWITCH_DATA:
201          return "PACKED SWITCH DATA";
202        case RAW_TYPE_SPARSE_SWITCH_DATA:
203          return "SPARSE SWITCH DATA";
204        case RAW_TYPE_FILL_ARRAY_DATA_DATA:
205          return "FILL ARRAY DATA DATA";
206        default:
207      }
208
209    }
210
211    String repr = info.name;
212
213    AbstractFormat format = info.format;
214
215    if (invokeFormatInfo != null) {
216      String vregs = "";
217
218      int numVregs = (int) vregA;
219
220      if (numVregs > 5) {
221        Log.debug("vA in an 35c invoke was greater than 5? Assuming 5.");
222        numVregs = 5;
223      } else if (numVregs < 0) {
224        Log.debug("vA in an 35c invoke was less than 0? Assuming 0.");
225        numVregs = 0;
226      }
227
228      switch (numVregs) {
229        case 5:
230          vregs = ", v" + invokeFormatInfo.vregG;
231          // fallthrough
232        case 4:
233          vregs = ", v" + invokeFormatInfo.vregF + vregs;
234          // fallthrough
235        case 3:
236          vregs = ", v" + invokeFormatInfo.vregE + vregs;
237          // fallthrough
238        case 2:
239          vregs = ", v" + invokeFormatInfo.vregD + vregs;
240          // fallthrough
241        case 1:
242          vregs = "v" + vregC + vregs;
243          break;
244        default:
245      }
246
247      repr += "(" + vregs + ")";
248
249      long poolIndex = ((ContainsPoolIndex)format).getPoolIndex(this);
250      repr += " meth@" + poolIndex;
251
252      return repr;
253    }
254
255
256
257    if (format instanceof ContainsVRegs) {
258      String vregs = "";
259      switch (((ContainsVRegs)format).getVRegCount()) {
260        case 3:
261          vregs = ", v" + vregC;
262          // fallthrough
263        case 2:
264          vregs = ", v" + vregB + vregs;
265          // fallthrough
266        case 1:
267          vregs = "v" + vregA + vregs;
268          break;
269        default:
270          Log.errorAndQuit("Invalid number of vregs reported by a Format.");
271      }
272
273      repr += " " + vregs;
274    }
275    if (format instanceof ContainsConst) {
276      long constant = ((ContainsConst)format).getConst(this);
277      repr += " #" + constant;
278    }
279    if (format instanceof ContainsPoolIndex) {
280      long poolIndex = ((ContainsPoolIndex)format).getPoolIndex(this);
281      repr += " pool@" + poolIndex;
282    }
283    if (format instanceof ContainsTarget) {
284      long target = ((ContainsTarget)format).getTarget(this);
285      repr += " +" + target;
286    }
287
288    return repr;
289  }
290
291  @Override
292  public void incrementIndex(IndexUpdateKind kind, int insertedIdx) {
293    // Do nothing.
294  }
295
296  // STATIC INSTRUCTION CODE
297  private static Map<Integer,OpcodeInfo> opcode_map_by_int = new HashMap<Integer,OpcodeInfo>();
298  private static Map<Opcode,OpcodeInfo> opcode_map_by_enum = new HashMap<Opcode,OpcodeInfo>();
299
300  public static OpcodeInfo getOpcodeInfo(Opcode opcode) {
301    return opcode_map_by_enum.get(opcode);
302  }
303
304  public static OpcodeInfo getOpcodeInfo(int opcodeValue) {
305    return opcode_map_by_int.get(opcodeValue);
306  }
307
308  private static void addOpcodeInfo(Opcode opcode, String name,
309      int opcodeValue, AbstractFormat fmt) {
310    OpcodeInfo info = new OpcodeInfo(opcode, name, opcodeValue, fmt);
311    if (opcode.ordinal() != opcodeValue) {
312      Log.errorAndQuit(String.format("Opcode: %s (enum ordinal 0x%x) != (value 0x%x)",
313          opcode.toString(), opcode.ordinal(), opcodeValue));
314    }
315    opcode_map_by_int.put(opcodeValue, info);
316    opcode_map_by_enum.put(opcode, info);
317  }
318
319  static {
320    addOpcodeInfo(Opcode.NOP, "nop", 0x00, new Format10x());
321    addOpcodeInfo(Opcode.MOVE, "move", 0x01, new Format12x());
322    addOpcodeInfo(Opcode.MOVE_FROM16, "move/from16", 0x02, new Format22x());
323    addOpcodeInfo(Opcode.MOVE_16, "move/16", 0x03, new Format32x());
324    addOpcodeInfo(Opcode.MOVE_WIDE, "move-wide", 0x04, new Format12x());
325    addOpcodeInfo(Opcode.MOVE_WIDE_FROM16, "move-wide/from16", 0x05, new Format22x());
326    addOpcodeInfo(Opcode.MOVE_WIDE_16, "move-wide/16", 0x06, new Format32x());
327    addOpcodeInfo(Opcode.MOVE_OBJECT, "move-object", 0x07, new Format12x());
328    addOpcodeInfo(Opcode.MOVE_OBJECT_FROM16, "move-object/from16", 0x08, new Format22x());
329    addOpcodeInfo(Opcode.MOVE_OBJECT_16, "move-object/16", 0x09, new Format32x());
330    addOpcodeInfo(Opcode.MOVE_RESULT, "move-result", 0x0a, new Format11x());
331    addOpcodeInfo(Opcode.MOVE_RESULT_WIDE, "move-result-wide", 0x0b, new Format11x());
332    addOpcodeInfo(Opcode.MOVE_RESULT_OBJECT, "move-result-object", 0x0c, new Format11x());
333    addOpcodeInfo(Opcode.MOVE_EXCEPTION, "move-exception", 0x0d, new Format11x());
334    addOpcodeInfo(Opcode.RETURN_VOID, "return-void", 0x0e, new Format10x());
335    addOpcodeInfo(Opcode.RETURN, "return", 0x0f, new Format11x());
336    addOpcodeInfo(Opcode.RETURN_WIDE, "return-wide", 0x10, new Format11x());
337    addOpcodeInfo(Opcode.RETURN_OBJECT, "return-object", 0x11, new Format11x());
338    addOpcodeInfo(Opcode.CONST_4, "const/4", 0x12, new Format11n());
339    addOpcodeInfo(Opcode.CONST_16, "const/16", 0x13, new Format21s());
340    addOpcodeInfo(Opcode.CONST, "const", 0x14, new Format31i());
341    addOpcodeInfo(Opcode.CONST_HIGH16, "const/high16", 0x15, new Format21h());
342    addOpcodeInfo(Opcode.CONST_WIDE_16, "const-wide/16", 0x16, new Format21s());
343    addOpcodeInfo(Opcode.CONST_WIDE_32, "const-wide/32", 0x17, new Format31i());
344    addOpcodeInfo(Opcode.CONST_WIDE, "const-wide", 0x18, new Format51l());
345    addOpcodeInfo(Opcode.CONST_WIDE_HIGH16, "const-wide/high16", 0x19, new Format21h());
346    addOpcodeInfo(Opcode.CONST_STRING, "const-string", 0x1a, new Format21c());
347    addOpcodeInfo(Opcode.CONST_STRING_JUMBO, "const-string/jumbo", 0x1b, new Format31c());
348    addOpcodeInfo(Opcode.CONST_CLASS, "const-class", 0x1c, new Format21c());
349    addOpcodeInfo(Opcode.MONITOR_ENTER, "monitor-enter", 0x1d, new Format11x());
350    addOpcodeInfo(Opcode.MONITOR_EXIT, "monitor-exit", 0x1e, new Format11x());
351    addOpcodeInfo(Opcode.CHECK_CAST, "check-cast", 0x1f, new Format21c());
352    addOpcodeInfo(Opcode.INSTANCE_OF, "instance-of", 0x20, new Format22c());
353    addOpcodeInfo(Opcode.ARRAY_LENGTH, "array-length", 0x21, new Format12x());
354    addOpcodeInfo(Opcode.NEW_INSTANCE, "new-instance", 0x22, new Format21c());
355    addOpcodeInfo(Opcode.NEW_ARRAY, "new-array", 0x23, new Format22c());
356    addOpcodeInfo(Opcode.FILLED_NEW_ARRAY, "filled-new-array", 0x24, new Format35c());
357    addOpcodeInfo(Opcode.FILLED_NEW_ARRAY_RANGE, "filled-new-array/range",
358        0x25, new Format3rc());
359    addOpcodeInfo(Opcode.FILL_ARRAY_DATA, "fill-array-data", 0x26, new Format31t());
360    addOpcodeInfo(Opcode.THROW, "throw", 0x27, new Format11x());
361    addOpcodeInfo(Opcode.GOTO, "goto", 0x28, new Format10t());
362    addOpcodeInfo(Opcode.GOTO_16, "goto/16", 0x29, new Format20t());
363    addOpcodeInfo(Opcode.GOTO_32, "goto/32", 0x2a, new Format30t());
364    addOpcodeInfo(Opcode.PACKED_SWITCH, "packed-switch", 0x2b, new Format31t());
365    addOpcodeInfo(Opcode.SPARSE_SWITCH, "sparse-switch", 0x2c, new Format31t());
366    addOpcodeInfo(Opcode.CMPL_FLOAT, "cmpl-float", 0x2d, new Format23x());
367    addOpcodeInfo(Opcode.CMPG_FLOAT, "cmpg-float", 0x2e, new Format23x());
368    addOpcodeInfo(Opcode.CMPL_DOUBLE, "cmpl-double", 0x2f, new Format23x());
369    addOpcodeInfo(Opcode.CMPG_DOUBLE, "cmpg-double", 0x30, new Format23x());
370    addOpcodeInfo(Opcode.CMP_LONG, "cmp-long", 0x31, new Format23x());
371    addOpcodeInfo(Opcode.IF_EQ, "if-eq", 0x32, new Format22t());
372    addOpcodeInfo(Opcode.IF_NE, "if-ne", 0x33, new Format22t());
373    addOpcodeInfo(Opcode.IF_LT, "if-lt", 0x34, new Format22t());
374    addOpcodeInfo(Opcode.IF_GE, "if-ge", 0x35, new Format22t());
375    addOpcodeInfo(Opcode.IF_GT, "if-gt", 0x36, new Format22t());
376    addOpcodeInfo(Opcode.IF_LE, "if-le", 0x37, new Format22t());
377    addOpcodeInfo(Opcode.IF_EQZ, "if-eqz", 0x38, new Format21t());
378    addOpcodeInfo(Opcode.IF_NEZ, "if-nez", 0x39, new Format21t());
379    addOpcodeInfo(Opcode.IF_LTZ, "if-ltz", 0x3a, new Format21t());
380    addOpcodeInfo(Opcode.IF_GEZ, "if-gez", 0x3b, new Format21t());
381    addOpcodeInfo(Opcode.IF_GTZ, "if-gtz", 0x3c, new Format21t());
382    addOpcodeInfo(Opcode.IF_LEZ, "if-lez", 0x3d, new Format21t());
383    addOpcodeInfo(Opcode.UNUSED_3E, "unused-3e", 0x3e, new Format10x());
384    addOpcodeInfo(Opcode.UNUSED_3F, "unused-3f", 0x3f, new Format10x());
385    addOpcodeInfo(Opcode.UNUSED_40, "unused-40", 0x40, new Format10x());
386    addOpcodeInfo(Opcode.UNUSED_41, "unused-41", 0x41, new Format10x());
387    addOpcodeInfo(Opcode.UNUSED_42, "unused-42", 0x42, new Format10x());
388    addOpcodeInfo(Opcode.UNUSED_43, "unused-43", 0x43, new Format10x());
389    addOpcodeInfo(Opcode.AGET, "aget", 0x44, new Format23x());
390    addOpcodeInfo(Opcode.AGET_WIDE, "aget-wide", 0x45, new Format23x());
391    addOpcodeInfo(Opcode.AGET_WIDE, "aget-wide", 0x45, new Format23x());
392    addOpcodeInfo(Opcode.AGET_OBJECT, "aget-object", 0x46, new Format23x());
393    addOpcodeInfo(Opcode.AGET_BOOLEAN, "aget-boolean", 0x47, new Format23x());
394    addOpcodeInfo(Opcode.AGET_BYTE, "aget-byte", 0x48, new Format23x());
395    addOpcodeInfo(Opcode.AGET_CHAR, "aget-char", 0x49, new Format23x());
396    addOpcodeInfo(Opcode.AGET_SHORT, "aget-short", 0x4a, new Format23x());
397    addOpcodeInfo(Opcode.APUT, "aput", 0x4b, new Format23x());
398    addOpcodeInfo(Opcode.APUT_WIDE, "aput-wide", 0x4c, new Format23x());
399    addOpcodeInfo(Opcode.APUT_OBJECT, "aput-object", 0x4d, new Format23x());
400    addOpcodeInfo(Opcode.APUT_BOOLEAN, "aput-boolean", 0x4e, new Format23x());
401    addOpcodeInfo(Opcode.APUT_BYTE, "aput-byte", 0x4f, new Format23x());
402    addOpcodeInfo(Opcode.APUT_CHAR, "aput-char", 0x50, new Format23x());
403    addOpcodeInfo(Opcode.APUT_SHORT, "aput-short", 0x51, new Format23x());
404    addOpcodeInfo(Opcode.IGET, "iget", 0x52, new Format22c());
405    addOpcodeInfo(Opcode.IGET_WIDE, "iget-wide", 0x53, new Format22c());
406    addOpcodeInfo(Opcode.IGET_OBJECT, "iget-object", 0x54, new Format22c());
407    addOpcodeInfo(Opcode.IGET_BOOLEAN, "iget-boolean", 0x55, new Format22c());
408    addOpcodeInfo(Opcode.IGET_BYTE, "iget-byte", 0x56, new Format22c());
409    addOpcodeInfo(Opcode.IGET_CHAR, "iget-char", 0x57, new Format22c());
410    addOpcodeInfo(Opcode.IGET_SHORT, "iget-short", 0x58, new Format22c());
411    addOpcodeInfo(Opcode.IPUT, "iput", 0x59, new Format22c());
412    addOpcodeInfo(Opcode.IPUT_WIDE, "iput-wide", 0x5a, new Format22c());
413    addOpcodeInfo(Opcode.IPUT_OBJECT, "iput-object", 0x5b, new Format22c());
414    addOpcodeInfo(Opcode.IPUT_BOOLEAN, "iput-boolean", 0x5c, new Format22c());
415    addOpcodeInfo(Opcode.IPUT_BYTE, "iput-byte", 0x5d, new Format22c());
416    addOpcodeInfo(Opcode.IPUT_CHAR, "iput-char", 0x5e, new Format22c());
417    addOpcodeInfo(Opcode.IPUT_SHORT, "iput-short", 0x5f, new Format22c());
418    addOpcodeInfo(Opcode.SGET, "sget", 0x60, new Format21c());
419    addOpcodeInfo(Opcode.SGET_WIDE, "sget-wide", 0x61, new Format21c());
420    addOpcodeInfo(Opcode.SGET_OBJECT, "sget-object", 0x62, new Format21c());
421    addOpcodeInfo(Opcode.SGET_BOOLEAN, "sget-boolean", 0x63, new Format21c());
422    addOpcodeInfo(Opcode.SGET_BYTE, "sget-byte", 0x64, new Format21c());
423    addOpcodeInfo(Opcode.SGET_CHAR, "sget-char", 0x65, new Format21c());
424    addOpcodeInfo(Opcode.SGET_SHORT, "sget-short", 0x66, new Format21c());
425    addOpcodeInfo(Opcode.SPUT, "sput", 0x67, new Format21c());
426    addOpcodeInfo(Opcode.SPUT_WIDE, "sput-wide", 0x68, new Format21c());
427    addOpcodeInfo(Opcode.SPUT_OBJECT, "sput-object", 0x69, new Format21c());
428    addOpcodeInfo(Opcode.SPUT_BOOLEAN, "sput-boolean", 0x6a, new Format21c());
429    addOpcodeInfo(Opcode.SPUT_BYTE, "sput-byte", 0x6b, new Format21c());
430    addOpcodeInfo(Opcode.SPUT_CHAR, "sput-char", 0x6c, new Format21c());
431    addOpcodeInfo(Opcode.SPUT_SHORT, "sput-short", 0x6d, new Format21c());
432    addOpcodeInfo(Opcode.INVOKE_VIRTUAL, "invoke-virtual", 0x6e, new Format35c());
433    addOpcodeInfo(Opcode.INVOKE_SUPER, "invoke-super", 0x6f, new Format35c());
434    addOpcodeInfo(Opcode.INVOKE_DIRECT, "invoke-direct", 0x70, new Format35c());
435    addOpcodeInfo(Opcode.INVOKE_STATIC, "invoke-static", 0x71, new Format35c());
436    addOpcodeInfo(Opcode.INVOKE_INTERFACE, "invoke-interface", 0x72, new Format35c());
437    addOpcodeInfo(Opcode.RETURN_VOID_NO_BARRIER, "return-void-no-barrier", 0x73, new Format10x());
438    addOpcodeInfo(Opcode.INVOKE_VIRTUAL_RANGE, "invoke-virtual/range", 0x74, new Format3rc());
439    addOpcodeInfo(Opcode.INVOKE_SUPER_RANGE, "invoke-super/range", 0x75, new Format3rc());
440    addOpcodeInfo(Opcode.INVOKE_DIRECT_RANGE, "invoke-direct/range", 0x76, new Format3rc());
441    addOpcodeInfo(Opcode.INVOKE_STATIC_RANGE, "invoke-static/range", 0x77, new Format3rc());
442    addOpcodeInfo(Opcode.INVOKE_INTERFACE_RANGE, "invoke-interface/range",
443        0x78, new Format3rc());
444    addOpcodeInfo(Opcode.UNUSED_79, "unused-79", 0x79, new Format10x());
445    addOpcodeInfo(Opcode.UNUSED_7A, "unused-7a", 0x7a, new Format10x());
446    addOpcodeInfo(Opcode.NEG_INT, "neg-int", 0x7b, new Format12x());
447    addOpcodeInfo(Opcode.NOT_INT, "not-int", 0x7c, new Format12x());
448    addOpcodeInfo(Opcode.NEG_LONG, "neg-long", 0x7d, new Format12x());
449    addOpcodeInfo(Opcode.NOT_LONG, "not-long", 0x7e, new Format12x());
450    addOpcodeInfo(Opcode.NEG_FLOAT, "neg-float", 0x7f, new Format12x());
451    addOpcodeInfo(Opcode.NEG_DOUBLE, "neg-double", 0x80, new Format12x());
452    addOpcodeInfo(Opcode.INT_TO_LONG, "int-to-long", 0x81, new Format12x());
453    addOpcodeInfo(Opcode.INT_TO_FLOAT, "int-to-float", 0x82, new Format12x());
454    addOpcodeInfo(Opcode.INT_TO_DOUBLE, "int-to-double", 0x83, new Format12x());
455    addOpcodeInfo(Opcode.LONG_TO_INT, "long-to-int", 0x84, new Format12x());
456    addOpcodeInfo(Opcode.LONG_TO_FLOAT, "long-to-float", 0x85, new Format12x());
457    addOpcodeInfo(Opcode.LONG_TO_DOUBLE, "long-to-double", 0x86, new Format12x());
458    addOpcodeInfo(Opcode.FLOAT_TO_INT, "float-to-int", 0x87, new Format12x());
459    addOpcodeInfo(Opcode.FLOAT_TO_LONG, "float-to-long", 0x88, new Format12x());
460    addOpcodeInfo(Opcode.FLOAT_TO_DOUBLE, "float-to-double", 0x89, new Format12x());
461    addOpcodeInfo(Opcode.DOUBLE_TO_INT, "double-to-int", 0x8a, new Format12x());
462    addOpcodeInfo(Opcode.DOUBLE_TO_LONG, "double-to-long", 0x8b, new Format12x());
463    addOpcodeInfo(Opcode.DOUBLE_TO_FLOAT, "double-to-float", 0x8c, new Format12x());
464    addOpcodeInfo(Opcode.INT_TO_BYTE, "int-to-byte", 0x8d, new Format12x());
465    addOpcodeInfo(Opcode.INT_TO_CHAR, "int-to-char", 0x8e, new Format12x());
466    addOpcodeInfo(Opcode.INT_TO_SHORT, "int-to-short", 0x8f, new Format12x());
467    addOpcodeInfo(Opcode.ADD_INT, "add-int", 0x90, new Format23x());
468    addOpcodeInfo(Opcode.SUB_INT, "sub-int", 0x91, new Format23x());
469    addOpcodeInfo(Opcode.MUL_INT, "mul-int", 0x92, new Format23x());
470    addOpcodeInfo(Opcode.DIV_INT, "div-int", 0x93, new Format23x());
471    addOpcodeInfo(Opcode.REM_INT, "rem-int", 0x94, new Format23x());
472    addOpcodeInfo(Opcode.AND_INT, "and-int", 0x95, new Format23x());
473    addOpcodeInfo(Opcode.OR_INT, "or-int", 0x96, new Format23x());
474    addOpcodeInfo(Opcode.XOR_INT, "xor-int", 0x97, new Format23x());
475    addOpcodeInfo(Opcode.SHL_INT, "shl-int", 0x98, new Format23x());
476    addOpcodeInfo(Opcode.SHR_INT, "shr-int", 0x99, new Format23x());
477    addOpcodeInfo(Opcode.USHR_INT, "ushr-int", 0x9a, new Format23x());
478    addOpcodeInfo(Opcode.ADD_LONG, "add-long", 0x9b, new Format23x());
479    addOpcodeInfo(Opcode.SUB_LONG, "sub-long", 0x9c, new Format23x());
480    addOpcodeInfo(Opcode.MUL_LONG, "mul-long", 0x9d, new Format23x());
481    addOpcodeInfo(Opcode.DIV_LONG, "div-long", 0x9e, new Format23x());
482    addOpcodeInfo(Opcode.REM_LONG, "rem-long", 0x9f, new Format23x());
483    addOpcodeInfo(Opcode.AND_LONG, "and-long", 0xa0, new Format23x());
484    addOpcodeInfo(Opcode.OR_LONG, "or-long", 0xa1, new Format23x());
485    addOpcodeInfo(Opcode.XOR_LONG, "xor-long", 0xa2, new Format23x());
486    addOpcodeInfo(Opcode.SHL_LONG, "shl-long", 0xa3, new Format23x());
487    addOpcodeInfo(Opcode.SHR_LONG, "shr-long", 0xa4, new Format23x());
488    addOpcodeInfo(Opcode.USHR_LONG, "ushr-long", 0xa5, new Format23x());
489    addOpcodeInfo(Opcode.ADD_FLOAT, "add-float", 0xa6, new Format23x());
490    addOpcodeInfo(Opcode.SUB_FLOAT, "sub-float", 0xa7, new Format23x());
491    addOpcodeInfo(Opcode.MUL_FLOAT, "mul-float", 0xa8, new Format23x());
492    addOpcodeInfo(Opcode.DIV_FLOAT, "div-float", 0xa9, new Format23x());
493    addOpcodeInfo(Opcode.REM_FLOAT, "rem-float", 0xaa, new Format23x());
494    addOpcodeInfo(Opcode.ADD_DOUBLE, "add-double", 0xab, new Format23x());
495    addOpcodeInfo(Opcode.SUB_DOUBLE, "sub-double", 0xac, new Format23x());
496    addOpcodeInfo(Opcode.MUL_DOUBLE, "mul-double", 0xad, new Format23x());
497    addOpcodeInfo(Opcode.DIV_DOUBLE, "div-double", 0xae, new Format23x());
498    addOpcodeInfo(Opcode.REM_DOUBLE, "rem-double", 0xaf, new Format23x());
499    addOpcodeInfo(Opcode.ADD_INT_2ADDR, "add-int/2addr", 0xb0, new Format12x());
500    addOpcodeInfo(Opcode.SUB_INT_2ADDR, "sub-int/2addr", 0xb1, new Format12x());
501    addOpcodeInfo(Opcode.MUL_INT_2ADDR, "mul-int/2addr", 0xb2, new Format12x());
502    addOpcodeInfo(Opcode.DIV_INT_2ADDR, "div-int/2addr", 0xb3, new Format12x());
503    addOpcodeInfo(Opcode.REM_INT_2ADDR, "rem-int/2addr", 0xb4, new Format12x());
504    addOpcodeInfo(Opcode.AND_INT_2ADDR, "and-int/2addr", 0xb5, new Format12x());
505    addOpcodeInfo(Opcode.OR_INT_2ADDR, "or-int/2addr", 0xb6, new Format12x());
506    addOpcodeInfo(Opcode.XOR_INT_2ADDR, "xor-int/2addr", 0xb7, new Format12x());
507    addOpcodeInfo(Opcode.SHL_INT_2ADDR, "shl-int/2addr", 0xb8, new Format12x());
508    addOpcodeInfo(Opcode.SHR_INT_2ADDR, "shr-int/2addr", 0xb9, new Format12x());
509    addOpcodeInfo(Opcode.USHR_INT_2ADDR, "ushr-int/2addr", 0xba, new Format12x());
510    addOpcodeInfo(Opcode.ADD_LONG_2ADDR, "add-long/2addr", 0xbb, new Format12x());
511    addOpcodeInfo(Opcode.SUB_LONG_2ADDR, "sub-long/2addr", 0xbc, new Format12x());
512    addOpcodeInfo(Opcode.MUL_LONG_2ADDR, "mul-long/2addr", 0xbd, new Format12x());
513    addOpcodeInfo(Opcode.DIV_LONG_2ADDR, "div-long/2addr", 0xbe, new Format12x());
514    addOpcodeInfo(Opcode.REM_LONG_2ADDR, "rem-long/2addr", 0xbf, new Format12x());
515    addOpcodeInfo(Opcode.AND_LONG_2ADDR, "and-long/2addr", 0xc0, new Format12x());
516    addOpcodeInfo(Opcode.OR_LONG_2ADDR, "or-long/2addr", 0xc1, new Format12x());
517    addOpcodeInfo(Opcode.XOR_LONG_2ADDR, "xor-long/2addr", 0xc2, new Format12x());
518    addOpcodeInfo(Opcode.SHL_LONG_2ADDR, "shl-long/2addr", 0xc3, new Format12x());
519    addOpcodeInfo(Opcode.SHR_LONG_2ADDR, "shr-long/2addr", 0xc4, new Format12x());
520    addOpcodeInfo(Opcode.USHR_LONG_2ADDR, "ushr-long/2addr", 0xc5, new Format12x());
521    addOpcodeInfo(Opcode.ADD_FLOAT_2ADDR, "add-float/2addr", 0xc6, new Format12x());
522    addOpcodeInfo(Opcode.SUB_FLOAT_2ADDR, "sub-float/2addr", 0xc7, new Format12x());
523    addOpcodeInfo(Opcode.MUL_FLOAT_2ADDR, "mul-float/2addr", 0xc8, new Format12x());
524    addOpcodeInfo(Opcode.DIV_FLOAT_2ADDR, "div-float/2addr", 0xc9, new Format12x());
525    addOpcodeInfo(Opcode.REM_FLOAT_2ADDR, "rem-float/2addr", 0xca, new Format12x());
526    addOpcodeInfo(Opcode.ADD_DOUBLE_2ADDR, "add-double/2addr", 0xcb, new Format12x());
527    addOpcodeInfo(Opcode.SUB_DOUBLE_2ADDR, "sub-double/2addr", 0xcc, new Format12x());
528    addOpcodeInfo(Opcode.MUL_DOUBLE_2ADDR, "mul-double/2addr", 0xcd, new Format12x());
529    addOpcodeInfo(Opcode.DIV_DOUBLE_2ADDR, "div-double/2addr", 0xce, new Format12x());
530    addOpcodeInfo(Opcode.REM_DOUBLE_2ADDR, "rem-double/2addr", 0xcf, new Format12x());
531    addOpcodeInfo(Opcode.ADD_INT_LIT16, "add-int/lit16", 0xd0, new Format22s());
532    addOpcodeInfo(Opcode.RSUB_INT, "rsub-int", 0xd1, new Format22s());
533    addOpcodeInfo(Opcode.MUL_INT_LIT16, "mul-int/lit16", 0xd2, new Format22s());
534    addOpcodeInfo(Opcode.DIV_INT_LIT16, "div-int/lit16", 0xd3, new Format22s());
535    addOpcodeInfo(Opcode.REM_INT_LIT16, "rem-int/lit16", 0xd4, new Format22s());
536    addOpcodeInfo(Opcode.AND_INT_LIT16, "and-int/lit16", 0xd5, new Format22s());
537    addOpcodeInfo(Opcode.OR_INT_LIT16, "or-int/lit16", 0xd6, new Format22s());
538    addOpcodeInfo(Opcode.XOR_INT_LIT16, "xor-int/lit16", 0xd7, new Format22s());
539    addOpcodeInfo(Opcode.ADD_INT_LIT8, "add-int/lit8", 0xd8, new Format22b());
540    addOpcodeInfo(Opcode.RSUB_INT_LIT8, "rsub-int/lit8", 0xd9, new Format22b());
541    addOpcodeInfo(Opcode.MUL_INT_LIT8, "mul-int/lit8", 0xda, new Format22b());
542    addOpcodeInfo(Opcode.DIV_INT_LIT8, "div-int/lit8", 0xdb, new Format22b());
543    addOpcodeInfo(Opcode.REM_INT_LIT8, "rem-int/lit8", 0xdc, new Format22b());
544    addOpcodeInfo(Opcode.AND_INT_LIT8, "and-int/lit8", 0xdd, new Format22b());
545    addOpcodeInfo(Opcode.OR_INT_LIT8, "or-int/lit8", 0xde, new Format22b());
546    addOpcodeInfo(Opcode.XOR_INT_LIT8, "xor-int/lit8", 0xdf, new Format22b());
547    addOpcodeInfo(Opcode.SHL_INT_LIT8, "shl-int/lit8", 0xe0, new Format22b());
548    addOpcodeInfo(Opcode.SHR_INT_LIT8, "shr-int/lit8", 0xe1, new Format22b());
549    addOpcodeInfo(Opcode.USHR_INT_LIT8, "ushr-int/lit8", 0xe2, new Format22b());
550    addOpcodeInfo(Opcode.IGET_QUICK, "+iget-quick", 0xe3, new Format22c());
551    addOpcodeInfo(Opcode.IGET_WIDE_QUICK, "+iget-wide-quick", 0xe4, new Format22c());
552    addOpcodeInfo(Opcode.IGET_OBJECT_QUICK, "+iget-object-quick", 0xe5, new Format22c());
553    addOpcodeInfo(Opcode.IPUT_QUICK, "+iput-quick", 0xe6, new Format22c());
554    addOpcodeInfo(Opcode.IPUT_WIDE_QUICK, "+iput-wide-quick", 0xe7, new Format22c());
555    addOpcodeInfo(Opcode.IPUT_OBJECT_QUICK, "+iput-object-quick", 0xe8, new Format22c());
556    addOpcodeInfo(Opcode.INVOKE_VIRTUAL_QUICK, "+invoke-virtual-quick", 0xe9, new Format35c());
557    addOpcodeInfo(Opcode.INVOKE_VIRTUAL_QUICK_RANGE, "+invoke-virtual-quick/range",
558        0xea, new Format3rc());
559    addOpcodeInfo(Opcode.IPUT_BOOLEAN_QUICK, "+iput-boolean-quick", 0xeb, new Format22c());
560    addOpcodeInfo(Opcode.IPUT_BYTE_QUICK, "+iput-byte-quick", 0xec, new Format22c());
561    addOpcodeInfo(Opcode.IPUT_CHAR_QUICK, "+iput-char-quick", 0xed, new Format22c());
562    addOpcodeInfo(Opcode.IPUT_SHORT_QUICK, "+iput-short-quick", 0xee, new Format22c());
563    addOpcodeInfo(Opcode.UNUSED_EF, "unused-ef", 0xef, new Format10x());
564    addOpcodeInfo(Opcode.UNUSED_F0, "unused-f0", 0xf0, new Format10x());
565    addOpcodeInfo(Opcode.UNUSED_F1, "unused-f1", 0xf1, new Format10x());
566    addOpcodeInfo(Opcode.UNUSED_F2, "unused-f2", 0xf2, new Format10x());
567    addOpcodeInfo(Opcode.UNUSED_F3, "unused-f3", 0xf3, new Format10x());
568    addOpcodeInfo(Opcode.UNUSED_F4, "unused-f4", 0xf4, new Format10x());
569    addOpcodeInfo(Opcode.UNUSED_F5, "unused-f5", 0xf5, new Format10x());
570    addOpcodeInfo(Opcode.UNUSED_F6, "unused-f6", 0xf6, new Format10x());
571    addOpcodeInfo(Opcode.UNUSED_F7, "unused-f7", 0xf7, new Format10x());
572    addOpcodeInfo(Opcode.UNUSED_F8, "unused-f8", 0xf8, new Format10x());
573    addOpcodeInfo(Opcode.UNUSED_F9, "unused-f9", 0xf9, new Format10x());
574    addOpcodeInfo(Opcode.UNUSED_FA, "unused-fa", 0xfa, new Format10x());
575    addOpcodeInfo(Opcode.UNUSED_FB, "unused-fb", 0xfb, new Format10x());
576    addOpcodeInfo(Opcode.UNUSED_FC, "unused-fc", 0xfc, new Format10x());
577    addOpcodeInfo(Opcode.UNUSED_FD, "unused-fd", 0xfd, new Format10x());
578    addOpcodeInfo(Opcode.UNUSED_FE, "unused-fe", 0xfe, new Format10x());
579    addOpcodeInfo(Opcode.UNUSED_FF, "unused-ff", 0xff, new Format10x());
580    if (opcode_map_by_int.size() != 256) {
581      Log.errorAndQuit("Incorrect number of bytecodes defined.");
582    }
583  }
584}
585