Support attach debugger to hooked process (#1807)
This commit is contained in:
parent
3ca1478a3a
commit
a884c1b2ba
|
|
@ -17,7 +17,6 @@
|
||||||
* Copyright (C) 2021 LSPosed Contributors
|
* Copyright (C) 2021 LSPosed Contributors
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.android.build.gradle.internal.dsl.BuildType
|
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
|
|
@ -78,7 +77,7 @@ android {
|
||||||
signingConfig = if (it.storeFile?.exists() == true) it
|
signingConfig = if (it.storeFile?.exists() == true) it
|
||||||
else signingConfigs.named("debug").get()
|
else signingConfigs.named("debug").get()
|
||||||
isMinifyEnabled = true
|
isMinifyEnabled = true
|
||||||
(this as BuildType).isShrinkResources = true
|
isShrinkResources = true
|
||||||
proguardFiles("proguard-rules.pro")
|
proguardFiles("proguard-rules.pro")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -101,12 +100,6 @@ autoResConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
materialThemeBuilder {
|
materialThemeBuilder {
|
||||||
// fun Theme.emplace() {
|
|
||||||
// lightThemeFormat.set("ThemeOverlay.Light.%s")
|
|
||||||
// darkThemeFormat.set("ThemeOverlay.Dark.%s")
|
|
||||||
//
|
|
||||||
// themes.add(this)
|
|
||||||
// }
|
|
||||||
themes {
|
themes {
|
||||||
for ((name, color) in listOf(
|
for ((name, color) in listOf(
|
||||||
"Red" to "F44336",
|
"Red" to "F44336",
|
||||||
|
|
|
||||||
|
|
@ -28,13 +28,15 @@
|
||||||
namespace art {
|
namespace art {
|
||||||
|
|
||||||
namespace hidden_api {
|
namespace hidden_api {
|
||||||
|
inline static bool is_debuggable = false;
|
||||||
|
|
||||||
using lsplant::operator""_tstr;
|
using lsplant::operator""_tstr;
|
||||||
CREATE_FUNC_SYMBOL_ENTRY(void, DexFile_setTrusted, JNIEnv *env, jclass clazz,
|
CREATE_FUNC_SYMBOL_ENTRY(void, DexFile_setTrusted, JNIEnv *env, jclass clazz,
|
||||||
jobject j_cookie) {
|
jobject j_cookie) {
|
||||||
if (DexFile_setTrustedSym != nullptr) [[likely]] {
|
if (DexFile_setTrustedSym != nullptr) [[likely]] {
|
||||||
Runtime::Current()->SetJavaDebuggable(true);
|
if (!is_debuggable) Runtime::Current()->SetJavaDebuggable(true);
|
||||||
DexFile_setTrustedSym(env, clazz, j_cookie);
|
DexFile_setTrustedSym(env, clazz, j_cookie);
|
||||||
Runtime::Current()->SetJavaDebuggable(false);
|
if (!is_debuggable) Runtime::Current()->SetJavaDebuggable(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -115,12 +117,20 @@ namespace art {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
inline void DisableHiddenApi(const lsplant::HookHandler &handler) {
|
inline void DisableHiddenApi(JNIEnv* env, const lsplant::HookHandler &handler) {
|
||||||
|
|
||||||
const int api_level = lspd::GetAndroidApiLevel();
|
const int api_level = lspd::GetAndroidApiLevel();
|
||||||
if (api_level < __ANDROID_API_P__) {
|
if (api_level < __ANDROID_API_P__) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto runtime_class = lsplant::JNI_FindClass(env, "dalvik/system/VMRuntime");
|
||||||
|
auto get_runtime_method = lsplant::JNI_GetStaticMethodID(env, runtime_class, "getRuntime", "()Ldalvik/system/VMRuntime;");
|
||||||
|
auto is_debuggable_method = lsplant::JNI_GetMethodID(env, runtime_class, "isJavaDebuggable", "()Z");
|
||||||
|
auto runtime = lsplant::JNI_CallStaticObjectMethod(env, runtime_class, get_runtime_method);
|
||||||
|
is_debuggable = lsplant::JNI_CallBooleanMethod(env, runtime, is_debuggable_method);
|
||||||
|
|
||||||
|
LOGD("java runtime debuggable %s", is_debuggable ? "true" : "false");
|
||||||
|
|
||||||
DexFile_setTrustedSym = reinterpret_cast<decltype(DexFile_setTrustedSym)>(lspd::symbol_cache->setTrusted);
|
DexFile_setTrustedSym = reinterpret_cast<decltype(DexFile_setTrustedSym)>(lspd::symbol_cache->setTrusted);
|
||||||
lsplant::HookSymNoHandle(handler, lspd::symbol_cache->openDexFileNative, DexFile_openDexFileNative);
|
lsplant::HookSymNoHandle(handler, lspd::symbol_cache->openDexFileNative, DexFile_openDexFileNative);
|
||||||
lsplant::HookSymNoHandle(handler, lspd::symbol_cache->openInMemoryDexFilesNative,
|
lsplant::HookSymNoHandle(handler, lspd::symbol_cache->openInMemoryDexFilesNative,
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,6 @@
|
||||||
#include "utils/hook_helper.hpp"
|
#include "utils/hook_helper.hpp"
|
||||||
|
|
||||||
namespace lspd {
|
namespace lspd {
|
||||||
void InstallInlineHooks(const lsplant::HookHandler &handler);
|
void InstallInlineHooks(JNIEnv* env, const lsplant::HookHandler &handler);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,7 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with LSPosed. If not, see <https://www.gnu.org/licenses/>.
|
* along with LSPosed. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2020 EdXposed Contributors
|
* Copyright (C) 2022 LSPosed Contributors
|
||||||
* Copyright (C) 2021 LSPosed Contributors
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "hook_bridge.h"
|
#include "hook_bridge.h"
|
||||||
|
|
|
||||||
|
|
@ -31,14 +31,14 @@
|
||||||
namespace lspd {
|
namespace lspd {
|
||||||
static std::atomic_bool installed = false;
|
static std::atomic_bool installed = false;
|
||||||
|
|
||||||
void InstallInlineHooks(const lsplant::HookHandler& handler) {
|
void InstallInlineHooks(JNIEnv* env, const lsplant::HookHandler& handler) {
|
||||||
if (installed.exchange(true)) [[unlikely]] {
|
if (installed.exchange(true)) [[unlikely]] {
|
||||||
LOGD("Inline hooks have been installed, skip");
|
LOGD("Inline hooks have been installed, skip");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LOGD("Start to install inline hooks");
|
LOGD("Start to install inline hooks");
|
||||||
art::Runtime::Setup(handler);
|
art::Runtime::Setup(handler);
|
||||||
art::hidden_api::DisableHiddenApi(handler);
|
art::hidden_api::DisableHiddenApi(env, handler);
|
||||||
LOGD("Inline hooks installed");
|
LOGD("Inline hooks installed");
|
||||||
}
|
}
|
||||||
} // namespace lspd
|
} // namespace lspd
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,7 @@ android {
|
||||||
}
|
}
|
||||||
release {
|
release {
|
||||||
isMinifyEnabled = true
|
isMinifyEnabled = true
|
||||||
|
isShrinkResources = true
|
||||||
proguardFiles("proguard-rules.pro")
|
proguardFiles("proguard-rules.pro")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit eb00b31d2591a4f46098c6d94161f3b872721881
|
Subproject commit 3d2e1f5fc73ae09ebe889f2c6ddfc49c57dda2c9
|
||||||
|
|
@ -10,4 +10,6 @@ public class VMRuntime {
|
||||||
public native boolean is64Bit();
|
public native boolean is64Bit();
|
||||||
|
|
||||||
public native String vmInstructionSet();
|
public native String vmInstructionSet();
|
||||||
|
|
||||||
|
public native boolean isJavaDebuggable();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,7 @@ namespace lspd {
|
||||||
return GetArt()->getSymbAddress<void*>(symbol);
|
return GetArt()->getSymbAddress<void*>(symbol);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
InstallInlineHooks(initInfo);
|
InstallInlineHooks(env, initInfo);
|
||||||
InitHooks(env, initInfo);
|
InitHooks(env, initInfo);
|
||||||
SetupEntryClass(env);
|
SetupEntryClass(env);
|
||||||
FindAndCall(env, "forkCommon",
|
FindAndCall(env, "forkCommon",
|
||||||
|
|
@ -194,7 +194,7 @@ namespace lspd {
|
||||||
return GetArt()->getSymbAddress<void*>(symbol);
|
return GetArt()->getSymbAddress<void*>(symbol);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
InstallInlineHooks(initInfo);
|
InstallInlineHooks(env, initInfo);
|
||||||
auto [dex_fd, size] = instance->RequestLSPDex(env, binder);
|
auto [dex_fd, size] = instance->RequestLSPDex(env, binder);
|
||||||
LoadDex(env, PreloadedDex(dex_fd, size));
|
LoadDex(env, PreloadedDex(dex_fd, size));
|
||||||
close(dex_fd);
|
close(dex_fd);
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ pluginManagement {
|
||||||
id("com.android.library") version agpVersion
|
id("com.android.library") version agpVersion
|
||||||
id("com.android.application") version agpVersion
|
id("com.android.application") version agpVersion
|
||||||
id("androidx.navigation.safeargs") version navVersion
|
id("androidx.navigation.safeargs") version navVersion
|
||||||
id("dev.rikka.tools.autoresconfig") version "1.1.0"
|
id("dev.rikka.tools.autoresconfig") version "1.1.1"
|
||||||
id("dev.rikka.tools.materialthemebuilder") version "1.1.0"
|
id("dev.rikka.tools.materialthemebuilder") version "1.1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue