diff --git a/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/DexBackedDexFile.java b/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/DexBackedDexFile.java index 89153ea2..80148a3a 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/DexBackedDexFile.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/DexBackedDexFile.java @@ -31,10 +31,7 @@ package org.jf.dexlib2.dexbacked; -import org.jf.dexlib2.dexbacked.raw.HeaderItem; -import org.jf.dexlib2.dexbacked.raw.ProtoIdItem; -import org.jf.dexlib2.dexbacked.raw.StringIdItem; -import org.jf.dexlib2.dexbacked.raw.TypeIdItem; +import org.jf.dexlib2.dexbacked.raw.*; import org.jf.dexlib2.dexbacked.util.FixedSizeSet; import org.jf.dexlib2.iface.DexFile; import org.jf.dexlib2.util.AnnotatedBytes; @@ -81,15 +78,10 @@ public abstract class DexBackedDexFile extends BaseDexBuffer implements DexFile private final int classStartOffset; - private static final int FIELD_ID_ITEM_SIZE = 8; private static final int METHOD_ID_ITEM_SIZE = 8; private static final int CLASS_DEF_ITEM_SIZE = 32; public static final int MAP_ITEM_SIZE = 12; - public static final int FIELD_CLASS_IDX_OFFSET = 0; - public static final int FIELD_TYPE_IDX_OFFSET = 2; - public static final int FIELD_NAME_IDX_OFFSET = 4; - public static final int METHOD_CLASS_IDX_OFFSET = 0; public static final int METHOD_PROTO_IDX_OFFSET = 2; public static final int METHOD_NAME_IDX_OFFSET = 4; @@ -181,7 +173,7 @@ public abstract class DexBackedDexFile extends BaseDexBuffer implements DexFile if (fieldIndex < 0 || fieldIndex >= fieldCount) { throw new ExceptionWithContext("Field index out of bounds: %d", fieldIndex); } - return fieldStartOffset + fieldIndex*FIELD_ID_ITEM_SIZE; + return fieldStartOffset + fieldIndex*FieldIdItem.ITEM_SIZE; } @Override @@ -275,6 +267,12 @@ public abstract class DexBackedDexFile extends BaseDexBuffer implements DexFile ProtoIdItem.getAnnotator().annotateSection(annotatedBytes, this, protoCount); } + if (fieldCount > 0) { + annotatedBytes.skipTo(getFieldIdItemOffset(0)); + annotatedBytes.annotate(0, " "); + FieldIdItem.getAnnotator().annotateSection(annotatedBytes, this, fieldCount); + } + annotatedBytes.writeAnnotations(out, buf); } } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/raw/FieldIdItem.java b/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/raw/FieldIdItem.java new file mode 100644 index 00000000..3bf0a932 --- /dev/null +++ b/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/raw/FieldIdItem.java @@ -0,0 +1,77 @@ +/* + * Copyright 2013, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.dexlib2.dexbacked.raw; + +import org.jf.dexlib2.dexbacked.DexBackedDexFile; +import org.jf.dexlib2.util.AnnotatedBytes; + +import javax.annotation.Nonnull; + +public class FieldIdItem { + public static final int ITEM_SIZE = 8; + + public static final int CLASS_OFFSET = 0; + public static final int TYPE_OFFSET = 2; + public static final int NAME_OFFSET = 4; + + public static SectionAnnotator getAnnotator() { + return new SectionAnnotator() { + @Override + public void annotateSection(@Nonnull AnnotatedBytes out, @Nonnull DexBackedDexFile dexFile, int length) { + if (length > 0) { + out.annotate(0, "-----------------------------"); + out.annotate(0, "field_id_item section"); + out.annotate(0, "-----------------------------"); + out.annotate(0, ""); + + for (int i=0; i