Fix soft reboot of YAHFA (Fix OatQuickMethodHeader issue)

This commit is contained in:
LoveSy 2021-01-28 17:48:27 +08:00
parent b04d830fba
commit 0ba98eaf62
4 changed files with 0 additions and 135 deletions

View File

@ -10,10 +10,6 @@
namespace art {
namespace art_method {
inline static size_t oat_header_length;
inline static int32_t oat_header_code_length_offset;
CREATE_MEM_FUNC_SYMBOL_ENTRY(std::string, PrettyMethod, void *thiz, bool with_signature) {
if (UNLIKELY(thiz == nullptr))
return "null";
@ -26,67 +22,8 @@ namespace art {
return PrettyMethod(thiz, true);
}
// CREATE_MEM_HOOK_STUB_ENTRIES(
// LP_SELECT("_ZN3art9ArtMethod23GetOatQuickMethodHeaderEj", "_ZN3art9ArtMethod23GetOatQuickMethodHeaderEm"),
// void *, GetOatQuickMethodHeader,
// (void * thiz, uintptr_t pc), {
// // This is a partial copy from AOSP. We only touch them if they are hooked.
// if (UNLIKELY(edxp::isHooked(thiz))) {
// uintptr_t original_ep =
// reinterpret_cast<uintptr_t>(getOriginalEntryPointFromTargetMethod(
// thiz)) & ~0x1;
// if (original_ep) {
// char *code_length_loc =
// reinterpret_cast<char *>(original_ep) +
// oat_header_code_length_offset;
// uint32_t code_length =
// *reinterpret_cast<uint32_t *>(code_length_loc) &
// ~0x80000000u;
// LOGD("art_method::GetOatQuickMethodHeader: ArtMethod=%p (%s), isHooked=true, original_ep=0x%zux, code_length=0x%x, pc=0x%zux",
// thiz, PrettyMethod(thiz).c_str(),
// original_ep, code_length, pc);
// if (original_ep <= pc &&
// pc <= original_ep + code_length)
// return reinterpret_cast<void *>(
// original_ep -
// oat_header_length);
// // If PC is not in range, we mark it as not found.
// LOGD("art_method::GetOatQuickMethodHeader: PC not found in current method.");
// return nullptr;
// } else {
// LOGD("art_method::GetOatQuickMethodHeader: ArtMethod=%p (%s) isHooked but not backup, fallback to system",
// thiz, PrettyMethod(thiz).c_str());
// }
// }
// return backup(thiz, pc);
// });
static void Setup(void *handle, HookFunType hook_func) {
LOGD("art_method hook setup, handle=%p", handle);
int api_level = edxp::GetAndroidApiLevel();
switch (api_level) {
case __ANDROID_API_O__:
[[fallthrough]];
case __ANDROID_API_O_MR1__:
[[fallthrough]];
case __ANDROID_API_P__:
oat_header_length = 24;
oat_header_code_length_offset = -4;
break;
default:
LOGW("No valid offset in SDK %d for oat_header_length, using offset from Android R",
api_level);
[[fallthrough]];
case __ANDROID_API_Q__:
[[fallthrough]];
case __ANDROID_API_R__:
oat_header_length = 8;
oat_header_code_length_offset = -4;
break;
}
// edxp::HookSyms(handle, hook_func, GetOatQuickMethodHeader);
RETRIEVE_MEM_FUNC_SYMBOL(PrettyMethod, "_ZN3art9ArtMethod12PrettyMethodEb");
}
}

View File

@ -1,34 +0,0 @@
#pragma once
#include "base/object.h"
#include "art/runtime/art_method.h"
namespace art {
namespace jit {
// CREATE_MEM_HOOK_STUB_ENTRIES("_ZN3art3jit12JitCodeCache37GetSavedEntryPointOfPreCompiledMethodEPNS_9ArtMethodE",
// const void*, GetSavedEntryPointOfPreCompiledMethod, (void *thiz,
// void *art_method), {
// if (UNLIKELY(edxp::isHooked(art_method))) {
// LOGD("Found hooked method %p (%s), return entrypoint as jit entrypoint", art_method,
// art::art_method::PrettyMethod(art_method).c_str());
// return getEntryPoint(art_method);
// }
// return backup(thiz, art_method);
// });
//
static void HookJitCacheCode(void *handle, HookFunType hook_func) {
const int api_level = edxp::GetAndroidApiLevel();
// For android R, the invisibly initialization makes static methods initializes multiple
// times in non-x86 devices. So we need to hook this function to make sure
// our hooked entry point won't be overwritten.
// This is for SandHook and YAHFA
if (api_level >= __ANDROID_API_R__) {
// edxp::HookSyms(handle, hook_func, GetSavedEntryPointOfPreCompiledMethod);
}
}
}
}

View File

@ -1,34 +0,0 @@
#pragma once
#include "base/object.h"
namespace art {
namespace oat_file_manager {
CREATE_HOOK_STUB_ENTRIES(
"_ZN3art14OatFileManager24SetOnlyUseSystemOatFilesEv", // 9 & 11
void, SetOnlyUseSystemOatFiles, (), {
return;
});
CREATE_HOOK_STUB_ENTRIES(
"_ZN3art14OatFileManager24SetOnlyUseSystemOatFilesEbb", // 10
void, SetOnlyUseSystemOatFilesQ, (), {
return;
});
// @ApiSensitive(Level.LOW)
// http://androidxref.com/9.0.0_r3/xref/art/runtime/oat_file_manager.cc#637
static void DisableOnlyUseSystemOatFiles(void *handle, HookFunType hook_func) {
const int api_level = edxp::GetAndroidApiLevel();
if (api_level >= __ANDROID_API_P__) {
edxp::HookSyms(handle, hook_func, SetOnlyUseSystemOatFiles,
SetOnlyUseSystemOatFilesQ);
}
}
}
}

View File

@ -17,8 +17,6 @@
#include "art/runtime/class_linker.h"
#include "art/runtime/gc/heap.h"
#include "art/runtime/hidden_api.h"
#include "art/runtime/oat_file_manager.h"
#include "art/runtime/jit/jit_code_cache.h"
#include "art/runtime/art_method.h"
#include "art/runtime/instrumentation.h"
#include "art/runtime/reflection.h"
@ -84,8 +82,6 @@ namespace edxp {
art::ClassLinker::Setup(art_handle, hook_func);
art::mirror::Class::Setup(art_handle, hook_func);
art::JNIEnvExt::Setup(art_handle, hook_func);
// art::oat_file_manager::DisableOnlyUseSystemOatFiles(art_handle, hook_func);
// art::jit::HookJitCacheCode(art_handle, hook_func);
art::instrumentation::DisableUpdateHookedMethodsCode(art_handle, hook_func);
art::PermissiveAccessByReflection(art_handle, hook_func);