Fix heap offset for all systems

This commit is contained in:
kotori0 2020-12-04 01:03:59 +08:00
parent d6c7570588
commit 1e9b307f54
1 changed files with 12 additions and 12 deletions

View File

@ -33,45 +33,45 @@ namespace art {
// @ApiSensitive(Level.MIDDLE) // @ApiSensitive(Level.MIDDLE)
static void Setup(void *handle, HookFunType hook_func) { static void Setup(void *handle, HookFunType hook_func) {
int api_level = edxp::GetAndroidApiLevel(); int api_level = edxp::GetAndroidApiLevel();
size_t OFFSET_classlinker; // Get offset from art::Runtime::RunRootClinits() call in IDA size_t OFFSET_heap; // Get offset from art::Runtime::RunRootClinits() call in IDA
switch (api_level) { switch (api_level) {
case __ANDROID_API_O__: case __ANDROID_API_O__:
[[fallthrough]]; [[fallthrough]];
case __ANDROID_API_O_MR1__: case __ANDROID_API_O_MR1__:
if constexpr(edxp::is64) { if constexpr(edxp::is64) {
OFFSET_classlinker = 464; OFFSET_heap = 0x180;
} else { } else {
OFFSET_classlinker = 284; OFFSET_heap = 0xF4;
} }
break; break;
case __ANDROID_API_P__: case __ANDROID_API_P__:
if constexpr(edxp::is64) { if constexpr(edxp::is64) {
OFFSET_classlinker = 528; OFFSET_heap = 0x1C0;
} else { } else {
OFFSET_classlinker = 336; OFFSET_heap = 0x128;
} }
break; break;
case __ANDROID_API_Q__: case __ANDROID_API_Q__:
if constexpr(edxp::is64) { if constexpr(edxp::is64) {
OFFSET_classlinker = 480; OFFSET_heap = 0x190;
} else { } else {
OFFSET_classlinker = 280; OFFSET_heap = 0xF0;
} }
break; break;
default: default:
LOGE("No valid offset for art::Runtime::class_linker_ found. Using Android R."); LOGE("No valid offset for art::Runtime::heap_ found. Using Android R.");
[[fallthrough]]; [[fallthrough]];
case __ANDROID_API_R__: case __ANDROID_API_R__:
if constexpr(edxp::is64) { if constexpr(edxp::is64) {
OFFSET_classlinker = 392; OFFSET_heap = 392;
} else { } else {
OFFSET_classlinker = 236; OFFSET_heap = 236;
} }
break; break;
} }
void *thiz = *reinterpret_cast<void **>( void *thiz = *reinterpret_cast<void **>(
reinterpret_cast<size_t>(Runtime::Current()->Get()) + OFFSET_classlinker); reinterpret_cast<size_t>(Runtime::Current()->Get()) + OFFSET_heap);
LOGD("HEAP object: %p", thiz); LOGD("art::runtime::Heap object: %p", thiz);
instance_ = new Heap(thiz); instance_ = new Heap(thiz);
RETRIEVE_FUNC_SYMBOL(WaitForGcToComplete, RETRIEVE_FUNC_SYMBOL(WaitForGcToComplete,
"_ZN3art2gc4Heap19WaitForGcToCompleteENS0_7GcCauseEPNS_6ThreadE"); "_ZN3art2gc4Heap19WaitForGcToCompleteENS0_7GcCauseEPNS_6ThreadE");