网站首页 > 博客文章 正文
一段简单地对系统服务LocationManager的hook代码(kotlin),用于排除可能的隐藏的定位调用逻辑。
参考: Hook技术(五)如何Hook系统中任意服务(https://blog.csdn.net/wangwei708846696/article/details/79569170)
object LocationServiceHook {
private const val TAG = "LocationServiceHook"
@JvmStatic
fun hook(){
val serviceManager = Class.forName("android.os.ServiceManager")!!
val getService = serviceManager.getDeclaredMethod("getService", String::class.java)!!
val rawBinder = getService.invoke(null, Context.LOCATION_SERVICE) as IBinder
val hookedBinder = Proxy.newProxyInstance(serviceManager.classLoader,
arrayOf<Class<*>>(IBinder::class.java),
LocationBinderProxyHookHandler(rawBinder)) as IBinder
val cacheField = serviceManager.getDeclaredField("sCache")
cacheField.isAccessible = true
val caches = cacheField.get(null) as MutableMap<String, IBinder>
caches[Context.LOCATION_SERVICE] = hookedBinder
MyLog.logI(TAG, "finish hook")
}
}
class LocationBinderProxyHookHandler(val base:IBinder):InvocationHandler{
companion object{
private const val TAG = "LocationBinderProxyHookHandler"
}
private val stub:Class<*>?
private val iinterface:Class<*>?
init {
stub = try {
Class.forName("android.location.ILocationManager\$Stub")
}catch (throwable:Throwable){
MyLog.logE(TAG, "android.location.ILocationManager", throwable)
null
}
iinterface = try{
Class.forName("android.location.ILocationManager")
}catch (throwable:Throwable){
MyLog.logE(TAG, "android.location.ILocationManager", throwable)
null
}
}
override fun invoke(proxy: Any?, method: Method?, args: Array<out Any>?): Any {
return if("queryLocalInterface" == method!!.name){
MyLog.logI(TAG, "queryLocalInterface")
Proxy.newProxyInstance(proxy!!.javaClass.classLoader,
arrayOf<Class<*>>(IBinder::class.java, IInterface::class.java, iinterface!!),
LocationBinderHookHandler(base, stub!!))
}else {
return if(args == null){
method.invoke(base, null)
}else{
method.invoke(base, *args)
}?:Unit
}
}
}
class LocationBinderHookHandler(base:IBinder, stubClass:Class<*> ):InvocationHandler{
companion object{
private const val TAG = "LocationBinderHookHandler"
}
private val base:Any?
init {
this.base = try {
val asInterfaceMethod = stubClass.getDeclaredMethod("asInterface", IBinder::class.java)
//ILocationManager.Stub.asInterface(base)
asInterfaceMethod.invoke(null, base)
}catch (throwable:Throwable){
MyLog.logE(TAG, "", throwable)
null
}
}
override fun invoke(proxy: Any?, method: Method?, args: Array<out Any>?): Any {
MyLog.logI(TAG, "nethod: ${method!!.name}, args: $args", Throwable())
return if(args == null){
method.invoke(base, null)
}else{
method.invoke(base, *args)
}?:Unit
}
}
猜你喜欢
- 2024-09-29 直击灵魂一问:协程到底是怎么切换线程的?
- 2024-09-29 八月冲刺别毁在传统一问一答模式,这份面试准备助你事半功倍
- 2024-09-29 Kotlin遇见数据结构丨说说顺序存储的二叉树如何创建遍历
- 2024-09-29 Kotlin实战—使用Room封装本地数据层
- 2024-09-29 知了堂|MybatisPlus—kotlin代码生成
- 2024-09-29 竟然有5种微服务框架可以替代Spring Boot
- 2024-09-29 ViewBinding 与 Kotlin 委托双剑合璧
- 2024-09-29 Kotlin编写一个GIFDialog 在线音视频解析三
- 2024-09-29 Kotlin+SpringBoot+Redis+Lua实现限流访问控制详解
- 2024-09-29 北上广程序员回重庆继续代码 kotlin音视频解析六 收藏
你 发表评论:
欢迎- 最近发表
- 标签列表
-
- ifneq (61)
- 字符串长度在线 (61)
- messagesource (56)
- aspose.pdf破解版 (56)
- promise.race (63)
- 2019cad序列号和密钥激活码 (62)
- window.performance (66)
- qt删除文件夹 (72)
- mysqlcaching_sha2_password (64)
- ubuntu升级gcc (58)
- nacos启动失败 (64)
- ssh-add (70)
- jwt漏洞 (58)
- macos14下载 (58)
- yarnnode (62)
- abstractqueuedsynchronizer (64)
- source~/.bashrc没有那个文件或目录 (65)
- springboot整合activiti工作流 (70)
- jmeter插件下载 (61)
- 抓包分析 (60)
- idea创建mavenweb项目 (65)
- vue回到顶部 (57)
- qcombobox样式表 (68)
- tomcatundertow (58)
- pastemac (61)
本文暂时没有评论,来添加一个吧(●'◡'●)