用安卓虚拟机运行程序时程序停止_程序运行时Trace:DynamoRIO Tool
1. 程序運行時Trace,DynamoRIO
最近在做一個trace程序執行路徑的項目,了解到DynamoRIO Dynamic Instrumentation Tool Platform
可以實現這個功能,在此記錄學習以下。首先,DynamoRIO是什么:DynamoRIO是一個運行時代碼控制系統(runtime code manipulation system),支持程序運行時對程序的任一部分進行修改。DynamoRIO exports an interface for building dynamic tools for a wide variety of uses: program analysis and understanding, profiling, instrumentation, optimization, translation, etc.。在此我們用來監控代碼的執行路徑,最終由此結果得出程序執行的CFG(控制流圖,Control-Flow Graphic)。
Ubuntu 16.04 下,獲取DynamoRIO方式。其中已經包含了DR的可執行文件。
wget https://github.com/DynamoRIO/dynamorio/releases/download/release_7_0_0_rc1/DynamoRIO-Linux-7.0.0-RC1.tar.gz tar -xzvf DynamoRIO-Linux-7.0.0-RC1.tar.gz mkdir dynamorio mv DynamoRIO-Linux-7.0.0-RC1 dynamorio rm DynamoRIO-Linux-7.0.0-RC1.tar.gz'2. 使用
DR工具下載好后,我們首先編譯其自帶的smapleC語言源文件進行簡單的使用嘗試。
cd dynamorio/ mkdir build && cd build/ cmake -DDynamoRIO_DIR=../cmake ../samples執行完以上命令后,可以看到在build文件目錄下,生成了以下文件。到這一步還沒有生成對應的so文件,還需要make 對應的鏈接腳本文件,例如make inscount。inscount 的作用是記錄指令執行的總數(count of the total number of instructions executed)。
├── bbbuf.ldscript ├── bbcount.ldscript ├── bbsize.ldscript ├── bin ... ├── countcalls.ldscript ├── div.ldscript ├── empty.ldscript ├── inc2add.ldscript ├── inline.ldscript ├── inscount.ldscript ├── instrace_simple.ldscript ├── instrace_x86_binary.ldscript ├── instrace_x86_text.ldscript ├── instrcalls.ldscript ├── Makefile ├── memtrace_simple.ldscript ... ├── ssljack.ldscript ├── stl_test.ldscript ├── syscall.ldscript └── wrap.ldscript執行make inscount后,首先會掃描目標的依賴集,告訴你生成的目標文件的用法。
make inscount Scanning dependencies of target inscount [ 50%] Building CXX object CMakeFiles/inscount.dir/inscount.cpp.o [100%] Linking CXX shared library bin/libinscount.so Usage: pass to drconfig or drrun: -c ../dynamorio/build/bin/libinscount.so [100%] Built target inscount重新回到dynamorio文件目錄下,運行./bin64/drrun -c ./build/bin/libinscount.so -- gedit,注意根據你的機器位數選擇對應的可執行文件。此處我們以統計可執行文件gedit的指令數量為例。其顯示結果為Instrumentation results: 38676535 instructions executed。
至此,DynamoRIO整個流程相當于是跑通了。通過閱讀inscont.cC源文件可以發現,其大部分是調用了DR的API來實現其功能。所以說如果我們需要實現對程序定制的控制邏輯,需要了解
The DynamoRIO API?dynamorio.org。
總結
以上是生活随笔為你收集整理的用安卓虚拟机运行程序时程序停止_程序运行时Trace:DynamoRIO Tool的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 联行号是什么意思
- 下一篇: python中index从列表中查_在P