I’ve been working on a sort of bootstrapper for an application I am writing. It buffers an application from a website and runs it. It works very well up to the point that I call the main method of the main class of the application, which requires libraries, which are also streamed. The LIBs and the Application are in the same classloader, but it says it was unable to locate the library due to an unsatisfied link. I searched for help, but could not find any.
Share
I assume you’re getting an
UnsatisfiedLinkErrorbecause you haven’t done aRuntime.loadLibraryto bring in native code to supportnativemethods. Such libraries need to be on the local file-system and are independent of any class loader. Javadoc:and obviously,
Runtime.getRuntime()is independent of any particular class loader.If a network class load could cause a network load of native code, that would be a huge remote code execution vulnerability because native code cannot be constrained by a
SecurityManagerthe way java bytecode can be.If you trust the website that produces the application, and are fetching it over a secure channel (encrypted to prevent MITM and tampering), then you can fetch the libraries, dump them to the local file system, verify any signatures or checksums, then call
Runtime.loadLibraryorSystem.loadLibraryto load the native libraries before causing the class to initialize.If you don’t trust the authors of the website that produces the application, or that website hosts third-party content, then don’t load JARs much less system libraries from it.
Even if the website authors are trustworthy, loading system libraries or other native code that you haven’t vetted and tested can be dangerous. Process sandboxing via
chrootand system call interception can help mitigate this risk somewhat but be careful.