Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DiDi
DoraemonKit
提交
8b71f2f7
D
DoraemonKit
项目概览
DiDi
/
DoraemonKit
10 个月 前同步成功
通知
166
Star
19623
Fork
3062
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
DoraemonKit
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
8b71f2f7
编写于
4月 26, 2021
作者:
J
jackjintai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify:
[Android]-hook getGpsStatus
上级
fbe146c0
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
87 addition
and
74 deletion
+87
-74
Android/java/buildSrc/src/main/kotlin/com/didichuxing/doraemonkit/plugin/classtransformer/CommTransformer.kt
...ng/doraemonkit/plugin/classtransformer/CommTransformer.kt
+29
-33
Android/java/doraemonkit-plugin/src/main/kotlin/com/didichuxing/doraemonkit/plugin/classtransformer/CommTransformer.kt
...ng/doraemonkit/plugin/classtransformer/CommTransformer.kt
+30
-17
Android/java/doraemonkit/src/main/java/com/didichuxing/doraemonkit/kit/gpsmock/GpsMockFragment.java
.../didichuxing/doraemonkit/kit/gpsmock/GpsMockFragment.java
+28
-24
未找到文件。
Android/java/buildSrc/src/main/kotlin/com/didichuxing/doraemonkit/plugin/classtransformer/CommTransformer.kt
浏览文件 @
8b71f2f7
...
...
@@ -44,9 +44,9 @@ class CommTransformer : ClassTransformer {
val
className
=
klass
.
className
val
superName
=
klass
.
formatSuperName
if
(
className
.
contains
(
"didihttp"
))
{
"${context.projectDir.lastPath()}==className===>$className"
.
println
()
}
//
if (className.contains("didihttp")) {
//
"${context.projectDir.lastPath()}==className===>$className".println()
//
}
//查找DoraemonKitReal&pluginConfig方法并插入指定字节码
if
(
className
==
"com.didichuxing.doraemonkit.DoKitReal"
)
{
...
...
@@ -68,6 +68,22 @@ class CommTransformer : ClassTransformer {
//gps字节码操作
if
(
DoKitExtUtil
.
commExt
.
gpsSwitch
)
{
//系统 gpsStatus hook
klass
.
methods
.
forEach
{
method
->
method
.
instructions
?.
iterator
()
?.
asIterable
()
?.
filterIsInstance
(
MethodInsnNode
::
class
.
java
)
?.
filter
{
it
.
opcode
==
INVOKEVIRTUAL
&&
it
.
owner
==
"android/location/LocationManager"
&&
it
.
name
==
"getGpsStatus"
&&
it
.
desc
==
"(Landroid/location/GpsStatus;)Landroid/location/GpsStatus;"
}
?.
forEach
{
"${context.projectDir.lastPath()}->hook LocationManager#getGpsStatus method succeed in : ${className}_${method.name}_${method.desc}"
.
println
()
method
.
instructions
.
insert
(
it
,
MethodInsnNode
(
INVOKESTATIC
,
"com/didichuxing/doraemonkit/aop/location/GpsStatusUtil"
,
"wrap"
,
"(Landroid/location/GpsStatus;)Landroid/location/GpsStatus;"
,
false
)
)
}
}
//插入高德地图定位相关字节码
if
(
className
==
"com.amap.api.location.AMapLocationClient"
)
{
...
...
@@ -97,25 +113,20 @@ class CommTransformer : ClassTransformer {
it
.
name
==
"getLastKnownLocation"
}.
let
{
methodNode
->
"${context.projectDir.lastPath()}->hook AMapLocationClient getLastKnownLocation succeed: ${className}_${methodNode?.name}_${methodNode?.desc}"
.
println
()
// methodNode?.instructions?.clear()
// for (instruction in methodNode!!.instructions) {
//// methodNode.instructions.remove(instruction)
// println("getLastKnownLocation===>${instruction.opcode}")
// }
methodNode
?.
instructions
?.
insert
(
createAMapClientLastKnownLocation
())
}
}
//插入高德 地图定位相关字节码
if
(
className
==
"com.amap.api.maps.AMap"
)
{
//设置LocationSource代理
klass
.
methods
?.
find
{
it
.
name
==
"setLocationSource"
}.
let
{
methodNode
->
"${context.projectDir.lastPath()}->hook amap map LocationSource succeed: ${className}_${methodNode?.name}_${methodNode?.desc}"
.
println
()
methodNode
?.
instructions
?.
insert
(
createAmapLocationSourceInsnList
())
}
}
//
if (className == "com.amap.api.maps.AMap") {
//
//设置LocationSource代理
//
klass.methods?.find {
//
it.name == "setLocationSource"
//
}.let { methodNode ->
//
"${context.projectDir.lastPath()}->hook amap map LocationSource succeed: ${className}_${methodNode?.name}_${methodNode?.desc}".println()
//
methodNode?.instructions?.insert(createAmapLocationSourceInsnList())
//
}
//
}
//插入高德地图导航相关字节码
// if (className == "com.amap.api.navi.AMapNavi") {
...
...
@@ -302,22 +313,7 @@ class CommTransformer : ClassTransformer {
}
// gpsStatus hook
klass
.
methods
.
forEach
{
method
->
method
.
instructions
?.
iterator
()
?.
asIterable
()
?.
filterIsInstance
(
MethodInsnNode
::
class
.
java
)
?.
filter
{
it
.
opcode
==
INVOKEVIRTUAL
&&
it
.
owner
==
"android/location/LocationManager"
&&
it
.
name
==
"getGpsStatus"
&&
it
.
desc
==
"(Landroid/location/GpsStatus;)Landroid/location/GpsStatus;"
}
?.
forEach
{
"${context.projectDir.lastPath()}->hook LocationManager#getGpsStatus method succeed in : ${className}_${method.name}_${method.desc}"
.
println
()
method
.
instructions
.
insert
(
it
,
MethodInsnNode
(
INVOKESTATIC
,
"com/didichuxing/doraemonkit/aop/location/GpsStatusUtil"
,
"wrap"
,
"(Landroid/location/GpsStatus;)Landroid/location/GpsStatus;"
,
false
)
)
}
}
//hook Androidx的ComponentActivity
if
(
className
!=
"com.didichuxing.doraemonkit.aop.mc.DoKitProxyActivity"
&&
superName
==
"android.app.Activity"
)
{
...
...
Android/java/doraemonkit-plugin/src/main/kotlin/com/didichuxing/doraemonkit/plugin/classtransformer/CommTransformer.kt
浏览文件 @
8b71f2f7
...
...
@@ -44,9 +44,9 @@ class CommTransformer : ClassTransformer {
val
className
=
klass
.
className
val
superName
=
klass
.
formatSuperName
if
(
className
.
contains
(
"didihttp"
))
{
"${context.projectDir.lastPath()}==className===>$className"
.
println
()
}
//
if (className.contains("didihttp")) {
//
"${context.projectDir.lastPath()}==className===>$className".println()
//
}
//查找DoraemonKitReal&pluginConfig方法并插入指定字节码
if
(
className
==
"com.didichuxing.doraemonkit.DoKitReal"
)
{
...
...
@@ -68,6 +68,22 @@ class CommTransformer : ClassTransformer {
//gps字节码操作
if
(
DoKitExtUtil
.
commExt
.
gpsSwitch
)
{
//系统 gpsStatus hook
klass
.
methods
.
forEach
{
method
->
method
.
instructions
?.
iterator
()
?.
asIterable
()
?.
filterIsInstance
(
MethodInsnNode
::
class
.
java
)
?.
filter
{
it
.
opcode
==
INVOKEVIRTUAL
&&
it
.
owner
==
"android/location/LocationManager"
&&
it
.
name
==
"getGpsStatus"
&&
it
.
desc
==
"(Landroid/location/GpsStatus;)Landroid/location/GpsStatus;"
}
?.
forEach
{
"${context.projectDir.lastPath()}->hook LocationManager#getGpsStatus method succeed in : ${className}_${method.name}_${method.desc}"
.
println
()
method
.
instructions
.
insert
(
it
,
MethodInsnNode
(
INVOKESTATIC
,
"com/didichuxing/doraemonkit/aop/location/GpsStatusUtil"
,
"wrap"
,
"(Landroid/location/GpsStatus;)Landroid/location/GpsStatus;"
,
false
)
)
}
}
//插入高德地图定位相关字节码
if
(
className
==
"com.amap.api.location.AMapLocationClient"
)
{
...
...
@@ -97,25 +113,20 @@ class CommTransformer : ClassTransformer {
it
.
name
==
"getLastKnownLocation"
}.
let
{
methodNode
->
"${context.projectDir.lastPath()}->hook AMapLocationClient getLastKnownLocation succeed: ${className}_${methodNode?.name}_${methodNode?.desc}"
.
println
()
// methodNode?.instructions?.clear()
// for (instruction in methodNode!!.instructions) {
//// methodNode.instructions.remove(instruction)
// println("getLastKnownLocation===>${instruction.opcode}")
// }
methodNode
?.
instructions
?.
insert
(
createAMapClientLastKnownLocation
())
}
}
//插入高德 地图定位相关字节码
if
(
className
==
"com.amap.api.maps.AMap"
)
{
//设置LocationSource代理
klass
.
methods
?.
find
{
it
.
name
==
"setLocationSource"
}.
let
{
methodNode
->
"${context.projectDir.lastPath()}->hook amap map LocationSource succeed: ${className}_${methodNode?.name}_${methodNode?.desc}"
.
println
()
methodNode
?.
instructions
?.
insert
(
createAmapLocationSourceInsnList
())
}
}
//
if (className == "com.amap.api.maps.AMap") {
//
//设置LocationSource代理
//
klass.methods?.find {
//
it.name == "setLocationSource"
//
}.let { methodNode ->
//
"${context.projectDir.lastPath()}->hook amap map LocationSource succeed: ${className}_${methodNode?.name}_${methodNode?.desc}".println()
//
methodNode?.instructions?.insert(createAmapLocationSourceInsnList())
//
}
//
}
//插入高德地图导航相关字节码
// if (className == "com.amap.api.navi.AMapNavi") {
...
...
@@ -302,6 +313,8 @@ class CommTransformer : ClassTransformer {
}
//hook Androidx的ComponentActivity
if
(
className
!=
"com.didichuxing.doraemonkit.aop.mc.DoKitProxyActivity"
&&
superName
==
"android.app.Activity"
)
{
createComponentActivitySuperActivityImpl
(
klass
)
...
...
Android/java/doraemonkit/src/main/java/com/didichuxing/doraemonkit/kit/gpsmock/GpsMockFragment.java
浏览文件 @
8b71f2f7
...
...
@@ -81,30 +81,35 @@ public class GpsMockFragment extends BaseFragment implements SettingItemAdapter.
mIvSearch
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
if
(!
checkInput
())
{
return
;
}
String
strLongLat
=
mEdLongLat
.
getText
().
toString
();
String
[]
longAndLat
=
strLongLat
.
split
(
" "
);
double
longitude
,
latitude
;
try
{
longitude
=
Double
.
valueOf
(
longAndLat
[
0
]);
latitude
=
Double
.
valueOf
(
longAndLat
[
1
]);
}
catch
(
Exception
e
)
{
ToastUtils
.
showShort
(
"经纬度必须为数字"
);
return
;
}
GpsMockManager
.
getInstance
().
mockLocationWithNotify
(
latitude
,
longitude
);
GpsMockConfig
.
saveMockLocation
(
new
LatLng
(
latitude
,
longitude
));
//刷新地图
String
url
=
String
.
format
(
"javascript:updateLocation(%s,%s)"
,
latitude
,
longitude
);
mWebView
.
loadUrl
(
url
);
ToastUtils
.
showShort
(
getString
(
R
.
string
.
dk_gps_location_change_toast
,
""
+
longitude
,
""
+
latitude
));
performMock
();
}
});
}
private
void
performMock
()
{
if
(!
checkInput
())
{
return
;
}
String
strLongLat
=
mEdLongLat
.
getText
().
toString
();
String
[]
longAndLat
=
strLongLat
.
split
(
" "
);
double
longitude
,
latitude
;
try
{
longitude
=
Double
.
parseDouble
(
longAndLat
[
0
]);
latitude
=
Double
.
parseDouble
(
longAndLat
[
1
]);
}
catch
(
Exception
e
)
{
ToastUtils
.
showShort
(
"经纬度必须为数字"
);
return
;
}
GpsMockManager
.
getInstance
().
mockLocationWithNotify
(
latitude
,
longitude
);
GpsMockConfig
.
saveMockLocation
(
new
LatLng
(
latitude
,
longitude
));
//刷新地图
String
url
=
String
.
format
(
"javascript:updateLocation(%s,%s)"
,
latitude
,
longitude
);
mWebView
.
loadUrl
(
url
);
ToastUtils
.
showShort
(
getString
(
R
.
string
.
dk_gps_location_change_toast
,
""
+
longitude
,
""
+
latitude
));
}
private
boolean
checkInput
()
{
String
strLongLat
=
mEdLongLat
.
getText
().
toString
();
if
(
TextUtils
.
isEmpty
(
strLongLat
))
{
...
...
@@ -125,8 +130,8 @@ public class GpsMockFragment extends BaseFragment implements SettingItemAdapter.
}
double
longitude
,
latitude
;
try
{
longitude
=
Double
.
valueOf
(
longAndLat
[
0
]);
latitude
=
Double
.
valueOf
(
longAndLat
[
1
]);
longitude
=
Double
.
parseDouble
(
longAndLat
[
0
]);
latitude
=
Double
.
parseDouble
(
longAndLat
[
1
]);
}
catch
(
Exception
e
)
{
ToastUtils
.
showShort
(
"经纬度必须为数字"
);
return
false
;
...
...
@@ -171,6 +176,7 @@ public class GpsMockFragment extends BaseFragment implements SettingItemAdapter.
public
void
onSettingItemSwitch
(
View
view
,
SettingItem
data
,
boolean
on
)
{
if
(
data
.
desc
==
R
.
string
.
dk_gpsmock_open
)
{
if
(
on
)
{
performMock
();
GpsMockManager
.
getInstance
().
startMock
();
}
else
{
GpsMockManager
.
getInstance
().
stopMock
();
...
...
@@ -180,8 +186,6 @@ public class GpsMockFragment extends BaseFragment implements SettingItemAdapter.
}
@Override
protected
int
onRequestLayout
()
{
return
R
.
layout
.
dk_fragment_gps_mock
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录