From 897c70b74a594d25b0d12676e6cb051ee58f0912 Mon Sep 17 00:00:00 2001 From: LoveSy Date: Tue, 6 Aug 2024 23:38:32 +0800 Subject: [PATCH] Make backup logic as a function --- lsplant/src/main/jni/art/runtime/art_method.cxx | 11 +++++++++++ lsplant/src/main/jni/lsplant.cc | 8 +------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lsplant/src/main/jni/art/runtime/art_method.cxx b/lsplant/src/main/jni/art/runtime/art_method.cxx index 1afe574..91e8ad2 100644 --- a/lsplant/src/main/jni/art/runtime/art_method.cxx +++ b/lsplant/src/main/jni/art/runtime/art_method.cxx @@ -155,6 +155,17 @@ public: reinterpret_cast(this) + declaring_class_offset)); } + void BackupTo(ArtMethod *backup) { + SetNonCompilable(); + + // copy after setNonCompilable + backup->CopyFrom(this); + + ClearFastInterpretFlag(); + + if (!backup->IsStatic()) backup->SetPrivate(); + } + static art::ArtMethod *FromReflectedMethod(JNIEnv *env, jobject method) { if (art_method_field) [[likely]] { return reinterpret_cast( diff --git a/lsplant/src/main/jni/lsplant.cc b/lsplant/src/main/jni/lsplant.cc index efd3bbe..9968127 100644 --- a/lsplant/src/main/jni/lsplant.cc +++ b/lsplant/src/main/jni/lsplant.cc @@ -592,18 +592,12 @@ bool DoHook(ArtMethod *target, ArtMethod *hook, ArtMethod *backup) { } else { LOGV("Generated trampoline %p", entrypoint); - target->SetNonCompilable(); hook->SetNonCompilable(); - // copy after setNonCompilable - backup->CopyFrom(target); - - target->ClearFastInterpretFlag(); + target->BackupTo(backup); target->SetEntryPoint(entrypoint); - if (!backup->IsStatic()) backup->SetPrivate(); - LOGV("Done hook: target(%p:0x%x) -> %p; backup(%p:0x%x) -> %p; hook(%p:0x%x) -> %p", target, target->GetAccessFlags(), target->GetEntryPoint(), backup, backup->GetAccessFlags(), backup->GetEntryPoint(), hook, hook->GetAccessFlags(), hook->GetEntryPoint());