Skip to content

Commit 951eb2e

Browse files
committed
Improve compatibility with 8.1/9.0
1 parent ef60a9e commit 951eb2e

File tree

21 files changed

+56
-28
lines changed

21 files changed

+56
-28
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ AndHook is a lightweight hook framework for android. It is primarily written in
1212
# How the method was intercepted?
1313
![CallFlow](https://github.com/Rprop/AndHook/raw/master/CallFlow.png)
1414

15+
# Special Thanks
16+
- cly.comp
17+
1518
# References
1619
- [Cydia Substrate](https://github.com/Rprop/AndHook/tree/6cca8575771d13cbe3907442e4ed6808381b6fd5/jni/utils/Substrate) (armeabi-v7a, x86, x86_64)
1720
- [And64InlineHook](https://github.com/Rprop/And64InlineHook) (arm64-v8a)

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ android {
55
buildToolsVersion "27.0.3"
66

77
defaultConfig {
8-
applicationId "andhook.ui"
8+
applicationId "andhook.test"
99
minSdkVersion 14
1010
targetSdkVersion 27
1111
compileOptions {

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.2">
5+
android:versionName="3.5.6">
66

77
<uses-sdk
88
android:minSdkVersion="14"

app/src/main/java/andhook/test/JNI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static void test() {
1414

1515
try {
1616
// libAndHook.so must be loaded before libmyjnihook.so
17-
AndHook.ensureNativeLibraryLoaded();
17+
AndHook.ensureNativeLibraryLoaded(null);
1818
System.loadLibrary("myjnihook");
1919
} catch (final Throwable t) {
2020
MainActivity.alert(t);

app/src/main/java/andhook/test/app/MainApplication.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ public final class MainApplication extends Application {
1515
public void onCreate() {
1616
super.onCreate();
1717
installDefaultUncaughtExceptionHandler();
18+
AndHook.ensureNativeLibraryLoaded(null);
1819

1920
Log.i(AndTest.LOG_TAG, "\nApplication started.\n--------------------------------");
20-
AndHook.ensureNativeLibraryLoaded();
21+
2122
sApp = new WeakReference<Application>(this);
2223
}
2324

app/src/main/jni/Android.mk

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ LOCAL_LDFLAGS += -Wl,--strip-all
99
LOCAL_C_INCLUDES := $(LOCAL_PATH)
1010
LOCAL_SRC_FILES := myjnihook.cpp
1111
LOCAL_LDLIBS := -llog
12-
#LOCAL_SHARED_LIBRARIES += libAndHook
13-
LOCAL_LDLIBS += -L$(LOCAL_PATH)/../../../../lib/src/main/jniLibs/$(TARGET_ARCH_ABI)/ -lAndHook
12+
#LOCAL_SHARED_LIBRARIES += libAK
13+
LOCAL_LDLIBS += -L$(LOCAL_PATH)/../../../../lib/src/main/jniLibs/$(TARGET_ARCH_ABI)/ -lAK
1414
include $(BUILD_SHARED_LIBRARY)
1515

1616
#include $(CLEAR_VARS)
17-
#OCAL_MODULE := libAndHook
18-
#LOCAL_SRC_FILES := libAndHook.so
17+
#OCAL_MODULE := libAK
18+
#LOCAL_SRC_FILES := libAK
1919
#include $(PREBUILT_SHARED_LIBRARY)

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.2">
5+
android:versionName="3.5.6">
66

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

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

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,44 +9,61 @@
99

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

19-
static {
20+
@SuppressWarnings("all")
21+
public static void ensureNativeLibraryLoaded(final File lib_dir) {
22+
try {
23+
getVersionInfo();
24+
return;
25+
} catch (final UnsatisfiedLinkError ignored) {
26+
}
27+
2028
// Check if there is a usable directory for temporary files
21-
final File tmpdir = new File(System.getProperty("java.io.tmpdir", "/data/local/tmp/"));
29+
final File tmpdir = new File(System.getProperty("java.io.tmpdir",
30+
"/data/local/tmp/"));
2231
if (!tmpdir.canWrite() || !tmpdir.canExecute())
23-
throw new RuntimeException("Unable to load AndHook due to missing cache directory");
32+
throw new RuntimeException(
33+
"Unable to load AndHook due to missing cache directory");
2434

2535
try {
26-
System.loadLibrary("AndHook");
36+
if (lib_dir == null) {
37+
System.loadLibrary(LIB_NAME);
38+
} else {
39+
System.load(new File(lib_dir, "lib" + LIB_NAME + ".so")
40+
.getAbsolutePath());
41+
}
2742
} catch (final UnsatisfiedLinkError e) {
2843
try {
2944
// compatible with libhoudini
30-
System.loadLibrary("AndHookCompat");
45+
if (lib_dir == null) {
46+
System.loadLibrary(LIB_NAME + "Compat");
47+
} else {
48+
System.load(new File(lib_dir, "lib" + LIB_NAME + "Compat"
49+
+ ".so").getAbsolutePath());
50+
}
3151
} catch (final UnsatisfiedLinkError ignored) {
32-
throw new RuntimeException("Incompatible platform", e);
52+
throw new RuntimeException("Incompatible platform "
53+
+ android.os.Build.VERSION.SDK_INT, e);
3354
}
3455
}
3556
}
3657

37-
public static void ensureNativeLibraryLoaded() {
38-
new AndHook();
39-
}
40-
4158
public static native String getVersionInfo();
4259

4360
public static native int backup(final Member origin);
4461

4562
public static native int backup(final Class<?> clazz, final String name,
4663
final String signature);
4764

48-
public static native boolean hook(final Member origin,
49-
final Object extra, int shared_backup);
65+
public static native boolean hook(final Member origin, final Object extra,
66+
int shared_backup);
5067

5168
public static native boolean hook(final Class<?> clazz, final String name,
5269
final String signature, final Object extra, int shared_backup);
@@ -94,8 +111,8 @@ public static void hookNoBackup(final Class<?> clazz, final String name,
94111
@SuppressWarnings("all")
95112
public static boolean ensureClassInitialized(final Class<?> clazz) {
96113
if (clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers())) {
97-
Log.w(LOG_TAG, "interface or abstract class `" + clazz.getName() +
98-
"` cannot be initialized!");
114+
Log.w(LOG_TAG, "interface or abstract class `" + clazz.getName()
115+
+ "` cannot be initialized!");
99116
return false;
100117
}
101118
return initializeClass(clazz);
@@ -218,9 +235,12 @@ public static <T> T invokeObjectMethod(final int slot,
218235
* Returns the result of dynamically invoking this method. Equivalent to
219236
* {@code receiver.methodName(arg1, arg2, ... , argN)}.
220237
* <p>
221-
* <p>If the method is static, the receiver argument is ignored (and may be null).
222238
* <p>
223-
* <p>If the invocation completes normally, the return value itself is
239+
* If the method is static, the receiver argument is ignored (and may be
240+
* null).
241+
* <p>
242+
* <p>
243+
* If the invocation completes normally, the return value itself is
224244
* returned. If the method is declared to return a primitive type, the
225245
* return value is boxed. If the return type is void, null is returned.
226246
*/

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* This class contains most of Xposed's central logic, such as initialization and callbacks used by
1818
* the native side. It also includes methods to add new hooks.
1919
* <p>
20-
* Latest Update 2018/04/16
20+
* Latest Update 2018/04/20
2121
*/
2222
@SuppressWarnings("WeakerAccess")
2323
public final class XposedBridge {
@@ -37,6 +37,10 @@ public final class XposedBridge {
3737
// built-in handlers
3838
private static final ConcurrentHashMap<Member, AdditionalHookInfo> sHookedMethodInfos = new ConcurrentHashMap<>();
3939

40+
static {
41+
AndHook.ensureNativeLibraryLoaded(null);
42+
}
43+
4044
/**
4145
* Writes a message to the logcat error log.
4246
*
149 KB
Binary file not shown.

0 commit comments

Comments
 (0)