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 17 package dexfuzz.rawdex.formats; 18 19 import dexfuzz.rawdex.DexRandomAccessFile; 20 import dexfuzz.rawdex.Instruction; 21 22 import java.io.IOException; 23 24 /** 25 * Every Format subclasses this AbstractFormat. The subclasses then implement these 26 * methods to write out a provided Instruction according to this format, and also methods 27 * to read the vregs from an Instruction's raw bytes. 28 * Hierarchy is as follows: 29 * AbstractFormat 30 * |____________Format1 31 * | |_____Format10t 32 * | |_____Format10x 33 * | |_____Format11n 34 * | |_____Format11x 35 * | |_____Format12x 36 * |____________Format2 37 * | |_____Format20bc 38 * | |_____Format20t 39 * etc... 40 */ 41 public abstract class AbstractFormat { 42 /** 43 * Get the size of an Instruction that has this format. 44 */ getSize()45 public abstract int getSize(); 46 47 /** 48 * Given a file handle and an instruction, write that Instruction out to the file 49 * correctly, considering the current format. 50 */ writeToFile(DexRandomAccessFile file, Instruction insn)51 public abstract void writeToFile(DexRandomAccessFile file, Instruction insn) throws IOException; 52 53 /** 54 * Read the value of vA, considering this format. 55 */ getA(byte[] raw)56 public abstract long getA(byte[] raw) throws IOException; 57 58 /** 59 * Read the value of vB, considering this format. 60 */ getB(byte[] raw)61 public abstract long getB(byte[] raw) throws IOException; 62 63 /** 64 * Read the value of vC, considering this format. 65 */ getC(byte[] raw)66 public abstract long getC(byte[] raw) throws IOException; 67 68 /** 69 * Only Format35c should return true for this. 70 */ needsInvokeFormatInfo()71 public abstract boolean needsInvokeFormatInfo(); 72 } 73