Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restrict native code functionality from Java

I have a java application which uses JNI in some parts to do some work. It follows the usual loading of DLL and then calling native methods of DLL. Is there any way we can restrict what native methods can do from the java application? For example, can we restrict DLLs not to open any files or not to open any sockets even if it has the code to do it? It can just forbid DLLs it loads for doing certain things, may be by loggin something or throwing an exception.

like image 645
vpram86 Avatar asked Jan 13 '10 14:01

vpram86


1 Answers

No you can't. The DLL gets loaded as a whole and then the Java side has no control on what the native code is doing.

One solution might be kind of man in the middle approach. This would involve coding a "shell" DLL that has the same interface as the original DLL. You tell Java to load a "shell" DLL for instance by putting it in a specific location and using the java.library.path property. Then the role of the "shell" DLL is to load the "true" DLL by sandboxing it and redirecting standard functions. This sounds like a lot of pain and this something that would happen in the native side on things, not from Java.

like image 163
Gregory Pakosz Avatar answered Oct 07 '22 00:10

Gregory Pakosz