Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search in CallGraph #207

Open
rohitcoder opened this issue Aug 25, 2024 · 1 comment
Open

Search in CallGraph #207

rohitcoder opened this issue Aug 25, 2024 · 1 comment
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@rohitcoder
Copy link

Hi Team,

Thank you for this amazing project! I was able to generate a call graph with the dependencies' calls as mentioned. I wanted to check if this project includes a feature to examine the call graph, such as searching for a specific function name from a library or just a function name. Can it identify whether the mentioned function is reachable? Essentially, I’m trying to address a reachability analysis issue, where I have the name of a vulnerable function from an open-source package, and I want to search the call graph to see if it's reachable.

If this feature isn't currently available, could you guide me through the process? I'd also be happy to contribute if I can.

Thanks,
Rohit

@errt
Copy link
Collaborator

errt commented Aug 26, 2024

Dear Rohit,

checking reachability is fairly straightforward: after you computed the call graph, get the callers property for the method you are interested in, either from the CallGraph: cg.callersPropertyOf(method) or directly from the PropertyStore: ps(method ,Callers.key).ub.
Check whether the result is NoCallers, in which case the method is not reachable, or anything else, in which case it is.
Note that this means you need to get the proper DeclaredMethod object for your method first. If you don't have that yet, you can get it like this:

val declaredMethods = project.getProjectInformationKey(DeclaredMethodsKey)
val myDeclaredMethod = declaredMethods(myMethod)

where myMethod in turn is the proper Method object for your method. You can get that from various sources, e.g., classFile.findMethod (efficient) or project.allMethods or classFile.methods (less efficient)
If you need the classfile, you can get it from project.classFile(ObjectType("fully/qualified/name/of/your/class")) (JVM notation with slashes, not Java notation with periods)

@maximilianruesch maximilianruesch added the documentation Improvements or additions to documentation label Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

4 participants