mirror of
https://github.com/revanced/smali.git
synced 2025-05-03 08:04:28 +02:00
Dex version 37 support
Make dexlib able to read and write version 37 dex files. Bug: 27809626 Change-Id: I3d0ca6201c7abe7763d2fb925e9ee1edbef24230
This commit is contained in:
parent
87d10dac27
commit
40bbf5c347
@ -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;
|
||||
|
@ -1221,8 +1221,8 @@ public abstract class DexWriter<
|
||||
}
|
||||
|
||||
private void writeHeader(@Nonnull DexDataWriter writer, int dataOffset, int fileSize) throws IOException {
|
||||
// always write the 035 version, there's no reason to use the 036 version for now
|
||||
writer.write(HeaderItem.MAGIC_VALUES[0]);
|
||||
// Write the appropriate header.
|
||||
writer.write(HeaderItem.getMagicForApi(opcodes.api));
|
||||
|
||||
// checksum placeholder
|
||||
writer.writeInt(0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user