用安卓虚拟机运行程序时程序停止_程序运行时Trace:DynamoRIO Tool
1. 程序運(yùn)行時(shí)Trace,DynamoRIO
最近在做一個(gè)trace程序執(zhí)行路徑的項(xiàng)目,了解到DynamoRIO Dynamic Instrumentation Tool Platform
可以實(shí)現(xiàn)這個(gè)功能,在此記錄學(xué)習(xí)以下。首先,DynamoRIO是什么:DynamoRIO是一個(gè)運(yùn)行時(shí)代碼控制系統(tǒng)(runtime code manipulation system),支持程序運(yùn)行時(shí)對(duì)程序的任一部分進(jìn)行修改。DynamoRIO exports an interface for building dynamic tools for a wide variety of uses: program analysis and understanding, profiling, instrumentation, optimization, translation, etc.。在此我們用來監(jiān)控代碼的執(zhí)行路徑,最終由此結(jié)果得出程序執(zhí)行的CFG(控制流圖,Control-Flow Graphic)。
Ubuntu 16.04 下,獲取DynamoRIO方式。其中已經(jīng)包含了DR的可執(zhí)行文件。
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語(yǔ)言源文件進(jìn)行簡(jiǎn)單的使用嘗試。
cd dynamorio/ mkdir build && cd build/ cmake -DDynamoRIO_DIR=../cmake ../samples執(zhí)行完以上命令后,可以看到在build文件目錄下,生成了以下文件。到這一步還沒有生成對(duì)應(yīng)的so文件,還需要make 對(duì)應(yīng)的鏈接腳本文件,例如make inscount。inscount 的作用是記錄指令執(zhí)行的總數(shù)(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執(zhí)行make inscount后,首先會(huì)掃描目標(biāo)的依賴集,告訴你生成的目標(biāo)文件的用法。
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文件目錄下,運(yùn)行./bin64/drrun -c ./build/bin/libinscount.so -- gedit,注意根據(jù)你的機(jī)器位數(shù)選擇對(duì)應(yīng)的可執(zhí)行文件。此處我們以統(tǒng)計(jì)可執(zhí)行文件gedit的指令數(shù)量為例。其顯示結(jié)果為Instrumentation results: 38676535 instructions executed。
至此,DynamoRIO整個(gè)流程相當(dāng)于是跑通了。通過閱讀inscont.cC源文件可以發(fā)現(xiàn),其大部分是調(diào)用了DR的API來實(shí)現(xiàn)其功能。所以說如果我們需要實(shí)現(xiàn)對(duì)程序定制的控制邏輯,需要了解
The DynamoRIO API?dynamorio.org。
總結(jié)
以上是生活随笔為你收集整理的用安卓虚拟机运行程序时程序停止_程序运行时Trace:DynamoRIO Tool的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 联行号是什么意思
- 下一篇: python中index从列表中查_在P