Skip to content

Commit 57ad9b9

Browse files
committed
Fix bridge to support @CriticalNative methods
1 parent 7da039e commit 57ad9b9

File tree

16 files changed

+63
-13
lines changed

16 files changed

+63
-13
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="andhook.test"
44
android:versionCode="3"
5-
android:versionName="3.5.6">
5+
android:versionName="3.5.8">
66

77
<uses-sdk
88
android:minSdkVersion="14"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package andhook.test;
2+
3+
import andhook.lib.HookHelper;
4+
import andhook.lib.HookHelper.Hook;
5+
import andhook.test.ui.MainActivity;
6+
7+
public final class Native {
8+
private static boolean passed = false;
9+
10+
// @CriticalNative since Android O
11+
@Hook(clazz = android.os.SystemClock.class, need_origin = true)
12+
private static long currentThreadTimeMillis(final Class<?> clazz) {
13+
passed = true;
14+
MainActivity.output("currentThreadTimeMillis called, class = " + clazz);
15+
MainActivity.output(new RuntimeException("test"));
16+
return HookHelper.invokeLongOrigin(null);
17+
}
18+
19+
public static void test() {
20+
MainActivity.clear();
21+
MainActivity.output("hook native java...");
22+
23+
passed = false;
24+
HookHelper.applyHooks(Native.class);
25+
android.os.SystemClock.currentThreadTimeMillis();
26+
27+
if (passed)
28+
MainActivity.info("native java hook test passed");
29+
else
30+
MainActivity.alert("native java hook test failed");
31+
}
32+
}

app/src/main/java/andhook/test/ui/MainActivity.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import andhook.test.InnerException;
1010
import andhook.test.JNI;
1111
import andhook.test.app.MainApplication;
12+
import andhook.test.Native;
1213
import andhook.test.R;
1314
import andhook.test.Static;
1415
import andhook.test.SystemClass;
@@ -138,6 +139,13 @@ public void onClick(final View v) {
138139
SystemClass.test(MainActivity.this.getContentResolver());
139140
}
140141
});
142+
findViewById(R.id.Native).setOnClickListener(
143+
new OnClickListener() {
144+
@Override
145+
public void onClick(final View v) {
146+
Native.test();
147+
}
148+
});
141149
findViewById(R.id.Thread).setOnClickListener(new OnClickListener() {
142150
@Override
143151
public void onClick(final View v) {

app/src/main/res/layout/activity_main.xml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@
8080
android:layout_alignParentStart="true"
8181
android:layout_alignParentLeft="true"
8282
android:layout_below="@+id/JNI"
83-
android:layout_marginStart="77dp"
84-
android:layout_marginLeft="77dp"
83+
android:layout_marginStart="84dp"
84+
android:layout_marginLeft="84dp"
8585
android:layout_marginTop="2dp"
8686
android:text="@string/Virtual" />
8787

@@ -108,6 +108,18 @@
108108
android:layout_marginLeft="1dp"
109109
android:layout_marginTop="2dp"
110110
android:text="@string/SystemClass" />
111+
112+
<Button
113+
android:id="@+id/Native"
114+
android:layout_width="wrap_content"
115+
android:layout_height="wrap_content"
116+
android:layout_alignParentStart="true"
117+
android:layout_alignParentLeft="true"
118+
android:layout_below="@+id/Static"
119+
android:layout_marginStart="87dp"
120+
android:layout_marginLeft="87dp"
121+
android:layout_marginTop="2dp"
122+
android:text="@string/Native" />
111123

112124
<Button
113125
android:id="@+id/Thread"

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
<string name="Static">Static</string>
1111
<string name="Virtual">Virtual</string>
1212
<string name="WideningConversion">WideningConversion</string>
13-
<string name="SystemClass">SystemClass</string>
13+
<string name="SystemClass">System</string>
14+
<string name="Native">Native</string>
1415
<string name="Thread">Thread</string>
1516
<string name="Exception">Exception</string>
1617

lib/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="andhook.lib"
44
android:versionCode="3"
5-
android:versionName="3.5.6">
5+
android:versionName="3.5.8">
66

77
<application android:hasCode="true" />
88
</manifest>

lib/src/main/java/andhook/lib/AndHook.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99

1010
/**
1111
* @author Rprop
12-
* @version 3.5.6
12+
* @version 3.5.8
1313
*/
1414
@SuppressWarnings({"unused", "WeakerAccess", "JniMissingFunction"})
1515
public final class AndHook {
1616
private final static String LIB_NAME = "AK";
17-
public final static String VERSION = "3.5.6";
17+
public final static String VERSION = "3.5.8";
1818
public final static String LOG_TAG = "AndHook";
1919

2020
@SuppressWarnings("all")

lib/src/main/java/andhook/lib/HookHelper.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ public final class HookHelper {
1919
public static final String constructorName = "<init>";
2020
private static final ConcurrentHashMap<Pair<String, String>, Integer> sBackups = new ConcurrentHashMap<>();
2121

22-
private static void warnKnownIssue(final Class<?> clazz,
23-
final Method replace) {
22+
private static void warnKnownIssue(final Method replace) {
2423
if (!Modifier.isStatic(replace.getModifiers())
2524
|| replace.getParameterTypes().length < 1
2625
|| replace.getParameterTypes()[0].isPrimitive()) {
@@ -37,7 +36,7 @@ public static void hook(final Member origin, final Method replace) {
3736
if (uniqueKey(replace) == null)
3837
return;
3938

40-
warnKnownIssue(origin.getDeclaringClass(), replace);
39+
warnKnownIssue(replace);
4140
final int slot = AndHook.backup(origin);
4241
if (slot != -1 && saveBackupSlot(slot, replace)) {
4342
AndHook.hook(origin, replace, slot);
@@ -49,7 +48,7 @@ public static void hook(final Class<?> clazz, final String name,
4948
if (uniqueKey(replace) == null)
5049
return;
5150

52-
warnKnownIssue(clazz, replace);
51+
warnKnownIssue(replace);
5352
final int slot = AndHook.backup(clazz, name, signature);
5453
if (slot != -1 && saveBackupSlot(slot, replace)) {
5554
AndHook.hook(clazz, name, signature, replace, slot);

lib/src/main/java/andhook/lib/xposed/XposedBridge.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ public static XC_MethodHook.Unhook hookMethod(final Member hookMethod, final XC_
111111
*
112112
* @param hookMethod The method for which the callback should be removed.
113113
* @param callback The reference to the callback as specified in {@link #hookMethod}.
114-
* @deprecated Use {@link XC_MethodHook.Unhook#unhook} instead. An instance of the {@code Unhook}
115-
* class is returned when you hook the method.
116114
*/
117115
@SuppressWarnings("all")
118116
public static void unhookMethod(final Member hookMethod, final XC_MethodHook callback) {
8.55 KB
Binary file not shown.

0 commit comments

Comments
 (0)