#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
#include <winternl.h>
DWORD
dwTest;
EXCEPTION_DISPOSITION NTAPI ExceptHandler(
_Inout_
struct
_EXCEPTION_RECORD *ExceptionRecord,
_In_
PVOID
EstablisherFrame,
_Inout_
struct
_CONTEXT *ContextRecord,
_In_
PVOID
DispatcherContext) {
printf
(
"进入异常处理\n"
);
printf
(
"异常地址:%X<异常代码:%X>\n"
, ExceptionRecord->ExceptionAddress,
ExceptionRecord->ExceptionCode);
ContextRecord->Eax = (
DWORD
)(&dwTest);
return
ExceptionContinueExecution;
}
int
main()
{
PTEB teb=NULL;
_asm
{
mov eax,fs:[0]
mov teb,eax
}
printf
(
"TEB %X \n"
, teb);
printf
(
"注册SEH\n"
);
__asm {
lea eax, ExceptHandler
push eax
push fs : [0]
mov dword ptr fs : [0], esp
}
__asm {
xor eax, eax
mov dword ptr[eax], 1234h
}
printf
(
"删除SEH\n"
);
__asm {
pop dword ptr fs : [0]
add esp, 4
}
printf
(
"dwTest=%X\n"
, dwTest);
system
(
"pause"
);
}