Java 代理、检测和数组创建

发布于 2024-10-10 03:24:22 字数 224 浏览 0 评论 0原文

我需要为我的 java 应用程序编写一个代理,它在每个数组创建时执行一些特定的操作。到目前为止,我无法找到任何方法来在此事件上运行我的代码。

  1. java.lang.instrument.ClassFileTransformer 没有获取“数组类”,因此无法挂钩“数组的构造函数”。并且“数组类永远不可修改”
  2. 没有 JVMTI 事件与此相对应 有

什么建议吗?

I need to write an agent for my java application, that does some specific stuff on every array creation. So far I was unable to find any way to run my code on this event.

  1. java.lang.instrument.ClassFileTransformer does not get "array classes", so no way to hook into "constructor of array". And "array classes are never modifiable"
  2. no JVMTI event corresponds to this

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紫罗兰の梦幻 2024-10-17 03:24:22

为此,您需要修改应用程序的字节码。我发现 ObjectWeb ASM 是完成这项工作的最佳工具。总体思路是:

  1. 创建一个 JVMTI 代理来拦截您感兴趣的类。
  2. 将您想要检测的类传递给 ASM 类转换器。
  3. 在类转换器中,您可以拦截与构造数组相关的 Java 操作码,例如 ANEWARRAY(请参阅 JVM 规范 了解更多)。

You'll need to modify the byte-code of your application to do that. I've found ObjectWeb ASM to be the best tool for the job. The general idea is to:

  1. Create a JVMTI agent which intercepts the classes you're interested in.
  2. Pass the classes you want to instrument to an ASM class transformer.
  3. In the class transformer, you can intercept the Java opcodes related to constructing an array, e.g. ANEWARRAY (see the JVM spec for more).
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文