Suppose I have a java process that is receiving a runnable jar file from a trusted process in the form of a byte [], is there a way to invoke it without having to write the jar file to disk and then invoke it(start a new process that is running the jar)?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Here is one way you can accomplish it:
- Create a
ByteArrayInputStream
from thebyte []
received. Now use
JarInputStream
to create in-memory representation of the jar file.ByteArrayInputStream bis = new ByteArrayInputStream(byteArray); JarInputStream jis = new JarInputStream(bis);
This way you have the jar loaded in the memory.
- Now you can use custom classloaders to further process it. Here is one example you can refer to.
回答2:
The easiest approach would be to write it to a ramdisk and avoid the in-memory idea completely.