Properly implement the art <-> api version map

This commit is contained in:
Ben Gruver 2016-10-02 16:05:22 -07:00
parent c2231759f5
commit 219bdff2d1
2 changed files with 48 additions and 12 deletions

View File

@ -39,6 +39,10 @@ import javax.annotation.Nullable;
import java.util.EnumMap;
import java.util.HashMap;
import static org.jf.dexlib2.VersionMap.NO_VERSION;
import static org.jf.dexlib2.VersionMap.mapApiToArtVersion;
import static org.jf.dexlib2.VersionMap.mapArtVersionToApi;
public class Opcodes {
/**
@ -52,12 +56,12 @@ public class Opcodes {
@Nonnull
public static Opcodes forApi(int api) {
return new Opcodes(api, VersionMap.mapApiToArtVersion(api));
return new Opcodes(api, NO_VERSION);
}
@Nonnull
public static Opcodes forArtVersion(int artVersion) {
return new Opcodes(VersionMap.mapArtVersionToApi(artVersion), artVersion);
return new Opcodes(NO_VERSION, artVersion);
}
/**
@ -70,8 +74,18 @@ public class Opcodes {
}
private Opcodes(int api, int artVersion) {
if (api >= 21) {
this.api = api;
this.artVersion = mapApiToArtVersion(api);
} else if (artVersion >= 0 && artVersion < 39) {
this.api = mapArtVersionToApi(artVersion);
this.artVersion = artVersion;
} else {
this.api = api;
this.artVersion = artVersion;
}
opcodeValues = new EnumMap<Opcode, Short>(Opcode.class);
opcodesByName = Maps.newHashMap();
@ -131,6 +145,6 @@ public class Opcodes {
}
public boolean isArt() {
return artVersion != VersionMap.NO_VERSION;
return artVersion != NO_VERSION;
}
}

View File

@ -35,16 +35,38 @@ public class VersionMap {
public static final int NO_VERSION = -1;
public static int mapArtVersionToApi(int artVersion) {
// TODO: implement this
return 20;
if (artVersion >= 79) {
return 24;
}
if (artVersion >= 64) {
return 23;
}
if (artVersion >= 45) {
return 22;
}
if (artVersion >= 39) {
return 21;
}
return 19;
}
public static int mapApiToArtVersion(int api) {
// TODO: implement this
if (api < 20) {
switch (api) {
case 19:
case 20:
return 7;
case 21:
return 39;
case 22:
return 45;
case 23:
return 64;
case 24:
return 79;
}
if (api > 24) {
return 79;
}
return NO_VERSION;
} else {
return 56;
}
}
}