Skip to content

Commit ba6c61f

Browse files
LoveSykotori2
LoveSy
authored andcommitted
Optimize dexmaker for yahfa
1 parent 6ea5186 commit ba6c61f

File tree

5 files changed

+151
-324
lines changed

5 files changed

+151
-324
lines changed

edxp-common/src/main/java/com/elderdrivers/riru/edxp/proxy/NormalProxy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ private void forkPostCommon(int pid, boolean isSystem, String appDataDir, String
4141
mRouter.initResourcesHook();
4242
mRouter.prepare(isSystem);
4343
PrebuiltMethodsDeopter.deoptBootMethods(); // do it once for secondary zygote
44-
mRouter.installBootstrapHooks(isSystem);
4544
ConfigManager.appDataDir = appDataDir;
4645
ConfigManager.niceName = niceName;
46+
mRouter.installBootstrapHooks(isSystem);
4747
XposedInit.prefsBasePath = ConfigManager.getPrefsPath("");
4848
mRouter.onEnterChildProcess();
4949
Utils.logI("Loading modules for " + niceName);

edxp-common/src/main/java/com/elderdrivers/riru/edxp/util/FileUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ public static String getPackageName(String dataDir) {
7272
}
7373

7474
public static String getDataPathPrefix() {
75-
return ConfigManager.getDataPathPrefix();
75+
return ConfigManager.getDataPathPrefix() + "/";
7676
}
7777
}

edxp-yahfa/src/main/java/com/elderdrivers/riru/edxp/yahfa/dexmaker/DynamicBridge.java

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.HashMap;
1313
import java.util.concurrent.atomic.AtomicBoolean;
1414

15+
import de.robv.android.xposed.EdHooker;
1516
import de.robv.android.xposed.XposedBridge;
1617

1718
import static com.elderdrivers.riru.edxp.util.FileUtils.getDataPathPrefix;
@@ -21,7 +22,7 @@
2122

2223
public final class DynamicBridge {
2324

24-
private static final HashMap<Member, Method> hookedInfo = new HashMap<>();
25+
private static final HashMap<Member, EdHooker> hookedInfo = new HashMap<>();
2526
private static final HookerDexMaker dexMaker = new HookerDexMaker();
2627
private static final AtomicBoolean dexPathInited = new AtomicBoolean(false);
2728
private static File dexDir;
@@ -47,17 +48,20 @@ public static synchronized void hookMethod(Member hookMethod, XposedBridge.Addit
4748
}
4849

4950
DexLog.d("start to generate class for: " + hookMethod);
51+
long startTime = System.nanoTime();
5052
try {
5153
// for Android Oreo and later use InMemoryClassLoader
5254
if (!shouldUseInMemoryHook()) {
5355
setupDexCachePath();
5456
}
5557
dexMaker.start(hookMethod, additionalHookInfo,
5658
hookMethod.getDeclaringClass().getClassLoader(), getDexDirPath());
57-
hookedInfo.put(hookMethod, dexMaker.getCallBackupMethod());
59+
hookedInfo.put(hookMethod, dexMaker.getHooker());
5860
} catch (Exception e) {
5961
DexLog.e("error occur when generating dex. dexDir=" + dexDir, e);
6062
}
63+
long endTime = System.nanoTime();
64+
DexLog.d("generated class for " + hookMethod + " in " + ((endTime-startTime) * 1.e-6) + "ms");
6165
}
6266

6367
private static String getDexDirPath() {
@@ -106,28 +110,11 @@ private static boolean checkMember(Member member) {
106110

107111
public static Object invokeOriginalMethod(Member method, Object thisObject, Object[] args)
108112
throws InvocationTargetException, IllegalAccessException {
109-
Method callBackup = hookedInfo.get(method);
110-
if (callBackup == null) {
113+
EdHooker hooker = hookedInfo.get(method);
114+
if (hooker == null) {
111115
throw new IllegalStateException("method not hooked, cannot call original method.");
112116
}
113-
if (!Modifier.isStatic(callBackup.getModifiers())) {
114-
throw new IllegalStateException("original method is not static, something must be wrong!");
115-
}
116-
callBackup.setAccessible(true);
117-
if (args == null) {
118-
args = new Object[0];
119-
}
120-
final int argsSize = args.length;
121-
if (Modifier.isStatic(method.getModifiers())) {
122-
return callBackup.invoke(null, args);
123-
} else {
124-
Object[] newArgs = new Object[argsSize + 1];
125-
newArgs[0] = thisObject;
126-
for (int i = 1; i < newArgs.length; i++) {
127-
newArgs[i] = args[i - 1];
128-
}
129-
return callBackup.invoke(null, newArgs);
130-
}
117+
return hooker.callBackup(thisObject, args);
131118
}
132119
}
133120

0 commit comments

Comments
 (0)