2014年6月25日 星期三

Debug 程式好用的指令 EB FE

0xEBFE 是一個短跳指令, 作用是跳到這個指令原本的位址
可以看做是單一指令的 infinite loop

有時候想 attach debugger 到某個程式時可以先把 EP 改成 EBFE
等程式在這邊 loop 時再 attach 上去就好了

2014年6月16日 星期一

Debug custom exception filter set by SetUnhandledExceptionFilter

SetUnhandledExceptionFilter 可以讓程式設定自定義的頂層 exception filter
用來處理程式中未被處理的 exception

之前想要 debug 這種 custom exception filter, 但用 debugger 開啟程式後卻怎麼也跑不到
查了後才發現這是 MS 的設計

MSDN 上的描述:

A pointer to a top-level exception filter function that will be called whenever the UnhandledExceptionFilter function gets control, and the process is not being debugged. A value of NULL for this parameter specifies default handling within UnhandledExceptionFilter

不過為什麼要有這麼奇怪的設計? 真的讓人猜不透
如果只有執行檔沒有 source code 時要怎麼 debug?

幸好網路上早有了怎麼 bypass 的方法,
UnhandledExceptionFilter 是呼叫 NtQueryInformationProcess 檢查程式是否正在被 debug 的
所以只要改掉 NtQueryInformationProcess 回傳的值就好了

Reference:
http://evilcodecave.wordpress.com/2008/07/24/setunhandledexception-filter-anti-debug-trick/

2014年6月3日 星期二

Program crash without WER dialog

在 XP 上很容易發生 process silent death,
因為在 XP 上做 error reporting 的機制是由 crashed process 負責,
所以只要將 stack 搞爛, 就可以讓 WER dialog 不顯示
甚至註冊的 unhandled exception handler 也不會被執行

但是在 Vista 之後, 實作 error reporting 的機制移到另外的 process 中, 所以在 XP 上
讓 process silent death 的方式在 Vista 之後就不行了
不過如果搞爛 stack, 雖然有 WER dialog,
但是 unhandled exception handler 不會被執行
猜測是因為 unhandled exception handler 的執行也需要 stack,
但是既然 stack 爛掉了, 自然也就無法執行

Reference:
http://stackoverflow.com/questions/14195327/how-to-crash-a-process-on-windows-7-without-getting-the-wer-dialog