Commit 76059892 authored by Administrator's avatar Administrator

适配腾讯地图

parent 545603e7
......@@ -8,8 +8,8 @@ android {
applicationId "com.virjar.ratel.virtuallocation"
minSdkVersion 19
targetSdkVersion 28
versionCode 20200825
versionName "v1.0"
versionCode 20200930
versionName "v1.1"
archivesBaseName = "JDY_${versionName}".replace(' ', '_')
ndk {
abiFilters "armeabi-v7a", "arm64-v8a"//, "x86","arm64-v8a","x86_64"
......@@ -55,5 +55,7 @@ dependencies {
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation files('libs/tencent-mapsdk-shell-vector-api-originalsearchsheetcloserelease-4.3.9.6.1a2ea2f40c.jar')
implementation files('libs/TencentLocationSdk_v7.2.6_rdbae62b0_20200322_210334.jar')
compileOnly 'com.virjar:ratel-api:1.3.4'
}
......@@ -11,9 +11,12 @@ import com.virjar.ratel.api.rposed.RposedBridge;
import com.virjar.ratel.api.rposed.RposedHelpers;
import com.virjar.ratel.api.rposed.callbacks.RC_LoadPackage;
import java.io.IOException;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import top.littlerich.virtuallocation.common.AppApplication;
......@@ -41,6 +44,7 @@ public class XPosedPlugin implements IRposedHookLoadPackage {
handleGaoDeMap();
handleBaiduMap();
handleTencent();
ClassLoadMonitor.addClassLoadMonitor(new ClassLoadMonitor.OnClassLoader() {
@Override
......@@ -53,6 +57,123 @@ public class XPosedPlugin implements IRposedHookLoadPackage {
}
private static void handleTencent() {
//com.tencent.map.geolocation.TencentLocationManager
ClassLoadMonitor.addClassLoadMonitor("com.tencent.map.geolocation.TencentLocationManager", new ClassLoadMonitor.OnClassLoader() {
@Override
public void onClassLoad(Class<?> clazz) {
// public final int requestLocationUpdates(TencentLocationRequest var1, TencentLocationListener var2) {
// public final int requestLocationUpdates(TencentLocationRequest var1, TencentLocationListener var2, Looper var3) {
//public final int requestSingleFreshLocation(TencentLocationRequest var1, TencentLocationListener var2, Looper var3) {
//public final void removeUpdates(TencentLocationListener var1) {
final Map<Object, Object> listenerMap = new ConcurrentHashMap<>();
RC_MethodHook replaceLocationListenerHook = new RC_MethodHook() {
private Object produceTencentLocation(final Object tencentLocation) throws IOException {
Class<?> TencentLocationClass = tencentLocation.getClass();
InvocationHandler invocationHandler = new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (method.getName().equals("getLatitude")) {
return AppApplication.mockGPS.mLatitude;
} else if (method.getName().equals("getLongitude")) {
return AppApplication.mockGPS.mLongitude;
} else if (method.getName().equals("getAddress")) {
return AppApplication.mockGPS.address;
}
return RposedHelpers.callMethod(tencentLocation, method.getName(), args);
}
};
Object fakeTencentLocation;
if (TencentLocationClass.isInterface()) {
fakeTencentLocation = Proxy.newProxyInstance(TencentLocationClass.getClassLoader(),
new Class[]{TencentLocationClass}, invocationHandler
);
} else {
fakeTencentLocation = RatelToolKit.dexMakerProxyBuilderHelper
.forClass(TencentLocationClass)
.parentClassLoader(TencentLocationClass.getClassLoader())
.onlyMethods(TencentLocationClass.getDeclaredMethods())
.handler(invocationHandler).build();
}
return fakeTencentLocation;
}
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
//com.tencent.map.geolocation.TencentLocationListener
for (int i = 0; i < param.args.length; i++) {
Class<?> TencentLocationListenerClass = param.args[i].getClass();
if (!TencentLocationListenerClass.getName().equals("com.tencent.map.geolocation.TencentLocationListener")) {
continue;
}
final Object originListener = param.args[i];
if (originListener == null) {
return;
}
InvocationHandler invocationHandler = new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
// Debug.waitForDebugger();
if (method.getName().equals("onLocationChanged")) {
// void onLocationChanged(com.tencent.map.geolocation.TencentLocation var1);
for (int j = 0; j < args.length; j++) {
Object tencentLocation = args[j];
if (!(tencentLocation.getClass().getName().equals("com.tencent.map.geolocation.TencentLocation"))) {
continue;
}
//TODO
args[j] = produceTencentLocation(tencentLocation);
}
}
return RposedHelpers.callMethod(originListener, method.getName(), args);
}
};
Object proxyListener;
if (TencentLocationListenerClass.isInterface()) {
proxyListener = Proxy.newProxyInstance(TencentLocationListenerClass.getClassLoader(),
new Class[]{TencentLocationListenerClass}, invocationHandler
);
} else {
proxyListener = RatelToolKit.dexMakerProxyBuilderHelper
.forClass(TencentLocationListenerClass)
.parentClassLoader(TencentLocationListenerClass.getClassLoader())
.onlyMethods(TencentLocationListenerClass.getDeclaredMethods())
.handler(invocationHandler).build();
}
listenerMap.put(param.args[i], proxyListener);
param.args[i] = proxyListener;
break;
}
}
};
RposedBridge.hookAllMethods(clazz, "requestLocationUpdates", replaceLocationListenerHook);
RposedBridge.hookAllMethods(clazz, "requestSingleFreshLocation", replaceLocationListenerHook);
RposedHelpers.findAndHookMethod(clazz,
"removeUpdates",
"com.tencent.map.geolocation.TencentLocationListener",
new RC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
Object fakeListener = listenerMap.get(param.args[0]);
if (fakeListener != null) {
param.args[0] = fakeListener;
}
}
}
);
}
});
}
private static void handleBaiduMap() {
//com.baidu.location.LocationClient.registerLocationListener(com.baidu.location.BDLocationListener)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment