Make EntryHook's this argument can be forwarded as Object type.
Bug: 63118776
EntryHook already has /this/ argument but not of Object type,
tests EntryHook for both non-Object type and Object type.
Test: dexter_tests
Change-Id: Ia46fe5305d34a3813089e02c6a6e2b587872de4f
diff --git a/dexter/experimental.cc b/dexter/experimental.cc
index 714d22a..5f9c14b 100644
--- a/dexter/experimental.cc
+++ b/dexter/experimental.cc
@@ -291,7 +291,8 @@
// Test slicer::MethodInstrumenter
void TestMethodInstrumenter(std::shared_ptr<ir::DexFile> dex_ir) {
slicer::MethodInstrumenter mi(dex_ir);
- mi.AddTransformation<slicer::EntryHook>(ir::MethodId("LTracer;", "onFooEntry"));
+ mi.AddTransformation<slicer::EntryHook>(ir::MethodId("LTracer;", "onFooEntry"), true);
+ mi.AddTransformation<slicer::EntryHook>(ir::MethodId("LTracer;", "onFooEntry"), false);
mi.AddTransformation<slicer::ExitHook>(ir::MethodId("LTracer;", "onFooExit"));
mi.AddTransformation<slicer::DetourVirtualInvoke>(
ir::MethodId("LBase;", "foo", "(ILjava/lang/String;)I"),
diff --git a/slicer/instrumentation.cc b/slicer/instrumentation.cc
index 80280fe..89dcb3a 100644
--- a/slicer/instrumentation.cc
+++ b/slicer/instrumentation.cc
@@ -26,7 +26,13 @@
// construct the hook method declaration
std::vector<ir::Type*> param_types;
if ((ir_method->access_flags & dex::kAccStatic) == 0) {
- param_types.push_back(ir_method->decl->parent);
+ ir::Type* this_argument_type;
+ if (use_object_type_for_this_argument_) {
+ this_argument_type = builder.GetType("Ljava/lang/Object;");
+ } else {
+ this_argument_type = ir_method->decl->parent;
+ }
+ param_types.push_back(this_argument_type);
}
if (ir_method->decl->prototype->param_types != nullptr) {
const auto& orig_param_types = ir_method->decl->prototype->param_types->types;
diff --git a/slicer/instrumentation.h b/slicer/instrumentation.h
index a131d39..eae4517 100644
--- a/slicer/instrumentation.h
+++ b/slicer/instrumentation.h
@@ -40,7 +40,11 @@
// an explicit "this" argument for non-static methods.
class EntryHook : public Transformation {
public:
- explicit EntryHook(const ir::MethodId& hook_method_id) : hook_method_id_(hook_method_id) {
+ explicit EntryHook(
+ const ir::MethodId& hook_method_id,
+ bool use_object_type_for_this_argument = false)
+ : hook_method_id_(hook_method_id),
+ use_object_type_for_this_argument_(use_object_type_for_this_argument) {
// hook method signature is generated automatically
CHECK(hook_method_id_.signature == nullptr);
}
@@ -49,6 +53,10 @@
private:
ir::MethodId hook_method_id_;
+ // If true, "this" argument of non-static methods is forwarded as Object type.
+ // For example "this" argument of OkHttpClient type is forwared as Object and
+ // is used to get OkHttp class loader.
+ bool use_object_type_for_this_argument_;
};
// Insert a call to the "exit hook" method before every return