How to verify Java Bytecode before injecting into the JVM?

孤人 提交于 2021-02-19 07:27:47

问题


I'm trying to verify "on the fly" generated bytecode!

I already had several attempts, one attempt was to compile my classes in runtime with the eclipse compiler another was to compile from memory as mentioned here:

Compile From Memory

First results looked okay but I'm still not a 100% sure if the verification process is truly valid according to the JAVA 6 guidelines and security measurements as well to normal OOP Models.

Any better way on how to verify bytecode?


回答1:


If you load the generated bytecode using a standard class loader, the bytecode verifier of the JVM will verify (make sure it type checks, never falls of the "edge" of a method and so on) the bytecode for you.




回答2:


You can use the class verifier provided by the ASM toolkit. That does not require actually loading the classes by the JVM, and gives you more detailed verification error reports.



来源:https://stackoverflow.com/questions/9926546/how-to-verify-java-bytecode-before-injecting-into-the-jvm

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