Reputation: 10642
I'm investigating ways to ensure a java class only calls a limited set of allowed methods from other classes. The usecase I have receives the class via the standard java serialization.
The approach I want to try is to simply list the methods it calls and only run the code if it passes a short whire list.
The question I have : how do I list the methods used in that class?
Upvotes: 0
Views: 223
Reputation: 26882
You could pass a dynamic proxy object to the caller, which inside checks the methods against your white list and throws exception when the call is not allowed.
Dynamic proxies basically allows you to insert piece of code between the caller's method invocation and the actual invocation of the called method.
I'd really think through though to if you really need this. Dynamic proxies are useful but they can also be very confusing and annoying to debug.
Upvotes: 1
Reputation: 17422
This is not a perfect solution but you coud use this if you can't find something better. You can use javap
, if you're in Linux, run in the command line (or run a proccess using Runtime.exec()
): javap -verbose /path/to/my/classfile.class | grep invoke
and you'll have the binary signatures that the class "calls" from other classes. Yes, I know, it's not what you wanted but you could use it as a last resource.
If you need a more "javaish" solution, you could have a look at a java library called "asm": http://asm.ow2.org/
Upvotes: 1