I would like to know if it is possible to get the bytes of a class loaded by the bootstrap class loader. Everywhere I look, people suggest to get the bytes of an arbitrary class, one must simply do
Class.forName(className).getClassLoader().getResourceAsStream(className.replace('.', '/') + ".class");
And then read the InputStream
with a method of your choice, however this is not possible on classes loaded by the bootstrap class loader (such as java.lang.Object
), as for those classes Class#getClassLoader()
returns null
.
> Class.forName("java.lang.Object").getClassLoader()
null
Is this even possible? I've heard it can be done with instrumentation but I'm hoping there's a "better" way to do it (outside of locating rt.jar
in the Java installation and reading the class data from there or something)
question from:
https://stackoverflow.com/questions/65852376/obtain-the-bytes-of-a-class-loaded-by-the-boostrap-class-loader 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…