Do not initialize VeriClass java objects unless precise mode is enabled.
This allows running veridex in inprecise mode where --core-stubs do not have java.lang.* classes to resolve.
Test: manual
Change-Id: I8d9eb49c22437c9f4da0101777391658f18e9b8c
diff --git a/tools/veridex/veridex.cc b/tools/veridex/veridex.cc
index bababce..0253611 100644
--- a/tools/veridex/veridex.cc
+++ b/tools/veridex/veridex.cc
@@ -192,35 +192,36 @@
std::vector<std::unique_ptr<VeridexResolver>> boot_resolvers;
Resolve(boot_dex_files, resolver_map, type_map, &boot_resolvers);
- // Now that boot classpath has been resolved, fill classes and reflection
- // methods.
- VeriClass::object_ = type_map["Ljava/lang/Object;"];
- VeriClass::class_ = type_map["Ljava/lang/Class;"];
- VeriClass::class_loader_ = type_map["Ljava/lang/ClassLoader;"];
- VeriClass::string_ = type_map["Ljava/lang/String;"];
- VeriClass::throwable_ = type_map["Ljava/lang/Throwable;"];
- VeriClass::forName_ = boot_resolvers[0]->LookupDeclaredMethodIn(
- *VeriClass::class_, "forName", "(Ljava/lang/String;)Ljava/lang/Class;");
- VeriClass::getField_ = boot_resolvers[0]->LookupDeclaredMethodIn(
- *VeriClass::class_, "getField", "(Ljava/lang/String;)Ljava/lang/reflect/Field;");
- VeriClass::getDeclaredField_ = boot_resolvers[0]->LookupDeclaredMethodIn(
- *VeriClass::class_, "getDeclaredField", "(Ljava/lang/String;)Ljava/lang/reflect/Field;");
- VeriClass::getMethod_ = boot_resolvers[0]->LookupDeclaredMethodIn(
- *VeriClass::class_,
- "getMethod",
- "(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;");
- VeriClass::getDeclaredMethod_ = boot_resolvers[0]->LookupDeclaredMethodIn(
- *VeriClass::class_,
- "getDeclaredMethod",
- "(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;");
- VeriClass::getClass_ = boot_resolvers[0]->LookupDeclaredMethodIn(
- *VeriClass::object_, "getClass", "()Ljava/lang/Class;");
- VeriClass::loadClass_ = boot_resolvers[0]->LookupDeclaredMethodIn(
- *VeriClass::class_loader_, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;");
+ if (options.precise) {
+ // For precise mode we expect core-stubs to contain java.lang classes.
+ VeriClass::object_ = type_map["Ljava/lang/Object;"];
+ VeriClass::class_ = type_map["Ljava/lang/Class;"];
+ VeriClass::class_loader_ = type_map["Ljava/lang/ClassLoader;"];
+ VeriClass::string_ = type_map["Ljava/lang/String;"];
+ VeriClass::throwable_ = type_map["Ljava/lang/Throwable;"];
+ VeriClass::forName_ = boot_resolvers[0]->LookupDeclaredMethodIn(
+ *VeriClass::class_, "forName", "(Ljava/lang/String;)Ljava/lang/Class;");
+ VeriClass::getField_ = boot_resolvers[0]->LookupDeclaredMethodIn(
+ *VeriClass::class_, "getField", "(Ljava/lang/String;)Ljava/lang/reflect/Field;");
+ VeriClass::getDeclaredField_ = boot_resolvers[0]->LookupDeclaredMethodIn(
+ *VeriClass::class_, "getDeclaredField", "(Ljava/lang/String;)Ljava/lang/reflect/Field;");
+ VeriClass::getMethod_ = boot_resolvers[0]->LookupDeclaredMethodIn(
+ *VeriClass::class_,
+ "getMethod",
+ "(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;");
+ VeriClass::getDeclaredMethod_ = boot_resolvers[0]->LookupDeclaredMethodIn(
+ *VeriClass::class_,
+ "getDeclaredMethod",
+ "(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;");
+ VeriClass::getClass_ = boot_resolvers[0]->LookupDeclaredMethodIn(
+ *VeriClass::object_, "getClass", "()Ljava/lang/Class;");
+ VeriClass::loadClass_ = boot_resolvers[0]->LookupDeclaredMethodIn(
+ *VeriClass::class_loader_, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;");
- VeriClass* version = type_map["Landroid/os/Build$VERSION;"];
- if (version != nullptr) {
- VeriClass::sdkInt_ = boot_resolvers[0]->LookupFieldIn(*version, "SDK_INT", "I");
+ VeriClass* version = type_map["Landroid/os/Build$VERSION;"];
+ if (version != nullptr) {
+ VeriClass::sdkInt_ = boot_resolvers[0]->LookupFieldIn(*version, "SDK_INT", "I");
+ }
}
std::vector<std::unique_ptr<VeridexResolver>> app_resolvers;