Copy all OAT header

This commit is contained in:
kotori0 2020-12-19 17:55:52 +08:00
parent 83e1212a05
commit 91d2a150c1
1 changed files with 17 additions and 3 deletions

View File

@ -131,10 +131,24 @@ void *genTrampoline(void *toMethod, void *entrypoint) {
size_t size = entrypoint == NULL ? sizeof(trampoline) : sizeof(trampolineForBackup);
// TODO: make use of thread_local to avoid frequent memory allocate
char *targetAddr = doInitHookCap(size + 4);
size_t oatHeaderLen;
switch (SDKVersion) {
case __ANDROID_API_O__:
case __ANDROID_API_O_MR1__:
case __ANDROID_API_P__:
oatHeaderLen = 12 + 12; // 3*u32 + QuickMethodFrameInfo(3*u32)
break;
default:
LOGW("No valid offset in SDK %d for oatHeaderLen, using Android R", SDKVersion);
case __ANDROID_API_Q__:
case __ANDROID_API_R__:
oatHeaderLen = 8; // 2*u32
break;
}
char *targetAddr = doInitHookCap(size + oatHeaderLen);
// 4 bytes for AOT header, then copy code_size_.
memcpy(targetAddr, toMethod - 4, 4);
targetAddr += 4;
memcpy(targetAddr, toMethod - oatHeaderLen, oatHeaderLen);
targetAddr += oatHeaderLen;
if (targetAddr == NULL) return NULL;