mirror of
https://github.com/revanced/smali.git
synced 2025-05-02 15:44:30 +02:00
Add back various methods removed during the refactoring
This commit is contained in:
parent
e8158c86ef
commit
132eeaedf7
@ -54,6 +54,7 @@ public abstract class DexBackedDexFile extends BaseDexBuffer implements DexFile
|
||||
public abstract int getMethodIdItemOffset(int methodIndex);
|
||||
public abstract int getProtoIdItemOffset(int protoIndex);
|
||||
public abstract int getFieldIdItemOffset(int fieldIndex);
|
||||
public abstract int getClassDefItemOffset(int classIndex);
|
||||
|
||||
@Override @Nonnull public abstract DexReader readerAt(int offset);
|
||||
|
||||
@ -178,6 +179,7 @@ public abstract class DexBackedDexFile extends BaseDexBuffer implements DexFile
|
||||
return protoStartOffset + protoIndex*ProtoIdItem.ITEM_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getClassDefItemOffset(int classIndex) {
|
||||
if (classIndex < 0 || classIndex >= classCount) {
|
||||
throw new ExceptionWithContext("Class index out of bounds: %d", classIndex);
|
||||
|
@ -33,6 +33,7 @@ package org.jf.dexlib2.dexbacked.raw;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import org.jf.dexlib2.AccessFlags;
|
||||
import org.jf.dexlib2.dexbacked.DexBackedDexFile;
|
||||
import org.jf.dexlib2.dexbacked.raw.util.DexAnnotator;
|
||||
import org.jf.dexlib2.util.AnnotatedBytes;
|
||||
|
||||
@ -115,4 +116,25 @@ public class ClassDefItem {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static String asString(@Nonnull DexBackedDexFile dexFile, int classIndex) {
|
||||
int offset = dexFile.getClassDefItemOffset(classIndex);
|
||||
int typeIndex = dexFile.readSmallUint(offset + CLASS_OFFSET);
|
||||
return dexFile.getType(typeIndex);
|
||||
}
|
||||
|
||||
public static String[] getClasses(@Nonnull RawDexFile dexFile) {
|
||||
MapItem mapItem = dexFile.getMapItemForSection(ItemType.CLASS_DEF_ITEM);
|
||||
if (mapItem == null) {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
int classCount = mapItem.getItemCount();
|
||||
String[] ret = new String[classCount];
|
||||
for (int i=0; i<classCount; i++) {
|
||||
ret[i] = asString(dexFile, i);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@ -91,4 +91,18 @@ public class FieldIdItem {
|
||||
}
|
||||
return String.format("field_id_item[%d]", fieldIndex);
|
||||
}
|
||||
|
||||
public static String[] getFields(@Nonnull RawDexFile dexFile) {
|
||||
MapItem mapItem = dexFile.getMapItemForSection(ItemType.FIELD_ID_ITEM);
|
||||
if (mapItem == null) {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
int fieldCount = mapItem.getItemCount();
|
||||
String[] ret = new String[fieldCount];
|
||||
for (int i=0; i<fieldCount; i++) {
|
||||
ret[i] = asString(dexFile, i);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,6 @@
|
||||
|
||||
package org.jf.dexlib2.dexbacked.raw;
|
||||
|
||||
import org.jf.dexlib2.dexbacked.DexBackedDexFile;
|
||||
import org.jf.dexlib2.dexbacked.raw.util.DexAnnotator;
|
||||
import org.jf.dexlib2.util.AnnotatedBytes;
|
||||
import org.jf.util.StringUtils;
|
||||
@ -78,12 +77,20 @@ public class HeaderItem {
|
||||
public static final int CLASS_COUNT_OFFSET = 96;
|
||||
public static final int CLASS_START_OFFSET = 100;
|
||||
|
||||
@Nonnull private DexBackedDexFile dexFile;
|
||||
@Nonnull private RawDexFile dexFile;
|
||||
|
||||
public HeaderItem(@Nonnull DexBackedDexFile dexFile) {
|
||||
public HeaderItem(@Nonnull RawDexFile dexFile) {
|
||||
this.dexFile = dexFile;
|
||||
}
|
||||
|
||||
public int getChecksum() {
|
||||
return dexFile.readSmallUint(CHECKSUM_OFFSET);
|
||||
}
|
||||
|
||||
@Nonnull public byte[] getSignature() {
|
||||
return dexFile.readByteRange(SIGNATURE_OFFSET, SIGNATURE_SIZE);
|
||||
}
|
||||
|
||||
public int getMapOffset() {
|
||||
return dexFile.readSmallUint(MAP_OFFSET);
|
||||
}
|
||||
|
@ -91,4 +91,18 @@ public class MethodIdItem {
|
||||
}
|
||||
return String.format("method_id_item[%d]", methodIndex);
|
||||
}
|
||||
|
||||
public static String[] getMethods(@Nonnull RawDexFile dexFile) {
|
||||
MapItem mapItem = dexFile.getMapItemForSection(ItemType.METHOD_ID_ITEM);
|
||||
if (mapItem == null) {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
int methodCount = mapItem.getItemCount();
|
||||
String[] ret = new String[methodCount];
|
||||
for (int i=0; i<methodCount; i++) {
|
||||
ret[i] = asString(dexFile, i);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@ -94,4 +94,18 @@ public class ProtoIdItem {
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String[] getProtos(@Nonnull RawDexFile dexFile) {
|
||||
MapItem mapItem = dexFile.getMapItemForSection(ItemType.PROTO_ID_ITEM);
|
||||
if (mapItem == null) {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
int protoCount = mapItem.getItemCount();
|
||||
String[] ret = new String[protoCount];
|
||||
for (int i=0; i<protoCount; i++) {
|
||||
ret[i] = asString(dexFile, i);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class RawDexFile extends DexBackedDexFile.Impl {
|
||||
@ -55,6 +56,10 @@ public class RawDexFile extends DexBackedDexFile.Impl {
|
||||
this.headerItem = new HeaderItem(this);
|
||||
}
|
||||
|
||||
public byte[] readByteRange(int start, int length) {
|
||||
return Arrays.copyOfRange(getBuf(), start, start+length);
|
||||
}
|
||||
|
||||
public int getMapOffset() {
|
||||
return headerItem.getMapOffset();
|
||||
}
|
||||
|
@ -101,4 +101,18 @@ public class StringIdItem {
|
||||
}
|
||||
return getReferenceAnnotation(dexFile, stringIndex, quote);
|
||||
}
|
||||
|
||||
public static String[] getStrings(@Nonnull RawDexFile dexFile) {
|
||||
MapItem mapItem = dexFile.getMapItemForSection(ItemType.STRING_ID_ITEM);
|
||||
if (mapItem == null) {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
int stringCount = mapItem.getItemCount();
|
||||
String[] ret = new String[stringCount];
|
||||
for (int i=0; i<stringCount; i++) {
|
||||
ret[i] = dexFile.getString(i);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@ -74,4 +74,18 @@ public class TypeIdItem {
|
||||
}
|
||||
return getReferenceAnnotation(dexFile, typeIndex);
|
||||
}
|
||||
|
||||
public static String[] getTypes(@Nonnull RawDexFile dexFile) {
|
||||
MapItem mapItem = dexFile.getMapItemForSection(ItemType.TYPE_ID_ITEM);
|
||||
if (mapItem == null) {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
int typeCount = mapItem.getItemCount();
|
||||
String[] ret = new String[typeCount];
|
||||
for (int i=0; i<typeCount; i++) {
|
||||
ret[i] = dexFile.getType(i);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user