Commit 8aa1f24a authored by swift_gan's avatar swift_gan

fix method stub on 64bit

parent 6e652fbf
...@@ -60,7 +60,8 @@ TEMP_STUB_INFO = """ ...@@ -60,7 +60,8 @@ TEMP_STUB_INFO = """
""" """
STUB_SIZES = [10,20,30,30,30,30,30,20,10,10,5,5,3] STUB_SIZES_32 = [10,20,30,30,30,30,30,20,10,10,5,5,3]
STUB_SIZES_64 = [10,20,30,30,30,30,50,50]
HAS_BACKUP = False HAS_BACKUP = False
...@@ -126,20 +127,29 @@ def genCallOriginClass(is64Bit, args, index): ...@@ -126,20 +127,29 @@ def genCallOriginClass(is64Bit, args, index):
method = TEMP_STUB_CALL_ORIGIN_CLASS % (getCallOriginClassName(args, index), getMethodBackupName(index), genArgsListForCallOriginMethod(is64Bit, args)) method = TEMP_STUB_CALL_ORIGIN_CLASS % (getCallOriginClassName(args, index), getMethodBackupName(index), genArgsListForCallOriginMethod(is64Bit, args))
return method return method
def genStubInfo(): def genStubInfo32():
hasStub = "true" if HAS_BACKUP else "false" hasStub = "true" if HAS_BACKUP else "false"
stubSizes = "" stubSizes = ""
for args in range(len(STUB_SIZES)): for args in range(len(STUB_SIZES_32)):
if (args != 0): if (args != 0):
stubSizes += ", " stubSizes += ", "
stubSizes += str(STUB_SIZES[args]) stubSizes += str(STUB_SIZES_32[args])
return TEMP_STUB_INFO % (hasStub, stubSizes)
def genStubInfo64():
hasStub = "true" if HAS_BACKUP else "false"
stubSizes = ""
for args in range(len(STUB_SIZES_64)):
if (args != 0):
stubSizes += ", "
stubSizes += str(STUB_SIZES_64[args])
return TEMP_STUB_INFO % (hasStub, stubSizes) return TEMP_STUB_INFO % (hasStub, stubSizes)
def gen32Stub(packageDir): def gen32Stub(packageDir):
class_content = genStubInfo() class_content = genStubInfo32()
class_name = STUB_FILE_NAME + "32" class_name = STUB_FILE_NAME + "32"
for args in range(len(STUB_SIZES)): for args in range(len(STUB_SIZES_32)):
for index in range(STUB_SIZES[args]): for index in range(STUB_SIZES_32[args]):
class_content += """\n\n\t//stub of arg size %d, index %d""" % (args, index) class_content += """\n\n\t//stub of arg size %d, index %d""" % (args, index)
class_content += genHookMethod(False, args, index) class_content += genHookMethod(False, args, index)
if HAS_BACKUP: if HAS_BACKUP:
...@@ -155,10 +165,10 @@ def gen32Stub(packageDir): ...@@ -155,10 +165,10 @@ def gen32Stub(packageDir):
def gen64Stub(packageDir): def gen64Stub(packageDir):
class_content = genStubInfo() class_content = genStubInfo64()
class_name = STUB_FILE_NAME + "64" class_name = STUB_FILE_NAME + "64"
for args in range(len(STUB_SIZES)): for args in range(len(STUB_SIZES_64)):
for index in range(STUB_SIZES[args]): for index in range(STUB_SIZES_64[args]):
class_content += """\n\n\t//stub of arg size %d, index %d""" % (args, index) class_content += """\n\n\t//stub of arg size %d, index %d""" % (args, index)
class_content += genHookMethod(True, args, index) class_content += genHookMethod(True, args, index)
if HAS_BACKUP: if HAS_BACKUP:
......
...@@ -24,12 +24,15 @@ import static de.robv.android.xposed.XposedBridge.sHookedMethodCallbacks; ...@@ -24,12 +24,15 @@ import static de.robv.android.xposed.XposedBridge.sHookedMethodCallbacks;
public class HookStubManager { public class HookStubManager {
public static volatile boolean is64Bit;
//64bits arg0 - arg7 is in reg x1 - x7 and > 7 is in stack, but can not match
public final static int MAX_64_ARGS = 7;
public static int MAX_STUB_ARGS = 0; public static int MAX_STUB_ARGS = 0;
public static int[] stubSizes; public static int[] stubSizes;
public static boolean hasStubBackup = false; public static boolean hasStubBackup;
public static AtomicInteger[] curUseStubIndexes; public static AtomicInteger[] curUseStubIndexes;
...@@ -42,7 +45,8 @@ public class HookStubManager { ...@@ -42,7 +45,8 @@ public class HookStubManager {
= sHookedMethodCallbacks; = sHookedMethodCallbacks;
static { static {
Class stubClass = SandHook.is64Bit() ? MethodHookerStubs64.class : MethodHookerStubs32.class; is64Bit = SandHook.is64Bit();
Class stubClass = is64Bit ? MethodHookerStubs64.class : MethodHookerStubs32.class;
stubSizes = (int[]) XposedHelpers.getStaticObjectField(stubClass, "stubSizes"); stubSizes = (int[]) XposedHelpers.getStaticObjectField(stubClass, "stubSizes");
Boolean hasBackup = (Boolean) XposedHelpers.getStaticObjectField(stubClass, "hasStubBackup"); Boolean hasBackup = (Boolean) XposedHelpers.getStaticObjectField(stubClass, "hasStubBackup");
hasStubBackup = hasBackup != null && (hasBackup && !XposedCompat.useNewCallBackup); hasStubBackup = hasBackup != null && (hasBackup && !XposedCompat.useNewCallBackup);
...@@ -90,6 +94,8 @@ public class HookStubManager { ...@@ -90,6 +94,8 @@ public class HookStubManager {
needStubArgCount += parType.length; needStubArgCount += parType.length;
if (needStubArgCount > MAX_STUB_ARGS) if (needStubArgCount > MAX_STUB_ARGS)
return null; return null;
if (is64Bit && needStubArgCount > MAX_64_ARGS)
return null;
for (Class par:parType) { for (Class par:parType) {
if (!ParamWrapper.support(par)) if (!ParamWrapper.support(par))
return null; return null;
...@@ -99,7 +105,7 @@ public class HookStubManager { ...@@ -99,7 +105,7 @@ public class HookStubManager {
} }
synchronized (HookStubManager.class) { synchronized (HookStubManager.class) {
StubMethodsInfo stubMethodInfo = getStubMethodPair(SandHook.is64Bit(), needStubArgCount); StubMethodsInfo stubMethodInfo = getStubMethodPair(is64Bit, needStubArgCount);
if (stubMethodInfo == null) if (stubMethodInfo == null)
return null; return null;
HookMethodEntity entity = new HookMethodEntity(origin, stubMethodInfo.hook, stubMethodInfo.backup); HookMethodEntity entity = new HookMethodEntity(origin, stubMethodInfo.hook, stubMethodInfo.backup);
...@@ -181,7 +187,7 @@ public class HookStubManager { ...@@ -181,7 +187,7 @@ public class HookStubManager {
} }
public static Method getCallOriginMethod(int args, int index) { public static Method getCallOriginMethod(int args, int index) {
Class stubClass = SandHook.is64Bit() ? MethodHookerStubs64.class : MethodHookerStubs32.class; Class stubClass = is64Bit ? MethodHookerStubs64.class : MethodHookerStubs32.class;
String className = stubClass.getName(); String className = stubClass.getName();
className += "$"; className += "$";
className += getCallOriginClassName(args, index); className += getCallOriginClassName(args, index);
......
...@@ -5,6 +5,7 @@ import android.util.Log; ...@@ -5,6 +5,7 @@ import android.util.Log;
import com.swift.sandhook.xposedcompat.methodgen.DynamicBridge; import com.swift.sandhook.xposedcompat.methodgen.DynamicBridge;
import com.swift.sandhook.xposedcompat.utils.DexLog;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
...@@ -122,8 +123,10 @@ public final class XposedBridge { ...@@ -122,8 +123,10 @@ public final class XposedBridge {
* @param text The log message. * @param text The log message.
*/ */
public synchronized static void log(String text) { public synchronized static void log(String text) {
if (DexLog.DEBUG) {
Log.i(TAG, text); Log.i(TAG, text);
} }
}
/** /**
* Logs a stack trace to the Xposed error log. * Logs a stack trace to the Xposed error log.
...@@ -134,8 +137,10 @@ public final class XposedBridge { ...@@ -134,8 +137,10 @@ public final class XposedBridge {
* @param t The Throwable object for the stack trace. * @param t The Throwable object for the stack trace.
*/ */
public synchronized static void log(Throwable t) { public synchronized static void log(Throwable t) {
if (DexLog.DEBUG) {
Log.e(TAG, Log.getStackTraceString(t)); Log.e(TAG, Log.getStackTraceString(t));
} }
}
/** /**
* Hook any method (or constructor) with the specified callback. See below for some wrappers * Hook any method (or constructor) with the specified callback. See below for some wrappers
......
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