mirror of
https://github.com/revanced/smali.git
synced 2025-05-30 20:40:11 +02:00
Get rid of the separate DexBackedDexFile.Impl class
This commit is contained in:
parent
132eeaedf7
commit
12659ec7db
@ -93,7 +93,7 @@ public final class DexFileFactory {
|
||||
dexBytes = Files.toByteArray(dexFile);
|
||||
}
|
||||
|
||||
return new DexBackedDexFile.Impl(dexBytes);
|
||||
return new DexBackedDexFile(dexBytes);
|
||||
}
|
||||
|
||||
public static void writeDexFile(String path, DexFile dexFile) throws IOException {
|
||||
|
@ -40,25 +40,7 @@ import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class DexBackedDexFile extends BaseDexBuffer implements DexFile {
|
||||
public DexBackedDexFile(@Nonnull byte[] buf) {
|
||||
super(buf);
|
||||
}
|
||||
|
||||
@Nonnull public abstract String getString(int stringIndex);
|
||||
@Nullable public abstract String getOptionalString(int stringIndex);
|
||||
@Nonnull public abstract String getType(int typeIndex);
|
||||
@Nullable public abstract String getOptionalType(int typeIndex);
|
||||
|
||||
// TODO: refactor how dex items are read
|
||||
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);
|
||||
|
||||
public static class Impl extends DexBackedDexFile {
|
||||
public class DexBackedDexFile extends BaseDexBuffer implements DexFile {
|
||||
private final int stringCount;
|
||||
private final int stringStartOffset;
|
||||
private final int typeCount;
|
||||
@ -72,11 +54,11 @@ public abstract class DexBackedDexFile extends BaseDexBuffer implements DexFile
|
||||
private final int classCount;
|
||||
private final int classStartOffset;
|
||||
|
||||
public Impl(@Nonnull BaseDexBuffer buf) {
|
||||
public DexBackedDexFile (@Nonnull BaseDexBuffer buf) {
|
||||
this(buf.buf);
|
||||
}
|
||||
|
||||
public Impl(@Nonnull byte[] buf) {
|
||||
public DexBackedDexFile (@Nonnull byte[] buf) {
|
||||
super(buf);
|
||||
|
||||
verifyMagic();
|
||||
@ -102,7 +84,7 @@ public abstract class DexBackedDexFile extends BaseDexBuffer implements DexFile
|
||||
@Nonnull
|
||||
@Override
|
||||
public DexBackedClassDef readItem(int index) {
|
||||
return new DexBackedClassDef(Impl.this, getClassDefItemOffset(index));
|
||||
return new DexBackedClassDef(DexBackedDexFile.this, getClassDefItemOffset(index));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -155,7 +137,6 @@ public abstract class DexBackedDexFile extends BaseDexBuffer implements DexFile
|
||||
return typeStartOffset + typeIndex*TypeIdItem.ITEM_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFieldIdItemOffset(int fieldIndex) {
|
||||
if (fieldIndex < 0 || fieldIndex >= fieldCount) {
|
||||
throw new ExceptionWithContext("Field index out of bounds: %d", fieldIndex);
|
||||
@ -163,7 +144,6 @@ public abstract class DexBackedDexFile extends BaseDexBuffer implements DexFile
|
||||
return fieldStartOffset + fieldIndex*FieldIdItem.ITEM_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMethodIdItemOffset(int methodIndex) {
|
||||
if (methodIndex < 0 || methodIndex >= methodCount) {
|
||||
throw new ExceptionWithContext("Method index out of bounds: %d", methodIndex);
|
||||
@ -171,7 +151,6 @@ public abstract class DexBackedDexFile extends BaseDexBuffer implements DexFile
|
||||
return methodStartOffset + methodIndex*MethodIdItem.ITEM_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getProtoIdItemOffset(int protoIndex) {
|
||||
if (protoIndex < 0 || protoIndex >= protoCount) {
|
||||
throw new ExceptionWithContext("Proto index out of bounds: %d", protoIndex);
|
||||
@ -179,7 +158,6 @@ 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);
|
||||
@ -191,7 +169,6 @@ public abstract class DexBackedDexFile extends BaseDexBuffer implements DexFile
|
||||
return classCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public String getString(int stringIndex) {
|
||||
int stringOffset = getStringIdItemOffset(stringIndex);
|
||||
@ -201,7 +178,6 @@ public abstract class DexBackedDexFile extends BaseDexBuffer implements DexFile
|
||||
return reader.readString(utf16Length);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getOptionalString(int stringIndex) {
|
||||
if (stringIndex == -1) {
|
||||
@ -210,7 +186,6 @@ public abstract class DexBackedDexFile extends BaseDexBuffer implements DexFile
|
||||
return getString(stringIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public String getType(int typeIndex) {
|
||||
int typeOffset = getTypeIdItemOffset(typeIndex);
|
||||
@ -218,7 +193,6 @@ public abstract class DexBackedDexFile extends BaseDexBuffer implements DexFile
|
||||
return getString(stringIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getOptionalType(int typeIndex) {
|
||||
if (typeIndex == -1) {
|
||||
@ -233,4 +207,3 @@ public abstract class DexBackedDexFile extends BaseDexBuffer implements DexFile
|
||||
return new DexReader(this, offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ import java.io.Writer;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class RawDexFile extends DexBackedDexFile.Impl {
|
||||
public class RawDexFile extends DexBackedDexFile {
|
||||
@Nonnull public final HeaderItem headerItem;
|
||||
|
||||
public RawDexFile(BaseDexBuffer buf) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user