remove libsandhook-native.so

This commit is contained in:
LoveSy 2020-12-11 17:19:18 +08:00 committed by kotori0
parent 9c0a5d6abc
commit f3fa952b25
7 changed files with 11 additions and 67 deletions

View File

@ -124,13 +124,8 @@ namespace art {
HOOK_FUNC(FixupStaticTrampolines, HOOK_FUNC(FixupStaticTrampolines,
"_ZN3art11ClassLinker22FixupStaticTrampolinesENS_6ObjPtrINS_6mirror5ClassEEE"); "_ZN3art11ClassLinker22FixupStaticTrampolinesENS_6ObjPtrINS_6mirror5ClassEEE");
// Sandhook will hook ShouldUseInterpreterEntrypoint, so we just skip HOOK_FUNC(ShouldUseInterpreterEntrypoint,
// edxp::Context::GetInstance()->GetVariant() will not work here, so we use smh dirty hack "_ZN3art11ClassLinker30ShouldUseInterpreterEntrypointEPNS_9ArtMethodEPKv");
if (!edxp::path_exists(edxp::kLibSandHookNativePath)) {
LOGD("Not sandhook, installing _ZN3art11ClassLinker30ShouldUseInterpreterEntrypointEPNS_9ArtMethodEPKv");
HOOK_FUNC(ShouldUseInterpreterEntrypoint,
"_ZN3art11ClassLinker30ShouldUseInterpreterEntrypointEPNS_9ArtMethodEPKv");
}
// MakeInitializedClassesVisiblyInitialized will cause deadlock // MakeInitializedClassesVisiblyInitialized will cause deadlock
// IsQuickToInterpreterBridge cannot be hooked by Dobby yet // IsQuickToInterpreterBridge cannot be hooked by Dobby yet

View File

@ -37,15 +37,12 @@ inline constexpr bool is64 = Is64();
static const auto kLibArtName = "libart.so"s; static const auto kLibArtName = "libart.so"s;
static const auto kLibFwName = "libandroidfw.so"s; static const auto kLibFwName = "libandroidfw.so"s;
static const auto kLibSandHookName = "libsandhook.edxp.so"s; static const auto kLibSandHookName = "libsandhook.edxp.so"s;
static const auto kLibDlName = "libdl.so"s;
static const auto kLibSandHookNativeName = "libsandhook-native.so"s;
static const auto kLibBasePath = static const auto kLibBasePath =
LP_SELECT("/system/lib/"s, LP_SELECT("/system/lib/"s,
"/system/lib64/"s); "/system/lib64/"s);
static const auto kLibArtLegacyPath = kLibBasePath + kLibArtName; static const auto kLibArtLegacyPath = kLibBasePath + kLibArtName;
static const auto kLibSandHookPath = kLibBasePath + kLibSandHookName; static const auto kLibSandHookPath = kLibBasePath + kLibSandHookName;
static const auto kLibSandHookNativePath = kLibBasePath + kLibSandHookNativeName;
static const auto kLibFwPath = kLibBasePath + kLibFwName; static const auto kLibFwPath = kLibBasePath + kLibFwName;
inline constexpr const char *const BoolToString(bool b) { inline constexpr const char *const BoolToString(bool b) {

View File

@ -246,7 +246,6 @@ else
ui_print "- Extracting arm libraries" ui_print "- Extracting arm libraries"
extract "$ZIPFILE" 'system/lib/libriru_edxp.so' "$MODPATH" extract "$ZIPFILE" 'system/lib/libriru_edxp.so' "$MODPATH"
if [[ "${VARIANTS}" == "SandHook" ]]; then if [[ "${VARIANTS}" == "SandHook" ]]; then
extract "$ZIPFILE" 'system/lib/libsandhook-native.so' "$MODPATH"
extract "$ZIPFILE" 'system/lib/libsandhook.edxp.so' "$MODPATH" extract "$ZIPFILE" 'system/lib/libsandhook.edxp.so' "$MODPATH"
fi fi
@ -254,7 +253,6 @@ else
ui_print "- Extracting arm64 libraries" ui_print "- Extracting arm64 libraries"
extract "$ZIPFILE" 'system/lib64/libriru_edxp.so' "$MODPATH" extract "$ZIPFILE" 'system/lib64/libriru_edxp.so' "$MODPATH"
if [[ "${VARIANTS}" == "SandHook" ]]; then if [[ "${VARIANTS}" == "SandHook" ]]; then
extract "$ZIPFILE" 'system/lib64/libsandhook-native.so' "$MODPATH"
extract "$ZIPFILE" 'system/lib64/libsandhook.edxp.so' "$MODPATH" extract "$ZIPFILE" 'system/lib64/libsandhook.edxp.so' "$MODPATH"
fi fi
fi fi

View File

@ -30,23 +30,9 @@ extern "C" {
void (*profileSaver_ForceProcessProfiles)() = nullptr; void (*profileSaver_ForceProcessProfiles)() = nullptr;
//for Android R jfieldID fieldArtMethod = nullptr;
void *jniIdManager = nullptr;
ArtMethod *(*origin_DecodeArtMethodId)(void *thiz, jmethodID jmethodId) = nullptr;
ArtMethod *replace_DecodeArtMethodId(void *thiz, jmethodID jmethodId) {
jniIdManager = thiz;
return origin_DecodeArtMethodId(thiz, jmethodId);
}
bool (*origin_ShouldUseInterpreterEntrypoint)(ArtMethod *artMethod, const void* quick_code) = nullptr; // paths
bool replace_ShouldUseInterpreterEntrypoint(ArtMethod *artMethod, const void* quick_code) {
if (SandHook::TrampolineManager::get().methodHooked(artMethod) && quick_code != nullptr) {
return false;
}
return origin_ShouldUseInterpreterEntrypoint(artMethod, quick_code);
}
// paths
const char* art_lib_path; const char* art_lib_path;
const char* jit_lib_path; const char* jit_lib_path;
@ -139,32 +125,9 @@ extern "C" {
profileSaver_ForceProcessProfiles = reinterpret_cast<void (*)()>(getSymCompat(art_lib_path, "_ZN3art12ProfileSaver20ForceProcessProfilesEv")); profileSaver_ForceProcessProfiles = reinterpret_cast<void (*)()>(getSymCompat(art_lib_path, "_ZN3art12ProfileSaver20ForceProcessProfilesEv"));
} }
//init native hook lib if (SDK_INT >=ANDROID_R) {
void* native_hook_handle = dlopen("libsandhook-native.so", RTLD_LAZY | RTLD_GLOBAL); auto classExecutable = env->FindClass("java/lang/reflect/Executable");
if (native_hook_handle) { fieldArtMethod = env->GetFieldID(classExecutable, "artMethod", "J");
hook_native = reinterpret_cast<void *(*)(void *, void *)>(dlsym(native_hook_handle, "SandInlineHook"));
} else {
hook_native = reinterpret_cast<void *(*)(void *, void *)>(getSymCompat(
"libsandhook-native.so", "SandInlineHook"));
}
if (SDK_INT >= ANDROID_R && hook_native) {
const char *symbol_decode_method = sizeof(void*) == 8 ? "_ZN3art3jni12JniIdManager15DecodeGenericIdINS_9ArtMethodEEEPT_m" : "_ZN3art3jni12JniIdManager15DecodeGenericIdINS_9ArtMethodEEEPT_j";
void *decodeArtMethod = getSymCompat(art_lib_path, symbol_decode_method);
if (art_lib_path != nullptr) {
origin_DecodeArtMethodId = reinterpret_cast<ArtMethod *(*)(void *,
jmethodID)>(hook_native(
decodeArtMethod,
reinterpret_cast<void *>(replace_DecodeArtMethodId)));
}
void *shouldUseInterpreterEntrypoint = getSymCompat(art_lib_path,
"_ZN3art11ClassLinker30ShouldUseInterpreterEntrypointEPNS_9ArtMethodEPKv");
if (shouldUseInterpreterEntrypoint != nullptr) {
origin_ShouldUseInterpreterEntrypoint = reinterpret_cast<bool (*)(ArtMethod *,
const void *)>(hook_native(
shouldUseInterpreterEntrypoint,
reinterpret_cast<void *>(replace_ShouldUseInterpreterEntrypoint)));
}
} }
} }
@ -283,8 +246,7 @@ extern "C" {
void fake_jit_update_options(void* handle) { void fake_jit_update_options(void* handle) {
//do nothing //do nothing
LOGW("android q: art request update compiler options"); LOGW("android q: art request update compiler options");
return; }
}
bool replaceUpdateCompilerOptionsQ() { bool replaceUpdateCompilerOptionsQ() {
if (SDK_INT < ANDROID_Q) if (SDK_INT < ANDROID_Q)
@ -349,16 +311,10 @@ extern "C" {
} }
ArtMethod* getArtMethod(JNIEnv *env, jobject method) { ArtMethod* getArtMethod(JNIEnv *env, jobject method) {
jmethodID methodId = env->FromReflectedMethod(method); if (SDK_INT >= ANDROID_R) {
if (SDK_INT >= ANDROID_R && isIndexId(methodId)) { return reinterpret_cast<ArtMethod *>(env->GetLongField(method, fieldArtMethod));
if (origin_DecodeArtMethodId == nullptr || jniIdManager == nullptr) {
auto res = callStaticMethodAddr(env, "com/swift/sandhook/SandHook", "getArtMethod",
"(Ljava/lang/reflect/Member;)J", method);
return reinterpret_cast<ArtMethod *>(res);
} else {
return origin_DecodeArtMethodId(jniIdManager, methodId);
}
} else { } else {
jmethodID methodId = env->FromReflectedMethod(method);
return reinterpret_cast<ArtMethod *>(methodId); return reinterpret_cast<ArtMethod *>(methodId);
} }
} }

View File

@ -95,8 +95,6 @@ public class SandHook {
if (SandHookConfig.delayHook && PendingHookHandler.canWork() && ClassStatusUtils.isStaticAndNoInited(entity.target)) { if (SandHookConfig.delayHook && PendingHookHandler.canWork() && ClassStatusUtils.isStaticAndNoInited(entity.target)) {
PendingHookHandler.addPendingHook(entity); PendingHookHandler.addPendingHook(entity);
return; return;
} else if (entity.initClass) {
resolveStaticMethod(target);
} }
resolveStaticMethod(backup); resolveStaticMethod(backup);