简体   繁体   English

如何检查是否正在调用特定的 class 或 class 的方法?

[英]How do I check if a particular class or a method of a class is being called or not?

There are multiple libraries/jar files that our project depends upon directly or indirectly.我们的项目直接或间接依赖于多个库/jar 文件。 How can we check if out of all the jars which classes and which methods of those classes are getting called by our code?我们如何检查所有 jars 中哪些类以及这些类的哪些方法被我们的代码调用? Considering that the codebase is huge and manually this is not possible to trace each method call, is there a tool or a way to do such an analysis?考虑到代码库很大并且手动跟踪每个方法调用是不可能的,有没有工具或方法来做这样的分析?

The reason I am looking for such a tool is that when new vulnerabilities are discovered in a direct dependency or transitive dependency we try to upgrade that to the latest version which does not have the discovered vulnerability without checking if that is applicable to us or not?我正在寻找这样一个工具的原因是,当在直接依赖或传递依赖中发现新漏洞时,我们会尝试将其升级到没有发现漏洞的最新版本,而不检查它是否适用于我们?

We can check for direct vulnerabilities by seeing if we are calling a particular method of a particular class or not but that is not possible to do that for calls made to the classes made within the library.我们可以通过查看我们是否调用特定 class 的特定方法来检查直接漏洞,但对于在库中进行的类的调用,这是不可能的。 I am sure many people would have faced this problem and there should be tools that do this, please share how you achieve this and if there are tools which can do this.我相信很多人都会遇到这个问题,应该有工具可以做到这一点,请分享你是如何做到这一点的,以及是否有工具可以做到这一点。

Any help is highly appreciated?任何帮助都受到高度赞赏?

There is absolutely no way to do this 100% accurately.绝对没有办法做到 100% 准确。 At least at the point when you think about reflection it is game over.至少在你考虑反思的时候,游戏结束了。 There is simply no way to predict based on code what will be called, as this turns to be decided at runtime.根本无法根据代码预测将调用什么,因为这将在运行时决定。 And some of the frameworks will use code generated at runtime and reflection to wide degree.并且一些框架将在很大程度上使用在运行时生成的代码和反射。

But lets think about it more and go deeper.但是让我们多想一想,go 更深入。 What if we check what is used in runtime?如果我们检查运行时使用的内容怎么办? Even assuming code instrumentation is possible (just like the profilers do), not all code paths will always be used.即使假设代码检测是可能的(就像分析器所做的那样),并不是所有的代码路径都会一直被使用。 And you would need to check the business logic in all possible directions to say, if a library/class/method is used or not.并且您需要在所有可能的方向上检查业务逻辑,以判断是否使用了库/类/方法。 This is simply impossible in a non-trivial system.这在非平凡的系统中根本是不可能的。

The best you have I believe are library dependencies and manual code analysis.我相信你拥有的最好的是库依赖和手动代码分析。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何确定是否正在从JAR文件中调用特定类中的方法 - How to determine if a method in a particular class is being called from a JAR file 如何检查类是否表示特定的原始类型 - How do I check if a class represents a particular primitive type 如何检查java类中是否有特定的方法? - How to check if a java class has a particular method in it? 如何使用特定类编写方法 - How do I write a method using a particular class 如何约束类以实现特定的静态方法? - How do I constrain a class to implement a particular static method? 我怎么知道哪个类称为抽象方法? - How do I know what class called the abstract method? 如何模拟正在被同一类测试的另一个方法内部调用的类的方法? - How to mock a method of a class being called inside another method that is being tested of the same class? 如何模拟和验证在子类中调用的ScheduledExcecutorService方法 - How to Mock and Verify a ScheduledExcecutorService's method being called in child class 如何从封闭的外部 class 调用同名方法作为在匿名 class 中实现的方法? - How do I call a method of same name from an enclosing outer class as the one being implemented in an anonymous class? 未调用Installer类的restore()方法 - restored() method of Installer class is not being called
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM