-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: use lsplant when no hook bridge is available
- Loading branch information
Showing
11 changed files
with
875 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// | ||
// Created by sulfate on 2024-08-03. | ||
// | ||
|
||
#include <string> | ||
#include <string_view> | ||
#include <vector> | ||
|
||
#include <jni.h> | ||
#include <android/log.h> | ||
|
||
#include <fmt/format.h> | ||
#include "natives_utils.h" | ||
#include "utils/MemoryDexLoader.h" | ||
|
||
#include "lsplant.hpp" | ||
|
||
static bool sLsplantInitSuccess = false; | ||
|
||
extern "C" | ||
JNIEXPORT void JNICALL | ||
Java_io_github_qauxv_util_hookimpl_lsplant_LsplantBridge_nativeInitializeLsplant(JNIEnv* env, jclass clazz) { | ||
if (sLsplantInitSuccess) { | ||
return; | ||
} | ||
using namespace qauxv; | ||
if (!InitLibArtElfView()) { | ||
env->ThrowNew(env->FindClass("java/lang/RuntimeException"), "libart symbol resolver init failed"); | ||
return; | ||
} | ||
if (!InitLSPlantImpl(env)) { | ||
env->ThrowNew(env->FindClass("java/lang/RuntimeException"), "lsplant init failed"); | ||
return; | ||
} | ||
sLsplantInitSuccess = true; | ||
} | ||
|
||
extern "C" | ||
JNIEXPORT jobject JNICALL | ||
Java_io_github_qauxv_util_hookimpl_lsplant_LsplantBridge_nativeHookMethod(JNIEnv* env, jclass clazz, jobject target, jobject callback, jobject context) { | ||
if (!sLsplantInitSuccess) { | ||
env->ThrowNew(env->FindClass("java/lang/IllegalAccessException"), "lsplant not initialized"); | ||
return nullptr; | ||
} | ||
return ::lsplant::Hook(env, target, context, callback); | ||
} | ||
|
||
extern "C" | ||
JNIEXPORT jboolean JNICALL | ||
Java_io_github_qauxv_util_hookimpl_lsplant_LsplantBridge_nativeIsMethodHooked(JNIEnv* env, jclass clazz, jobject target) { | ||
if (!sLsplantInitSuccess) { | ||
env->ThrowNew(env->FindClass("java/lang/IllegalAccessException"), "lsplant not initialized"); | ||
return false; | ||
} | ||
return ::lsplant::IsHooked(env, target); | ||
} | ||
|
||
extern "C" | ||
JNIEXPORT jboolean JNICALL | ||
Java_io_github_qauxv_util_hookimpl_lsplant_LsplantBridge_nativeUnhookMethod(JNIEnv* env, jclass clazz, jobject target) { | ||
if (!sLsplantInitSuccess) { | ||
env->ThrowNew(env->FindClass("java/lang/IllegalAccessException"), "lsplant not initialized"); | ||
return false; | ||
} | ||
return ::lsplant::UnHook(env, target); | ||
} | ||
|
||
extern "C" | ||
JNIEXPORT jboolean JNICALL | ||
Java_io_github_qauxv_util_hookimpl_lsplant_LsplantBridge_nativeDeoptimizeMethod(JNIEnv* env, jclass clazz, jobject target) { | ||
if (!sLsplantInitSuccess) { | ||
env->ThrowNew(env->FindClass("java/lang/IllegalAccessException"), "lsplant not initialized"); | ||
return false; | ||
} | ||
return ::lsplant::Deoptimize(env, target); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <string> | ||
#include <string_view> | ||
|
||
#include <jni.h> | ||
|
||
namespace qauxv { | ||
|
||
std::string GetLibArtPath(); | ||
|
||
bool InitLibArtElfView(); | ||
|
||
bool InitLSPlantImpl(JNIEnv* env); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
app/src/main/java/io/github/qauxv/util/hookimpl/lsplant/LsplantBridge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* QAuxiliary - An Xposed module for QQ/TIM | ||
* Copyright (C) 2019-2024 QAuxiliary developers | ||
* https://github.com/cinit/QAuxiliary | ||
* | ||
* This software is an opensource software: you can redistribute it | ||
* and/or modify it under the terms of the General Public License | ||
* as published by the Free Software Foundation; either | ||
* version 3 of the License, or any later version as published | ||
* by QAuxiliary contributors. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the General Public License for more details. | ||
* | ||
* You should have received a copy of the General Public License | ||
* along with this software. | ||
* If not, see | ||
* <https://github.com/cinit/QAuxiliary/blob/master/LICENSE.md>. | ||
*/ | ||
|
||
package io.github.qauxv.util.hookimpl.lsplant; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import java.lang.reflect.Member; | ||
|
||
public class LsplantBridge { | ||
|
||
private LsplantBridge() { | ||
throw new AssertionError("No instance for you!"); | ||
} | ||
|
||
static native void nativeInitializeLsplant() throws RuntimeException; | ||
|
||
// return backup method if success, or null if failed | ||
@Nullable | ||
static native Member nativeHookMethod(@NonNull Member target, @NonNull Member callback, @NonNull Object context) throws RuntimeException; | ||
|
||
static native boolean nativeIsMethodHooked(@NonNull Member target) throws RuntimeException; | ||
|
||
static native boolean nativeUnhookMethod(@NonNull Member target) throws RuntimeException; | ||
|
||
static native boolean nativeDeoptimizeMethod(@NonNull Member target) throws RuntimeException; | ||
|
||
} |
Oops, something went wrong.