Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DiDi
DoraemonKit
提交
fa8dfa9d
D
DoraemonKit
项目概览
DiDi
/
DoraemonKit
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
fa8dfa9d
编写于
5月 13, 2021
作者:
J
jackjintai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify:
[Android]-通过auto_server代替反射创建kit
上级
73998038
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
143 addition
and
62 deletion
+143
-62
Android/java/buildSrc/src/main/kotlin/com/didichuxing/doraemonkit/plugin/classtransformer/AbsClassTransformer.kt
...oraemonkit/plugin/classtransformer/AbsClassTransformer.kt
+34
-0
Android/java/buildSrc/src/main/kotlin/com/didichuxing/doraemonkit/plugin/classtransformer/BigImgTransformer.kt
.../doraemonkit/plugin/classtransformer/BigImgTransformer.kt
+65
-12
Android/java/buildSrc/src/main/kotlin/com/didichuxing/doraemonkit/plugin/classtransformer/CommTransformer.kt
...ng/doraemonkit/plugin/classtransformer/CommTransformer.kt
+10
-7
Android/java/buildSrc/src/main/kotlin/com/didichuxing/doraemonkit/plugin/classtransformer/EnterMethodStackTransformer.kt
...it/plugin/classtransformer/EnterMethodStackTransformer.kt
+3
-5
Android/java/buildSrc/src/main/kotlin/com/didichuxing/doraemonkit/plugin/classtransformer/GlobalSlowMethodTransformer.kt
...it/plugin/classtransformer/GlobalSlowMethodTransformer.kt
+2
-6
Android/java/buildSrc/src/main/kotlin/com/didichuxing/doraemonkit/plugin/classtransformer/MethodStackDepTransformer.kt
...nkit/plugin/classtransformer/MethodStackDepTransformer.kt
+2
-5
Android/java/buildSrc/src/main/kotlin/com/didichuxing/doraemonkit/plugin/classtransformer/UrlConnectionTransformer.kt
...onkit/plugin/classtransformer/UrlConnectionTransformer.kt
+17
-16
Android/java/doraemonkit/build.gradle
Android/java/doraemonkit/build.gradle
+10
-7
Android/java/doraemonkit/src/main/java/com/didichuxing/doraemonkit/kit/loginfo/LogInfoKit.java
...a/com/didichuxing/doraemonkit/kit/loginfo/LogInfoKit.java
+0
-4
未找到文件。
Android/java/buildSrc/src/main/kotlin/com/didichuxing/doraemonkit/plugin/classtransformer/AbsClassTransformer.kt
0 → 100644
浏览文件 @
fa8dfa9d
package
com.didichuxing.doraemonkit.plugin.classtransformer
import
com.didichuxing.doraemonkit.plugin.DoKitExtUtil
import
com.didichuxing.doraemonkit.plugin.isRelease
import
com.didiglobal.booster.transform.TransformContext
import
com.didiglobal.booster.transform.asm.ClassTransformer
import
com.didiglobal.booster.transform.asm.className
import
org.objectweb.asm.tree.ClassNode
/**
* ================================================
* 作 者:jint(金台)
* 版 本:1.0
* 创建日期:2021/5/12-18:06
* 描 述:
* 修订历史:
* ================================================
*/
open
class
AbsClassTransformer
:
ClassTransformer
{
fun
onCommInterceptor
(
context
:
TransformContext
,
klass
:
ClassNode
):
Boolean
{
if
(
context
.
isRelease
())
{
return
true
}
if
(!
DoKitExtUtil
.
dokitPluginSwitchOpen
())
{
return
true
}
return
false
}
}
\ No newline at end of file
Android/java/buildSrc/src/main/kotlin/com/didichuxing/doraemonkit/plugin/classtransformer/BigImgTransformer.kt
浏览文件 @
fa8dfa9d
...
...
@@ -23,16 +23,13 @@ import org.objectweb.asm.tree.VarInsnNode
*/
@Priority
(
1
)
@AutoService
(
ClassTransformer
::
class
)
class
BigImgTransformer
:
ClassTransformer
{
class
BigImgTransformer
:
AbsClassTransformer
()
{
override
fun
transform
(
context
:
TransformContext
,
klass
:
ClassNode
):
ClassNode
{
if
(
context
.
isRelease
(
))
{
if
(
onCommInterceptor
(
context
,
klass
))
{
return
klass
}
if
(!
DoKitExtUtil
.
dokitPluginSwitchOpen
())
{
return
klass
}
if
(!
DoKitExtUtil
.
commExt
.
bigImgSwitch
)
{
return
klass
...
...
@@ -101,7 +98,15 @@ class BigImgTransformer : ClassTransformer {
private
fun
createGlideInsnList
():
InsnList
{
return
with
(
InsnList
())
{
add
(
VarInsnNode
(
ALOAD
,
0
))
add
(
MethodInsnNode
(
INVOKESTATIC
,
"com/didichuxing/doraemonkit/aop/bigimg/glide/GlideHook"
,
"proxy"
,
"(Ljava/lang/Object;)V"
,
false
))
add
(
MethodInsnNode
(
INVOKESTATIC
,
"com/didichuxing/doraemonkit/aop/bigimg/glide/GlideHook"
,
"proxy"
,
"(Ljava/lang/Object;)V"
,
false
)
)
this
}
}
...
...
@@ -112,7 +117,15 @@ class BigImgTransformer : ClassTransformer {
private
fun
createPicassoInsnList
():
InsnList
{
return
with
(
InsnList
())
{
add
(
VarInsnNode
(
ALOAD
,
0
))
add
(
MethodInsnNode
(
INVOKESTATIC
,
"com/didichuxing/doraemonkit/aop/bigimg/picasso/PicassoHook"
,
"proxy"
,
"(Ljava/lang/Object;)V"
,
false
))
add
(
MethodInsnNode
(
INVOKESTATIC
,
"com/didichuxing/doraemonkit/aop/bigimg/picasso/PicassoHook"
,
"proxy"
,
"(Ljava/lang/Object;)V"
,
false
)
)
this
}
...
...
@@ -126,11 +139,43 @@ class BigImgTransformer : ClassTransformer {
return
with
(
InsnList
())
{
add
(
VarInsnNode
(
ALOAD
,
1
))
add
(
VarInsnNode
(
ALOAD
,
1
))
add
(
MethodInsnNode
(
INVOKEVIRTUAL
,
"com/facebook/imagepipeline/request/ImageRequestBuilder"
,
"getSourceUri"
,
"()Landroid/net/Uri;"
,
false
))
add
(
MethodInsnNode
(
INVOKEVIRTUAL
,
"com/facebook/imagepipeline/request/ImageRequestBuilder"
,
"getSourceUri"
,
"()Landroid/net/Uri;"
,
false
)
)
add
(
VarInsnNode
(
ALOAD
,
1
))
add
(
MethodInsnNode
(
INVOKEVIRTUAL
,
"com/facebook/imagepipeline/request/ImageRequestBuilder"
,
"getPostprocessor"
,
"()Lcom/facebook/imagepipeline/request/Postprocessor;"
,
false
))
add
(
MethodInsnNode
(
INVOKESTATIC
,
"com/didichuxing/doraemonkit/aop/bigimg/fresco/FrescoHook"
,
"proxy"
,
"(Landroid/net/Uri;Lcom/facebook/imagepipeline/request/Postprocessor;)Lcom/facebook/imagepipeline/request/Postprocessor;"
,
false
))
add
(
MethodInsnNode
(
INVOKEVIRTUAL
,
"com/facebook/imagepipeline/request/ImageRequestBuilder"
,
"setPostprocessor"
,
"(Lcom/facebook/imagepipeline/request/Postprocessor;)Lcom/facebook/imagepipeline/request/ImageRequestBuilder;"
,
false
))
add
(
MethodInsnNode
(
INVOKEVIRTUAL
,
"com/facebook/imagepipeline/request/ImageRequestBuilder"
,
"getPostprocessor"
,
"()Lcom/facebook/imagepipeline/request/Postprocessor;"
,
false
)
)
add
(
MethodInsnNode
(
INVOKESTATIC
,
"com/didichuxing/doraemonkit/aop/bigimg/fresco/FrescoHook"
,
"proxy"
,
"(Landroid/net/Uri;Lcom/facebook/imagepipeline/request/Postprocessor;)Lcom/facebook/imagepipeline/request/Postprocessor;"
,
false
)
)
add
(
MethodInsnNode
(
INVOKEVIRTUAL
,
"com/facebook/imagepipeline/request/ImageRequestBuilder"
,
"setPostprocessor"
,
"(Lcom/facebook/imagepipeline/request/Postprocessor;)Lcom/facebook/imagepipeline/request/ImageRequestBuilder;"
,
false
)
)
this
}
...
...
@@ -143,7 +188,15 @@ class BigImgTransformer : ClassTransformer {
private
fun
createImageLoaderInsnList
():
InsnList
{
return
with
(
InsnList
())
{
add
(
VarInsnNode
(
ALOAD
,
6
))
add
(
MethodInsnNode
(
INVOKESTATIC
,
"com/didichuxing/doraemonkit/aop/bigimg/imageloader/ImageLoaderHook"
,
"proxy"
,
"(Lcom/nostra13/universalimageloader/core/listener/ImageLoadingListener;)Lcom/nostra13/universalimageloader/core/listener/ImageLoadingListener;"
,
false
))
add
(
MethodInsnNode
(
INVOKESTATIC
,
"com/didichuxing/doraemonkit/aop/bigimg/imageloader/ImageLoaderHook"
,
"proxy"
,
"(Lcom/nostra13/universalimageloader/core/listener/ImageLoadingListener;)Lcom/nostra13/universalimageloader/core/listener/ImageLoadingListener;"
,
false
)
)
add
(
VarInsnNode
(
ASTORE
,
6
))
this
}
...
...
Android/java/buildSrc/src/main/kotlin/com/didichuxing/doraemonkit/plugin/classtransformer/CommTransformer.kt
浏览文件 @
fa8dfa9d
...
...
@@ -23,7 +23,7 @@ import org.objectweb.asm.tree.*
*/
@Priority
(
0
)
@AutoService
(
ClassTransformer
::
class
)
class
CommTransformer
:
ClassTransformer
{
class
CommTransformer
:
AbsClassTransformer
()
{
private
val
SHADOW_URL
=
"com/didichuxing/doraemonkit/aop/urlconnection/HttpUrlConnectionProxyUtil"
private
val
DESC
=
"(Ljava/net/URLConnection;)Ljava/net/URLConnection;"
...
...
@@ -33,14 +33,12 @@ class CommTransformer : ClassTransformer {
* 转化
*/
override
fun
transform
(
context
:
TransformContext
,
klass
:
ClassNode
):
ClassNode
{
if
(
context
.
isRelease
())
{
return
klass
}
if
(
!
DoKitExtUtil
.
dokitPluginSwitchOpen
(
))
{
if
(
onCommInterceptor
(
context
,
klass
))
{
return
klass
}
val
className
=
klass
.
className
val
superName
=
klass
.
formatSuperName
...
...
@@ -80,7 +78,13 @@ class CommTransformer : ClassTransformer {
"${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
)
MethodInsnNode
(
INVOKESTATIC
,
"com/didichuxing/doraemonkit/aop/location/GpsStatusUtil"
,
"wrap"
,
"(Landroid/location/GpsStatus;)Landroid/location/GpsStatus;"
,
false
)
)
}
}
...
...
@@ -314,7 +318,6 @@ class CommTransformer : ClassTransformer {
}
//hook Androidx的ComponentActivity
if
(
className
!=
"com.didichuxing.doraemonkit.aop.mc.DoKitProxyActivity"
&&
superName
==
"android.app.Activity"
)
{
createComponentActivitySuperActivityImpl
(
klass
)
...
...
Android/java/buildSrc/src/main/kotlin/com/didichuxing/doraemonkit/plugin/classtransformer/EnterMethodStackTransformer.kt
浏览文件 @
fa8dfa9d
...
...
@@ -25,16 +25,14 @@ import org.objectweb.asm.tree.*
*/
@Priority
(
3
)
@AutoService
(
ClassTransformer
::
class
)
class
EnterMethodStackTransformer
:
ClassTransformer
{
class
EnterMethodStackTransformer
:
AbsClassTransformer
()
{
private
val
thresholdTime
=
DoKitExtUtil
.
slowMethodExt
.
stackMethod
.
thresholdTime
private
val
level
=
0
override
fun
transform
(
context
:
TransformContext
,
klass
:
ClassNode
):
ClassNode
{
if
(
context
.
isRelease
())
{
return
klass
}
if
(!
DoKitExtUtil
.
dokitPluginSwitchOpen
())
{
if
(
onCommInterceptor
(
context
,
klass
))
{
return
klass
}
...
...
Android/java/buildSrc/src/main/kotlin/com/didichuxing/doraemonkit/plugin/classtransformer/GlobalSlowMethodTransformer.kt
浏览文件 @
fa8dfa9d
...
...
@@ -22,15 +22,11 @@ import org.objectweb.asm.tree.*
*/
@Priority
(
2
)
@AutoService
(
ClassTransformer
::
class
)
class
GlobalSlowMethodTransformer
:
ClassTransformer
{
class
GlobalSlowMethodTransformer
:
AbsClassTransformer
()
{
val
thresholdTime
=
DoKitExtUtil
.
slowMethodExt
.
normalMethod
.
thresholdTime
override
fun
transform
(
context
:
TransformContext
,
klass
:
ClassNode
):
ClassNode
{
if
(
context
.
isRelease
())
{
return
klass
}
if
(!
DoKitExtUtil
.
dokitPluginSwitchOpen
())
{
if
(
onCommInterceptor
(
context
,
klass
))
{
return
klass
}
...
...
Android/java/buildSrc/src/main/kotlin/com/didichuxing/doraemonkit/plugin/classtransformer/MethodStackDepTransformer.kt
浏览文件 @
fa8dfa9d
...
...
@@ -21,17 +21,14 @@ import org.objectweb.asm.tree.*
* 原理:transform()方法的调用是无序的 原因:哪一个class会先被transformer执行是不确定的 但是每一个class被transformer执行顺序是遵循transformer的Priority规则的
* ================================================
*/
class
MethodStackDepTransformer
(
private
val
level
:
Int
=
1
)
:
ClassTransformer
{
class
MethodStackDepTransformer
(
private
val
level
:
Int
=
1
)
:
AbsClassTransformer
()
{
private
val
thresholdTime
=
DoKitExtUtil
.
slowMethodExt
.
stackMethod
.
thresholdTime
override
fun
transform
(
context
:
TransformContext
,
klass
:
ClassNode
):
ClassNode
{
if
(
context
.
isRelease
(
))
{
if
(
onCommInterceptor
(
context
,
klass
))
{
return
klass
}
if
(!
DoKitExtUtil
.
dokitPluginSwitchOpen
())
{
return
klass
}
if
(!
DoKitExtUtil
.
dokitSlowMethodSwitchOpen
())
{
return
klass
...
...
Android/java/buildSrc/src/main/kotlin/com/didichuxing/doraemonkit/plugin/classtransformer/UrlConnectionTransformer.kt
浏览文件 @
fa8dfa9d
...
...
@@ -26,16 +26,13 @@ import org.objectweb.asm.tree.MethodInsnNode
*/
//@Priority(1)
//@AutoService(ClassTransformer::class)
class
UrlConnectionTransformer
:
ClassTransformer
{
private
val
SHADOW_URL
=
"com/didichuxing/doraemonkit/aop/urlconnection/HttpUrlConnectionProxyUtil"
class
UrlConnectionTransformer
:
AbsClassTransformer
()
{
private
val
SHADOW_URL
=
"com/didichuxing/doraemonkit/aop/urlconnection/HttpUrlConnectionProxyUtil"
private
val
DESC
=
"(Ljava/net/URLConnection;)Ljava/net/URLConnection;"
override
fun
transform
(
context
:
TransformContext
,
klass
:
ClassNode
):
ClassNode
{
if
(
context
.
isRelease
())
{
return
klass
}
if
(!
DoKitExtUtil
.
dokitPluginSwitchOpen
())
{
if
(
onCommInterceptor
(
context
,
klass
))
{
return
klass
}
...
...
@@ -48,15 +45,19 @@ class UrlConnectionTransformer : ClassTransformer {
}
klass
.
methods
.
forEach
{
method
->
method
.
instructions
?.
iterator
()
?.
asIterable
()
?.
filterIsInstance
(
MethodInsnNode
::
class
.
java
)
?.
filter
{
it
.
opcode
==
INVOKEVIRTUAL
&&
it
.
owner
==
"java/net/URL"
&&
it
.
name
==
"openConnection"
&&
it
.
desc
==
"()Ljava/net/URLConnection;"
}
?.
forEach
{
"${context.projectDir.lastPath()}-> hook urlconnection succeed:${klass.name}_${it.name}_${it.desc}"
.
println
()
method
.
instructions
.
insert
(
it
,
MethodInsnNode
(
INVOKESTATIC
,
SHADOW_URL
,
"proxy"
,
DESC
,
false
))
}
method
.
instructions
?.
iterator
()
?.
asIterable
()
?.
filterIsInstance
(
MethodInsnNode
::
class
.
java
)
?.
filter
{
it
.
opcode
==
INVOKEVIRTUAL
&&
it
.
owner
==
"java/net/URL"
&&
it
.
name
==
"openConnection"
&&
it
.
desc
==
"()Ljava/net/URLConnection;"
}
?.
forEach
{
"${context.projectDir.lastPath()}-> hook urlconnection succeed:${klass.name}_${it.name}_${it.desc}"
.
println
()
method
.
instructions
.
insert
(
it
,
MethodInsnNode
(
INVOKESTATIC
,
SHADOW_URL
,
"proxy"
,
DESC
,
false
)
)
}
}
return
klass
...
...
Android/java/doraemonkit/build.gradle
浏览文件 @
fa8dfa9d
...
...
@@ -36,10 +36,15 @@ android {
buildConfigField
(
"String"
,
"DOKIT_VERSION"
,
"\""
+
dokitVersion
+
"\""
)
}
}
// compileOptions {
// sourceCompatibility JavaVersion.VERSION_1_8
// targetCompatibility JavaVersion.VERSION_1_8
// }
compileOptions
{
sourceCompatibility
JavaVersion
.
VERSION_1_8
targetCompatibility
JavaVersion
.
VERSION_1_8
}
kotlinOptions
{
jvmTarget
=
"1.8"
}
dataBinding
{
...
...
@@ -47,9 +52,7 @@ android {
}
kotlinOptions
{
jvmTarget
=
"1.8"
}
}
...
...
Android/java/doraemonkit/src/main/java/com/didichuxing/doraemonkit/kit/loginfo/LogInfoKit.java
浏览文件 @
fa8dfa9d
...
...
@@ -4,11 +4,7 @@ import android.content.Context;
import
com.didichuxing.doraemonkit.R
;
import
com.didichuxing.doraemonkit.config.LogInfoConfig
;
import
com.didichuxing.doraemonkit.constant.FragmentIndex
;
import
com.didichuxing.doraemonkit.kit.AbstractKit
;
import
com.didichuxing.doraemonkit.kit.Category
;
import
com.didichuxing.doraemonkit.kit.core.DokitIntent
;
import
com.didichuxing.doraemonkit.kit.core.DokitViewManager
;
import
com.didichuxing.doraemonkit.kit.core.SimpleDokitStarter
;
import
com.google.auto.service.AutoService
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录