参考:https://sumsec.me/2022/CodeQL-Usage-Tricks.html#CodeQL with SCA

https://www.yuque.com/loulan-b47wt/rc30f7/ll3a4z

实操

  1. import java
  2. import semmle.code.java.DependencyCounts
  3. predicate jarDependencyCount(int total, string entity) {
  4. exists(JarFile targetJar, string jarStem |
  5. jarStem = targetJar.getStem() and
  6. jarStem != "rt"
  7. |
  8. total =
  9. sum(RefType r, RefType dep, int num |
  10. r.fromSource() and
  11. not dep.fromSource() and
  12. dep.getFile().getParentContainer*() = targetJar and
  13. numDepends(r, dep, num)
  14. |
  15. num
  16. ) and
  17. entity = jarStem
  18. )
  19. }
  20. from string name, int ndeps
  21. where jarDependencyCount(ndeps, name)
  22. select name, ndeps order by ndeps desc

CodeQL With SCA - 图1