refactor: clean up obsolete code, dead imports, and refine architecture
This commit is contained in:
1 parent
2f5b852e00
commit
8b49607efe
9 files changed
+28
-153
No files matched your search
@@ -1,125 +0,0 @@
|
|||||||
package com.lzxnone.openloc.hook.client
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.location.Location
|
|
||||||
import android.location.LocationManager
|
|
||||||
import com.lzxnone.openloc.hook.ipc.ConfigFetcher
|
|
||||||
import com.lzxnone.openloc.hook.model.GlobalMockMemory
|
|
||||||
import de.robv.android.xposed.XC_MethodHook
|
|
||||||
import de.robv.android.xposed.XposedBridge
|
|
||||||
import de.robv.android.xposed.XposedHelpers
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 客户端系统私有 Transport 内部类与 Fused 融合引流拦截器
|
|
||||||
* (基于 GhostMapX 核心架构设计)
|
|
||||||
*/
|
|
||||||
object ClientTransportHook {
|
|
||||||
|
|
||||||
fun hook(classLoader: ClassLoader, packageName: String, contextProvider: () -> Context?) {
|
|
||||||
hookSystemTransports(classLoader, packageName, contextProvider)
|
|
||||||
hookFusedProviderRedirect(classLoader, packageName, contextProvider)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 1. 深度拦截客户端必经的系统 Transport 内部类
|
|
||||||
*/
|
|
||||||
private fun hookSystemTransports(classLoader: ClassLoader, packageName: String, contextProvider: () -> Context?) {
|
|
||||||
val transportClassNames = listOf(
|
|
||||||
"android.location.LocationManager\$LocationListenerTransport",
|
|
||||||
"android.location.LocationManager\$GetCurrentLocationTransport",
|
|
||||||
"android.location.LocationManager\$BatchedLocationCallbackWrapper"
|
|
||||||
)
|
|
||||||
|
|
||||||
for (className in transportClassNames) {
|
|
||||||
val clazz = try {
|
|
||||||
XposedHelpers.findClass(className, classLoader)
|
|
||||||
} catch (_: Throwable) {
|
|
||||||
null
|
|
||||||
} ?: continue
|
|
||||||
|
|
||||||
for (method in clazz.declaredMethods) {
|
|
||||||
if (method.name == "onLocationChanged" || method.name == "onLocation") {
|
|
||||||
try {
|
|
||||||
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
|
||||||
override fun beforeHookedMethod(param: MethodHookParam) {
|
|
||||||
if (!getEffectiveParams(packageName, contextProvider)) return
|
|
||||||
|
|
||||||
for (arg in param.args) {
|
|
||||||
modifyLocationArgument(arg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} catch (_: Throwable) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 2. 强行阻断并重定向 Fused (融合定位) 提供商
|
|
||||||
*/
|
|
||||||
private fun hookFusedProviderRedirect(classLoader: ClassLoader, packageName: String, contextProvider: () -> Context?) {
|
|
||||||
try {
|
|
||||||
val lmClass = LocationManager::class.java
|
|
||||||
for (method in lmClass.declaredMethods) {
|
|
||||||
if (method.name == "requestLocationUpdates" || method.name == "requestSingleUpdate") {
|
|
||||||
try {
|
|
||||||
XposedBridge.hookMethod(method, object : XC_MethodHook() {
|
|
||||||
override fun beforeHookedMethod(param: MethodHookParam) {
|
|
||||||
if (!getEffectiveParams(packageName, contextProvider)) return
|
|
||||||
|
|
||||||
// 如果入参 provider 是 fused,强行引流至 gps
|
|
||||||
val providerIndex = param.args.indexOfFirst { it is String && it.equals("fused", ignoreCase = true) }
|
|
||||||
if (providerIndex != -1) {
|
|
||||||
param.args[providerIndex] = LocationManager.GPS_PROVIDER
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} catch (_: Throwable) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (_: Throwable) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getEffectiveParams(packageName: String, contextProvider: () -> Context?): Boolean {
|
|
||||||
if (packageName == "com.lzxnone.openloc") return false
|
|
||||||
if (GlobalMockMemory.isEnabled && GlobalMockMemory.shouldMock(packageName)) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
val ctx = contextProvider()
|
|
||||||
if (ctx != null) {
|
|
||||||
val config = ConfigFetcher.getConfig(ctx)
|
|
||||||
return config.shouldMock(packageName.ifBlank { ctx.packageName })
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun modifyLocationArgument(arg: Any?) {
|
|
||||||
if (arg == null) return
|
|
||||||
if (arg is Location) {
|
|
||||||
GlobalMockMemory.applyToLocation(arg)
|
|
||||||
} else if (arg is List<*>) {
|
|
||||||
for (item in arg) {
|
|
||||||
if (item is Location) {
|
|
||||||
GlobalMockMemory.applyToLocation(item)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (arg.javaClass.name.contains("LocationResult")) {
|
|
||||||
try {
|
|
||||||
val list = (XposedHelpers.callMethod(arg, "asList") as? List<*>)
|
|
||||||
?: (XposedHelpers.getObjectField(arg, "mLocations") as? List<*>)
|
|
||||||
if (list != null) {
|
|
||||||
for (loc in list) {
|
|
||||||
if (loc is Location) {
|
|
||||||
GlobalMockMemory.applyToLocation(loc)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val lastLoc = XposedHelpers.callMethod(arg, "getLastLocation") as? Location
|
|
||||||
if (lastLoc != null) {
|
|
||||||
GlobalMockMemory.applyToLocation(lastLoc)
|
|
||||||
}
|
|
||||||
} catch (_: Throwable) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.lzxnone.openloc.hook.interceptor
|
package com.lzxnone.openloc.hook.interceptor
|
||||||
|
|
||||||
import android.bluetooth.le.ScanCallback
|
import android.bluetooth.le.ScanCallback
|
||||||
import android.bluetooth.le.ScanResult
|
|
||||||
import com.lzxnone.openloc.hook.model.GlobalMockMemory
|
import com.lzxnone.openloc.hook.model.GlobalMockMemory
|
||||||
import de.robv.android.xposed.XC_MethodHook
|
import de.robv.android.xposed.XC_MethodHook
|
||||||
import de.robv.android.xposed.XposedBridge
|
import de.robv.android.xposed.XposedBridge
|
||||||
|
|||||||
@@ -3,10 +3,8 @@
|
|||||||
package com.lzxnone.openloc.hook.interceptor
|
package com.lzxnone.openloc.hook.interceptor
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.location.GnssStatus
|
|
||||||
import android.location.GpsStatus
|
import android.location.GpsStatus
|
||||||
import android.location.LocationManager
|
import android.location.LocationManager
|
||||||
import android.location.OnNmeaMessageListener
|
|
||||||
import com.lzxnone.openloc.hook.model.GlobalMockMemory
|
import com.lzxnone.openloc.hook.model.GlobalMockMemory
|
||||||
import de.robv.android.xposed.XC_MethodHook
|
import de.robv.android.xposed.XC_MethodHook
|
||||||
import de.robv.android.xposed.XposedBridge
|
import de.robv.android.xposed.XposedBridge
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import de.robv.android.xposed.XC_MethodHook
|
|||||||
import de.robv.android.xposed.XposedBridge
|
import de.robv.android.xposed.XposedBridge
|
||||||
import de.robv.android.xposed.XposedHelpers
|
import de.robv.android.xposed.XposedHelpers
|
||||||
import java.util.Collections
|
import java.util.Collections
|
||||||
import java.util.WeakHashMap
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 客户端 LocationManager 拦截器(严格对齐 GhostMapX LYe/LXe 实现)
|
* 客户端 LocationManager 拦截器(严格对齐 GhostMapX LYe/LXe 实现)
|
||||||
|
|||||||
@@ -126,24 +126,4 @@ object GlobalMockMemory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 就地覆写现有 Location 对象
|
|
||||||
*/
|
|
||||||
fun applyToLocation(location: Location) {
|
|
||||||
location.latitude = latitude
|
|
||||||
location.longitude = longitude
|
|
||||||
location.altitude = altitude
|
|
||||||
location.accuracy = accuracy
|
|
||||||
location.bearing = bearing
|
|
||||||
location.speed = speed
|
|
||||||
location.time = System.currentTimeMillis()
|
|
||||||
location.elapsedRealtimeNanos = SystemClock.elapsedRealtimeNanos()
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
||||||
location.verticalAccuracyMeters = 1.5f
|
|
||||||
location.speedAccuracyMetersPerSecond = 0.1f
|
|
||||||
location.bearingAccuracyDegrees = 1.0f
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -16,6 +16,16 @@ data class MockConfig(
|
|||||||
if (!isEnabled) return false
|
if (!isEnabled) return false
|
||||||
if (packageName.isNullOrBlank()) return true
|
if (packageName.isNullOrBlank()) return true
|
||||||
if (packageName == "com.lzxnone.openloc" || packageName == "android") return false
|
if (packageName == "com.lzxnone.openloc" || packageName == "android") return false
|
||||||
|
if (packageName.startsWith("com.android.server.") ||
|
||||||
|
packageName.startsWith("android.") ||
|
||||||
|
packageName.startsWith("com.qualcomm.") ||
|
||||||
|
packageName.startsWith("com.qti.") ||
|
||||||
|
packageName == "com.xiaomi.metoknlp" ||
|
||||||
|
packageName == "com.xiaomi.location.fused" ||
|
||||||
|
packageName.contains(".hal.") ||
|
||||||
|
packageName.contains("Gpo4Client")) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
return when (mode.uppercase()) {
|
return when (mode.uppercase()) {
|
||||||
"WHITELIST" -> whitelist.contains(packageName)
|
"WHITELIST" -> whitelist.contains(packageName)
|
||||||
"BLACKLIST" -> !blacklist.contains(packageName)
|
"BLACKLIST" -> !blacklist.contains(packageName)
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ object SystemServerHook {
|
|||||||
arg.javaClass.name.contains("Consumer") ||
|
arg.javaClass.name.contains("Consumer") ||
|
||||||
arg.javaClass.name.contains("Transport"))) {
|
arg.javaClass.name.contains("Transport"))) {
|
||||||
val binder = (arg as? IInterface)?.asBinder() ?: (arg as? IBinder)
|
val binder = (arg as? IInterface)?.asBinder() ?: (arg as? IBinder)
|
||||||
if (binder != null && pkg != null) {
|
if (binder != null) {
|
||||||
activeCallbacks[binder] = pkg
|
activeCallbacks[binder] = pkg
|
||||||
TraceLogger.i("SystemServer", "Bound callback binder=$binder to pkg=$pkg")
|
TraceLogger.i("SystemServer", "Bound callback binder=$binder to pkg=$pkg")
|
||||||
try {
|
try {
|
||||||
@@ -188,7 +188,7 @@ object SystemServerHook {
|
|||||||
arg.javaClass.name.contains("Transport") ||
|
arg.javaClass.name.contains("Transport") ||
|
||||||
arg.javaClass.name.contains("Callback"))) {
|
arg.javaClass.name.contains("Callback"))) {
|
||||||
val binder = (arg as? IInterface)?.asBinder() ?: (arg as? IBinder)
|
val binder = (arg as? IInterface)?.asBinder() ?: (arg as? IBinder)
|
||||||
if (binder != null && pkg != null) {
|
if (binder != null) {
|
||||||
activeListeners[binder] = pkg
|
activeListeners[binder] = pkg
|
||||||
TraceLogger.i("SystemServer", "Bound listener binder=$binder to pkg=$pkg")
|
TraceLogger.i("SystemServer", "Bound listener binder=$binder to pkg=$pkg")
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -80,8 +80,6 @@ import androidx.compose.material3.ModalBottomSheet
|
|||||||
import androidx.compose.material3.OutlinedTextField
|
import androidx.compose.material3.OutlinedTextField
|
||||||
import androidx.compose.material3.OutlinedTextFieldDefaults
|
import androidx.compose.material3.OutlinedTextFieldDefaults
|
||||||
import androidx.compose.material3.Surface
|
import androidx.compose.material3.Surface
|
||||||
import androidx.compose.material3.Switch
|
|
||||||
import androidx.compose.material3.SwitchDefaults
|
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TextButton
|
import androidx.compose.material3.TextButton
|
||||||
import androidx.compose.material3.rememberModalBottomSheetState
|
import androidx.compose.material3.rememberModalBottomSheetState
|
||||||
|
|||||||
@@ -62,4 +62,20 @@ class HookSafetyTest {
|
|||||||
assertFalse("hookStackTrace must be completely removed", methodNames.contains("hookStackTrace"))
|
assertFalse("hookStackTrace must be completely removed", methodNames.contains("hookStackTrace"))
|
||||||
assertFalse("hookSettingsCamouflage must be completely removed", methodNames.contains("hookSettingsCamouflage"))
|
assertFalse("hookSettingsCamouflage must be completely removed", methodNames.contains("hookSettingsCamouflage"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testHardwareAndSystemProvidersAreExemptFromMock() {
|
||||||
|
val config = MockConfig(
|
||||||
|
isEnabled = true,
|
||||||
|
mode = "GLOBAL"
|
||||||
|
)
|
||||||
|
assertFalse(config.shouldMock("com.lzxnone.openloc"))
|
||||||
|
assertFalse(config.shouldMock("android"))
|
||||||
|
assertFalse(config.shouldMock("com.android.server.location"))
|
||||||
|
assertFalse(config.shouldMock("com.android.server.location.gnss.hal.Gpo4Client"))
|
||||||
|
assertFalse(config.shouldMock("com.qualcomm.location"))
|
||||||
|
assertFalse(config.shouldMock("com.qti.location"))
|
||||||
|
assertFalse(config.shouldMock("com.xiaomi.metoknlp"))
|
||||||
|
assertFalse(config.shouldMock("com.xiaomi.location.fused"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user