aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Herman <davidherman@google.com>2019-11-20 15:16:41 -0800
committerDavid Herman <davidherman@google.com>2019-11-20 16:31:19 -0800
commitd0dccb6533e4ccd17c6733e7220a70b197a89920 (patch)
tree25c71d2af0f551511f7172981ebb583ab3a5f6c3
parent1925e38f36d2c3951254def125eece70fe01b844 (diff)
downloadplatform_tools_dexter-d0dccb6533e4ccd17c6733e7220a70b197a89920.tar.gz
platform_tools_dexter-d0dccb6533e4ccd17c6733e7220a70b197a89920.tar.bz2
platform_tools_dexter-d0dccb6533e4ccd17c6733e7220a70b197a89920.zip
Change EntryHook API to take an enum instead of a bool
Besides more readability, this will help in a followup CL where we need to add a new behavior. Bug: N/A Test: Covered by existing Change-Id: If6caf171abe1dc88650dc72a633faeee6fb53ee9
-rw-r--r--dexter/experimental.cc7
-rw-r--r--slicer/export/slicer/instrumentation.h29
-rw-r--r--slicer/instrumentation.cc11
3 files changed, 32 insertions, 15 deletions
diff --git a/dexter/experimental.cc b/dexter/experimental.cc
index 97a126a..545a340 100644
--- a/dexter/experimental.cc
+++ b/dexter/experimental.cc
@@ -291,8 +291,11 @@ void StressExitHook(std::shared_ptr<ir::DexFile> dex_ir) {
// 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"), true);
- mi.AddTransformation<slicer::EntryHook>(ir::MethodId("LTracer;", "onFooEntry"), false);
+ mi.AddTransformation<slicer::EntryHook>(
+ ir::MethodId("LTracer;", "onFooEntry"),
+ slicer::EntryHook::Tweak::ThisAsObject);
+ mi.AddTransformation<slicer::EntryHook>(
+ ir::MethodId("LTracer;", "onFooEntry"));
mi.AddTransformation<slicer::ExitHook>(ir::MethodId("LTracer;", "onFooExit"));
mi.AddTransformation<slicer::DetourVirtualInvoke>(
ir::MethodId("LBase;", "foo", "(ILjava/lang/String;)I"),
diff --git a/slicer/export/slicer/instrumentation.h b/slicer/export/slicer/instrumentation.h
index c6ad454..b9fda8c 100644
--- a/slicer/export/slicer/instrumentation.h
+++ b/slicer/export/slicer/instrumentation.h
@@ -40,23 +40,34 @@ class Transformation {
// an explicit "this" argument for non-static methods.
class EntryHook : public Transformation {
public:
- 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) {
+ enum class Tweak {
+ None,
+ // Expose the "this" argument of non-static methods as the "Object" type.
+ // This can be helpful when the code you want to handle the hook doesn't
+ // have access to the actual type in its classpath.
+ ThisAsObject
+ };
+
+ explicit EntryHook(const ir::MethodId& hook_method_id, Tweak tweak)
+ : hook_method_id_(hook_method_id), tweak_(tweak) {
// hook method signature is generated automatically
SLICER_CHECK(hook_method_id_.signature == nullptr);
}
+ // TODO: Delete this legacy constrcutor.
+ // It is left in temporarily so we can move callers away from it to the new
+ // `tweak` constructor.
+ explicit EntryHook(const ir::MethodId& hook_method_id,
+ bool use_object_type_for_this_argument = false)
+ : EntryHook(hook_method_id, use_object_type_for_this_argument
+ ? Tweak::ThisAsObject
+ : Tweak::None) {}
+
virtual bool Apply(lir::CodeIr* code_ir) override;
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_;
+ Tweak tweak_;
};
// Insert a call to the "exit hook" method before every return
diff --git a/slicer/instrumentation.cc b/slicer/instrumentation.cc
index 0781594..83a524d 100644
--- a/slicer/instrumentation.cc
+++ b/slicer/instrumentation.cc
@@ -39,10 +39,13 @@ bool EntryHook::Apply(lir::CodeIr* code_ir) {
std::vector<ir::Type*> param_types;
if ((ir_method->access_flags & dex::kAccStatic) == 0) {
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;
+ switch (tweak_) {
+ case Tweak::ThisAsObject:
+ this_argument_type = builder.GetType("Ljava/lang/Object;");
+ break;
+ default:
+ this_argument_type = ir_method->decl->parent;
+ break;
}
param_types.push_back(this_argument_type);
}