AppVerifier的用法
This section discusses how to test an application using AppVerfier.
The first thing to note about AppVerifier is that it is not an automated test program for your applications. AppVerifier attaches to a program and performs tests whenever you run the program. It is possible to use AppVerifier and an automated test procedure simultaneously. AppVerifier attaches a "stub" or small piece of code to the executable program you are testing so that AppVerifier will be engaged every time the program is run.
To test an application with AppVerifier
To open AppVerifier, click Start, and then click Programs.
Under Programs, click Application Verifier.
Right click the mouse in the Application section of the main page and click Add Application to display the Add Application dialog box shown in Figure 2.
Figure 2: Using the Add Application dialog box to select an executable file to test
Browse to your application, and select the executable file to test. Double-click to open the file. Repeat Steps 3 and 4 for any additional executables to be tested.
In the test settings pane, see Figure 3, select the tests you want to perform from the following list:
Figure 3: Using the Tests area, click the checkbox next to the test to run.
Memory
Ensures APIs for virtual space manipulations are used correctly.
TLS
Ensures that Thread Local Storage APIs are used correctly
Low Resource Simulation
This simulates an environment under low resources for example, out of memory.
Limited User Account Predictor
This test simulates an environment running as a user with a limited user account and has two primary goals: predictive and diagnostic. The predictive element determines whether an application that is running in an administrative environment would also run well in an environment with less privilege, as a limited user, for example. The diagnostic element evaluates an application when it is running as a limited user and identifies potential problems.
Miscellaneous
Consists of Dirty stacks and Dangerous APIs.
Save the settings within Application Verifier
To start testing, simply use the application. Try to use all of the program's functions to generate the best data for the AppVerifier logs. Close the application when finished.
View the test results in the AppVerifier log file by clicking View Logs in AppVerifier.
The test settings you specify for a particular application will remain active every time you run the program until the program is removed from the list of applications in AppVerifier. You can run programs repeatedly while working out problems.
“Bug”中最頭痛的是那麼一類:野指標、無效控制代碼,存取違規,跟Windows核心打交道比較多的那些,它們發現難,調試難,定位難。不過AppVerifier就是解決這些問題的工具,實際上,以微軟為首的大的Windows軟體開發商都在使用這個軟體作輔助測試。我在這裡推薦它的原因,除了它善於抓這些比較核心的、底層的Bug之外,是微軟出品,可以免費使用和非常簡單是另外幾個因素。
AppVerifier的客觀介紹
AppVerifier 可以免費下載,特別用於檢測和協助調試記憶體損壞、危險的安全性漏洞以及限制的使用者帳戶特權問題。AppVerifier 有助於建立可靠且安全的應用程式,方法是監視應用程式與 Microsoft? Windows? 作業系統的互動,並配置應用程式使用的對象、註冊表、檔案系統和 Win32 API(包括堆、控制代碼和鎖)。AppVerifier 還包括檢查,以便預測應用程式在非管理員環境中的執行情況。
上面是微軟MSDN中對它的介紹原文。MSDN在“C++安全性最佳做法”中推薦使用它來驗證軟體安全性。MSDN甚至還提倡在整個開發生命週期中使用這個軟體:“在整個軟體開發生命週期中使用時,AppVerifier可節約開發工作的成本,因為它能方便地在早期就識別出問題,而在早期修複錯誤是比較容易且成本較低的。”
AppVerifier能識別的問題
AppVerifier 有助於確定: (Copy於MSDN)
? 應用程式正確地使用 API 的時刻:
? 不安全的 TerminateThread API。
? 正確使用執行緒區域儲存(Thread Local Storage,TLS)API。
? 正確使用虛擬空間操作(例如,VirtualAlloc 和 MapViewOfFile)。
? 應用程式是否使用結構化的異常處理隱藏存取違規。
? 應用程式是否試圖使用無效的控制代碼。
? 堆中是否有記憶體損壞或存在記憶體問題。
? 應用程式是否在資源不足的情況下用盡了記憶體。
? 是否正確使用了臨界區。
? 運行在管理員環境中的應用程式在具有較低特權的環境中是否能良好運行。
? 當應用程式作為受限使用者運行時是否會存在潛在的問題。
? 線上程的上下文中,是否在將來的函數調用中會存在未初始化的變數。
AppVerifier的使用
下面結合自己的應用介紹一下它的使用方法(非常簡單)。
1。下載AppVerifier
在微軟網站下載,並安裝軟體
http://www.microsoft.com/downloads/details.aspx?FamilyID=bd02c19c-1250-433c-8c1b-2619bd93b3a2&DisplayLang=en
2。運行AppVerifier
在AppVerifier中增加需要驗證的應用程式,對於開發人員,直接選擇工程中輸出的Debug版的可執行檔,可以添加多個檔案,也可以添加動態庫DLL。
3。配置需要驗證的項目
AppVerifier大致可以驗證異常、控制代碼、堆棧、記憶體、未初始化參數等18個方面(3.3版)的隱患,選擇需要進行測試的項目,並儲存設定。
4。在IDE中偵錯工具
這些跟以前是一樣的,只是在調試過程中AppVerifier會向你報告它檢測到的問題,以異常的方式,或者輸出資訊到輸出框中,一般的情況,程式停在發生問題的地方不遠處。
5。取消驗證
在AppVerifier中取消要驗證的程式,否則,驗證代碼一直掛在程式中。
好了,先拿手上的軟體試試法吧,以前沒有任何錯誤,現在,多出來了不少的異常,趕緊看看。。。。
與它是同一個系列的另一個軟體:Driver Verifier,專門來測試驅動的安全。
參考文獻:
感興趣的同事google一下“Application Verifier”,看看簡介。
想學習的同事請閱讀MSDN:
《在軟體開發生命週期中使用應用程式驗證器》
http://www.microsoft.com/china/MSDN/library/enterprisedevelopment/softwaredev/WDdnclinicscripting.mspx?mfr=true
《使用應用程式驗證程式排除 Windows XP中的程式問題》
http://support.microsoft.com/default.aspx/kb/286568/zh-cn
《C++ 安全性最佳做法》
http://msdn2.microsoft.com/zh-cn/library/k3a3hzw7(VS.80).aspx