Commit 09f7d702 authored by swift_gan's avatar swift_gan

tweak so name & add custom classloader

parent b55f58e4
......@@ -11,13 +11,13 @@ cmake_minimum_required(VERSION 3.4.1)
# Gradle automatically packages shared libraries with your APK.
add_library( # Sets the name of the library.
native-lib
lib-sandhook
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/main/cpp/native-lib.cpp
src/main/cpp/sandhooklib.cpp
src/main/cpp/trampoline/trampoline.cpp
src/main/cpp/trampoline/trampoline_manager.cpp
src/main/cpp/utils/fake_dlfcn.cpp
......@@ -43,7 +43,7 @@ find_library( # Sets the name of the path variable.
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
native-lib
lib-sandhook
# Links the target library to the log library
# included in the NDK.
......
......@@ -24,7 +24,7 @@ public class SandHook {
public static int testAccessFlag;
static {
System.loadLibrary("native-lib");
System.loadLibrary("lib-sandhook");
init();
}
......@@ -47,6 +47,10 @@ public class SandHook {
HookWrapper.addHookClass(hookWrapperClass);
}
public static void addHookClass(ClassLoader classLoader, Class... hookWrapperClass) throws HookErrorException {
HookWrapper.addHookClass(hookWrapperClass);
}
public static boolean hook(Member target, Method hook, Method backup) {
if (target == null || hook == null)
return false;
......
......@@ -24,13 +24,17 @@ public class HookWrapper {
static Map<Member,HookEntity> globalHookEntityMap = new ConcurrentHashMap<>();
public static void addHookClass(Class<?>... classes) throws HookErrorException {
addHookClass(null, classes);
}
public static void addHookClass(ClassLoader classLoader, Class<?>... classes) throws HookErrorException {
for (Class clazz:classes) {
addHookClass(clazz);
addHookClass(classLoader, clazz);
}
}
public static void addHookClass(Class<?> clazz) throws HookErrorException {
Class targetHookClass = getTargetHookClass(clazz);
public static void addHookClass(ClassLoader classLoader, Class<?> clazz) throws HookErrorException {
Class targetHookClass = getTargetHookClass(classLoader, clazz);
if (targetHookClass == null)
throw new HookErrorException("error hook wrapper class :" + clazz.getName());
Map<Member,HookEntity> hookEntityMap = getHookMethods(targetHookClass, clazz);
......@@ -194,14 +198,18 @@ public class HookWrapper {
private static Class getTargetHookClass(Class<?> hookWrapperClass) {
private static Class getTargetHookClass(ClassLoader classLoader, Class<?> hookWrapperClass) {
HookClass hookClass = hookWrapperClass.getAnnotation(HookClass.class);
HookReflectClass hookReflectClass = hookWrapperClass.getAnnotation(HookReflectClass.class);
if (hookClass != null) {
return hookClass.value();
} else if (hookReflectClass != null) {
try {
return Class.forName(hookReflectClass.value());
if (classLoader == null) {
return Class.forName(hookReflectClass.value());
} else {
return Class.forName(hookReflectClass.value(), true, classLoader);
}
} catch (ClassNotFoundException e) {
return null;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment