llvm-journ-ast.gv 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* example graph converting llvm bytecode to journ software
  2. https://joern.io/
  3. https://docs.joern.io/home
  4. https://docs.joern.io/llvm2cpg/hello-llvm/
  5. https://github.com/ShiftLeftSecurity/llvm2cpg
  6. https://github.com/ShiftLeftSecurity/joern
  7. Joern is a platform for robust analysis of C/C++ code. It generates code property graphs, a graph representation of code for cross-language code analysis. Code property graphs are stored in a custom graph database. This allows code to be mined using search queries formulated in a Scala-based domain-specific query language. Joern is developed with the goal of providing a useful tool for vulnerability discovery and research in static program analysis.
  8. See also:
  9. https://blog.llvm.org/posts/2021-02-23-llvm-meets-code-property-graphs/
  10. to analyze sourcecode and the joern-export command line utility can generate dot graph data of source:
  11. In summary, Joern can create the following graph representations for C/C++ code:
  12. Abstract Syntax Trees (AST)
  13. Control Flow Graphs (CFG)
  14. Control Dependence Graphs (CDG)
  15. Data Dependence Graphs (DDG)
  16. Program Dependence graphs (PDG)
  17. Code Property Graphs (CPG14)
  18. This is the source of this graph data:
  19. importCode.c.fromString( """
  20. int myfunc(int b) {
  21. int a = 42;
  22. if (b > 10) {
  23. foo(a)
  24. }
  25. bar(a);
  26. }
  27. """
  28. )
  29. the dot representation of the AST as dot is this:
  30. */
  31. digraph myfunc {
  32. "1000102" [label = "(METHOD,myfunc)" ]
  33. "1000103" [label = "(PARAM,int b)" ]
  34. "1000104" [label = "(BLOCK,,)" ]
  35. "1000105" [label = "(LOCAL,a: int)" ]
  36. "1000106" [label = "(<operator>.assignment,a = 42)" ]
  37. "1000107" [label = "(IDENTIFIER,a,a = 42)" ]
  38. "1000108" [label = "(LITERAL,42,a = 42)" ]
  39. "1000109" [label = "(CONTROL_STRUCTURE,if (b > 10),if (b > 10))" ]
  40. "1000110" [label = "(<operator>.greaterThan,b > 10)" ]
  41. "1000111" [label = "(IDENTIFIER,b,b > 10)" ]
  42. "1000112" [label = "(LITERAL,10,b > 10)" ]
  43. "1000113" [label = "(BLOCK,,)" ]
  44. "1000114" [label = "(bar,bar(a))" ]
  45. "1000115" [label = "(IDENTIFIER,a,bar(a))" ]
  46. "1000116" [label = "(METHOD_RETURN,int)" ]
  47. "1000102" -> "1000103"
  48. "1000102" -> "1000104"
  49. "1000102" -> "1000116"
  50. "1000104" -> "1000105"
  51. "1000104" -> "1000106"
  52. "1000104" -> "1000109"
  53. "1000104" -> "1000114"
  54. "1000106" -> "1000107"
  55. "1000106" -> "1000108"
  56. "1000109" -> "1000110"
  57. "1000109" -> "1000113"
  58. "1000110" -> "1000111"
  59. "1000110" -> "1000112"
  60. "1000114" -> "1000115"
  61. }