Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge pull request ganyao114#43 from MlgmXyysd/master #13

Merged
merged 3 commits into from
Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions hooklib/src/main/java/com/swift/sandhook/SandHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ private static Object[] getFakeArgs(Method method) {
}

public static Object getObject(long address) {
if (address == 0) {
return null;
}
long threadSelf = getThreadId();
return getObjectNative(threadSelf, address);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import android.app.Application;
import android.content.Context;

import com.swift.sandhook.xposedcompat.classloaders.ComposeClassLoader;
import com.swift.sandhook.xposedcompat.classloaders.ProxyClassLoader;
import com.swift.sandhook.xposedcompat.methodgen.DynamicBridge;
import com.swift.sandhook.xposedcompat.utils.ApplicationUtils;
import com.swift.sandhook.xposedcompat.utils.FileUtils;
Expand Down Expand Up @@ -76,7 +76,7 @@ public static ClassLoader getSandHookXposedClassLoader(ClassLoader appOriginClas
if (sandHookXposedClassLoader != null) {
return sandHookXposedClassLoader;
} else {
sandHookXposedClassLoader = new ComposeClassLoader(sandBoxHostClassLoader, appOriginClassLoader);
sandHookXposedClassLoader = new ProxyClassLoader(sandBoxHostClassLoader, appOriginClassLoader);
return sandHookXposedClassLoader;
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.swift.sandhook.xposedcompat.classloaders;

public class ProxyClassLoader extends ClassLoader {

private final ClassLoader mClassLoader;

public ProxyClassLoader(ClassLoader parentCL, ClassLoader appCL) {
super(parentCL);
mClassLoader = appCL;
}

@Override
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
Class clazz = null;

try {
clazz = mClassLoader.loadClass(name);
} catch (ClassNotFoundException ignored) {
}

if (clazz == null) {
clazz = super.loadClass(name, resolve);
if (clazz == null) {
throw new ClassNotFoundException();
}
}

return clazz;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.swift.sandhook.blacklist.HookBlackList;
import com.swift.sandhook.wrapper.HookWrapper;
import com.swift.sandhook.xposedcompat.XposedCompat;
import com.swift.sandhook.xposedcompat.classloaders.ComposeClassLoader;
import com.swift.sandhook.xposedcompat.classloaders.ProxyClassLoader;
import com.swift.sandhook.xposedcompat.hookstub.HookMethodEntity;
import com.swift.sandhook.xposedcompat.hookstub.HookStubManager;
import com.swift.sandhook.xposedcompat.utils.DexLog;
Expand Down Expand Up @@ -73,7 +73,7 @@ public static synchronized void hookMethod(Member hookMethod, XposedBridge.Addit
hookMaker = defaultHookMaker;
}
hookMaker.start(hookMethod, additionalHookInfo,
new ComposeClassLoader(DynamicBridge.class.getClassLoader(), hookMethod.getDeclaringClass().getClassLoader()), dexDir == null ? null : dexDir.getAbsolutePath());
new ProxyClassLoader(DynamicBridge.class.getClassLoader(), hookMethod.getDeclaringClass().getClassLoader()), dexDir == null ? null : dexDir.getAbsolutePath());
hookedInfo.put(hookMethod, hookMaker.getCallBackupMethod());
}
DexLog.d("hook method <" + hookMethod.toString() + "> cost " + (System.currentTimeMillis() - timeStart) + " ms, by " + (stub != null ? "internal stub" : "dex maker"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import com.swift.sandhook.wrapper.StubMethodsFactory;
import com.swift.sandhook.xposedcompat.utils.ApplicationUtils;
import com.swift.sandhook.xposedcompat.utils.ClassUtils;
import com.swift.sandhook.xposedcompat.utils.ComposeClassLoader;
import com.swift.sandhook.xposedcompat.utils.ProxyClassLoader;
import com.swift.sandhook.xposedcompat.utils.ProcessUtils;

import java.lang.reflect.Constructor;
Expand Down Expand Up @@ -227,7 +227,7 @@ public static ClassLoader getSandHookXposedClassLoader(ClassLoader appOriginClas
if (sandHookXposedClassLoader != null) {
return sandHookXposedClassLoader;
} else {
sandHookXposedClassLoader = new ComposeClassLoader(sandBoxHostClassLoader, appOriginClassLoader);
sandHookXposedClassLoader = new ProxyClassLoader(sandBoxHostClassLoader, appOriginClassLoader);
return sandHookXposedClassLoader;
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.swift.sandhook.xposedcompat.utils;

public class ProxyClassLoader extends ClassLoader {

private final ClassLoader mClassLoader;

public ProxyClassLoader(ClassLoader parentCL, ClassLoader appCL) {
super(parentCL);
mClassLoader = appCL;
}

@Override
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
Class clazz = null;

try {
clazz = mClassLoader.loadClass(name);
} catch (ClassNotFoundException ignored) {
}

if (clazz == null) {
clazz = super.loadClass(name, resolve);
if (clazz == null) {
throw new ClassNotFoundException();
}
}

return clazz;
}
}