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; 18 19 import java.io.IOException; 20 21 /** 22 * Base class for any data structure that we may read or write from a DEX file. 23 */ 24 public interface RawDexObject { 25 /** 26 * Populate information for this DEX data from the file. 27 * @param file Input file, should already be "seeked" to the correct position. 28 * @throws IOException If there's a problem writing to the file. 29 */ read(DexRandomAccessFile file)30 public void read(DexRandomAccessFile file) throws IOException; 31 32 /** 33 * Write information for this DEX data to the file. 34 * @param file Output file, should already be "seeked" to the correct position. 35 * @throws IOException If there's a problem writing to the file. 36 */ write(DexRandomAccessFile file)37 public void write(DexRandomAccessFile file) throws IOException; 38 39 public static enum IndexUpdateKind { 40 STRING_ID, 41 TYPE_ID, 42 PROTO_ID, 43 FIELD_ID, 44 METHOD_ID 45 } 46 47 /** 48 * When we insert a new string, type, proto, field or method into the DEX file, 49 * this must be called. We may have inserted something into the middle of a table, 50 * so any indices pointing afterwards must be updated. 51 */ incrementIndex(IndexUpdateKind kind, int insertedIdx)52 public void incrementIndex(IndexUpdateKind kind, int insertedIdx); 53 } 54