Commit f249c30f authored by Administrator's avatar Administrator

update

parent 1ab64c03
......@@ -287,149 +287,153 @@ public class XPosedPlugin implements IRposedHookLoadPackage {
}
});
}
private static void handleqywxTencent() {
ClassLoadMonitor.addClassLoadMonitor(new ClassLoadMonitor.OnClassLoader() {
@Override
public void onClassLoad(Class<?> clazz) {
if (clazz.getName().contains("location")) {
Log.i(AppApplication.tag, "init class: " + clazz.getName());
}
}
});
Class<?> classIfExists = RposedHelpers.findClassIfExists("com.tencent.map.qywxgeolocation.TencentLocationManager", RatelToolKit.hostClassLoader);
if (classIfExists != null) {
handleqywxTencentClass(classIfExists);
} else {
//com.amap.api.location.AMapLocationClient.setLocationListener(com.amap.api.location.AMapLocationListener lis)
ClassLoadMonitor.addClassLoadMonitor("com.tencent.map.qywxgeolocation.TencentLocationManager",
//com.tencent.map.geolocation.TencentLocationManager
//com.tencent.map.geolocation.TencentLocationListener
ClassLoadMonitor.addClassLoadMonitor("com.tencent.map.qywxgeolocation.TencentLocationManager", new ClassLoadMonitor.OnClassLoader() {
@Override
public void onClassLoad(final Class<?> clazz) {
Log.i(AppApplication.tag, "命中企业微信腾讯API:" + clazz);
hasMapApi = true;
// 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) {
new ClassLoadMonitor.OnClassLoader() {
@Override
public void onClassLoad(Class<?> clazz) {
handleqywxTencentClass(clazz);
}
final Map<Object, Object> listenerMap = new ConcurrentHashMap<>();
});
}
}
RC_MethodHook replaceLocationListenerHook = new RC_MethodHook() {
private static void handleqywxTencentClass(final Class clazz) {
private Object produceTencentLocation(final Object tencentLocation, Class<?> TencentLocationClass) 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;
}
if (args == null) {
return RposedHelpers.callMethod(tencentLocation, method.getName());
} else {
return RposedHelpers.callMethod(tencentLocation, method.getName(), args);
}
}
};
Log.i(AppApplication.tag, "命中企业微信腾讯API:" + clazz);
hasMapApi = true;
// 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) {
Object fakeTencentLocation;
if (TencentLocationClass.isInterface()) {
fakeTencentLocation = Proxy.newProxyInstance(TencentLocationClass.getClassLoader(),
new Class[]{TencentLocationClass}, invocationHandler
);
final Map<Object, Object> listenerMap = new ConcurrentHashMap<>();
RC_MethodHook replaceLocationListenerHook = new RC_MethodHook() {
private Object produceTencentLocation(final Object tencentLocation, Class<?> TencentLocationClass) 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;
}
if (args == null) {
return RposedHelpers.callMethod(tencentLocation, method.getName());
} else {
fakeTencentLocation = RatelToolKit.dexMakerProxyBuilderHelper
.forClass(TencentLocationClass)
.parentClassLoader(TencentLocationClass.getClassLoader())
.onlyMethods(TencentLocationClass.getDeclaredMethods())
.handler(invocationHandler).build();
return RposedHelpers.callMethod(tencentLocation, method.getName(), args);
}
return fakeTencentLocation;
}
};
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
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();
}
//com.tencent.map.geolocation.TencentLocationListener
for (int i = 0; i < param.args.length; i++) {
Class<?> tencentLocationListenerSubclass = param.args[i].getClass();
Class<?> TencentLocationListenerClass = RposedHelpers.findClass("com.tencent.map.qywxgeolocation.TencentLocationListener", clazz.getClassLoader());
return fakeTencentLocation;
}
if (!TencentLocationListenerClass.isAssignableFrom(tencentLocationListenerSubclass)) {
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();
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (method.getName().equals("onLocationChanged")) {
Class<?> TencentLocationClass = RposedHelpers.findClass("com.tencent.map.qywxgeolocation.TencentLocation", clazz.getClassLoader());
// void onLocationChanged(com.tencent.map.geolocation.TencentLocation var1);
for (int j = 0; j < args.length; j++) {
Object tencentLocation = args[j];
if (!TencentLocationClass.isAssignableFrom(args[j].getClass())) {
continue;
}
//com.tencent.map.geolocation.TencentLocationListener
for (int i = 0; i < param.args.length; i++) {
Class<?> tencentLocationListenerSubclass = param.args[i].getClass();
Class<?> TencentLocationListenerClass = RposedHelpers.findClass("com.tencent.map.qywxgeolocation.TencentLocationListener", clazz.getClassLoader());
args[j] = produceTencentLocation(tencentLocation, TencentLocationClass);
break;
}
}
if (args == null) {
return RposedHelpers.callMethod(originListener, method.getName());
} else {
return RposedHelpers.callMethod(originListener, method.getName(), args);
if (!TencentLocationListenerClass.isAssignableFrom(tencentLocationListenerSubclass)) {
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")) {
Class<?> TencentLocationClass = RposedHelpers.findClass("com.tencent.map.qywxgeolocation.TencentLocation", clazz.getClassLoader());
// void onLocationChanged(com.tencent.map.geolocation.TencentLocation var1);
for (int j = 0; j < args.length; j++) {
Object tencentLocation = args[j];
if (!TencentLocationClass.isAssignableFrom(args[j].getClass())) {
continue;
}
args[j] = produceTencentLocation(tencentLocation, TencentLocationClass);
break;
}
};
Object proxyListener;
if (TencentLocationListenerClass.isInterface()) {
proxyListener = Proxy.newProxyInstance(TencentLocationListenerClass.getClassLoader(),
new Class[]{TencentLocationListenerClass}, invocationHandler
);
}
if (args == null) {
return RposedHelpers.callMethod(originListener, method.getName());
} else {
proxyListener = RatelToolKit.dexMakerProxyBuilderHelper
.forClass(tencentLocationListenerSubclass)
.parentClassLoader(tencentLocationListenerSubclass.getClassLoader())
.onlyMethods(tencentLocationListenerSubclass.getDeclaredMethods())
.handler(invocationHandler).build();
return RposedHelpers.callMethod(originListener, method.getName(), args);
}
listenerMap.put(param.args[i], proxyListener);
param.args[i] = proxyListener;
break;
}
};
Object proxyListener;
if (TencentLocationListenerClass.isInterface()) {
proxyListener = Proxy.newProxyInstance(TencentLocationListenerClass.getClassLoader(),
new Class[]{TencentLocationListenerClass}, invocationHandler
);
} else {
proxyListener = RatelToolKit.dexMakerProxyBuilderHelper
.forClass(tencentLocationListenerSubclass)
.parentClassLoader(tencentLocationListenerSubclass.getClassLoader())
.onlyMethods(tencentLocationListenerSubclass.getDeclaredMethods())
.handler(invocationHandler).build();
}
};
RposedBridge.hookAllMethods(clazz, "requestLocationUpdates", replaceLocationListenerHook);
RposedBridge.hookAllMethods(clazz, "requestSingleFreshLocation", replaceLocationListenerHook);
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.qywxgeolocation.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;
}
}
RposedHelpers.findAndHookMethod(clazz,
"removeUpdates",
"com.tencent.map.qywxgeolocation.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() {
......@@ -499,106 +503,117 @@ public class XPosedPlugin implements IRposedHookLoadPackage {
}
private static void handleGaoDeMap() {
//com.amap.api.location.AMapLocationClient.setLocationListener(com.amap.api.location.AMapLocationListener lis)
ClassLoadMonitor.addClassLoadMonitor("com.amap.api.location.AMapLocationClient", new ClassLoadMonitor.OnClassLoader() {
@Override
public void onClassLoad(Class<?> clazz) {
Log.i(AppApplication.tag, "命中高德API:" + clazz);
hasMapApi = true;
RposedHelpers.findAndHookMethod(clazz, "setLocationListener",
"com.amap.api.location.AMapLocationListener",
new RC_MethodHook() {
private static void handleGaodeAMapLocationClientClass(Class<?> clazz) {
Log.i(AppApplication.tag, "命中高德API:" + clazz);
hasMapApi = true;
RposedHelpers.findAndHookMethod(clazz, "setLocationListener",
"com.amap.api.location.AMapLocationListener",
new RC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
//TODO param.parameterTypes is null
Method method = (Method) param.method;
param.parameterTypes = method.getParameterTypes();
Class<?> aMapLocationListenerInterfaceClass = param.parameterTypes[0];
final Object originListener = param.args[0];
if (originListener == null) {
Log.i(AppApplication.tag, "originListener is null");
return;
}
Log.i(AppApplication.tag, "原始定位回掉监听器:" + originListener.getClass().getName());
if (RatelToolKit.dexMakerProxyBuilderHelper.isProxyClass(originListener.getClass())) {
Log.i(AppApplication.tag, "this is proxyClass");
return;
}
InvocationHandler invocationHandler = new InvocationHandler() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
//TODO param.parameterTypes is null
Method method = (Method) param.method;
param.parameterTypes = method.getParameterTypes();
Class<?> aMapLocationListenerInterfaceClass = param.parameterTypes[0];
final Object originListener = param.args[0];
if (originListener == null) {
Log.i(AppApplication.tag, "originListener is null");
return;
}
Log.i(AppApplication.tag, "原始定位回掉监听器:" + originListener.getClass().getName());
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
// Debug.waitForDebugger();
if (method.getName().equals("onLocationChanged")) {
Log.i(AppApplication.tag, "回掉onLocationChanged");
// void onLocationChanged(AMapLocation var1);
for (Object obj : args) {
if (!(obj instanceof Location)) {
continue;
}
if (RatelToolKit.dexMakerProxyBuilderHelper.isProxyClass(originListener.getClass())) {
Log.i(AppApplication.tag, "this is proxyClass");
return;
}
Location location = (Location) obj;
location.setLatitude(AppApplication.mockGPS.mLatitude);
location.setLongitude(AppApplication.mockGPS.mLongitude);
InvocationHandler invocationHandler = new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
// Debug.waitForDebugger();
if (method.getName().equals("onLocationChanged")) {
Log.i(AppApplication.tag, "回掉onLocationChanged");
// void onLocationChanged(AMapLocation var1);
for (Object obj : args) {
if (!(obj instanceof Location)) {
continue;
}
// public void setAddress(String var1) {
try {
RposedHelpers.callMethod(obj, "setAddress", AppApplication.mockGPS.address);
Integer errorCode = (Integer) RposedHelpers.callMethod(obj, "getErrorCode");
if (errorCode != 0) {
// 高德返回了错误,我们这里把他覆盖为成功
RposedHelpers.callMethod(obj, "setErrorInfo", "");
Location location = (Location) obj;
location.setLatitude(AppApplication.mockGPS.mLatitude);
location.setLongitude(AppApplication.mockGPS.mLongitude);
// public void setAddress(String var1) {
try {
RposedHelpers.callMethod(obj, "setAddress", AppApplication.mockGPS.address);
Integer errorCode = (Integer) RposedHelpers.callMethod(obj, "getErrorCode");
if (errorCode != 0) {
// 高德返回了错误,我们这里把他覆盖为成功
RposedHelpers.callMethod(obj, "setErrorInfo", "");
// 比较麻烦,这里看如果写如果,第二次写入无法生效,但是由于混淆,属性名称不定,无法直接反射
for (Field field : obj.getClass().getDeclaredFields()) {
if (!field.getType().equals(int.class)) {
continue;
}
field.setAccessible(true);
int anInt = field.getInt(obj);
if (anInt == errorCode) {
Log.i(TAG, "find int field: " + field);
field.set(obj, 0);
}
}
RposedHelpers.callMethod(obj, "setErrorCode", 0);
// 比较麻烦,这里看如果写如果,第二次写入无法生效,但是由于混淆,属性名称不定,无法直接反射
for (Field field : obj.getClass().getDeclaredFields()) {
if (!field.getType().equals(int.class)) {
continue;
}
} catch (Throwable throwable) {
Log.w(TAG, "error", throwable);
throwable.printStackTrace();
}
field.setAccessible(true);
int anInt = field.getInt(obj);
if (anInt == errorCode) {
Log.i(TAG, "find int field: " + field);
field.set(obj, 0);
}
}
RposedHelpers.callMethod(obj, "setErrorCode", 0);
}
} catch (Throwable throwable) {
Log.w(TAG, "error", throwable);
throwable.printStackTrace();
}
Log.i(TAG, "call method: " + method + " param: " + args[0]);
return RposedHelpers.callMethod(originListener, method.getName(), args);
}
};
Object proxyListener;
if (aMapLocationListenerInterfaceClass.isInterface()) {
proxyListener = Proxy.newProxyInstance(aMapLocationListenerInterfaceClass.getClassLoader(),
new Class[]{aMapLocationListenerInterfaceClass}, invocationHandler
);
} else {
proxyListener = RatelToolKit.dexMakerProxyBuilderHelper
.forClass(aMapLocationListenerInterfaceClass)
.parentClassLoader(aMapLocationListenerInterfaceClass.getClassLoader())
.onlyMethods(aMapLocationListenerInterfaceClass.getDeclaredMethods())
.handler(invocationHandler).build();
}
}
param.args[0] = proxyListener;
Log.i(TAG, "call method: " + method + " param: " + args[0]);
return RposedHelpers.callMethod(originListener, method.getName(), args);
}
});
};
}
Object proxyListener;
if (aMapLocationListenerInterfaceClass.isInterface()) {
proxyListener = Proxy.newProxyInstance(aMapLocationListenerInterfaceClass.getClassLoader(),
new Class[]{aMapLocationListenerInterfaceClass}, invocationHandler
);
} else {
proxyListener = RatelToolKit.dexMakerProxyBuilderHelper
.forClass(aMapLocationListenerInterfaceClass)
.parentClassLoader(aMapLocationListenerInterfaceClass.getClassLoader())
.onlyMethods(aMapLocationListenerInterfaceClass.getDeclaredMethods())
.handler(invocationHandler).build();
}
param.args[0] = proxyListener;
}
});
}
});
private static void handleGaoDeMap() {
Class<?> classIfExists = RposedHelpers.findClassIfExists("com.amap.api.location.AMapLocationClient", RatelToolKit.hostClassLoader);
if (classIfExists != null) {
handleGaodeAMapLocationClientClass(classIfExists);
} else {
//com.amap.api.location.AMapLocationClient.setLocationListener(com.amap.api.location.AMapLocationListener lis)
ClassLoadMonitor.addClassLoadMonitor("com.amap.api.location.AMapLocationClient",
new ClassLoadMonitor.OnClassLoader() {
@Override
public void onClassLoad(Class<?> clazz) {
handleGaodeAMapLocationClientClass(clazz);
}
});
}
}
}
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