在Java中挂钩现有方法 [英] Hooking an existing method in Java
问题描述
我希望在Java中挂钩方法System.out.print,并且能够在调用方法的部分之前读取/更改方法中使用的变量,该方法实际上将字符串添加到输出流的任何位置。
I want to hook the method System.out.print in Java and have the ability to read/change the variables used in the method before the part of the method is called that actually adds the string to whatever the output stream is.
在C ++中我只是绕道该函数,或者设置一个int3指令,这样我就可以访问寄存器但是在java中我不知道如何完成类似的东西。
In C++ I would just detour the function, or set an int3 instruction so I could access the registers but in java I have no idea how to accomplish something similar.
推荐答案
您可以重写方法的字节代码,并在此过程中捕获/更改局部变量。这不是微不足道的。请参阅此处。
You can rewrite the byte code of the methods, and in the process capture/change the local variables. It is not trivial. See some notes here.
也许您真正想要的是java调试器?您可以使用eclipse将调试器连接到远程进程,添加断点以及非常轻松地捕获/更改局部变量。
Maybe what you really want is a java debugger? You can connect a debugger to a remote process, add a breakpoint, and capture/change the local variables pretty easily using eclipse.
您尝试的实际问题是什么?解决?
What is the real problem you are trying to solve?
这篇关于在Java中挂钩现有方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!