用joern画AST、CFG、CDG、DDG、PDG、CPG
生活随笔
收集整理的這篇文章主要介紹了
用joern画AST、CFG、CDG、DDG、PDG、CPG
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
之前寫了一點joern的博客,發(fā)現(xiàn)很多人在問我怎么畫圖。確實,用joern這個工具的話,畫代碼屬性圖是這個工具的亮點了。
這篇文章怎么說呢,也可以看作是對官方文檔的翻譯和實現(xiàn)吧。
能搜到這篇文章,想必應(yīng)該是搜到上面的一個圖的名字進來的。就不詳細介紹每個圖了,就簡單介紹下縮寫的含義。
- AST:abstract syntax tree
- CFG:control flow graph
- CDG:Control Dependence Graphs
- DDG:Data Dependence Graphs
- PDG:Program Dependence graphs
- CPG:Code Property Graphs
命令行操作
首先解析源碼目錄(下面代碼的/src/directory)的代碼,然后用export命令將圖導(dǎo)出到outdir文件夾下,默認的cpg的名字是當前目錄下的cpg.bin。
- –repr:指定畫什么圖ast|cfg|ddg|cdg|pdg|cpg14
- –out:指定輸出圖dot文件目錄名字(自動創(chuàng)建)
此外需要注意outdir文件夾不需要你自己建,如果你自己建的話,可能會報下面的錯誤:
Output directory outdir already exists. Bailing out
成功運行后,會發(fā)現(xiàn)你的outdir文件夾都是圖的dot文件了。
輸入命令:
dot -Tpng -o test.png [dot-file-name]同理也可以畫出別的圖。
joern終端操作
首先,導(dǎo)入一段測試代碼
joern> importCode.c.fromString( """int myfunc(int b) {int a = 42;if (b > 10) {foo(a)}bar(a);}""")畫各種圖的命令:
cpg.method("myfunc").plotDotAst cpg.method("myfunc").plotDotCfg cpg.method("myfunc").plotDotCdg cpg.method("myfunc").plotDotDdg cpg.method("myfunc").plotDotPdg cpg.method("myfunc").plotDotCpg14AST
CFG
CPG
暫時不知道終端怎么畫這CDG、PDG、DDG。
總結(jié)
以上是生活随笔為你收集整理的用joern画AST、CFG、CDG、DDG、PDG、CPG的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: deadine怎么修改服务器,PDG使用
- 下一篇: python应用程序无法正常启动0x00