publicclass Main { publicstaticvoid main(String[] args) throws ClassNotFoundException {
System.loadLibrary(args[0]);
// Run the initialization routine. This will enable hidden API checks in // the runtime, in case they are not enabled by default.
init();
// Load the '-ex' APK and attach it to the boot class path.
appendToBootClassLoader(DEX_EXTRA, /* isCorePlatform */ false);
// Find the test class in boot class loader and verify that its members are hidden. Class<?> klass = Class.forName("art.Test999", true, BOOT_CLASS_LOADER);
assertFieldIsHidden(klass, "before redefinition");
assertMethodIsHidden(klass, "before redefinition");
// Redefine the class using JVMTI. Use dex file without hiddenapi flags.
art.Redefinition.setTestConfiguration(art.Redefinition.Config.COMMON_REDEFINE);
art.Redefinition.doCommonClassRedefinition(klass, CLASS_BYTES, DEX_BYTES);
// Verify that the class members are still hidden.
assertFieldIsHidden(klass, "after first redefinition");
assertMethodIsHidden(klass, "after first redefinition");
}
privatestaticvoid assertMethodIsHidden(Class<?> klass, String msg) { try {
klass.getDeclaredMethod("foo"); // Unexpected. Should have thrown NoSuchMethodException. thrownew RuntimeException("Method should not be accessible " + msg);
} catch (NoSuchMethodException ex) {
}
}
privatestaticvoid assertFieldIsHidden(Class<?> klass, String msg) { try {
klass.getDeclaredField("bar"); // Unexpected. Should have thrown NoSuchFieldException. thrownew RuntimeException("Field should not be accessible " + msg);
} catch (NoSuchFieldException ex) {
}
}
privatestaticfinal String DEX_EXTRA = new File(
System.getenv("DEX_LOCATION"), "999-redefine-hiddenapi-ex.jar").getAbsolutePath();
// Native functions. Note that these are implemented in 674-hiddenapi/hiddenapi.cc. privatestaticnativevoid appendToBootClassLoader(String dexPath, boolean isCorePlatform); privatestaticnativevoid init();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.