Skip to content

Commit

Permalink
更换 hook 点
Browse files Browse the repository at this point in the history
  • Loading branch information
wuxiaosu committed Nov 10, 2020
1 parent 7e81caa commit 5ca84d8
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 85 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.android.tools.build:gradle:4.1.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
12 changes: 9 additions & 3 deletions rimethelper/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 26
compileSdkVersion 30
defaultConfig {
applicationId "com.wuxiaosu.rimethelper"
minSdkVersion 21
targetSdkVersion 23
versionCode 5
versionName "1.04"
versionCode 6
versionName "1.05"
}

signingConfigs {
Expand Down Expand Up @@ -50,6 +50,12 @@ android {
]
}
}
android {
lintOptions {
checkReleaseBuilds false
abortOnError false
}
}
}

dependencies {
Expand Down
11 changes: 7 additions & 4 deletions rimethelper/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.wuxiaosu.rimethelper">

<!--允许程序打开网络套接字-->
Expand All @@ -16,16 +17,17 @@
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:resizeableActivity="true"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
tools:targetApi="n">
<activity
android:name=".activity.MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down Expand Up @@ -60,7 +62,8 @@

<meta-data
android:name="com.amap.api.v2.apikey"
android:value="${AMapKey}"/>
android:value="${AMapKey}" />

<activity
android:name=".activity.AMapLiteActivity"
android:screenOrientation="portrait"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected void afterHookedMethod(XC_MethodHook.MethodHookParam param) throws Thr
}

private void handleHook(ClassLoader classLoader, String versionName) {
new LocationHook(versionName).hook(classLoader);
LocationHook.hook(classLoader);
}

private String getVersionName(Context context, String pkgName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class MainActivity extends BaseActivity {
private EditText mEtLocationStartTime;

private final String[] supportVersions =
new String[]{"4.2.0", "4.2.1", "4.2.6", "4.2.8", "4.3.0", "4.3.1", "4.3.2", "4.3.3", "4.3.5", "4.3.7"};
new String[]{"4.2.0", "4.2.1", "4.2.6", "4.2.8", "4.3.0", "4.3.1", "4.3.2", "4.3.3", "4.3.5", "4.3.7", "5.1.35"};

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package com.wuxiaosu.rimethelper.hook;

import android.annotation.SuppressLint;

import com.wuxiaosu.rimethelper.BuildConfig;
import com.wuxiaosu.widget.SettingLabelView;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XSharedPreferences;
Expand All @@ -21,98 +23,64 @@
*/

public class LocationHook {
private XSharedPreferences xsp;

private boolean fakeLocation;
private boolean fakeLocationTime;
private String startTime;
private String latitude;
private String longitude;
private static XSharedPreferences sXsp;

private static boolean sFakeLocation;
private static boolean sFakeLocationTime;
private static String sStartTime;
private static String sLatitude;
private static String sLongitude;

public LocationHook(String versionName) {
xsp = new XSharedPreferences(BuildConfig.APPLICATION_ID, SettingLabelView.DEFAULT_PREFERENCES_NAME);
xsp.makeWorldReadable();
}
private static final List<String> LISTENER_CLASS = new ArrayList<>();

public void hook(final ClassLoader classLoader) {
public static void hook(final ClassLoader classLoader) {
try {
final Class aMapLocationClientClazz =
final Class<?> aMapLocationClientClazz =
XposedHelpers.findClass("com.amap.api.location.AMapLocationClient", classLoader);
XposedBridge.hookAllConstructors(aMapLocationClientClazz, new XC_MethodHook() {
XposedBridge.hookAllMethods(aMapLocationClientClazz, "setLocationListener", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
Field[] fields = aMapLocationClientClazz.getDeclaredFields();
for (Field field : fields) {
Object object = XposedHelpers.getObjectField(param.thisObject, field.getName());
if (object != null &&
!(object.getClass().getName()).equals("com.alibaba.android.rimet.LauncherApplication")) {
Class locationManagerClazz =
XposedHelpers.findClass(object.getClass().getName(), classLoader);
hookLocationManager(locationManagerClazz);
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
if (param.args.length == 1) {
Class<?> listenerClazz = param.args[0].getClass();
if (!LISTENER_CLASS.contains(listenerClazz.getName())) {
LISTENER_CLASS.add(listenerClazz.getName());
XposedBridge.hookAllMethods(listenerClazz, "onLocationChanged", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
param.args[0] = fakeAMapLocationObject(param.args[0]);
super.beforeHookedMethod(param);
}
});
}
}
super.afterHookedMethod(param);
}
});
} catch (Error | Exception e) {
XposedBridge.log(e);
}
}

private void reload() {
xsp.reload();
fakeLocation = xsp.getBoolean("fake_location", false);
fakeLocationTime = xsp.getBoolean("fake_location_time", false);
startTime = xsp.getString("location_start_time", "8:40");
latitude = xsp.getString("latitude", "39.908692");
longitude = xsp.getString("longitude", "116.397477");
}


private void hookLocationManager(Class locationManagerClazz) {
try {
//chat location
XposedBridge.hookAllMethods(locationManagerClazz, "setLocationListener", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
Class listenerClazz = param.args[0].getClass();
XposedBridge.hookAllMethods(listenerClazz, "onLocationChanged", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
param.args[0] = fakeAMapLocationObject(param.args[0]);
super.beforeHookedMethod(param);
}
});
super.beforeHookedMethod(param);
}
});
//web location
Method[] methods = locationManagerClazz.getMethods();
for (Method method : methods) {
Class[] classes = method.getParameterTypes();
if (classes.length == 1 && classes[0].getName().equals("com.amap.api.location.AMapLocation")) {
XposedBridge.hookMethod(method, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
param.args[0] = fakeAMapLocationObject(param.args[0]);
super.beforeHookedMethod(param);
}
});
break;
}
}
} catch (Throwable e) {
XposedBridge.log(e);
private static void reload() {
if (sXsp == null) {
sXsp = new XSharedPreferences(BuildConfig.APPLICATION_ID, SettingLabelView.DEFAULT_PREFERENCES_NAME);
sXsp.makeWorldReadable();
}
sXsp.reload();
sFakeLocation = sXsp.getBoolean("fake_location", false);
sFakeLocationTime = sXsp.getBoolean("fake_location_time", false);
sStartTime = sXsp.getString("location_start_time", "8:40");
sLatitude = sXsp.getString("latitude", "39.908692");
sLongitude = sXsp.getString("longitude", "116.397477");
}

private Object fakeAMapLocationObject(Object object) {
private static Object fakeAMapLocationObject(Object object) {
reload();
if (fakeLocation) {
if (!fakeLocationTime || isAfterSetTime(startTime)) {
XposedHelpers.callMethod(object, "setLatitude", Double.valueOf(latitude));
XposedHelpers.callMethod(object, "setLongitude", Double.valueOf(longitude));
if (sFakeLocation) {
if (!sFakeLocationTime || isAfterSetTime(sStartTime)) {
XposedHelpers.callMethod(object, "setLatitude", Double.valueOf(sLatitude));
XposedHelpers.callMethod(object, "setLongitude", Double.valueOf(sLongitude));
}
}
return object;
Expand All @@ -124,7 +92,8 @@ private Object fakeAMapLocationObject(Object object) {
* @param setTime 01:12
* @return
*/
private boolean isAfterSetTime(String setTime) {
@SuppressLint("SimpleDateFormat")
private static boolean isAfterSetTime(String setTime) {
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
Date date = null;
Date now = null;
Expand Down

0 comments on commit 5ca84d8

Please sign in to comment.