如何审核用户提供的类文件以将包、类和方法列入黑名单
我正在开发一个应用程序,该应用程序托管作为 Java 类文件提供的用户定义的存储过程。这些过程需要是确定性的,我想将作为非确定性来源的各种包和方法列入黑名单。我查看了 java.lang.Class 和 javax.tools.* 中可用的内容。
看起来我可以使用 java.lang.Class 审核成员、方法参数和返回类型。然而,要审核方法内容,我似乎必须分析原始类文件。
还有一些极端情况,例如我需要审核的静态初始化块和成员变量初始化。在某些情况下,例如 java.util.Date,默认构造函数是不确定的,但其他情况都很好。
是否有一个框架或工具可以使分析类文件的这些方面变得容易?
I am working on an application that hosts user defined stored procedures that are provided as Java class files. The procedures need to be deterministic, and I want to black list various packages and methods that are sources of non-determinism. I have looked at what is available in java.lang.Class and javax.tools.*.
It looks like I can audit members, method parameters, and return types using java.lang.Class. However to audit the method contents it looks like I would have to analyze the raw class file.
There also corner cases like static intitialization blocks and member variable intialization that I need to audit. There are cases like java.util.Date where the default constructor is non-deterministic, but the others are fine.
Is there a framework or tool that would make analyzing these aspects of a class file easy?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,有。正如您所说的“分析这些方面”,例如 AspectJ ;)您可以使用加载时编织例如javaagent。另一种方法是使用aspectj类加载器加载用户的类。
您可以声明寻找给定方法调用的切入点。您还可以包含用户方法并计算执行时间等。
Yest there is. As you say to 'analyze these aspects' use e.g. AspectJ ;) You can use load-time weaving with javaagent for example. Another way is to load users' classes with aspectj classloader.
You can declare poincuts looking for given method invocations. You can also enclose users method and count execution time and so on.