1 /* 2 * Copyright 2015, Google Inc. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: 8 * 9 * Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * Redistributions in binary form must reproduce the above 12 * copyright notice, this list of conditions and the following disclaimer 13 * in the documentation and/or other materials provided with the 14 * distribution. 15 * Neither the name of Google Inc. nor the names of its 16 * contributors may be used to endorse or promote products derived from 17 * this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 package org.jf.dexlib2; 33 34 public class VersionMap { 35 public static final int NO_VERSION = -1; 36 mapDexVersionToApi(int dexVersion)37 public static int mapDexVersionToApi(int dexVersion) { 38 switch (dexVersion) { 39 case 35: 40 return 23; 41 case 37: 42 return 25; 43 case 38: 44 return 27; 45 case 39: 46 return 28; 47 default: 48 return NO_VERSION; 49 } 50 } 51 mapApiToDexVersion(int api)52 public static int mapApiToDexVersion(int api) { 53 if (api <= 23) { 54 return 35; 55 } 56 if (api <= 25) { 57 return 37; 58 } 59 if (api <= 27) { 60 return 38; 61 } 62 return 39; 63 } 64 mapArtVersionToApi(int artVersion)65 public static int mapArtVersionToApi(int artVersion) { 66 // 144 is the current version in the master branch of AOSP as of 2018-05-22 67 if (artVersion >= 144) { 68 return 28; 69 } 70 if (artVersion >= 131) { 71 return 27; 72 } 73 if (artVersion >= 124) { 74 return 26; 75 } 76 if (artVersion >= 79) { 77 return 24; 78 } 79 if (artVersion >= 64) { 80 return 23; 81 } 82 if (artVersion >= 45) { 83 return 22; 84 } 85 if (artVersion >= 39) { 86 return 21; 87 } 88 return 19; 89 } 90 mapApiToArtVersion(int api)91 public static int mapApiToArtVersion(int api) { 92 if (api < 19) { 93 return NO_VERSION; 94 } 95 96 switch (api) { 97 case 19: 98 case 20: 99 return 7; 100 case 21: 101 return 39; 102 case 22: 103 return 45; 104 case 23: 105 return 64; 106 case 24: 107 case 25: 108 return 79; 109 case 26: 110 return 124; 111 case 27: 112 return 131; 113 default: 114 // 144 is the current version in the master branch of AOSP as of 2018-05-22 115 return 144; 116 } 117 } 118 } 119