hook依赖库的jar包没效
lvandroid opened this issue · 7 comments
lvandroid commented
hook jar包无效是什么情况
sky-lijinbo commented
兄弟..需要自己配置包名路径 才可以成功hook哦
nailperry-zd commented
关于这一点我在ReadMe中注明了的,请知悉。请重点查看 targetPackages 的说明。
app的build.grade中添加如下代码,各配置项的含义请参考英文注释
codelessdaConfig {
//this will determine the name of this plugin transform, no practical use.
pluginName = 'myPluginTest'
//turn this on to make it print help content, default value is true
showHelp = true
//this flag will decide whether the log of the modifying process be printed or not, default value is false
keepQuiet = false
//this is a kit feature of the plugin, set it true to see the time consume of this build
watchTimeConsume = false
//this is the most important part, 3rd party JAR packages that want our plugin to inject;
//our plugin will inject package defined in 'AndroidManifest.xml' and 'butterknife.internal.butterknife.internal.DebouncingOnClickListener' by default.
//structure is like ['butterknife.internal','com.a.c'], type is HashSet<String>.
//You can also specify the name of the class;
//example: ['com.xxx.xxx.BaseFragment']
targetPackages = []
}
lvandroid commented
比如我要hook okhttp中的一个方法,我添加了 targetPackages=['okhttp3'],重写了visitMethodInsn()方法,我对比了run后的代码,只是复制了okhttp jar包的内容,没有注入成功。我以前用hiBeaver库的时候注入是成功的,用这个没有注入成功
nailperry-zd commented
回顾了下代码,我的插件只对 interface中的方法 和 Fragment中的方法 进行注入,实现方式较hiBeaver有所调整。
nailperry-zd commented
@lvandroid 从Gradle Console打印结果来看,okhttp3的确加入到扫描路径,只不过没有满足注入条件的方法。
====revisit modified okhttp3.internal.io.FileSystem====
* visit * ACC_ABSTRACT ACC_INTERFACE ACC_PUBLIC okhttp3/internal/io/FileSystem null java/lang/Object []
* visitInnerClass * okhttp3/internal/io/FileSystem$1 null null ACC_STATIC
* visitField * ACC_PUBLIC ACC_STATIC ACC_FINAL SYSTEM Lokhttp3/internal/io/FileSystem; null null
* visitEnd *
====finish modifying okhttp3.internal.io.FileSystem====
====start modifying okhttp3.internal.io.RealConnection====
* visit * ACC_PUBLIC ACC_FINAL ACC_SUPER okhttp3/internal/io/RealConnection null okhttp3/internal/framed/FramedConnection$Listener [okhttp3/Connection ]
* visitInnerClass * okhttp3/internal/framed/FramedConnection$Builder okhttp3/internal/framed/FramedConnection Builder ACC_PUBLIC ACC_STATIC
* visitInnerClass * okhttp3/Request$Builder okhttp3/Request Builder ACC_PUBLIC ACC_STATIC
* visitInnerClass * okhttp3/internal/framed/FramedConnection$Listener okhttp3/internal/framed/FramedConnection Listener ACC_ABSTRACT ACC_PUBLIC ACC_STATIC
* visitInnerClass * java/net/Proxy$Type java/net/Proxy Type ACC_ENUM ACC_PUBLIC ACC_STATIC ACC_FINAL
* visitInnerClass * okhttp3/Response$Builder okhttp3/Response Builder ACC_PUBLIC ACC_STATIC
* visitField * ACC_PRIVATE ACC_FINAL route Lokhttp3/Route; null null
* visitField * ACC_PRIVATE rawSocket Ljava/net/Socket; null null
* visitField * ACC_PUBLIC socket Ljava/net/Socket; null null
* visitField * ACC_PRIVATE handshake Lokhttp3/Handshake; null null
* visitField * ACC_PRIVATE protocol Lokhttp3/Protocol; null null
* visitField * ACC_BRIDGE ACC_PUBLIC framedConnection Lokhttp3/internal/framed/FramedConnection; null null
* visitField * ACC_PUBLIC successCount I null null
* visitField * ACC_PUBLIC source Lokio/BufferedSource; null null
* visitField * ACC_PUBLIC sink Lokio/BufferedSink; null null
* visitField * ACC_PUBLIC allocationLimit I null null
* visitField * ACC_PUBLIC ACC_FINAL allocations Ljava/util/List; Ljava/util/List<Ljava/lang/ref/Reference<Lokhttp3/internal/http/StreamAllocation;>;>; null
* visitField * ACC_PUBLIC noNewStreams Z null null
* visitField * ACC_PUBLIC idleAtNanos J null null
* visitMethod * ACC_PUBLIC <init> (Lokhttp3/Route;)V null null
* visitMethod * ACC_PUBLIC connect (IIILjava/util/List;Z)V (IIILjava/util/List<Lokhttp3/ConnectionSpec;>;Z)V [okhttp3/internal/http/RouteException ]
* visitMethod * ACC_PRIVATE connectSocket (IIILokhttp3/internal/ConnectionSpecSelector;)V null [java/io/IOException ]
* visitMethod * ACC_PRIVATE connectTls (IILokhttp3/internal/ConnectionSpecSelector;)V null [java/io/IOException ]
* visitMethod * ACC_PRIVATE createTunnel (II)V null [java/io/IOException ]
* visitMethod * ACC_PRIVATE createTunnelRequest ()Lokhttp3/Request; null [java/io/IOException ]
* visitMethod * isConnected ()Z null null
* visitMethod * ACC_PUBLIC route ()Lokhttp3/Route; null null
* visitMethod * ACC_PUBLIC cancel ()V null null
* visitMethod * ACC_PUBLIC socket ()Ljava/net/Socket; null null
* visitMethod * ACC_PUBLIC isHealthy (Z)Z null null
* visitMethod * ACC_PUBLIC onStream (Lokhttp3/internal/framed/FramedStream;)V null [java/io/IOException ]
* visitMethod * ACC_PUBLIC onSettings (Lokhttp3/internal/framed/FramedConnection;)V null null
* visitMethod * ACC_PUBLIC handshake ()Lokhttp3/Handshake; null null
* visitMethod * ACC_PUBLIC isMultiplexed ()Z null null
* visitMethod * ACC_PUBLIC protocol ()Lokhttp3/Protocol; null null
* visitMethod * ACC_PUBLIC toString ()Ljava/lang/String; null null
* visitEnd *
====revisit modified okhttp3.internal.io.RealConnection====
lvandroid commented
ok了,因为我hook的是方法中变量调用的方法,比如interceptor.intercept(chain),hook了把这个包装成我的方法,你的是在现有方法里添加方法。我条件匹配没写好。
还有个在AS 3.0中,需要project的 gradle.properties, 添加android.enableD8=true才行,不知道你们有没有这个问题
nailperry-zd commented
@lvandroid 调研了下AS3.0 D8,这块的确没有考虑过,谢谢你的提醒^_^