Can I modify the byte code of a Java method in the runtime?

后端 未结 4 975
花落未央
花落未央 2021-01-03 01:18

I am writing a plugin of another large java program .

I want to modify some byte code of some java method of the java program during runtime, so that I can intercept

4条回答
  •  孤独总比滥情好
    2021-01-03 01:42

    Yes, you can, but the process would be a bit tricky, as you would operate directly with memory. For this purpose, you'd look at unofficial documentation on sun.misc package and its Unsafe class.

    • Warning 1: the Unsafe class would be removed in JDK 9 according to official sources.
    • Warning 2: the Sun company would not take responsibility for your code to work correctly, as this class should not be used at all, and exists for system usage only.

提交回复
热议问题