Java: Method hooking & Finding object instances

家住魔仙堡 提交于 2019-12-04 19:20:23
apangin

What you need is JVMTI agent - a native library that makes use of JVM Tool Interface.

Agents can be attached dynamically to a running VM using the Attach API.
See VirtualMachine.loadAgentPath.

  1. To get all instances of a given class use JVMTI IterateOverInstancesOfClass function.
    See the related question for details.

  2. To intercept a method of a foreign class you'll need JVMTI RetransformClasses API. The same can be also achieved by using Java-level instrumentation API, see Instrumentation.retransformClasses.

For the example of JVMTI-level method interception refer to demo/jvmti/mtrace from Oracle JDK demos and samples package.

Java-level instrumentation will be easier with bytecode manipulation libraries like Byte Buddy.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!