| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
import java.io.File; |
| 18 |
import java.lang.reflect.Method; |
| 19 |
import java.util.Base64; |
| 20 |
|
| 21 |
public class Main { |
| 22 |
public static void main(String[] args) throws ClassNotFoundException { |
| 23 |
System.loadLibrary(args[0]); |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
init(); |
| 28 |
|
| 29 |
|
| 30 |
appendToBootClassLoader(DEX_EXTRA, false); |
| 31 |
|
| 32 |
|
| 33 |
Class<?> klass = Class.forName("art.Test2038", true, BOOT_CLASS_LOADER); |
| 34 |
assertFieldIsHidden(klass, "before set-policy"); |
| 35 |
assertMethodIsHidden(klass, "before set-policy"); |
| 36 |
|
| 37 |
int old_policy = disablePolicy(); |
| 38 |
|
| 39 |
|
| 40 |
assertFieldNotHidden(klass, "after disable-policy"); |
| 41 |
assertMethodNotHidden(klass, "after disable-policy"); |
| 42 |
|
| 43 |
setPolicy(old_policy); |
| 44 |
|
| 45 |
assertFieldIsHidden(klass, "after set-policy 2"); |
| 46 |
assertMethodIsHidden(klass, "after set-policy 2"); |
| 47 |
} |
| 48 |
|
| 49 |
private static void assertMethodNotHidden(Class<?> klass, String msg) { |
| 50 |
try { |
| 51 |
klass.getDeclaredMethod("foo"); |
| 52 |
} catch (NoSuchMethodException ex) { |
| 53 |
|
| 54 |
throw new RuntimeException("Method should be accessible " + msg); |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
private static void assertFieldNotHidden(Class<?> klass, String msg) { |
| 59 |
try { |
| 60 |
klass.getDeclaredField("bar"); |
| 61 |
} catch (NoSuchFieldException ex) { |
| 62 |
|
| 63 |
throw new RuntimeException("Field should be accessible " + msg); |
| 64 |
} |
| 65 |
} |
| 66 |
private static void assertMethodIsHidden(Class<?> klass, String msg) { |
| 67 |
try { |
| 68 |
klass.getDeclaredMethod("foo"); |
| 69 |
|
| 70 |
throw new RuntimeException("Method should not be accessible " + msg); |
| 71 |
} catch (NoSuchMethodException ex) { |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
private static void assertFieldIsHidden(Class<?> klass, String msg) { |
| 76 |
try { |
| 77 |
klass.getDeclaredField("bar"); |
| 78 |
|
| 79 |
throw new RuntimeException("Field should not be accessible " + msg); |
| 80 |
} catch (NoSuchFieldException ex) { |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
private static final String DEX_EXTRA = |
| 85 |
new File(System.getenv("DEX_LOCATION"), "2038-hiddenapi-jvmti-ext-ex.jar").getAbsolutePath(); |
| 86 |
|
| 87 |
private static ClassLoader BOOT_CLASS_LOADER = Object.class.getClassLoader(); |
| 88 |
|
| 89 |
|
| 90 |
private static native void appendToBootClassLoader(String dexPath, boolean isCorePlatform); |
| 91 |
private static native void init(); |
| 92 |
|
| 93 |
|
| 94 |
private static native int setPolicy(int new_policy); |
| 95 |
private static native int disablePolicy(); |
| 96 |
} |