Crash test - DLL Hook

 近期有个测试项目,要求产品crash后用户友好的对话框(CER)会弹出来,而不是出现 unhandle exception. 测试方案是人为的让产品crash,

然后看CER能不能工作。Test Design要求在不同的场合crash都能被CER捕获, 所以将导致crash的代码写在所有需要测试的地方不是一个好的方

案,一个理想的情况是,测试者可能让产品在任何时候crash,所以用DLL Hook监听键盘,当测试者按下某些组合键,比如Ctrl+Alt+Backspace的时候,执行Hook 的callback函数(里面有导致crash的代码),让产品crash,来测试CER是否能在产品运行的任何时候都起作用.

 

Windows Hook简介,见MSDN,这里省略了:)

简单的步骤如下:

  1. Create a dll which will be used to create hook, store the dll instance at dllmain, e.g.

 

 

2. Create a dll export function which will install a hook, note that, in order to crash the test product, I am going to set a local hook instead of global one, code snippet looks like below, our product(.exe) will call this method when need to install the hook.

 

 3. Create a method used to uninstall the hook, in the project, which will be called when our product detach the dll, it also can be call outside the dll(e.g. test product) as I declare it as an export function

 

4. at last, define the hook callback function which will be called when keyboard event happened in this case

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值