Commit 8aa1f24a authored by swift_gan's avatar swift_gan

fix method stub on 64bit

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