Commit f249c30f authored by Administrator's avatar Administrator

update

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