生活随笔
收集整理的這篇文章主要介紹了
1.异常记录
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
我們主要圍繞這個(gè)主線展開:
異常的分類
CPU產(chǎn)生的異常軟件模擬產(chǎn)生的常
這種屬于CPU產(chǎn)生的異常
int main()
{int a
= 10;int b
= 0;int val
= a
/ b
;
}
這種屬于軟件模擬的異常
void a()
{throw
1;
}
int main()
{a();
}
CPU異常產(chǎn)生過程
CPU指令檢測(cè)到異常查IDT表,執(zhí)行中斷處理函數(shù)調(diào)用CommonDispatchException(構(gòu)建EXCEPTION_RECORD)KiDispatchException(分發(fā)異常:目的是找到異常的處理函數(shù))
下面跟一下除0異常處理執(zhí)行過程,ida中Alt+T搜索_IDT
CommonDispatchException這個(gè)函數(shù)就是構(gòu)建一個(gè)_EXCEPTION_RECORD結(jié)構(gòu)體并賦值
typedef struct _EXCEPTION_RECORD
{DWORD ExceptionCode
; DWORD ExceptionFlags
; struct _EXCEPTION_RECORD
* ExceptionRecord
; PVOID ExceptionAddress
; DWORD NumberParameters
; ULONG_PTR ExceptionInformation
[EXCEPTION_MAXIMUM_PARAMETERS
];
};
軟件模擬異常的過程
CxxThrowException(KERNEL32.DLL)RaiseException(DWORD dwExceptionCode, DWORD dwExceptionFlags, DWORD nNumberOfArguments, const ULONG PTR "IpArguments)NTDLL.DLL! RtIRaiseException()NT!NtRaiseExceptionNT!KiRaiseException
(KERNEL32.DLL)RaiseException函數(shù)分析
0xE06D7363就是異常碼,軟件模擬的異常碼是固定的依賴與編譯環(huán)境。
RaiseException
KiRaiseException行為
EXCEPTION_RECORD.ExceptionCode最高位清零用于區(qū)分CPU異常。調(diào)用 KiDispatchException 開始分發(fā)異常
總結(jié)
以上是生活随笔為你收集整理的1.异常记录的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。