Make ide happy about native methods

This commit is contained in:
LoveSy 2021-01-30 02:52:11 +08:00
parent 4131c18cb6
commit 91c49dd6d0
31 changed files with 84 additions and 72 deletions

View File

@ -28,6 +28,19 @@
_NATIVEHELPER_JNI_MACRO_CAST(void*) (className ## _ ## functionName) \
}
#endif
#ifndef LSP_NATIVE_METHOD
#define LSP_NATIVE_METHOD(className, functionName, signature) \
{ #functionName, \
signature, \
_NATIVEHELPER_JNI_MACRO_CAST(void*) (Java_io_github_lsposed_lspd_nativebridge_## className ## _ ## functionName) \
}
#endif
#ifndef LSP_DEF_NATIVE_METHOD
#define LSP_DEF_NATIVE_METHOD(ret, className, functionName, ...) \
extern "C" ret Java_io_github_lsposed_lspd_nativebridge_## className ## _ ## functionName (JNI_START, ## __VA_ARGS__)
#endif
// Intended to construct a JNINativeMethod (when the C name doesn't match the Java name).
// (Assumes the C name is the ClassName_Identifier).
#ifndef OVERLOADED_NATIVE_METHOD

View File

@ -30,7 +30,7 @@ inline constexpr bool is64 = Is64();
#endif
static const auto kEntryClassName = "io.github.lsposed.lspd.core.Main"s;
static const auto kClassLinkerClassName = "io.github.lsposed.lspd.art.ClassLinker"s;
static const auto kClassLinkerClassName = "io.github.lsposed.lspd.nativebridge.ClassLinker"s;
static const auto kSandHookClassName = "com.swift.sandhook.SandHook"s;
static const auto kSandHookNeverCallClassName = "com.swift.sandhook.ClassNeverCall"s;

View File

@ -11,7 +11,7 @@ namespace lspd {
static std::unordered_set<void *> deopted_methods;
static void ClassLinker_setEntryPointsToInterpreter(JNI_START, jobject method) {
LSP_DEF_NATIVE_METHOD(void, ClassLinker, setEntryPointsToInterpreter, jobject method) {
void *reflected_method = getArtMethodYahfa(env, method);
if (deopted_methods.count(reflected_method)) {
LOGD("method %p has been deopted before, skip...", reflected_method);
@ -24,7 +24,8 @@ namespace lspd {
}
static JNINativeMethod gMethods[] = {
NATIVE_METHOD(ClassLinker, setEntryPointsToInterpreter, "(Ljava/lang/reflect/Member;)V")
LSP_NATIVE_METHOD(ClassLinker, setEntryPointsToInterpreter,
"(Ljava/lang/reflect/Member;)V")
};
void RegisterArtClassLinker(JNIEnv *env) {

View File

@ -9,18 +9,18 @@
namespace lspd {
static jint Heap_waitForGcToComplete(JNI_START) {
LSP_DEF_NATIVE_METHOD(jint, Heap, waitForGcToComplete) {
art::gc::collector::GcType gcType = art::gc::Heap::Current()->WaitForGcToComplete(
art::gc::GcCause::kGcCauseNone, art::Thread::Current().Get());
return gcType;
}
static JNINativeMethod gMethods[] = {
NATIVE_METHOD(Heap, waitForGcToComplete, "()I")
LSP_NATIVE_METHOD(Heap, waitForGcToComplete, "()I")
};
void RegisterArtHeap(JNIEnv *env) {
REGISTER_EDXP_NATIVE_METHODS("io.github.lsposed.lspd.art.Heap");
REGISTER_EDXP_NATIVE_METHODS("io.github.lsposed.lspd.nativebridge.Heap");
}
}

View File

@ -7,77 +7,78 @@
namespace lspd {
static jboolean ConfigManager_isResourcesHookEnabled(JNI_START) {
LSP_DEF_NATIVE_METHOD(jboolean, ConfigManager, isResourcesHookEnabled) {
return (jboolean) ConfigManager::GetInstance()->IsResourcesHookEnabled();
}
static jboolean ConfigManager_isNoModuleLogEnabled(JNI_START) {
LSP_DEF_NATIVE_METHOD(jboolean, ConfigManager, isNoModuleLogEnabled) {
return (jboolean) ConfigManager::GetInstance()->IsNoModuleLogEnabled();
}
static jstring ConfigManager_getInstallerPackageName(JNI_START) {
LSP_DEF_NATIVE_METHOD(jstring, ConfigManager, getInstallerPackageName) {
return env->NewStringUTF(ConfigManager::GetInstance()->GetInstallerPackageName().c_str());
}
static jstring ConfigManager_getDataPathPrefix(JNI_START) {
LSP_DEF_NATIVE_METHOD(jstring, ConfigManager, getDataPathPrefix) {
return env->NewStringUTF(ConfigManager::GetInstance()->GetDataPathPrefix().c_str());
}
static jstring ConfigManager_getConfigPath(JNI_START, jstring jSuffix) {
LSP_DEF_NATIVE_METHOD(jstring, ConfigManager, getConfigPath, jstring jSuffix) {
const char *suffix = env->GetStringUTFChars(jSuffix, JNI_FALSE);
auto result = ConfigManager::GetInstance()->GetConfigPath(suffix);
env->ReleaseStringUTFChars(jSuffix, suffix);
return env->NewStringUTF(result.c_str());
}
static jstring ConfigManager_getPrefsPath(JNI_START, jstring jSuffix) {
LSP_DEF_NATIVE_METHOD(jstring, ConfigManager, getPrefsPath, jstring jSuffix) {
const char *suffix = env->GetStringUTFChars(jSuffix, JNI_FALSE);
auto result = ConfigManager::GetInstance()->GetPrefsPath(suffix);
env->ReleaseStringUTFChars(jSuffix, suffix);
return env->NewStringUTF(result.c_str());
}
static jstring ConfigManager_getCachePath(JNI_START, jstring jSuffix) {
LSP_DEF_NATIVE_METHOD(jstring, ConfigManager, getCachePath, jstring jSuffix) {
const char *suffix = env->GetStringUTFChars(jSuffix, JNI_FALSE);
auto result = ConfigManager::GetCachePath(suffix);
env->ReleaseStringUTFChars(jSuffix, suffix);
return env->NewStringUTF(result.c_str());
}
static jstring ConfigManager_getBaseConfigPath(JNI_START) {
LSP_DEF_NATIVE_METHOD(jstring, ConfigManager, getBaseConfigPath) {
auto result = ConfigManager::GetInstance()->GetBaseConfigPath();
return env->NewStringUTF(result.c_str());
}
static jstring ConfigManager_getMiscPath(JNI_START) {
auto result = ConfigManager::GetInstance()->GetMiscPath();
LSP_DEF_NATIVE_METHOD(jstring, ConfigManager, getMiscPath) {
auto result = ConfigManager::GetMiscPath();
return env->NewStringUTF(result.c_str());
}
static jstring ConfigManager_getModulesList(JNI_START) {
LSP_DEF_NATIVE_METHOD(jstring, ConfigManager, getModulesList) {
auto module_list = Context::GetInstance()->GetAppModulesList();
std::ostringstream join;
std::copy(module_list.begin(), module_list.end(), std::ostream_iterator<std::string>(join, "\n"));
std::copy(module_list.begin(), module_list.end(),
std::ostream_iterator<std::string>(join, "\n"));
const auto &list = join.str();
LOGD("module list: %s", list.c_str());
return env->NewStringUTF(list.c_str());
}
static JNINativeMethod gMethods[] = {
NATIVE_METHOD(ConfigManager, isResourcesHookEnabled, "()Z"),
NATIVE_METHOD(ConfigManager, isNoModuleLogEnabled, "()Z"),
NATIVE_METHOD(ConfigManager, getInstallerPackageName, "()Ljava/lang/String;"),
NATIVE_METHOD(ConfigManager, getDataPathPrefix, "()Ljava/lang/String;"),
NATIVE_METHOD(ConfigManager, getPrefsPath,
"(Ljava/lang/String;)Ljava/lang/String;"),
NATIVE_METHOD(ConfigManager, getCachePath,
"(Ljava/lang/String;)Ljava/lang/String;"),
NATIVE_METHOD(ConfigManager, getBaseConfigPath, "()Ljava/lang/String;"),
NATIVE_METHOD(ConfigManager, getModulesList, "()Ljava/lang/String;"),
LSP_NATIVE_METHOD(ConfigManager, isResourcesHookEnabled, "()Z"),
LSP_NATIVE_METHOD(ConfigManager, isNoModuleLogEnabled, "()Z"),
LSP_NATIVE_METHOD(ConfigManager, getInstallerPackageName, "()Ljava/lang/String;"),
LSP_NATIVE_METHOD(ConfigManager, getDataPathPrefix, "()Ljava/lang/String;"),
LSP_NATIVE_METHOD(ConfigManager, getPrefsPath,
"(Ljava/lang/String;)Ljava/lang/String;"),
LSP_NATIVE_METHOD(ConfigManager, getCachePath,
"(Ljava/lang/String;)Ljava/lang/String;"),
LSP_NATIVE_METHOD(ConfigManager, getBaseConfigPath, "()Ljava/lang/String;"),
LSP_NATIVE_METHOD(ConfigManager, getModulesList, "()Ljava/lang/String;"),
};
void RegisterConfigManagerMethods(JNIEnv *env) {
REGISTER_EDXP_NATIVE_METHODS("io.github.lsposed.lspd.config.ConfigManager");
REGISTER_EDXP_NATIVE_METHODS("io.github.lsposed.lspd.nativebridge.ConfigManager");
}
}

View File

@ -9,41 +9,41 @@
namespace lspd {
static void Yahfa_init(JNI_START, jint sdkVersion) {
LSP_DEF_NATIVE_METHOD(void, Yahfa, init, jint sdkVersion) {
Java_lab_galaxy_yahfa_HookMain_init(env, clazz, sdkVersion);
}
static jobject Yahfa_findMethodNative(JNI_START, jclass targetClass,
LSP_DEF_NATIVE_METHOD(jobject, Yahfa, findMethodNative, jclass targetClass,
jstring methodName, jstring methodSig) {
return Java_lab_galaxy_yahfa_HookMain_findMethodNative(env, clazz, targetClass, methodName,
methodSig);
}
static jboolean Yahfa_backupAndHookNative(JNI_START, jobject target,
LSP_DEF_NATIVE_METHOD(jboolean, Yahfa, backupAndHookNative, jobject target,
jobject hook, jobject backup) {
return Java_lab_galaxy_yahfa_HookMain_backupAndHookNative(env, clazz, target, hook, backup);
}
static void Yahfa_recordHooked(JNI_START, jobject member) {
LSP_DEF_NATIVE_METHOD(void, Yahfa, recordHooked, jobject member) {
lspd::recordHooked(getArtMethodYahfa(env, member));
}
static jboolean Yahfa_isHooked(JNI_START, jobject member) {
LSP_DEF_NATIVE_METHOD(jboolean, Yahfa, isHooked, jobject member) {
return lspd::isHooked(getArtMethodYahfa(env, member));
}
static JNINativeMethod gMethods[] = {
NATIVE_METHOD(Yahfa, init, "(I)V"),
NATIVE_METHOD(Yahfa, findMethodNative,
LSP_NATIVE_METHOD(Yahfa, init, "(I)V"),
LSP_NATIVE_METHOD(Yahfa, findMethodNative,
"(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/reflect/Member;"),
NATIVE_METHOD(Yahfa, backupAndHookNative,
LSP_NATIVE_METHOD(Yahfa, backupAndHookNative,
"(Ljava/lang/Object;Ljava/lang/reflect/Method;Ljava/lang/reflect/Method;)Z"),
NATIVE_METHOD(Yahfa, recordHooked, "(Ljava/lang/reflect/Member;)V"),
NATIVE_METHOD(Yahfa, isHooked, "(Ljava/lang/reflect/Member;)Z"),
LSP_NATIVE_METHOD(Yahfa, recordHooked, "(Ljava/lang/reflect/Member;)V"),
LSP_NATIVE_METHOD(Yahfa, isHooked, "(Ljava/lang/reflect/Member;)Z")
};
void RegisterEdxpYahfa(JNIEnv *env) {
REGISTER_EDXP_NATIVE_METHODS("io.github.lsposed.lspd.core.Yahfa");
REGISTER_EDXP_NATIVE_METHODS("io.github.lsposed.lspd.nativebridge.Yahfa");
}
}

View File

@ -5,7 +5,7 @@ import android.content.res.TypedArray;
import android.util.Log;
import io.github.lsposed.lspd.BuildConfig;
import io.github.lsposed.lspd.config.ConfigManager;
import io.github.lsposed.lspd.nativebridge.ConfigManager;
import io.github.lsposed.lspd.config.LSPdConfigGlobal;
import java.lang.reflect.AccessibleObject;

View File

@ -4,7 +4,6 @@ import android.app.ActivityThread;
import android.app.AndroidAppHelper;
import android.content.pm.ApplicationInfo;
import android.content.res.Resources;
import android.content.res.ResourcesImpl;
import android.content.res.TypedArray;
import android.content.res.XResources;
import android.os.Build;
@ -14,7 +13,7 @@ import android.util.ArraySet;
import android.util.Log;
import com.android.internal.os.ZygoteInit;
import io.github.lsposed.lspd.config.ConfigManager;
import io.github.lsposed.lspd.nativebridge.ConfigManager;
import io.github.lsposed.lspd.config.LSPdConfigGlobal;
import java.io.BufferedReader;

View File

@ -10,7 +10,7 @@ import android.content.pm.ApplicationInfo;
import android.content.res.CompatibilityInfo;
import android.content.res.XResources;
import io.github.lsposed.lspd.config.ConfigManager;
import io.github.lsposed.lspd.nativebridge.ConfigManager;
import io.github.lsposed.lspd.util.Hookers;
import io.github.lsposed.lspd.util.MetaDataReader;
import io.github.lsposed.lspd.util.Utils;

View File

@ -2,7 +2,7 @@ package io.github.lsposed.lspd._hooker.impl;
import android.app.LoadedApk;
import io.github.lsposed.lspd.config.ConfigManager;
import io.github.lsposed.lspd.nativebridge.ConfigManager;
import io.github.lsposed.lspd.hooker.XposedInstallerHooker;
import io.github.lsposed.lspd.util.Hookers;

View File

@ -1,6 +1,6 @@
package io.github.lsposed.lspd.config;
import io.github.lsposed.lspd.core.Yahfa;
import io.github.lsposed.lspd.nativebridge.Yahfa;
import io.github.lsposed.lspd.deopt.PrebuiltMethodsDeopter;
import io.github.lsposed.lspd.hook.HookProvider;

View File

@ -1,7 +1,7 @@
package io.github.lsposed.lspd.core.yahfa;
import io.github.lsposed.lspd.art.Heap;
import io.github.lsposed.lspd.core.Yahfa;
import io.github.lsposed.lspd.nativebridge.Heap;
import io.github.lsposed.lspd.nativebridge.Yahfa;
import io.github.lsposed.lspd.util.Utils;
import java.lang.reflect.Constructor;

View File

@ -2,7 +2,7 @@ package io.github.lsposed.lspd.deopt;
import android.text.TextUtils;
import io.github.lsposed.lspd.config.ConfigManager;
import io.github.lsposed.lspd.nativebridge.ConfigManager;
import io.github.lsposed.lspd.config.LSPdConfigGlobal;
import io.github.lsposed.lspd.util.Utils;

View File

@ -4,7 +4,7 @@ import de.robv.android.xposed.XC_MethodReplacement;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import io.github.lsposed.lspd.BuildConfig;
import io.github.lsposed.lspd.config.ConfigManager;
import io.github.lsposed.lspd.nativebridge.ConfigManager;
import io.github.lsposed.lspd.core.EdxpImpl;
import io.github.lsposed.lspd.core.Main;
import io.github.lsposed.lspd.util.Utils;

View File

@ -1,4 +1,4 @@
package io.github.lsposed.lspd.art;
package io.github.lsposed.lspd.nativebridge;
import io.github.lsposed.common.KeepAll;

View File

@ -1,4 +1,4 @@
package io.github.lsposed.lspd.config;
package io.github.lsposed.lspd.nativebridge;
public class ConfigManager {

View File

@ -1,7 +1,5 @@
package io.github.lsposed.lspd.art;
package io.github.lsposed.lspd.nativebridge;
public class Heap {
public static native int waitForGcToComplete();
}

View File

@ -1,4 +1,4 @@
package io.github.lsposed.lspd.core;
package io.github.lsposed.lspd.nativebridge;
import java.lang.reflect.Member;
import java.lang.reflect.Method;

View File

@ -1,6 +1,6 @@
package io.github.lsposed.lspd.proxy;
import io.github.lsposed.lspd.config.ConfigManager;
import io.github.lsposed.lspd.nativebridge.ConfigManager;
import io.github.lsposed.lspd.deopt.PrebuiltMethodsDeopter;
import io.github.lsposed.lspd.util.Utils;

View File

@ -2,10 +2,10 @@ package io.github.lsposed.lspd.sandhook.config;
import android.util.Log;
import io.github.lsposed.lspd.art.ClassLinker;
import io.github.lsposed.lspd.nativebridge.ClassLinker;
import io.github.lsposed.lspd.config.BaseHookProvider;
import io.github.lsposed.lspd.core.ResourcesHook;
import io.github.lsposed.lspd.core.Yahfa;
import io.github.lsposed.lspd.nativebridge.Yahfa;
import com.swift.sandhook.xposedcompat.XposedCompat;
import com.swift.sandhook.xposedcompat.methodgen.SandHookXposedBridge;

View File

@ -5,7 +5,7 @@ import android.os.Build;
import io.github.lsposed.lspd.core.BaseEdxpImpl;
import io.github.lsposed.lspd.core.EdxpImpl;
import io.github.lsposed.lspd.core.Main;
import io.github.lsposed.lspd.core.Yahfa;
import io.github.lsposed.lspd.nativebridge.Yahfa;
import com.swift.sandhook.xposedcompat.methodgen.SandHookXposedBridge;
public class SandHookEdxpImpl extends BaseEdxpImpl {

View File

@ -2,7 +2,7 @@ package io.github.lsposed.lspd.util;
import android.text.TextUtils;
import io.github.lsposed.lspd.config.ConfigManager;
import io.github.lsposed.lspd.nativebridge.ConfigManager;
import java.io.BufferedReader;
import java.io.BufferedWriter;

View File

@ -1,9 +1,9 @@
package io.github.lsposed.lspd.yahfa.config;
import io.github.lsposed.lspd.art.ClassLinker;
import io.github.lsposed.lspd.nativebridge.ClassLinker;
import io.github.lsposed.lspd.config.BaseHookProvider;
import io.github.lsposed.lspd.core.ResourcesHook;
import io.github.lsposed.lspd.core.Yahfa;
import io.github.lsposed.lspd.nativebridge.Yahfa;
import io.github.lsposed.lspd.yahfa.dexmaker.DynamicBridge;
import java.lang.reflect.Member;

View File

@ -6,7 +6,7 @@ import io.github.lsposed.lspd.core.BaseEdxpImpl;
import io.github.lsposed.lspd.core.EdxpImpl;
import io.github.lsposed.lspd.core.Main;
import io.github.lsposed.lspd.core.Proxy;
import io.github.lsposed.lspd.core.Yahfa;
import io.github.lsposed.lspd.nativebridge.Yahfa;
import io.github.lsposed.lspd.proxy.NormalProxy;
import io.github.lsposed.lspd.proxy.Router;

View File

@ -1,6 +1,6 @@
package io.github.lsposed.lspd.yahfa.dexmaker;
import io.github.lsposed.lspd.config.ConfigManager;
import io.github.lsposed.lspd.nativebridge.ConfigManager;
import io.github.lsposed.lspd.util.Utils;
import java.io.File;

View File

@ -4,7 +4,7 @@ import android.annotation.TargetApi;
import android.os.Build;
import io.github.lsposed.lspd.BuildConfig;
import io.github.lsposed.lspd.config.ConfigManager;
import io.github.lsposed.lspd.nativebridge.ConfigManager;
import io.github.lsposed.lspd.core.yahfa.HookMain;
import io.github.lsposed.lspd.util.ProxyClassLoader;

View File

@ -3,7 +3,7 @@ package com.swift.sandhook.xposedcompat;
import android.os.Process;
import android.text.TextUtils;
import io.github.lsposed.lspd.config.ConfigManager;
import io.github.lsposed.lspd.nativebridge.ConfigManager;
import io.github.lsposed.lspd.util.FileUtils;
import io.github.lsposed.lspd.util.ProcessUtils;
import io.github.lsposed.lspd.util.ProxyClassLoader;

View File

@ -1,6 +1,6 @@
package com.swift.sandhook.xposedcompat.methodgen;
import io.github.lsposed.lspd.config.ConfigManager;
import io.github.lsposed.lspd.nativebridge.ConfigManager;
import com.swift.sandhook.SandHook;
import com.swift.sandhook.SandHookMethodResolver;
import com.swift.sandhook.wrapper.HookWrapper;

View File

@ -1,6 +1,6 @@
package com.swift.sandhook.xposedcompat.methodgen;
import io.github.lsposed.lspd.config.ConfigManager;
import io.github.lsposed.lspd.nativebridge.ConfigManager;
import com.swift.sandhook.SandHook;
import com.swift.sandhook.wrapper.HookWrapper;
import com.swift.sandhook.xposedcompat.hookstub.HookStubManager;

View File

@ -4,8 +4,8 @@ import android.os.Build;
import android.os.Process;
import android.os.Trace;
import io.github.lsposed.lspd.config.ConfigManager;
import io.github.lsposed.lspd.core.Yahfa;
import io.github.lsposed.lspd.nativebridge.ConfigManager;
import io.github.lsposed.lspd.nativebridge.Yahfa;
import io.github.lsposed.lspd.util.ClassLoaderUtils;
import io.github.lsposed.lspd.util.FileUtils;
import com.swift.sandhook.SandHook;

View File

@ -1,5 +1,5 @@
package com.swift.sandhook.xposedcompat.utils;
import io.github.lsposed.lspd.config.ConfigManager;
import io.github.lsposed.lspd.nativebridge.ConfigManager;
import io.github.lsposed.lspd.util.Utils;
import java.io.File;