12
12
import java .util .HashMap ;
13
13
import java .util .concurrent .atomic .AtomicBoolean ;
14
14
15
+ import de .robv .android .xposed .EdHooker ;
15
16
import de .robv .android .xposed .XposedBridge ;
16
17
17
18
import static com .elderdrivers .riru .edxp .util .FileUtils .getDataPathPrefix ;
21
22
22
23
public final class DynamicBridge {
23
24
24
- private static final HashMap <Member , Method > hookedInfo = new HashMap <>();
25
+ private static final HashMap <Member , EdHooker > hookedInfo = new HashMap <>();
25
26
private static final HookerDexMaker dexMaker = new HookerDexMaker ();
26
27
private static final AtomicBoolean dexPathInited = new AtomicBoolean (false );
27
28
private static File dexDir ;
@@ -47,17 +48,20 @@ public static synchronized void hookMethod(Member hookMethod, XposedBridge.Addit
47
48
}
48
49
49
50
DexLog .d ("start to generate class for: " + hookMethod );
51
+ long startTime = System .nanoTime ();
50
52
try {
51
53
// for Android Oreo and later use InMemoryClassLoader
52
54
if (!shouldUseInMemoryHook ()) {
53
55
setupDexCachePath ();
54
56
}
55
57
dexMaker .start (hookMethod , additionalHookInfo ,
56
58
hookMethod .getDeclaringClass ().getClassLoader (), getDexDirPath ());
57
- hookedInfo .put (hookMethod , dexMaker .getCallBackupMethod ());
59
+ hookedInfo .put (hookMethod , dexMaker .getHooker ());
58
60
} catch (Exception e ) {
59
61
DexLog .e ("error occur when generating dex. dexDir=" + dexDir , e );
60
62
}
63
+ long endTime = System .nanoTime ();
64
+ DexLog .d ("generated class for " + hookMethod + " in " + ((endTime -startTime ) * 1.e-6 ) + "ms" );
61
65
}
62
66
63
67
private static String getDexDirPath () {
@@ -106,28 +110,11 @@ private static boolean checkMember(Member member) {
106
110
107
111
public static Object invokeOriginalMethod (Member method , Object thisObject , Object [] args )
108
112
throws InvocationTargetException , IllegalAccessException {
109
- Method callBackup = hookedInfo .get (method );
110
- if (callBackup == null ) {
113
+ EdHooker hooker = hookedInfo .get (method );
114
+ if (hooker == null ) {
111
115
throw new IllegalStateException ("method not hooked, cannot call original method." );
112
116
}
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 );
131
118
}
132
119
}
133
120
0 commit comments