aboutsummaryrefslogtreecommitdiff
path: root/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/raw/HeaderItem.java
diff options
context:
space:
mode:
Diffstat (limited to 'dexlib2/src/main/java/org/jf/dexlib2/dexbacked/raw/HeaderItem.java')
-rw-r--r--dexlib2/src/main/java/org/jf/dexlib2/dexbacked/raw/HeaderItem.java24
1 files changed, 22 insertions, 2 deletions
diff --git a/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/raw/HeaderItem.java b/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/raw/HeaderItem.java
index 3499eadc..531ff461 100644
--- a/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/raw/HeaderItem.java
+++ b/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/raw/HeaderItem.java
@@ -42,9 +42,14 @@ import javax.annotation.Nullable;
public class HeaderItem {
public static final int ITEM_SIZE = 0x70;
+ /**
+ * The magic numbers for dex files.
+ *
+ * They are: "dex\n035\0" and "dex\n037\0".
+ */
public static final byte[][] MAGIC_VALUES= new byte[][] {
new byte[]{0x64, 0x65, 0x78, 0x0a, 0x30, 0x33, 0x35, 0x00},
- new byte[]{0x64, 0x65, 0x78, 0x0a, 0x30, 0x33, 0x36, 0x00}};
+ new byte[]{0x64, 0x65, 0x78, 0x0a, 0x30, 0x33, 0x37, 0x00}};
public static final int LITTLE_ENDIAN_TAG = 0x12345678;
public static final int BIG_ENDIAN_TAG = 0x78563412;
@@ -225,6 +230,21 @@ public class HeaderItem {
return "Invalid";
}
+
+ /**
+ * Get the higest magic number supported by Android for this api level.
+ * @return The dex file magic number
+ */
+ public static byte[] getMagicForApi(int api) {
+ if (api < 24) {
+ // Prior to Android N we only support dex version 035.
+ return HeaderItem.MAGIC_VALUES[0];
+ } else {
+ // On android N and later we support dex version 037.
+ return HeaderItem.MAGIC_VALUES[1];
+ }
+ }
+
private static int getVersion(byte[] buf, int offset) {
if (buf.length - offset < 8) {
return 0;
@@ -241,7 +261,7 @@ public class HeaderItem {
}
}
if (matches) {
- return i==0?35:36;
+ return i==0?35:37;
}
}
return 0;