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 java.io.IOException; 20 21public class MapItem implements RawDexObject { 22 public static final int TYPE_HEADER_ITEM = 0x0; 23 public static final int TYPE_STRING_ID_ITEM = 0x1; 24 public static final int TYPE_TYPE_ID_ITEM = 0x2; 25 public static final int TYPE_PROTO_ID_ITEM = 0x3; 26 public static final int TYPE_FIELD_ID_ITEM = 0x4; 27 public static final int TYPE_METHOD_ID_ITEM = 0x5; 28 public static final int TYPE_CLASS_DEF_ITEM = 0x6; 29 public static final int TYPE_MAP_LIST = 0x1000; 30 public static final int TYPE_TYPE_LIST = 0x1001; 31 public static final int TYPE_ANNOTATION_SET_REF_LIST = 0x1002; 32 public static final int TYPE_ANNOTATION_SET_ITEM = 0x1003; 33 public static final int TYPE_CLASS_DATA_ITEM = 0x2000; 34 public static final int TYPE_CODE_ITEM = 0x2001; 35 public static final int TYPE_STRING_DATA_ITEM = 0x2002; 36 public static final int TYPE_DEBUG_INFO_ITEM = 0x2003; 37 public static final int TYPE_ANNOTATION_ITEM = 0x2004; 38 public static final int TYPE_ENCODED_ARRAY_ITEM = 0x2005; 39 public static final int TYPE_ANNOTATIONS_DIRECTORY_ITEM = 0x2006; 40 41 public short type; 42 public int size; 43 public Offset offset; 44 45 @Override 46 public void read(DexRandomAccessFile file) throws IOException { 47 type = file.readUShort(); 48 file.readUShort(); // Unused padding. 49 size = file.readUInt(); 50 if (type == TYPE_HEADER_ITEM) { 51 offset = file.getOffsetTracker().getNewHeaderOffset(file.readUInt()); 52 } else { 53 offset = file.getOffsetTracker().getNewOffset(file.readUInt()); 54 } 55 } 56 57 @Override 58 public void write(DexRandomAccessFile file) throws IOException { 59 file.writeUShort(type); 60 file.writeUShort((short) 0); // Unused padding. 61 file.writeUInt(size); 62 file.getOffsetTracker().tryToWriteOffset(offset, file, false /* ULEB128 */); 63 } 64 65 @Override 66 public void incrementIndex(IndexUpdateKind kind, int insertedIdx) { 67 // Do nothing. 68 } 69} 70