Closed lzmhehe closed 7 years ago
个人觉得这样分包处理更好,这样把核心代码分开加载,能有效的通过类加载器对greys的类进行隔离,这样可以防止对目标应用的污染
@YuhuiFeng 说得对,可以看下AgentLauncher
的ClassLoader加载截图
+----------------------------------------------------+----------------------------------------------------------------------------------+
| class-info | com.github.ompc.greys.agent.AgentLauncher |
+----------------------------------------------------+----------------------------------------------------------------------------------+
| code-source | /Users/vlinux/.greys/lib/1.7.6.4/greys/greys-agent.jar |
+----------------------------------------------------+----------------------------------------------------------------------------------+
| name | com.github.ompc.greys.agent.AgentLauncher |
+----------------------------------------------------+----------------------------------------------------------------------------------+
| isInterface | false |
+----------------------------------------------------+----------------------------------------------------------------------------------+
| isAnnotation | false |
+----------------------------------------------------+----------------------------------------------------------------------------------+
| isEnum | false |
+----------------------------------------------------+----------------------------------------------------------------------------------+
| isAnonymousClass | false |
+----------------------------------------------------+----------------------------------------------------------------------------------+
| isArray | false |
+----------------------------------------------------+----------------------------------------------------------------------------------+
| isLocalClass | false |
+----------------------------------------------------+----------------------------------------------------------------------------------+
| isMemberClass | false |
+----------------------------------------------------+----------------------------------------------------------------------------------+
| isPrimitive | false |
+----------------------------------------------------+----------------------------------------------------------------------------------+
| isSynthetic | false |
+----------------------------------------------------+----------------------------------------------------------------------------------+
| simple-name | AgentLauncher |
+----------------------------------------------------+----------------------------------------------------------------------------------+
| modifier | public |
+----------------------------------------------------+----------------------------------------------------------------------------------+
| annotation | |
+----------------------------------------------------+----------------------------------------------------------------------------------+
| interfaces | |
+----------------------------------------------------+----------------------------------------------------------------------------------+
| super-class | java.lang.Object |
+----------------------------------------------------+----------------------------------------------------------------------------------+
| class-loader | sun.misc.Launcher$AppClassLoader@2a139a55 |
| | `-sun.misc.Launcher$ExtClassLoader@655e7a34 |
+----------------------------------------------------+----------------------------------------------------------------------------------+
可以看到在agent.jar
被attach所加载的时候是被AppClassLoader
所加载,如果core.jar
作为引导jar包被加载进来,在后续的编码工作中一个不下心,很容易就被AppClassLoader
所误加载其他非greys的类。
所以为了后续整个工程的维护方便,单独隔离了一个agent模块
出来,这个模块的pom引用都被非常严格的限制。
多谢作者 我自己写了一段代码,被classloader搞晕后,就马上理解你们为什么这么处理了
纸上得来终觉浅,绝知此事须 宫刑 !:)
您好 非常感谢greys团队开源的这个项目,对我的实际工作,提供很大帮助。 有个疑问 为什么项目会分两个包,agent仅是一个空壳, 把agent的内容放到core中,attach的时候再把core.jar传个目标jvm是否可以