mirror of
https://github.com/revanced/smali.git
synced 2025-05-02 23:54:38 +02:00
Add the ability to parse dependencies from odex files
This commit is contained in:
parent
7172de2aab
commit
ac2686b3fc
@ -33,15 +33,22 @@ package org.jf.dexlib2.dexbacked;
|
|||||||
|
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import org.jf.dexlib2.dexbacked.raw.OdexHeaderItem;
|
import org.jf.dexlib2.dexbacked.raw.OdexHeaderItem;
|
||||||
|
import org.jf.dexlib2.dexbacked.util.VariableSizeList;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.io.EOFException;
|
import java.io.EOFException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class DexBackedOdexFile extends DexBackedDexFile {
|
public class DexBackedOdexFile extends DexBackedDexFile {
|
||||||
|
private static final int DEPENDENCY_COUNT_OFFSET = 12;
|
||||||
|
private static final int DEPENDENCY_START_OFFSET = 16;
|
||||||
|
|
||||||
private final byte[] odexBuf;
|
private final byte[] odexBuf;
|
||||||
|
|
||||||
|
|
||||||
public DexBackedOdexFile(@Nonnull byte[] odexBuf, byte[] dexBuf) {
|
public DexBackedOdexFile(@Nonnull byte[] odexBuf, byte[] dexBuf) {
|
||||||
super(dexBuf);
|
super(dexBuf);
|
||||||
|
|
||||||
@ -52,6 +59,27 @@ public class DexBackedOdexFile extends DexBackedDexFile {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getDependencies() {
|
||||||
|
final int dexOffset = OdexHeaderItem.getDexOffset(odexBuf);
|
||||||
|
final int dependencyOffset = OdexHeaderItem.getDependenciesOffset(odexBuf) - dexOffset;
|
||||||
|
|
||||||
|
BaseDexBuffer buf = new BaseDexBuffer(this.buf);
|
||||||
|
int dependencyCount = buf.readInt(dependencyOffset + DEPENDENCY_COUNT_OFFSET);
|
||||||
|
|
||||||
|
return new VariableSizeList<String>(this, dependencyOffset + DEPENDENCY_START_OFFSET, dependencyCount) {
|
||||||
|
@Override protected String readNextItem(@Nonnull DexReader reader, int index) {
|
||||||
|
int length = reader.readInt();
|
||||||
|
int offset = reader.getOffset();
|
||||||
|
reader.moveRelative(length + 20);
|
||||||
|
try {
|
||||||
|
return new String(DexBackedOdexFile.this.buf, offset, length-1, "US-ASCII");
|
||||||
|
} catch (UnsupportedEncodingException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public static DexBackedOdexFile fromInputStream(@Nonnull InputStream is) throws IOException {
|
public static DexBackedOdexFile fromInputStream(@Nonnull InputStream is) throws IOException {
|
||||||
if (!is.markSupported()) {
|
if (!is.markSupported()) {
|
||||||
throw new IllegalArgumentException("InputStream must support mark");
|
throw new IllegalArgumentException("InputStream must support mark");
|
||||||
|
@ -82,4 +82,9 @@ public class OdexHeaderItem {
|
|||||||
BaseDexBuffer bdb = new BaseDexBuffer(buf);
|
BaseDexBuffer bdb = new BaseDexBuffer(buf);
|
||||||
return bdb.readSmallUint(DEX_OFFSET);
|
return bdb.readSmallUint(DEX_OFFSET);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getDependenciesOffset(byte[] buf) {
|
||||||
|
BaseDexBuffer bdb = new BaseDexBuffer(buf);
|
||||||
|
return bdb.readSmallUint(DEPENDENCIES_OFFSET);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user