mirror of
https://github.com/revanced/smali.git
synced 2025-05-22 19:08:52 +02:00
Annotate ProtoIdItems
This commit is contained in:
parent
658dfb0880
commit
5b71582325
@ -32,6 +32,7 @@
|
|||||||
package org.jf.dexlib2.dexbacked;
|
package org.jf.dexlib2.dexbacked;
|
||||||
|
|
||||||
import org.jf.dexlib2.dexbacked.raw.HeaderItem;
|
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.StringIdItem;
|
||||||
import org.jf.dexlib2.dexbacked.raw.TypeIdItem;
|
import org.jf.dexlib2.dexbacked.raw.TypeIdItem;
|
||||||
import org.jf.dexlib2.dexbacked.util.FixedSizeSet;
|
import org.jf.dexlib2.dexbacked.util.FixedSizeSet;
|
||||||
@ -79,7 +80,7 @@ public abstract class DexBackedDexFile extends BaseDexBuffer implements DexFile
|
|||||||
private final int classCount;
|
private final int classCount;
|
||||||
private final int classStartOffset;
|
private final int classStartOffset;
|
||||||
|
|
||||||
private static final int PROTO_ID_ITEM_SIZE = 12;
|
|
||||||
private static final int FIELD_ID_ITEM_SIZE = 8;
|
private static final int FIELD_ID_ITEM_SIZE = 8;
|
||||||
private static final int METHOD_ID_ITEM_SIZE = 8;
|
private static final int METHOD_ID_ITEM_SIZE = 8;
|
||||||
private static final int CLASS_DEF_ITEM_SIZE = 32;
|
private static final int CLASS_DEF_ITEM_SIZE = 32;
|
||||||
@ -93,9 +94,6 @@ public abstract class DexBackedDexFile extends BaseDexBuffer implements DexFile
|
|||||||
public static final int METHOD_PROTO_IDX_OFFSET = 2;
|
public static final int METHOD_PROTO_IDX_OFFSET = 2;
|
||||||
public static final int METHOD_NAME_IDX_OFFSET = 4;
|
public static final int METHOD_NAME_IDX_OFFSET = 4;
|
||||||
|
|
||||||
public static final int PROTO_RETURN_TYPE_IDX_OFFSET = 4;
|
|
||||||
public static final int PROTO_PARAM_LIST_OFF_OFFSET = 8;
|
|
||||||
|
|
||||||
public static final int TYPE_LIST_SIZE_OFFSET = 0;
|
public static final int TYPE_LIST_SIZE_OFFSET = 0;
|
||||||
public static final int TYPE_LIST_LIST_OFFSET = 4;
|
public static final int TYPE_LIST_LIST_OFFSET = 4;
|
||||||
|
|
||||||
@ -199,7 +197,7 @@ public abstract class DexBackedDexFile extends BaseDexBuffer implements DexFile
|
|||||||
if (protoIndex < 0 || protoIndex >= protoCount) {
|
if (protoIndex < 0 || protoIndex >= protoCount) {
|
||||||
throw new ExceptionWithContext("Proto index out of bounds: %d", protoIndex);
|
throw new ExceptionWithContext("Proto index out of bounds: %d", protoIndex);
|
||||||
}
|
}
|
||||||
return protoStartOffset + protoIndex*PROTO_ID_ITEM_SIZE;
|
return protoStartOffset + protoIndex*ProtoIdItem.ITEM_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getClassDefItemOffset(int classIndex) {
|
public int getClassDefItemOffset(int classIndex) {
|
||||||
@ -259,13 +257,23 @@ public abstract class DexBackedDexFile extends BaseDexBuffer implements DexFile
|
|||||||
AnnotatedBytes annotatedBytes = new AnnotatedBytes(width);
|
AnnotatedBytes annotatedBytes = new AnnotatedBytes(width);
|
||||||
HeaderItem.getAnnotator().annotateSection(annotatedBytes, this, 1);
|
HeaderItem.getAnnotator().annotateSection(annotatedBytes, this, 1);
|
||||||
|
|
||||||
annotatedBytes.skipTo(getStringIdItemOffset(0));
|
if (stringCount > 0) {
|
||||||
annotatedBytes.annotate(0, " ");
|
annotatedBytes.skipTo(getStringIdItemOffset(0));
|
||||||
StringIdItem.getAnnotator().annotateSection(annotatedBytes, this, stringCount);
|
annotatedBytes.annotate(0, " ");
|
||||||
|
StringIdItem.getAnnotator().annotateSection(annotatedBytes, this, stringCount);
|
||||||
|
}
|
||||||
|
|
||||||
annotatedBytes.skipTo(getTypeIdItemOffset(0));
|
if (typeCount > 0) {
|
||||||
annotatedBytes.annotate(0, " ");
|
annotatedBytes.skipTo(getTypeIdItemOffset(0));
|
||||||
TypeIdItem.getAnnotator().annotateSection(annotatedBytes, this, typeCount);
|
annotatedBytes.annotate(0, " ");
|
||||||
|
TypeIdItem.getAnnotator().annotateSection(annotatedBytes, this, typeCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (protoCount > 0) {
|
||||||
|
annotatedBytes.skipTo(getProtoIdItemOffset(0));
|
||||||
|
annotatedBytes.annotate(0, " ");
|
||||||
|
ProtoIdItem.getAnnotator().annotateSection(annotatedBytes, this, protoCount);
|
||||||
|
}
|
||||||
|
|
||||||
annotatedBytes.writeAnnotations(out, buf);
|
annotatedBytes.writeAnnotations(out, buf);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* 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 ProtoIdItem {
|
||||||
|
public static final int ITEM_SIZE = 12;
|
||||||
|
|
||||||
|
public static final int SHORTY_OFFSET = 0;
|
||||||
|
public static final int RETURN_TYPE_OFFSET = 4;
|
||||||
|
public static final int PARAMETERS_OFFSET = 8;
|
||||||
|
|
||||||
|
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, "proto_id_item section");
|
||||||
|
out.annotate(0, "-----------------------------");
|
||||||
|
out.annotate(0, "");
|
||||||
|
|
||||||
|
for (int i=0; i<length; i++) {
|
||||||
|
out.annotate(0, "[%d] proto_id_item", i);
|
||||||
|
out.indent();
|
||||||
|
annotateProto(out, dexFile);
|
||||||
|
out.deindent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void annotateProto(@Nonnull AnnotatedBytes out, @Nonnull DexBackedDexFile dexFile) {
|
||||||
|
int shortyIndex = dexFile.readSmallUint(out.getCursor());
|
||||||
|
out.annotate(4, "shorty_idx = %s", StringIdItem.getReferenceAnnotation(dexFile, shortyIndex));
|
||||||
|
|
||||||
|
int returnTypeIndex = dexFile.readSmallUint(out.getCursor());
|
||||||
|
out.annotate(4, "return_type_idx = %s", TypeIdItem.getReferenceAnnotation(dexFile, returnTypeIndex));
|
||||||
|
|
||||||
|
// TODO: add formatted type list to output
|
||||||
|
int parametersOffset = dexFile.readSmallUint(out.getCursor());
|
||||||
|
if (parametersOffset != 0) {
|
||||||
|
out.annotate(4, "parameters_off = type_list_item[0x%x]", parametersOffset);
|
||||||
|
} else {
|
||||||
|
out.annotate(4, "parameters_off = 0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -40,6 +40,7 @@ import javax.annotation.Nonnull;
|
|||||||
public class StringIdItem {
|
public class StringIdItem {
|
||||||
public static final int ITEM_SIZE = 4;
|
public static final int ITEM_SIZE = 4;
|
||||||
|
|
||||||
|
|
||||||
public static SectionAnnotator getAnnotator() {
|
public static SectionAnnotator getAnnotator() {
|
||||||
return new SectionAnnotator() {
|
return new SectionAnnotator() {
|
||||||
@Override
|
@Override
|
||||||
@ -77,4 +78,14 @@ public class StringIdItem {
|
|||||||
|
|
||||||
out.annotate(4, "string_id_item[0x%x]", stringDataOffset);
|
out.annotate(4, "string_id_item[0x%x]", stringDataOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getReferenceAnnotation(@Nonnull DexBackedDexFile dexFile, int stringIndex) {
|
||||||
|
try {
|
||||||
|
String string = dexFile.getString(stringIndex);
|
||||||
|
return String.format("string_id_item[%d]: \"%s\"", stringIndex, StringUtils.escapeString(string));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace(System.err);
|
||||||
|
}
|
||||||
|
return String.format("string_id_item[%d]", stringIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,6 @@ public class TypeIdItem {
|
|||||||
return new SectionAnnotator() {
|
return new SectionAnnotator() {
|
||||||
@Override
|
@Override
|
||||||
public void annotateSection(@Nonnull AnnotatedBytes out, @Nonnull DexBackedDexFile dexFile, int length) {
|
public void annotateSection(@Nonnull AnnotatedBytes out, @Nonnull DexBackedDexFile dexFile, int length) {
|
||||||
int startOffset = out.getCursor();
|
|
||||||
if (length > 0) {
|
if (length > 0) {
|
||||||
out.annotate(0, "-----------------------------");
|
out.annotate(0, "-----------------------------");
|
||||||
out.annotate(0, "type_id_item section");
|
out.annotate(0, "type_id_item section");
|
||||||
@ -54,7 +53,7 @@ public class TypeIdItem {
|
|||||||
for (int i=0; i<length; i++) {
|
for (int i=0; i<length; i++) {
|
||||||
out.annotate(0, "[%d] type_id_item", i);
|
out.annotate(0, "[%d] type_id_item", i);
|
||||||
out.indent();
|
out.indent();
|
||||||
annotateString(out, dexFile, i, startOffset + i * ITEM_SIZE);
|
annotateString(out, dexFile);
|
||||||
out.deindent();
|
out.deindent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -62,19 +61,18 @@ public class TypeIdItem {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void annotateString(@Nonnull AnnotatedBytes out, @Nonnull DexBackedDexFile dexFile, int index,
|
private static void annotateString(@Nonnull AnnotatedBytes out, @Nonnull DexBackedDexFile dexFile) {
|
||||||
int offset) {
|
int stringIndex = dexFile.readSmallUint(out.getCursor());
|
||||||
int stringIndex = dexFile.readSmallUint(offset);
|
out.annotate(4, StringIdItem.getReferenceAnnotation(dexFile, stringIndex));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getReferenceAnnotation(@Nonnull DexBackedDexFile dexFile, int typeIndex) {
|
||||||
try {
|
try {
|
||||||
String stringValue = dexFile.getString(stringIndex);
|
String typeString = dexFile.getType(typeIndex);
|
||||||
out.annotate(4, "string_id_item[%d]: \"%s\"", stringIndex, StringUtils.escapeString(stringValue));
|
return String.format("type_id_item[%d]: \"%s\"", typeIndex, StringUtils.escapeString(typeString));
|
||||||
return;
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
System.err.print("Error while resolving string value of type at index: ");
|
|
||||||
System.err.print(index);
|
|
||||||
ex.printStackTrace(System.err);
|
ex.printStackTrace(System.err);
|
||||||
}
|
}
|
||||||
|
return String.format("type_id_item[%d]", typeIndex);
|
||||||
out.annotate(4, "string_id_item[%d]", stringIndex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ package org.jf.dexlib2.dexbacked.reference;
|
|||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import org.jf.dexlib2.base.reference.BaseMethodReference;
|
import org.jf.dexlib2.base.reference.BaseMethodReference;
|
||||||
import org.jf.dexlib2.dexbacked.DexBackedDexFile;
|
import org.jf.dexlib2.dexbacked.DexBackedDexFile;
|
||||||
|
import org.jf.dexlib2.dexbacked.raw.ProtoIdItem;
|
||||||
import org.jf.dexlib2.dexbacked.util.FixedSizeList;
|
import org.jf.dexlib2.dexbacked.util.FixedSizeList;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@ -66,8 +67,7 @@ public class DexBackedMethodReference extends BaseMethodReference {
|
|||||||
@Override
|
@Override
|
||||||
public List<String> getParameterTypes() {
|
public List<String> getParameterTypes() {
|
||||||
int protoIdItemOffset = getProtoIdItemOffset();
|
int protoIdItemOffset = getProtoIdItemOffset();
|
||||||
final int parametersOffset = dexFile.readSmallUint(protoIdItemOffset +
|
final int parametersOffset = dexFile.readSmallUint(protoIdItemOffset + ProtoIdItem.PARAMETERS_OFFSET);
|
||||||
DexBackedDexFile.Impl.PROTO_PARAM_LIST_OFF_OFFSET);
|
|
||||||
if (parametersOffset > 0) {
|
if (parametersOffset > 0) {
|
||||||
final int parameterCount = dexFile.readSmallUint(parametersOffset +
|
final int parameterCount = dexFile.readSmallUint(parametersOffset +
|
||||||
DexBackedDexFile.Impl.TYPE_LIST_SIZE_OFFSET);
|
DexBackedDexFile.Impl.TYPE_LIST_SIZE_OFFSET);
|
||||||
@ -88,8 +88,7 @@ public class DexBackedMethodReference extends BaseMethodReference {
|
|||||||
@Override
|
@Override
|
||||||
public String getReturnType() {
|
public String getReturnType() {
|
||||||
int protoIdItemOffset = getProtoIdItemOffset();
|
int protoIdItemOffset = getProtoIdItemOffset();
|
||||||
return dexFile.getType(dexFile.readSmallUint(protoIdItemOffset +
|
return dexFile.getType(dexFile.readSmallUint(protoIdItemOffset + ProtoIdItem.RETURN_TYPE_OFFSET));
|
||||||
DexBackedDexFile.Impl.PROTO_RETURN_TYPE_IDX_OFFSET));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getProtoIdItemOffset() {
|
private int getProtoIdItemOffset() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user