mirror of
https://github.com/revanced/smali.git
synced 2025-06-12 12:17:37 +02:00
Add support for the new dey36 odex header
git-svn-id: https://smali.googlecode.com/svn/trunk@725 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
@ -175,6 +175,7 @@ public class DexFile
|
||||
*/
|
||||
private boolean isOdex = false;
|
||||
|
||||
private OdexHeader odexHeader;
|
||||
private OdexDependencies odexDependencies;
|
||||
|
||||
private int dataOffset;
|
||||
@ -332,25 +333,21 @@ public class DexFile
|
||||
}
|
||||
|
||||
byte[] dexMagic, odexMagic;
|
||||
boolean isDex = false;
|
||||
this.isOdex = false;
|
||||
|
||||
dexMagic = org.jf.dexlib.HeaderItem.MAGIC;
|
||||
odexMagic = OdexHeader.MAGIC;
|
||||
|
||||
boolean isDex = true;
|
||||
this.isOdex = true;
|
||||
for (int i=0; i<8; i++) {
|
||||
if (magic[i] != dexMagic[i]) {
|
||||
isDex = false;
|
||||
}
|
||||
if (magic[i] != odexMagic[i]) {
|
||||
isOdex = false;
|
||||
}
|
||||
if (Arrays.equals(magic, HeaderItem.MAGIC)) {
|
||||
isDex = true;
|
||||
} else if (Arrays.equals(magic, OdexHeader.MAGIC_35)) {
|
||||
isOdex = true;
|
||||
} else if (Arrays.equals(magic, OdexHeader.MAGIC_36)) {
|
||||
isOdex = true;
|
||||
}
|
||||
|
||||
if (isOdex) {
|
||||
byte[] odexHeaderBytes = FileUtils.readStream(inputStream, 40);
|
||||
Input odexHeaderIn = new ByteArrayInput(odexHeaderBytes);
|
||||
OdexHeader odexHeader = new OdexHeader(odexHeaderIn);
|
||||
odexHeader = new OdexHeader(odexHeaderIn);
|
||||
|
||||
int dependencySkip = odexHeader.depsOffset - odexHeader.dexOffset - odexHeader.dexLength;
|
||||
if (dependencySkip < 0) {
|
||||
@ -536,6 +533,14 @@ public class DexFile
|
||||
return odexDependencies;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return An OdexHeader object containing the information from the odex header in this dex file, or null if there
|
||||
* is no odex header
|
||||
*/
|
||||
public OdexHeader getOdexHeader() {
|
||||
return odexHeader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a boolean value indicating whether items in this dex file should be
|
||||
* written back out "in-place", or whether the normal layout logic should be
|
||||
|
@ -30,13 +30,15 @@ package org.jf.dexlib;
|
||||
|
||||
import org.jf.dexlib.Util.Input;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class OdexHeader {
|
||||
|
||||
/**
|
||||
* the file format magic number, represented as the
|
||||
* low-order bytes of a string
|
||||
* the possible file format magic numbers, represented as the low-order bytes of a string.
|
||||
*/
|
||||
public static final byte[] MAGIC = new byte[] {0x64, 0x65, 0x79, 0x0A, 0x30, 0x33, 0x35, 0x00};//"dey\n035" + '\0';
|
||||
public static final byte[] MAGIC_35 = new byte[] {0x64, 0x65, 0x79, 0x0A, 0x30, 0x33, 0x35, 0x00}; //"dey\n035" + '\0';
|
||||
public static final byte[] MAGIC_36 = new byte[] {0x64, 0x65, 0x79, 0x0A, 0x30, 0x33, 0x36, 0x00}; //"dey\n036" + '\0';
|
||||
|
||||
public final byte[] magic;
|
||||
public final int dexOffset;
|
||||
@ -47,13 +49,17 @@ public class OdexHeader {
|
||||
public final int auxLength;
|
||||
public final int flags;
|
||||
|
||||
public final int version;
|
||||
|
||||
public OdexHeader(Input in) {
|
||||
magic = in.readBytes(8);
|
||||
|
||||
for (int i=0; i<8; i++) {
|
||||
if (MAGIC[i] != magic[i]) {
|
||||
throw new RuntimeException("The magic value is not the expected value");
|
||||
}
|
||||
if (Arrays.equals(MAGIC_35, magic)) {
|
||||
version = 35;
|
||||
} else if (Arrays.equals(MAGIC_36, magic)) {
|
||||
version = 36;
|
||||
} else {
|
||||
throw new RuntimeException("The magic value is not one of the expected values");
|
||||
}
|
||||
|
||||
dexOffset = in.readInt();
|
||||
@ -65,5 +71,4 @@ public class OdexHeader {
|
||||
flags = in.readInt();
|
||||
in.readInt(); //padding
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user